|
| 1 | +package com.featurevisor.sdk; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import java.util.List; |
| 6 | +import java.util.Map; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 10 | + |
| 11 | +public class HelpersTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + public void testStringMismatchReturnsNull() { |
| 15 | + assertNull(Helpers.getValueByType(1, "string")); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testStringValueReturnedAsIs() { |
| 20 | + assertEquals("1", Helpers.getValueByType("1", "string")); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + public void testBooleanValueReturnedAsIs() { |
| 25 | + assertEquals(Boolean.TRUE, Helpers.getValueByType(true, "boolean")); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testBooleanStrictness() { |
| 30 | + assertEquals(Boolean.FALSE, Helpers.getValueByType("true", "boolean")); |
| 31 | + assertEquals(Boolean.FALSE, Helpers.getValueByType(1, "boolean")); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testObjectValueReturnedAsIs() { |
| 36 | + Map<String, Integer> value = Map.of("a", 1, "b", 2); |
| 37 | + assertEquals(value, Helpers.getValueByType(value, "object")); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testJsonValueReturnedAsIs() { |
| 42 | + String json = "{\"a\":1,\"b\":2}"; |
| 43 | + assertEquals(json, Helpers.getValueByType(json, "json")); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void testArrayValueReturnedAsIs() { |
| 48 | + List<String> arr = List.of("1", "2", "3"); |
| 49 | + assertEquals(arr, Helpers.getValueByType(arr, "array")); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testIntegerParsing() { |
| 54 | + assertEquals(Integer.valueOf(1), Helpers.getValueByType("1", "integer")); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void testDoubleParsing() { |
| 59 | + assertEquals(1.1d, Helpers.getValueByType("1.1", "double")); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testNullValueReturnsNull() { |
| 64 | + assertNull(Helpers.getValueByType(null, "string")); |
| 65 | + } |
| 66 | +} |
0 commit comments