### Question:
HalflingThief { public void changeMethod(StealingMethod method) { this.method = method; } HalflingThief(StealingMethod method); void steal(); void changeMethod(StealingMethod method);  }### Answer:
@Test public void testChangeMethod() { final var initialMethod = mock(StealingMethod.class); final var thief = new HalflingThief(initialMethod); thief.steal(); verify(initialMethod).steal(); final var newMethod = mock(StealingMethod.class); thief.changeMethod(newMethod); thief.steal(); verify(newMethod).steal(); verifyNoMoreInteractions(initialMethod, newMethod); }
@Test public void testChangeMethod() { final StealingMethod initialMethod = mock(StealingMethod.class); final HalflingThief thief = new HalflingThief(initialMethod); thief.steal(); verify(initialMethod).steal(); final StealingMethod newMethod = mock(StealingMethod.class); thief.changeMethod(newMethod); thief.steal(); verify(newMethod).steal(); verifyNoMoreInteractions(initialMethod, newMethod); }