blob: 0b0937fa29b757c577b2189f8cde9b5707e5b57c (
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
45
46
47
48
49
50
51
52
|
package bjc.data;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* Test for boolean toggles.
*
* @author bjculkin
*
*/
public class BooleanToggleTest {
/**
* Test that boolean toggles work right.
*/
@Test
public void test() {
BooleanToggle tog = new BooleanToggle();
// Check initial value is false.
assertEquals(false, tog.peek());
// Check that 'get' returns the old value
assertEquals(false, tog.get());
// Check that 'get' swaps the value
assertEquals(true, tog.peek());
// Check that we can round-trip back.
assertEquals(true, tog.get());
assertEquals(false, tog.peek());
tog.set(true);
// Check set works
assertEquals(true, tog.peek());
BooleanToggle tog2 = new BooleanToggle(true);
// Test equals/hashcode
assertEquals(tog, tog2);
assertEquals(tog.hashCode(), tog2.hashCode());
// Swap toggle
tog2.get();
assertNotEquals(tog.hashCode(), tog2.hashCode());
assertNotEquals(tog, tog2);
// Test toString
assertEquals("true", tog.toString());
}
}
|