Merge pull request #800 from trumvekhuya/master
Fix small points in Strategy and Decorator pattern.
This commit is contained in:
		@@ -104,9 +104,9 @@ troll.attack(); // The troll tries to grab you!
 | 
				
			|||||||
troll.fleeBattle(); // The troll shrieks in horror and runs away!
 | 
					troll.fleeBattle(); // The troll shrieks in horror and runs away!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// change the behavior of the simple troll by adding a decorator
 | 
					// change the behavior of the simple troll by adding a decorator
 | 
				
			||||||
troll = new ClubbedTroll(troll);
 | 
					Troll clubbedTroll = new ClubbedTroll(troll);
 | 
				
			||||||
troll.attack(); // The troll tries to grab you! The troll swings at you with a club!
 | 
					clubbedTroll.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!
 | 
					clubbedTroll.fleeBattle(); // The troll shrieks in horror and runs away!
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Applicability
 | 
					## Applicability
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,9 +57,9 @@ public class App {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // change the behavior of the simple troll by adding a decorator
 | 
					    // change the behavior of the simple troll by adding a decorator
 | 
				
			||||||
    LOGGER.info("A troll with huge club surprises you.");
 | 
					    LOGGER.info("A troll with huge club surprises you.");
 | 
				
			||||||
    troll = new ClubbedTroll(troll);
 | 
					    Troll clubbedTroll = new ClubbedTroll(troll);
 | 
				
			||||||
    troll.attack();
 | 
					    clubbedTroll.attack();
 | 
				
			||||||
    troll.fleeBattle();
 | 
					    clubbedTroll.fleeBattle();
 | 
				
			||||||
    LOGGER.info("Clubbed troll power {}.\n", troll.getAttackPower());
 | 
					    LOGGER.info("Clubbed troll power {}.\n", clubbedTroll.getAttackPower());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ import static org.mockito.internal.verification.VerificationModeFactory.times;
 | 
				
			|||||||
public class ClubbedTrollTest {
 | 
					public class ClubbedTrollTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testClubbedTroll() throws Exception {
 | 
					  public void testClubbedTroll() {
 | 
				
			||||||
    // Create a normal troll first, but make sure we can spy on it later on.
 | 
					    // Create a normal troll first, but make sure we can spy on it later on.
 | 
				
			||||||
    final Troll simpleTroll = spy(new SimpleTroll());
 | 
					    final Troll simpleTroll = spy(new SimpleTroll());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,7 +53,7 @@ public class SimpleTrollTest {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testTrollActions() throws Exception {
 | 
					  public void testTrollActions() {
 | 
				
			||||||
    final SimpleTroll troll = new SimpleTroll();
 | 
					    final SimpleTroll troll = new SimpleTroll();
 | 
				
			||||||
    assertEquals(10, troll.getAttackPower());
 | 
					    assertEquals(10, troll.getAttackPower());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,7 +52,7 @@ public class DragonSlayerTest {
 | 
				
			|||||||
   * Verify if the dragon slayer uses the new strategy during battle after a change of strategy
 | 
					   * Verify if the dragon slayer uses the new strategy during battle after a change of strategy
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  @Test
 | 
					  @Test
 | 
				
			||||||
  public void testChangeStrategy() throws Exception {
 | 
					  public void testChangeStrategy() {
 | 
				
			||||||
    final DragonSlayingStrategy initialStrategy = mock(DragonSlayingStrategy.class);
 | 
					    final DragonSlayingStrategy initialStrategy = mock(DragonSlayingStrategy.class);
 | 
				
			||||||
    final DragonSlayer dragonSlayer = new DragonSlayer(initialStrategy);
 | 
					    final DragonSlayer dragonSlayer = new DragonSlayer(initialStrategy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user