summaryrefslogtreecommitdiff
path: root/base/src/test/java/bjc/utils/data/BooleanToggleTest.java
blob: 66f44c062753138823c6f3ca41ce1bb5e81c9ff4 (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
package bjc.utils.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());
	}
}