|
| 1 | +package cloud.eppo.api; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.Arrays; |
| 7 | +import java.util.List; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +public class EppoValueTest { |
| 11 | + @Test |
| 12 | + public void testDoubleValue() { |
| 13 | + EppoValue eppoValue = EppoValue.valueOf(123.4567); |
| 14 | + assertEquals(123.4567, eppoValue.doubleValue(), 0.0); |
| 15 | + } |
| 16 | + |
| 17 | + @Test |
| 18 | + public void testToStringWithStringArray() { |
| 19 | + // Test with multiple values |
| 20 | + List<String> values = Arrays.asList("one", "two", "three"); |
| 21 | + EppoValue value = EppoValue.valueOf(values); |
| 22 | + assertEquals("one, two, three", value.toString()); |
| 23 | + |
| 24 | + // Test with single value |
| 25 | + List<String> singleValue = Arrays.asList("solo"); |
| 26 | + EppoValue singleValueObj = EppoValue.valueOf(singleValue); |
| 27 | + assertEquals("solo", singleValueObj.toString()); |
| 28 | + |
| 29 | + // Test with empty list |
| 30 | + List<String> emptyList = new ArrayList<>(); |
| 31 | + EppoValue emptyValue = EppoValue.valueOf(emptyList); |
| 32 | + assertEquals("", emptyValue.toString()); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testStringArrayJoining() { |
| 37 | + // Test joining behavior with various arrays |
| 38 | + List<String> values = Arrays.asList("a", "b", "c"); |
| 39 | + EppoValue value = EppoValue.valueOf(values); |
| 40 | + assertEquals("a, b, c", value.toString()); |
| 41 | + |
| 42 | + // Test with values containing the delimiter |
| 43 | + List<String> commaValues = Arrays.asList("first,item", "second ,item"); |
| 44 | + EppoValue commaValue = EppoValue.valueOf(commaValues); |
| 45 | + assertEquals("first,item, second ,item", commaValue.toString()); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testToStringConsistencyAcrossTypes() { |
| 50 | + // Verify string representation is consistent across types |
| 51 | + EppoValue boolValue = EppoValue.valueOf(true); |
| 52 | + assertEquals("true", boolValue.toString()); |
| 53 | + |
| 54 | + EppoValue numValue = EppoValue.valueOf(42.5); |
| 55 | + assertEquals("42.5", numValue.toString()); |
| 56 | + |
| 57 | + EppoValue strValue = EppoValue.valueOf("test"); |
| 58 | + assertEquals("test", strValue.toString()); |
| 59 | + |
| 60 | + EppoValue nullValue = EppoValue.nullValue(); |
| 61 | + assertEquals("", nullValue.toString()); |
| 62 | + |
| 63 | + // String array should now use our custom joiner |
| 64 | + List<String> array = Arrays.asList("test1", "test2"); |
| 65 | + EppoValue arrayValue = EppoValue.valueOf(array); |
| 66 | + assertEquals("test1, test2", arrayValue.toString()); |
| 67 | + } |
| 68 | +} |
0 commit comments