1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.chabala.brick.controllab;
20
21 import org.chabala.brick.controllab.sensor.SensorListener;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 import org.mockito.Mock;
28 import org.mockito.junit.MockitoJUnit;
29 import org.mockito.junit.MockitoRule;
30
31 import static org.hamcrest.Matchers.*;
32 import static org.junit.Assert.*;
33 import static org.mockito.Mockito.*;
34
35
36
37
38 public class InputTest {
39
40 @Rule
41 public MockitoRule rule = MockitoJUnit.rule();
42
43 @Rule
44 public ExpectedException thrown = ExpectedException.none();
45
46 @Mock
47 private InputManager inputManager;
48
49 @Mock
50 private SensorListener listener;
51
52 private InputId inputId;
53
54 private Input input;
55
56 private RandomEnum randomEnum = new RandomEnum();
57
58 @Before
59 public void setUp() {
60 inputId = randomEnum.get(InputId.class);
61 input = new Input(inputManager, inputId);
62 }
63
64 @After
65 public void tearDown() {
66 input = null;
67 inputId = null;
68 }
69
70 @Test
71 public void testAddListener() {
72 input.addListener(listener);
73 verify(inputManager, times(1)).addSensorListener(inputId, listener);
74 }
75
76 @Test
77 public void testRemoveListener() {
78 input.removeListener(listener);
79 verify(inputManager, times(1)).removeSensorListener(inputId, listener);
80 }
81
82 @Test
83 public void testToString() {
84 assertThat(input + "", containsString("inputId=" + inputId.name()));
85 }
86 }