1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package model;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class GroupObserverTest {
private GroupObserver target;
private MockObserver<Integer> obsInt;
private MockObserver<String> obsStr;
private MockObserver<Observer> obsObs;
private MockObserver<ArrayList> obsArrList;
private MockObserver<List> obsList;
@BeforeEach
void setup() {
target = new GroupObserver();
obsInt = new MockObserver<>();
obsStr = new MockObserver<>();
obsObs = new MockObserver<>();
obsArrList = new MockObserver<>();
obsList = new MockObserver<>();
target.register(Integer.class, obsInt);
target.register(String.class, obsStr);
target.register(Observer.class, obsObs);
target.register(List.class, obsList);
target.register(ArrayList.class, obsArrList);
}
@Test
void testRegister() {
assertEquals(5, target.getRegisteredObserverCount());
}
@Test
void testAccept() {
target.accept(this, Observer.DIRECTION_CHANGE, 100);
assertEquals(0, obsInt.getCount());
assertEquals(0, obsStr.getCount());
target.accept("123", Observer.DIRECTION_CHANGE, 1000);
obsStr.assertCalled(Observer.DIRECTION_CHANGE);
assertEquals(0, obsInt.getCount());
assertEquals(1000, obsStr.getIndex());
target.accept(114514, Observer.DIRECTION_ADD, 1919810);
obsInt.assertCalled(Observer.DIRECTION_ADD);
assertEquals(1919810, obsInt.getIndex());
target.accept(obsInt, Observer.DIRECTION_CHANGE, 1);
obsObs.assertCalled(Observer.DIRECTION_CHANGE);
target.accept(new ArrayList<>(), Observer.DIRECTION_CHANGE, 2);
obsArrList.assertCalled(Observer.DIRECTION_CHANGE);
assertEquals(0, obsList.getCount());
}
}
|