From ad09f526cb0477e7880088bd6fad0e6442cae995 Mon Sep 17 00:00:00 2001 From: Sergei Prokofev Date: Sun, 3 Mar 2024 10:52:02 +0400 Subject: [PATCH 1/5] update params to update array of string --- src/main/java/com/amadeus/Params.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/amadeus/Params.java b/src/main/java/com/amadeus/Params.java index e08c689a..b4e3988c 100644 --- a/src/main/java/com/amadeus/Params.java +++ b/src/main/java/com/amadeus/Params.java @@ -3,6 +3,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -48,6 +49,11 @@ public static Params with(@NonNull String key, Object value) { * @return the Param object, allowing for convenient chaining */ public Params and(@NonNull String key, Object value) { + if(value instanceof List){ + @SuppressWarnings("unchecked") List values = (List) value; + put(key, String.join(",", values)); + return this; + } put(key, String.valueOf(value)); return this; } From 925a6e31fa32f59c419be443aaa30d8ffb3a060a Mon Sep 17 00:00:00 2001 From: Sergei Prokofev Date: Mon, 4 Mar 2024 19:05:30 +0400 Subject: [PATCH 2/5] write test to params's accept array string --- src/test/java/com/amadeus/ParamsTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/com/amadeus/ParamsTest.java b/src/test/java/com/amadeus/ParamsTest.java index 8ec29cb8..fa895977 100644 --- a/src/test/java/com/amadeus/ParamsTest.java +++ b/src/test/java/com/amadeus/ParamsTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test; +import java.util.List; + public class ParamsTest { /** * Params Test. @@ -22,6 +24,11 @@ public class ParamsTest { assertEquals(params.toQueryString(), "bar=234&foo=123"); } + @Test public void testToQueryStringWithList(){ + Params params = Params.with("foo", List.of("id1", "id2")); + assertEquals(params.toQueryString(), "foo=id1%2Cid2"); + } + @Test public void testToQueryStringWithEncodingError() { Params params = Params.with("foo", "123"); params.encoding = "foobar"; From 891e32708f89003704a8a0b9537d51802b3de0eb Mon Sep 17 00:00:00 2001 From: Sergei Prokofev Date: Wed, 6 Mar 2024 17:34:09 +0400 Subject: [PATCH 3/5] corrected code style --- src/main/java/com/amadeus/Params.java | 6 +++--- src/test/java/com/amadeus/ParamsTest.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/amadeus/Params.java b/src/main/java/com/amadeus/Params.java index b4e3988c..be4f42e7 100644 --- a/src/main/java/com/amadeus/Params.java +++ b/src/main/java/com/amadeus/Params.java @@ -49,12 +49,12 @@ public static Params with(@NonNull String key, Object value) { * @return the Param object, allowing for convenient chaining */ public Params and(@NonNull String key, Object value) { - if(value instanceof List){ + if(value instanceof List) { @SuppressWarnings("unchecked") List values = (List) value; put(key, String.join(",", values)); - return this; + } else { + put(key, String.valueOf(value)); } - put(key, String.valueOf(value)); return this; } diff --git a/src/test/java/com/amadeus/ParamsTest.java b/src/test/java/com/amadeus/ParamsTest.java index fa895977..e4bbfb15 100644 --- a/src/test/java/com/amadeus/ParamsTest.java +++ b/src/test/java/com/amadeus/ParamsTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; -import java.util.List; +import java.util.Arrays; public class ParamsTest { /** @@ -24,8 +24,8 @@ public class ParamsTest { assertEquals(params.toQueryString(), "bar=234&foo=123"); } - @Test public void testToQueryStringWithList(){ - Params params = Params.with("foo", List.of("id1", "id2")); + @Test public void testToQueryStringWithList() { + Params params = Params.with("foo", Arrays.asList("id1", "id2")); assertEquals(params.toQueryString(), "foo=id1%2Cid2"); } From 1ba992af9351e8e694edf46f30f180720ae7fc9e Mon Sep 17 00:00:00 2001 From: Sergei Prokofev Date: Thu, 7 Mar 2024 12:57:56 +0400 Subject: [PATCH 4/5] add whitespace around if --- src/main/java/com/amadeus/Params.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/amadeus/Params.java b/src/main/java/com/amadeus/Params.java index be4f42e7..1d26313d 100644 --- a/src/main/java/com/amadeus/Params.java +++ b/src/main/java/com/amadeus/Params.java @@ -49,7 +49,7 @@ public static Params with(@NonNull String key, Object value) { * @return the Param object, allowing for convenient chaining */ public Params and(@NonNull String key, Object value) { - if(value instanceof List) { + if (value instanceof List) { @SuppressWarnings("unchecked") List values = (List) value; put(key, String.join(",", values)); } else { From f49c3bf5537f4b4c9cde54fca76c479d715af31c Mon Sep 17 00:00:00 2001 From: Sergei Prokofev Date: Thu, 7 Mar 2024 22:50:49 +0400 Subject: [PATCH 5/5] corrected imports order in ParamsTest --- src/test/java/com/amadeus/ParamsTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/amadeus/ParamsTest.java b/src/test/java/com/amadeus/ParamsTest.java index e4bbfb15..f2b76e91 100644 --- a/src/test/java/com/amadeus/ParamsTest.java +++ b/src/test/java/com/amadeus/ParamsTest.java @@ -3,9 +3,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; - import java.util.Arrays; +import org.junit.jupiter.api.Test; public class ParamsTest { /**