blob: a34f4b93a4d8def7d4998a533ad551b853a603bb (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.file;
import com.yahoo.vespa.hosted.node.admin.component.TaskContext;
import com.yahoo.vespa.test.file.TestFileSystem;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
/**
* @author hakonhall
*/
public class StoredBooleanTest {
private final TaskContext context = mock(TaskContext.class);
private final FileSystem fileSystem = TestFileSystem.create();
private final Path path = fileSystem.getPath("/foo");
private final StoredBoolean storedBoolean = new StoredBoolean(path);
@Test
public void storedBoolean() {
assertFalse(storedBoolean.value());
storedBoolean.set(context);
assertTrue(storedBoolean.value());
storedBoolean.clear(context);
assertFalse(storedBoolean.value());
}
@Test
public void testCompatibility() throws IOException {
StoredInteger storedInteger = new StoredInteger(path);
assertFalse(storedBoolean.value());
storedInteger.write(context, 1);
assertTrue(storedBoolean.value());
storedInteger.write(context, 2);
assertTrue(storedBoolean.value());
storedInteger.write(context, 0);
assertFalse(storedBoolean.value());
Files.delete(path);
assertFalse(storedBoolean.value());
}
}
|