-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFallbackConfigurationTest.java
More file actions
72 lines (55 loc) · 2.5 KB
/
FallbackConfigurationTest.java
File metadata and controls
72 lines (55 loc) · 2.5 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package io.split.android.client.fallback;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertSame;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
public class FallbackConfigurationTest {
@Test
public void constructorSetsFields() {
FallbackTreatment global = new FallbackTreatment("off");
Map<String, FallbackTreatment> map = new HashMap<>();
map.put("flagA", new FallbackTreatment("off"));
FallbackConfiguration cfg = FallbackConfiguration.builder()
.global(global)
.byFlag(map)
.build();
assertSame(global, cfg.getGlobal());
assertEquals(1, cfg.getByFlag().size());
assertEquals("off", cfg.getByFlag().get("flagA").getTreatment());
}
@Test
public void byFlagIsUnmodifiable() {
FallbackTreatment global = new FallbackTreatment("off");
Map<String, FallbackTreatment> byFlag = new HashMap<>();
byFlag.put("flagA", new FallbackTreatment("off"));
FallbackConfiguration config = FallbackConfiguration.builder()
.global(global)
.byFlag(byFlag)
.build();
byFlag.put("flagB", new FallbackTreatment("on"));
// config map must not change
assertEquals(1, config.getByFlag().size());
try {
config.getByFlag().put("x", new FallbackTreatment("on"));
throw new AssertionError("Map should be unmodifiable");
} catch (UnsupportedOperationException expected) {
}
}
@Test
public void equalityAndHashCodeByValue() {
FallbackTreatment global = new FallbackTreatment("off");
Map<String, FallbackTreatment> a = new HashMap<>();
a.put("flagA", new FallbackTreatment("off"));
Map<String, FallbackTreatment> b = new HashMap<>();
b.put("flagA", new FallbackTreatment("off"));
FallbackConfiguration configOne = FallbackConfiguration.builder().global(global).byFlag(a).build();
FallbackConfiguration configTwo = FallbackConfiguration.builder().global(global).byFlag(b).build();
FallbackConfiguration configThree = FallbackConfiguration.builder().global(null).byFlag(b).build();
assertEquals(configOne, configTwo);
assertEquals(configOne.hashCode(), configTwo.hashCode());
assertNotEquals(configOne, configThree);
assertNotEquals(configOne.hashCode(), configThree.hashCode());
}
}