Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EgorkaKulikov opened this issue Dec 14, 2023 · 1 comment
Labels
comp-fuzzing Issue is related to the fuzzing comp-spring Issue is related to Spring projects support ctg-bug Issue is a bug

Comments

@EgorkaKulikov
Copy link
Collaborator

EgorkaKulikov commented Dec 14, 2023

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):

    @Test
    public void testProcessCreationFormByFuzzer1() {
        Owner ownerMock = mock(Owner.class);
        (((Owner) (doNothing()).when(ownerMock))).addPet(any());
        Pet petMock = mock(Pet.class);
        (when(petMock.getName())).thenReturn("duplicate");
        (when(petMock.isNew())).thenReturn(false);
        LocalDate localDateMock = mock(LocalDate.class);
        (when(localDateMock.isAfter(any()))).thenReturn(true);
        (when(petMock.getBirthDate())).thenReturn(localDateMock);
        BindingResult resultMock = mock(BindingResult.class);
        (((Errors) (doNothing()).when(resultMock))).rejectValue(any(), any());
        (when(resultMock.hasErrors())).thenReturn(true);
        ModelMap model = new ModelMap();
        OwnerRepository ownersMock = mock(OwnerRepository.class);
        PetController petController = new PetController(ownersMock);
        model.put(((Object) "abc"), ((Object) petController));

        String actual = petController.processCreationForm(ownerMock, petMock, resultMock, model);

        String expected = "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.

@EgorkaKulikov EgorkaKulikov added ctg-bug Issue is a bug comp-fuzzing Issue is related to the fuzzing comp-spring Issue is related to Spring projects support labels Dec 14, 2023
@EgorkaKulikov
Copy link
Collaborator Author

@IlyaMuravjov may be you now why does it happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-fuzzing Issue is related to the fuzzing comp-spring Issue is related to Spring projects support ctg-bug Issue is a bug
Projects
Status: Todo
Development

No branches or pull requests

1 participant