Skip to content

Strange casts in fuzzed Spring tests, sometimes leading to compilation errors #2722

Description

@EgorkaKulikov

Description

Run unit tests generation for PetController class in spring-petclinic application.
Use standard settings, just click OK on UI.

Actual behavior

The following test is generated (there are more than ten strange tests, this is just an example):

@TestpublicvoidtestProcessCreationFormByFuzzer1() {
OwnerownerMock = mock(Owner.class);
(((Owner) (doNothing()).when(ownerMock))).addPet(any());
PetpetMock = mock(Pet.class);
(when(petMock.getName())).thenReturn("duplicate");
(when(petMock.isNew())).thenReturn(false);
LocalDatelocalDateMock = mock(LocalDate.class);
(when(localDateMock.isAfter(any()))).thenReturn(true);
(when(petMock.getBirthDate())).thenReturn(localDateMock);
BindingResultresultMock = mock(BindingResult.class);
(((Errors) (doNothing()).when(resultMock))).rejectValue(any(), any());
(when(resultMock.hasErrors())).thenReturn(true);
ModelMapmodel = newModelMap();
OwnerRepositoryownersMock = mock(OwnerRepository.class);
PetControllerpetController = newPetController(ownersMock);
model.put(((Object) "abc"), ((Object) petController));
Stringactual = petController.processCreationForm(ownerMock, petMock, resultMock, model);
Stringexpected = "pets/createOrUpdatePetForm";
assertEquals(expected, actual);
}

Note that there are two types of strange casts: to Object and to Owner/Errors. One of them leads to compilation error.

Additional context

Kirill says that this bug also reproduces on October release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-fuzzingIssue is related to the fuzzingcomp-springIssue is related to Spring projects supportctg-bugIssue is a bug

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions