mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 08:58:26 +00:00
fix: fix template-method mockito tests
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -27,8 +27,8 @@ package com.iluwatar.templatemethod;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
@@ -41,43 +41,26 @@ class HalflingThiefTest {
|
||||
* Verify if the thief uses the provided stealing method
|
||||
*/
|
||||
@Test
|
||||
@Disabled
|
||||
void testSteal() {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the thief uses the provided stealing method, and the new method after changing it
|
||||
*/
|
||||
@Test
|
||||
@Disabled
|
||||
void testChangeMethod() {
|
||||
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 = 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