UnitTestBot / UTBotJava

Automated unit test generation and precise code analysis for Java
Apache License 2.0
136 stars 43 forks source link

Two identical integration tests. #2728

Open ancavar opened 11 months ago

ancavar commented 11 months ago

To Reproduce Generate integration tests for controller's method which has @PreAuthorize, e.g.

    @GetMapping("/demo")
    @PreAuthorize("hasAuthority('write')")
    public String demo() {
        return "demo";
    }

Expected behavior

Only one such test is expected.

Actual behavior

    @Test
    @DisplayName("demo: ")
    public void testDemo() throws Exception {
        Object[] uriVariables = {};
        MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get("/demo", uriVariables);

        ResultActions actual = mockMvc.perform(mockHttpServletRequestBuilder);

        actual.andDo(print());
        actual.andExpect((status()).is(403));
        actual.andExpect((content()).string(""));
    }

    /**
     * @utbot.classUnderTest {@link NameController}
     * @utbot.methodUnderTest {@link NameController#demo()}
     */
    @Test
    @DisplayName("demo: ")
    public void testDemo1() throws Exception {
        Object[] uriVariables = {};
        MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get("/demo", uriVariables);

        ResultActions actual = mockMvc.perform(mockHttpServletRequestBuilder);

        actual.andDo(print());
        actual.andExpect((status()).is(403));
        actual.andExpect((content()).string(""));
    }