diff --git a/mvc/src/test/java/duplicate/case1/TestController.java b/mvc/src/test/java/duplicate/case1/TestController.java new file mode 100644 index 0000000000..ab89f06ea7 --- /dev/null +++ b/mvc/src/test/java/duplicate/case1/TestController.java @@ -0,0 +1,22 @@ +package duplicate.case1; + +import context.org.springframework.stereotype.Controller; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import web.org.springframework.web.bind.annotation.RequestMapping; +import web.org.springframework.web.bind.annotation.RequestMethod; +import webmvc.org.springframework.web.servlet.ModelAndView; + +@Controller +public class TestController { + + private static final Logger log = LoggerFactory.getLogger(samples.TestController.class); + + @RequestMapping(value = "/get-test", method = RequestMethod.GET) + public ModelAndView duplicatedMethod(final HttpServletRequest request, + final HttpServletResponse response) { + return null; + } +} diff --git a/mvc/src/test/java/duplicate/case2/TestController.java b/mvc/src/test/java/duplicate/case2/TestController.java new file mode 100644 index 0000000000..0e56116850 --- /dev/null +++ b/mvc/src/test/java/duplicate/case2/TestController.java @@ -0,0 +1,28 @@ +package duplicate.case2; + +import context.org.springframework.stereotype.Controller; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import web.org.springframework.web.bind.annotation.RequestMapping; +import web.org.springframework.web.bind.annotation.RequestMethod; +import webmvc.org.springframework.web.servlet.ModelAndView; + +@Controller +public class TestController { + + private static final Logger log = LoggerFactory.getLogger(samples.TestController.class); + + @RequestMapping(value = "/get-test", method = RequestMethod.GET) + public ModelAndView duplicatedMethod1(final HttpServletRequest request, + final HttpServletResponse response) { + return null; + } + + @RequestMapping(value = "/get-test", method = RequestMethod.GET) + public ModelAndView duplicatedMethod2(final HttpServletRequest request, + final HttpServletResponse response) { + return null; + } +} diff --git a/mvc/src/test/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMappingTest.java b/mvc/src/test/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMappingTest.java index dcec215a3f..494f21936f 100644 --- a/mvc/src/test/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMappingTest.java +++ b/mvc/src/test/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMappingTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -19,6 +20,27 @@ void setUp() { handlerMapping.initialize(); } + @Test + void methodDuplicationException_case1() { + // given & when & then + AnnotationHandlerMapping duplicatedHandlerMapping = new AnnotationHandlerMapping( + "samples", + "duplicate.case1"); + assertThatThrownBy(() -> duplicatedHandlerMapping.initialize()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Duplicated HandlerKey"); + } + + @Test + void methodDuplicationException_case2() { + // given & when & then + AnnotationHandlerMapping duplicatedHandlerMapping = new AnnotationHandlerMapping( + "duplicate.case2"); + assertThatThrownBy(() -> duplicatedHandlerMapping.initialize()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Duplicated HandlerKey"); + } + @Test void get() throws Exception { final var request = mock(HttpServletRequest.class);