-
Notifications
You must be signed in to change notification settings - Fork 45
Labels
comp-codegenIssue is related to code generatorIssue is related to code generatorcomp-springIssue is related to Spring projects supportIssue is related to Spring projects supportctg-bugIssue is a bugIssue is a bugstatus-verifiedBug fix is verifiedBug fix is verified
Milestone
Description
Description
Controller is cast to String in the mock definition for spring-petclinic project.
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 OwnerController
- Check compilation errors in the generated test class
Expected behavior
There should not be casts of Controller classes to String.
Also OwnerController is added as a field with @Injectmocks annotation.
Actual behavior
There are two tests in ERROR SUITE where Controller is cast to String in the mock definition.
1 - in SYMBOLIC EXECUTION: ERROR SUITE for method processFindForm
2 - in OTHER: ERROR SUITE for method processFindForm
Visual proofs (screenshots, logs, images)
public final class OwnerControllerTest {
@InjectMocks
public OwnerController ownerController;
/**
* @utbot.classUnderTest {@link OwnerController}
* @utbot.methodUnderTest {@link OwnerController#processFindForm(int, Owner, BindingResult, Model)}
* @utbot.executesCondition {@code (owner.getLastName() == null): False}
* @utbot.throwsException {@link NullPointerException} in: ownersResults.isEmpty()
*/
@Test
@DisplayName("processFindForm: ownersResults.isEmpty() -> ThrowNullPointerException")
public void testProcessFindForm_OwnerGetLastNameNotEqualsNull() {
org.mockito.MockedStatic mockedStatic = null;
try {
mockedStatic = mockStatic(PageRequest.class);
(mockedStatic.when(() -> PageRequest.of(anyInt(), anyInt()))).thenReturn(((PageRequest) null));
/* WARNING!!! Automatically used "Mockito static mocking" framework for mocking statics
because execution encountered flaky methods
To change this behaviour edit [Settings -> UtBot -> Force static mocking] */
(when(ownerRepositoryMock.findByLastName(any(), any()))).thenReturn(((Page) null));
Owner ownerMock = mock(Owner.class);
(when(ownerMock.getLastName())).thenReturn(((String) ownerController), ((String) null));
/* This test fails because method [org.springframework.samples.petclinic.owner.OwnerController.processFindForm] produces [java.lang.NullPointerException] */
ownerController.processFindForm(-255, ownerMock, null, null);
} finally {
mockedStatic.close();
}
}
@Test
public void testProcessFindForm2() {
org.mockito.MockedStatic mockedStatic = null;
try {
mockedStatic = mockStatic(PageRequest.class);
(mockedStatic.when(() -> PageRequest.of(anyInt(), anyInt()))).thenReturn(((PageRequest) null));
/* WARNING!!! Automatically used "Mockito static mocking" framework for mocking statics
because execution encountered flaky methods
To change this behaviour edit [Settings -> UtBot -> Force static mocking] */
(when(pageMock.isEmpty())).thenReturn(false);
(when(pageMock.getTotalElements())).thenReturn(-9223372036854775806L);
(when(ownerRepositoryMock.findByLastName(any(), any()))).thenReturn(pageMock);
Owner ownerMock = mock(Owner.class);
(when(ownerMock.getLastName())).thenReturn(((String) ownerController), ((String) null));
/* This test fails because method [org.springframework.samples.petclinic.owner.OwnerController.processFindForm] produces [java.lang.NullPointerException]
org.springframework.samples.petclinic.owner.OwnerController.addPaginationModel(OwnerController.java:114)
org.springframework.samples.petclinic.owner.OwnerController.processFindForm(OwnerController.java:110) */
ownerController.processFindForm(0, ownerMock, null, null);
} finally {
mockedStatic.close();
}
}Environment
Windows 10 Pro
IntelliJ IDEA 2022.3.3 Ultimate
Project is opened as Gradle
Metadata
Metadata
Assignees
Labels
comp-codegenIssue is related to code generatorIssue is related to code generatorcomp-springIssue is related to Spring projects supportIssue is related to Spring projects supportctg-bugIssue is a bugIssue is a bugstatus-verifiedBug fix is verifiedBug fix is verified
Type
Projects
Status
Done