|
6 | 6 |
|
7 | 7 | import static org.hamcrest.Matchers.arrayContaining;
|
8 | 8 | import static org.hamcrest.junit.MatcherAssert.assertThat;
|
| 9 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 10 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
9 | 11 |
|
10 | 12 | import java.util.Arrays;
|
11 | 13 | import java.util.HashMap;
|
12 | 14 | import java.util.Map;
|
13 | 15 | import org.junit.jupiter.api.BeforeAll;
|
| 16 | +import org.junit.jupiter.api.DisplayName; |
14 | 17 | import org.junit.jupiter.api.Test;
|
15 | 18 |
|
16 | 19 | @SuppressWarnings("EmptyMethod")
|
@@ -41,6 +44,60 @@ public void whenStringArrayValueIsList_returnAsArray() {
|
41 | 44 | assertThat(MapUtils.getStringArray(map, "values"), arrayContaining("7", "8", "true"));
|
42 | 45 | }
|
43 | 46 |
|
| 47 | + @DisplayName("Check getBooleanValue for true values") |
| 48 | + @Test |
| 49 | + public void checkGetBooleanForTrueValues() { |
| 50 | + Map<String, Object> map = new HashMap<>(); |
| 51 | + map.put("1", "true"); |
| 52 | + map.put("2", "t"); |
| 53 | + map.put("3", "yes"); |
| 54 | + map.put("4", "on"); |
| 55 | + map.put("5", "y"); |
| 56 | + map.put("6", "truenot"); |
| 57 | + map.put("7", "nottrue"); |
| 58 | + map.put("8", "yesss"); |
| 59 | + map.put("9", "y "); |
| 60 | + map.put("10", " y "); |
| 61 | + |
| 62 | + assertEquals(true, MapUtils.getBooleanValue(map, "1")); |
| 63 | + assertEquals(true, MapUtils.getBooleanValue(map, "2")); |
| 64 | + assertEquals(true, MapUtils.getBooleanValue(map, "3")); |
| 65 | + assertEquals(true, MapUtils.getBooleanValue(map, "4")); |
| 66 | + assertEquals(true, MapUtils.getBooleanValue(map, "5")); |
| 67 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "6")); |
| 68 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "7")); |
| 69 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "8")); |
| 70 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "9")); |
| 71 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "10")); |
| 72 | + } |
| 73 | + |
| 74 | + @DisplayName("Check getBooleanValue for false values") |
| 75 | + @Test |
| 76 | + public void checkGetBooleanForFalseValues() { |
| 77 | + Map<String, Object> map = new HashMap<>(); |
| 78 | + map.put("1", "false"); |
| 79 | + map.put("2", "f"); |
| 80 | + map.put("3", "no"); |
| 81 | + map.put("4", "off"); |
| 82 | + map.put("5", "n"); |
| 83 | + map.put("6", "falsedata"); |
| 84 | + map.put("7", "sofalse"); |
| 85 | + map.put("8", "ono"); |
| 86 | + map.put("9", "n "); |
| 87 | + map.put("10", " n "); |
| 88 | + |
| 89 | + assertEquals(false, MapUtils.getBooleanValue(map, "1")); |
| 90 | + assertEquals(false, MapUtils.getBooleanValue(map, "2")); |
| 91 | + assertEquals(false, MapUtils.getBooleanValue(map, "3")); |
| 92 | + assertEquals(false, MapUtils.getBooleanValue(map, "4")); |
| 93 | + assertEquals(false, MapUtils.getBooleanValue(map, "5")); |
| 94 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "6")); |
| 95 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "7")); |
| 96 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "8")); |
| 97 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "9")); |
| 98 | + assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "10")); |
| 99 | + } |
| 100 | + |
44 | 101 | private Map<String, Object> createMapWithValue(Object value) {
|
45 | 102 | Map<String, Object> map = new HashMap<>();
|
46 | 103 | map.put("values", value);
|
|
0 commit comments