Description
Need to use short class names instead of fully qualified ones in static mocks.
To Reproduce
- Install UnitTestBot plugin built from main in IntelliJ IDEA
- Open
spring-petclinic project
- Generate tests for
PetValidator
Expected behavior
import org.springframework.util.StringUtils is expected to use short class name StringUtils in mockStatic.
Actual behavior
There are fully qualified name for org.springframework.util.StringUtils.class in mockStatic definition.
Screenshots, logs
public void testValidate_PetGetBirthDateNotEqualsNull() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
org.mockito.MockedStatic mockedStatic = null;
try {
mockedStatic = mockStatic(org.springframework.util.StringUtils.class);
(mockedStatic.when(() -> org.springframework.util.StringUtils.hasLength(any(String.class)))).thenReturn(false);
PetValidator petValidator = new PetValidator();
NamedEntity objMock = mock(NamedEntity.class);
(when(objMock.getName())).thenReturn(((String) null));
(when(objMock.isNew())).thenReturn(false);
LocalDate localDateMock = mock(LocalDate.class);
Class petClazz = Class.forName("org.springframework.samples.petclinic.owner.Pet");
Method getBirthDateMethod = petClazz.getDeclaredMethod("getBirthDate");
getBirthDateMethod.setAccessible(true);
Object[] getBirthDateMethodArguments = new Object[0];
(when(getBirthDateMethod.invoke(objMock, getBirthDateMethodArguments))).thenReturn(localDateMock);
Errors errorsMock = mock(Errors.class);
((doNothing()).when(errorsMock)).rejectValue(any(), any(), any());
petValidator.validate(objMock, errorsMock);
} finally {
mockedStatic.close();
}
}
Environment
IntelliJ IDEA version - 2023.1 Ultimate
JDK - 17
Description
Need to use short class names instead of fully qualified ones in static mocks.
To Reproduce
spring-petclinicprojectPetValidatorExpected behavior
import org.springframework.util.StringUtilsis expected to use short class nameStringUtilsin mockStatic.Actual behavior
There are fully qualified name for
org.springframework.util.StringUtils.classinmockStaticdefinition.Screenshots, logs
Environment
IntelliJ IDEA version - 2023.1 Ultimate
JDK - 17