@Test public void testChangeStrategy() throws Exception { final DragonSlayingStrategy initialStrategy = mock(DragonSlayingStrategy.class); final DragonSlayer dragonSlayer = new DragonSlayer(initialStrategy); dragonSlayer.goToBattle(); verify(initialStrategy).execute(); final DragonSlayingStrategy newStrategy = mock(DragonSlayingStrategy.class); dragonSlayer.changeStrategy(newStrategy); dragonSlayer.goToBattle(); verify(newStrategy).execute(); verifyNoMoreInteractions(initialStrategy, newStrategy); }
public void changeStrategy(DragonSlayingStrategy strategy) { this.strategy = strategy; }
DragonSlayer { public void changeStrategy(DragonSlayingStrategy strategy) { this.strategy = strategy; } }
DragonSlayer { public void changeStrategy(DragonSlayingStrategy strategy) { this.strategy = strategy; } DragonSlayer(DragonSlayingStrategy strategy); }
DragonSlayer { public void changeStrategy(DragonSlayingStrategy strategy) { this.strategy = strategy; } DragonSlayer(DragonSlayingStrategy strategy); void changeStrategy(DragonSlayingStrategy strategy); void goToBattle(); }
DragonSlayer { public void changeStrategy(DragonSlayingStrategy strategy) { this.strategy = strategy; } DragonSlayer(DragonSlayingStrategy strategy); void changeStrategy(DragonSlayingStrategy strategy); void goToBattle();  }