From c2b6eab7fc985269ee92a4cce6871cc1e5fecce1 Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 12 Sep 2023 22:06:17 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/duplicate/case1/TestController.java | 22 +++++++++++++++ .../java/duplicate/case2/TestController.java | 28 +++++++++++++++++++ .../tobe/AnnotationHandlerMappingTest.java | 22 +++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 mvc/src/test/java/duplicate/case1/TestController.java create mode 100644 mvc/src/test/java/duplicate/case2/TestController.java 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);