Closed alisevych closed 1 year ago
Description
assertNull is applied to the method returned value, while it's method is mocked. assertEquals to exact value is expected.
To Reproduce
spring-petclinic
Unit tests
PetTypeFormatter
PetClinicApplication
Expected behavior
Method PetType$getName() is mocked with exact return value. assertEquals for the actualName is expected.
PetType$getName()
assertEquals
actualName
Actual behavior
There is failing assertNull for actualName in successful test.
assertNull
Screenshots, logs
@Test @DisplayName("parse: text = 'XZ', locale = Locale(String, String, String)") public void testParseWithNonEmptyString() throws ParseException { ArrayList arrayList = new ArrayList(); PetType petTypeMock = mock(PetType.class); (when(petTypeMock.getName())).thenReturn("XZ"); arrayList.add(petTypeMock); (when(ownerRepositoryMock.findPetTypes())).thenReturn(arrayList); Locale locale = new Locale("\n\t\r", "#$\\\"'", "#$\\\"'"); PetType actual = petTypeFormatter.parse("XZ", locale); String actualName = actual.getName(); assertNull(actualName); Integer actualId = actual.getId(); assertNull(actualId); }
Environment
IntelliJ IDEA version - Community 2023.2 Project - Maven JDK - 17
Description
assertNull is applied to the method returned value, while it's method is mocked. assertEquals to exact value is expected.
To Reproduce
spring-petclinic
Unit tests
forPetTypeFormatter
withPetClinicApplication
configurationExpected behavior
Method
PetType$getName()
is mocked with exact return value.assertEquals
for theactualName
is expected.Actual behavior
There is failing
assertNull
foractualName
in successful test.Screenshots, logs
Environment
IntelliJ IDEA version - Community 2023.2 Project - Maven JDK - 17