Skip to content

Commit 3809ea5

Browse files
committed
working with mockito
1 parent 7874791 commit 3809ea5

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed
203 Bytes
Binary file not shown.

test/halterman/command/CommandPatternTest.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
package halterman.command;
22

3-
import static org.junit.Assert.*;
4-
import halterman.command.Command;
5-
import halterman.command.Light;
6-
import halterman.command.LightOnCommand;
7-
import halterman.command.Switch;
8-
9-
import org.mockito.InjectMocks;
10-
import org.mockito.Mock;
11-
import org.mockito.Mockito;
12-
import org.mockito.MockitoAnnotations;
133
import static org.mockito.Mockito.verify;
144

155
import org.junit.Before;
166
import org.junit.Test;
7+
import org.mockito.InjectMocks;
8+
import org.mockito.Mock;
9+
import org.mockito.MockitoAnnotations;
10+
import org.mockito.Spy;
1711

1812
public class CommandPatternTest {
1913

@@ -23,20 +17,20 @@ public class CommandPatternTest {
2317
@Mock
2418
Light light;
2519

26-
@Mock
27-
Command lightsOn;
20+
@Spy
21+
Command lightsOn = new LightOnCommand(light);
2822

2923
@Before
3024
public void setUp() {
3125
MockitoAnnotations.initMocks(this);
3226
lightSwitch = new Switch();
27+
lightSwitch.setCommand(lightsOn);
3328
}
3429

3530
@Test
3631
public void shouldTurnOnLight() {
3732
lightSwitch.pressButton();
3833

39-
4034
verify(light).switchOn();
4135
}
4236

0 commit comments

Comments
 (0)