Description
Description
Incorrect mock is generated for the method of a Repository that returns List
PetType is the entity.
To Reproduce
- Open as Gradle the spring-petclinic project in IntelliJ Idea 2022.3.3
- Install the latest plugin built from main
- Generate tests for PetTypeFormatter$parse
- Check compilation errors in the generated test class
Expected behavior
Some valid List of PetType should be instantiated and used in the mock.
Some valid String should be passed into the method call.
Actual behavior
There is arrayList
word returned from mock. It is not defined anywhere in the test. It is used in several tests.
There is string
word as the input parameter of the method parse
call. It is not defined anywhere in the test either.
Visual proofs (screenshots, logs, images)
The following test is generated:
///region Test suites for executable org.springframework.samples.petclinic.owner.PetTypeFormatter.parse
///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method parse(java.lang.String, java.util.Locale)
/**
* @utbot.classUnderTest {@link PetTypeFormatter}
* @utbot.methodUnderTest {@link PetTypeFormatter#parse(String, Locale)}
* @utbot.invokes {@link OwnerRepository#findPetTypes()}
* @utbot.invokes {@link java.util.Collection#iterator()}
* @utbot.iterates iterate the loop {@code for(PetType type: findPetTypes)} once
*/
@Test
@DisplayName("parse: OwnerRepositoryFindPetTypes -> return type")
public void testParse_TypeGetNameEquals() throws ParseException, ClassNotFoundException, IllegalAccessException, NoSuchFieldException, InvocationTargetException, NoSuchMethodException {
(when(ownerRepositoryMock.findPetTypes())).thenReturn(arrayList);
PetType actual = petTypeFormatter.parse(string, ((Locale) null));
String petTypeFormatterName = ((String) getFieldValue(petTypeFormatter, "org.springframework.samples.petclinic.model.NamedEntity", "name"));
String actualName = ((String) getFieldValue(actual, "org.springframework.samples.petclinic.model.NamedEntity", "name"));
assertEquals(petTypeFormatterName, actualName);
Integer actualId = ((Integer) getFieldValue(actual, "org.springframework.samples.petclinic.model.BaseEntity", "id"));
assertNull(actualId);
}
///endregion
Environment
Windows 10 Pro
IntelliJ IDEA 2022.3.3 Ultimate
Project is opened as Gradle
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done