diff --git a/advanced/src/test/java/hello/advanced/trace/strategy/ContextV1Test.java b/advanced/src/test/java/hello/advanced/trace/strategy/ContextV1Test.java index ebb6e34..f68f284 100644 --- a/advanced/src/test/java/hello/advanced/trace/strategy/ContextV1Test.java +++ b/advanced/src/test/java/hello/advanced/trace/strategy/ContextV1Test.java @@ -44,4 +44,64 @@ void strategyV1() { ContextV1 context2 = new ContextV1(strategyLogic2); context2.execute(); } + + /** + * 전략 패턴 익명 내부 클래스1 + */ + @Test + void strategyV2() { + Strategy strategyLogic1 = new Strategy() { + @Override + public void call() { + log.info("비즈니스 로직1 실행"); + } + }; + log.info("strategyLogic1={}", strategyLogic1.getClass()); + ContextV1 context1 = new ContextV1(strategyLogic1); + context1.execute(); + + Strategy strategyLogic2 = new Strategy() { + @Override + public void call() { + log.info("비즈니스 로직2 실행"); + } + }; + log.info("strategyLogic2={}", strategyLogic2.getClass()); + ContextV1 context2 = new ContextV1(strategyLogic2); + context2.execute(); + } + + /** + * 전략 패턴 익명 내부 클래스2 + */ + @Test + void strategyV3() { + ContextV1 context1 = new ContextV1(new Strategy() { + @Override + public void call() { + log.info("비즈니스 로직1 실행"); + } + }); + context1.execute(); + + ContextV1 context2 = new ContextV1(new Strategy() { + @Override + public void call() { + log.info("비즈니스 로직2 실행"); + } + }); + context2.execute(); + } + + /** + * 전략 패턴, 람다 + */ + @Test + void strategyV4() { + ContextV1 context1 = new ContextV1(() -> log.info("비즈니스 로직1 실행")); + context1.execute(); + + ContextV1 context2 = new ContextV1(() -> log.info("비즈니스 로직2 실행")); + context2.execute(); + } }