Open
Description
Description
linkedListSpy is created and configured, but not injected into Entity under test
To Reproduce
- Install -IU- UnitTestBot plugin in IntelliJ IDEA
- Open
spring-petclinic
- Generate
Unit tests
forOwner
withPetClinicApplication
configuration - Run the tests
Expected behavior
No NPE should be thrown from get-methods of the entity before assertions.
Actual behavior
There are several tests throwing NPE when getting fields of actual Pet.
Screenshots, logs
@Test
@DisplayName("getPet: id = zero (mutated from min)")
public void testGetPetWithCornerCase5() throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException, InvocationTargetException, NoSuchMethodException {
owner.setLastName("-3");
Pet petMock = mock(Pet.class);
(when(petMock.isNew())).thenReturn(true);
linkedListSpy.add(petMock);
Pet petMock1 = mock(Pet.class);
(when(petMock1.isNew())).thenReturn(false);
(when(petMock1.getId())).thenReturn(0);
linkedListSpy.add(petMock1);
Pet petMock2 = mock(Pet.class);
linkedListSpy.add(petMock2);
Pet petMock3 = mock(Pet.class);
linkedListSpy.add(petMock3);
Pet petMock4 = mock(Pet.class);
linkedListSpy.add(petMock4);
Pet actual = owner.getPet(0);
LocalDate actualBirthDate = actual.getBirthDate();
assertNull(actualBirthDate);
PetType actualType = actual.getType();
assertNull(actualType);
Set actualVisits = ((Set) getFieldValue(actual, "org.springframework.samples.petclinic.owner.Pet", "visits"));
assertNull(actualVisits);
String actualName = actual.getName();
assertNull(actualName);
Integer actualId = actual.getId();
assertNull(actualId);
}
Environment
IntelliJ IDEA version - Community 2023.2
Project - Maven
JDK - 17
Additional context
When debugging, linkedListSpy is returning expected values.
There is pet returning isNew()=false and getId()=0.
But owner.getPets() returns empty list.
Metadata
Metadata
Assignees
Type
Projects
Status
Todo