From a6e6c22bf628a80238143f4ad6e0e745ba661c2e Mon Sep 17 00:00:00 2001 From: hoangNam Date: Mon, 15 Oct 2018 10:44:14 +0700 Subject: [PATCH 1/3] Remove redundant Exception from throws list in DragonSlayerTest --- .../src/test/java/com/iluwatar/strategy/DragonSlayerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strategy/src/test/java/com/iluwatar/strategy/DragonSlayerTest.java b/strategy/src/test/java/com/iluwatar/strategy/DragonSlayerTest.java index d22bf4235..81afa53b4 100644 --- a/strategy/src/test/java/com/iluwatar/strategy/DragonSlayerTest.java +++ b/strategy/src/test/java/com/iluwatar/strategy/DragonSlayerTest.java @@ -52,7 +52,7 @@ public class DragonSlayerTest { * Verify if the dragon slayer uses the new strategy during battle after a change of strategy */ @Test - public void testChangeStrategy() throws Exception { + public void testChangeStrategy() { final DragonSlayingStrategy initialStrategy = mock(DragonSlayingStrategy.class); final DragonSlayer dragonSlayer = new DragonSlayer(initialStrategy); From 86e9c66ca5d325a415563edcabeca9422eef3401 Mon Sep 17 00:00:00 2001 From: hoangNam Date: Mon, 15 Oct 2018 11:41:14 +0700 Subject: [PATCH 2/3] - Assign new clubberTroll instance to another variable. - Remove redundant Exception from throws list in unit tests. --- decorator/src/main/java/com/iluwatar/decorator/App.java | 8 ++++---- .../java/com/iluwatar/decorator/ClubbedTrollTest.java | 2 +- .../test/java/com/iluwatar/decorator/SimpleTrollTest.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/decorator/src/main/java/com/iluwatar/decorator/App.java b/decorator/src/main/java/com/iluwatar/decorator/App.java index 5b072b9c2..997b649eb 100644 --- a/decorator/src/main/java/com/iluwatar/decorator/App.java +++ b/decorator/src/main/java/com/iluwatar/decorator/App.java @@ -57,9 +57,9 @@ public class App { // change the behavior of the simple troll by adding a decorator LOGGER.info("A troll with huge club surprises you."); - troll = new ClubbedTroll(troll); - troll.attack(); - troll.fleeBattle(); - LOGGER.info("Clubbed troll power {}.\n", troll.getAttackPower()); + Troll clubbedTroll = new ClubbedTroll(troll); + clubbedTroll.attack(); + clubbedTroll.fleeBattle(); + LOGGER.info("Clubbed troll power {}.\n", clubbedTroll.getAttackPower()); } } diff --git a/decorator/src/test/java/com/iluwatar/decorator/ClubbedTrollTest.java b/decorator/src/test/java/com/iluwatar/decorator/ClubbedTrollTest.java index 5221eb2da..ffa6e41a7 100644 --- a/decorator/src/test/java/com/iluwatar/decorator/ClubbedTrollTest.java +++ b/decorator/src/test/java/com/iluwatar/decorator/ClubbedTrollTest.java @@ -36,7 +36,7 @@ import static org.mockito.internal.verification.VerificationModeFactory.times; public class ClubbedTrollTest { @Test - public void testClubbedTroll() throws Exception { + public void testClubbedTroll() { // Create a normal troll first, but make sure we can spy on it later on. final Troll simpleTroll = spy(new SimpleTroll()); diff --git a/decorator/src/test/java/com/iluwatar/decorator/SimpleTrollTest.java b/decorator/src/test/java/com/iluwatar/decorator/SimpleTrollTest.java index 14d944b2e..d572ad139 100644 --- a/decorator/src/test/java/com/iluwatar/decorator/SimpleTrollTest.java +++ b/decorator/src/test/java/com/iluwatar/decorator/SimpleTrollTest.java @@ -53,7 +53,7 @@ public class SimpleTrollTest { } @Test - public void testTrollActions() throws Exception { + public void testTrollActions() { final SimpleTroll troll = new SimpleTroll(); assertEquals(10, troll.getAttackPower()); From b3f0cc7e00448c0367f06f5f73282e45f88ebb57 Mon Sep 17 00:00:00 2001 From: hoangNam Date: Mon, 15 Oct 2018 11:52:56 +0700 Subject: [PATCH 3/3] - Assign ClubberTroll to another variable in README --- decorator/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/decorator/README.md b/decorator/README.md index 9998b9938..c003325fd 100644 --- a/decorator/README.md +++ b/decorator/README.md @@ -104,9 +104,9 @@ troll.attack(); // The troll tries to grab you! troll.fleeBattle(); // The troll shrieks in horror and runs away! // change the behavior of the simple troll by adding a decorator -troll = new ClubbedTroll(troll); -troll.attack(); // The troll tries to grab you! The troll swings at you with a club! -troll.fleeBattle(); // The troll shrieks in horror and runs away! +Troll clubbedTroll = new ClubbedTroll(troll); +clubbedTroll.attack(); // The troll tries to grab you! The troll swings at you with a club! +clubbedTroll.fleeBattle(); // The troll shrieks in horror and runs away! ``` ## Applicability