diff options
author | Yuuta Liang <yuutaw@student.cs.ubc.ca> | 2023-11-23 08:09:01 +0800 |
---|---|---|
committer | Yuuta Liang <yuutaw@student.cs.ubc.ca> | 2023-11-23 08:09:01 +0800 |
commit | 65ea6c17a0c1348aa9ef4e158102ddf173936882 (patch) | |
tree | 7615366f76b6c94f46d8039aa20091f9ccd5609a /src/test/model/ObservedDataTest.java | |
parent | b94b18c133f06cb176d8aa8bb40a8e24918d9ed6 (diff) | |
download | jca-65ea6c17a0c1348aa9ef4e158102ddf173936882.tar jca-65ea6c17a0c1348aa9ef4e158102ddf173936882.tar.gz jca-65ea6c17a0c1348aa9ef4e158102ddf173936882.tar.bz2 jca-65ea6c17a0c1348aa9ef4e158102ddf173936882.zip |
Add GUI
Signed-off-by: Yuuta Liang <yuutaw@student.cs.ubc.ca>
Diffstat (limited to 'src/test/model/ObservedDataTest.java')
-rw-r--r-- | src/test/model/ObservedDataTest.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/model/ObservedDataTest.java b/src/test/model/ObservedDataTest.java new file mode 100644 index 0000000..60ed2ed --- /dev/null +++ b/src/test/model/ObservedDataTest.java @@ -0,0 +1,44 @@ +package model; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class ObservedDataTest { + private ObservedData<Integer> target; + + private int callbackCount = 0; + private int callbackDirection = Integer.MIN_VALUE; + private int callbackIndex = Integer.MIN_VALUE; + + private final Observer<Integer> obs = ((data, direction, index) -> { + callbackCount++; + callbackDirection = direction; + callbackIndex = index; + }); + + @BeforeEach + void setup() { + target = new ObservedData<>(0, obs); + callbackCount = 0; + callbackDirection = Integer.MIN_VALUE; + callbackIndex = Integer.MIN_VALUE; + } + + @Test + void testConstructor() { + assertEquals(0, target.get()); + assertNotNull(target.getAcceptor()); + } + + @Test + void testSet() { + target.set(114514); + assertEquals(114514, target.get()); + assertEquals(1, callbackCount); + assertEquals(Observer.DIRECTION_CHANGE, callbackDirection); + assertEquals(Observer.INDEX_NOT_IN_LIST, callbackIndex); + } +} |