mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 20:59:29 +00:00
refactor: Declares the template method as final (Issue 1099) (#2057)
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.templatemethod;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
@@ -42,11 +42,14 @@ public class HalflingThiefTest {
|
||||
*/
|
||||
@Test
|
||||
void testSteal() {
|
||||
final var method = mock(StealingMethod.class);
|
||||
final var method = spy(StealingMethod.class);
|
||||
final var thief = new HalflingThief(method);
|
||||
|
||||
thief.steal();
|
||||
verify(method).steal();
|
||||
String target = verify(method).pickTarget();
|
||||
verify(method).confuseTarget(target);
|
||||
verify(method).stealTheItem(target);
|
||||
|
||||
verifyNoMoreInteractions(method);
|
||||
}
|
||||
@@ -56,19 +59,23 @@ public class HalflingThiefTest {
|
||||
*/
|
||||
@Test
|
||||
void testChangeMethod() {
|
||||
final var initialMethod = mock(StealingMethod.class);
|
||||
final var initialMethod = spy(StealingMethod.class);
|
||||
final var thief = new HalflingThief(initialMethod);
|
||||
|
||||
thief.steal();
|
||||
verify(initialMethod).steal();
|
||||
String target = verify(initialMethod).pickTarget();
|
||||
verify(initialMethod).confuseTarget(target);
|
||||
verify(initialMethod).stealTheItem(target);
|
||||
|
||||
final var newMethod = mock(StealingMethod.class);
|
||||
final var newMethod = spy(StealingMethod.class);
|
||||
thief.changeMethod(newMethod);
|
||||
|
||||
thief.steal();
|
||||
verify(newMethod).steal();
|
||||
|
||||
String newTarget = verify(newMethod).pickTarget();
|
||||
verify(newMethod).confuseTarget(newTarget);
|
||||
verify(newMethod).stealTheItem(newTarget);
|
||||
verifyNoMoreInteractions(initialMethod, newMethod);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user