-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MVC 구현하기 - 1단계] 푸우(백승준) 미션 제출합니다. (#344)
* chore: reflection 학습 테스트 작성 * chore: Servlet 학습 테스트 작성 * feat: 핸들러 매핑 구현 * test: 테스트 케이스 추가 * feat: HandlerExecution 재정의 * refactor: AnnotationHandlerMapping 메서드 리팩터링 * test: 테스트 케이스 추가 * refactor: AnnotationHandlerMapping 메서드 리팩터링 * refactor: Method.isAnnotationPresent() 사용 * refactor: 메서드 네이밍 변경
- Loading branch information
Showing
14 changed files
with
369 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package duplicate.case3; | ||
|
||
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, | ||
RequestMethod.GET, | ||
RequestMethod.GET, | ||
RequestMethod.GET, | ||
RequestMethod.GET | ||
}) | ||
public ModelAndView duplicatedMethod1(final HttpServletRequest request, | ||
final HttpServletResponse response) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
package reflection; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class Junit3TestRunner { | ||
|
||
@Test | ||
void run() throws Exception { | ||
Class<Junit3Test> clazz = Junit3Test.class; | ||
List<Method> methods = Arrays.stream(clazz.getMethods()) | ||
.filter(method -> method.getName().startsWith("test")) | ||
.collect(Collectors.toList()); | ||
|
||
// TODO Junit3Test에서 test로 시작하는 메소드 실행 | ||
Junit3Test junit3Test = clazz.getConstructor() | ||
.newInstance(); | ||
|
||
for (Method method : methods) { | ||
method.invoke(junit3Test); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
package reflection; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class Junit4TestRunner { | ||
|
||
@Test | ||
void run() throws Exception { | ||
Class<Junit4Test> clazz = Junit4Test.class; | ||
List<Method> methods = Arrays.stream(clazz.getMethods()) | ||
.filter(method -> haveTestAnnotation(method)) | ||
.collect(Collectors.toList()); | ||
|
||
// TODO Junit4Test에서 @MyTest 애노테이션이 있는 메소드 실행 | ||
Junit4Test junit4Test = clazz.getConstructor() | ||
.newInstance(); | ||
|
||
for (Method method : methods) { | ||
method.invoke(junit4Test); | ||
} | ||
} | ||
|
||
private boolean haveTestAnnotation(Method method) { | ||
return Arrays.stream(method.getDeclaredAnnotations()) | ||
.anyMatch(annotation -> annotation instanceof MyTest); | ||
} | ||
} |
Oops, something went wrong.