From 0e3961055c8584f042c4bee3e68036afe00c74bc Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 12 Aug 2024 20:45:02 +0200 Subject: [PATCH] test (Core/URLParameter): Extends unit tests --- .../sdk/core/http/URLParameterUtilsTest.java | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java b/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java index 61bc42d8..35b58238 100644 --- a/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java +++ b/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java @@ -135,7 +135,31 @@ void encodeFormStringExplode() { } @Test - void encodeDynamicEnumStringNoExplode() { + void encodeFormStringArrayNoExplode() { + assertEquals( + Optional.of("foo=value1+with+space+and+%26%2C%2E,value2+with+space+and+%26%2C%2E"), + URLParameterUtils.encode( + new URLParameter( + "foo", + Arrays.asList("value1 with space and &,.", "value2 with space and &,."), + URLParameter.STYLE.FORM, + false))); + } + + @Test + void encodeFormStringArrayExplode() { + assertEquals( + Optional.of("foo=value1+with+space+and+%26%2C%2E&foo=value2+with+space+and+%26%2C%2E"), + URLParameterUtils.encode( + new URLParameter( + "foo", + Arrays.asList("value1 with space and &,.", "value2 with space and &,."), + URLParameter.STYLE.FORM, + true))); + } + + @Test + void encodeDynamicEnumNoExplode() { assertEquals( Optional.of("foo=ENUM1+value"), URLParameterUtils.encode( @@ -143,13 +167,31 @@ void encodeDynamicEnumStringNoExplode() { } @Test - void encodeDynamicEnumStringExplode() { + void encodeDynamicEnumExplode() { assertEquals( Optional.of("foo=ENUM1+value"), URLParameterUtils.encode( new URLParameter("foo", AnEnum.ENUM1, URLParameter.STYLE.FORM, true))); } + @Test + void encodeDynamicEnumArrayNoExplode() { + assertEquals( + Optional.of("foo=ENUM1+value,ENUM2+value"), + URLParameterUtils.encode( + new URLParameter( + "foo", Arrays.asList(AnEnum.ENUM1, AnEnum.ENUM2), URLParameter.STYLE.FORM, false))); + } + + @Test + void encodeDynamicEnumArrayExplode() { + assertEquals( + Optional.of("foo=ENUM1+value&foo=ENUM2+value"), + URLParameterUtils.encode( + new URLParameter( + "foo", Arrays.asList(AnEnum.ENUM1, AnEnum.ENUM2), URLParameter.STYLE.FORM, true))); + } + @Test void encodeSimpleEmptyStringNoExplode() { assertThrows(