### Question:
DragonSlayer { public void changeStrategy(DragonSlayingStrategy strategy) { this.strategy = strategy; } DragonSlayer(DragonSlayingStrategy strategy); void changeStrategy(DragonSlayingStrategy strategy); void goToBattle();  }### Answer:
@Test public void testChangeStrategy() { 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); }
@Test public void testChangeStrategy() { final var initialStrategy = mock(DragonSlayingStrategy.class); final var dragonSlayer = new DragonSlayer(initialStrategy); dragonSlayer.goToBattle(); verify(initialStrategy).execute(); final var newStrategy = mock(DragonSlayingStrategy.class); dragonSlayer.changeStrategy(newStrategy); dragonSlayer.goToBattle(); verify(newStrategy).execute(); verifyNoMoreInteractions(initialStrategy, newStrategy); }
@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); }