blob: bd75a4166d966cda643bb9b6475b163a5246e5df (
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
|
package bjc.data;
import static org.junit.Assert.assertEquals;
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());
// Test toString
assertEquals("true", tog.toString());
}
}
|