aboutsummaryrefslogtreecommitdiff
path: root/src/test/model/ObservedDataTest.java
blob: 60ed2ed7bcb4a7ba9717e869662fc324c2c41007 (plain)
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
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);
    }
}