From c8ff2644da8e50759f1d35cf3be3dc745aa13415 Mon Sep 17 00:00:00 2001 From: salander85 Date: Mon, 6 Nov 2023 16:17:39 +0100 Subject: [PATCH 1/7] Override toString method using reflection. --- .../api/models/common/LocalizedStringImpl.java | 7 +++++++ .../test/java/com/commercetools/LocalizedStringTest.java | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java index 69d19957556..df56e598d3f 100644 --- a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java +++ b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java @@ -13,6 +13,8 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import static java.util.stream.Collectors.joining; + /** * LocalizedString implementation */ @@ -57,4 +59,9 @@ public int hashCode() { return new HashCodeBuilder(17, 37).append(values).toHashCode(); } + @Override + public String toString() { + return reflectionString(); + } + } diff --git a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java index e147dbc471c..1d1cc2f2780 100644 --- a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java +++ b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java @@ -13,6 +13,7 @@ import com.commercetools.api.models.common.LocalizedString; import com.commercetools.api.models.common.LocalizedStringEntry; +import com.commercetools.api.models.common.LocalizedStringImpl; import io.vrap.rmf.base.client.ModelBase; import io.vrap.rmf.base.client.utils.json.JsonUtils; @@ -186,7 +187,7 @@ public void returnPresentLocales() throws Exception { @Test public void implementToString() throws Exception { - assertThat(((ModelBase) LOCALIZED_STRING).reflectionString()) + assertThat(LOCALIZED_STRING.toString()) .isEqualTo(format("LocalizedStringImpl[values={de=%s, en=%s}]", DEFAULT_STRING_1, DEFAULT_STRING_2)); } From aed7d88ae109071c30a2a5fc45eb675917f726cb Mon Sep 17 00:00:00 2001 From: Auto Mation Date: Mon, 6 Nov 2023 15:21:34 +0000 Subject: [PATCH 2/7] spotless: Fix code style --- .../commercetools/api/models/common/LocalizedStringImpl.java | 2 -- .../src/test/java/com/commercetools/LocalizedStringTest.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java index df56e598d3f..5ea86b6b813 100644 --- a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java +++ b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java @@ -13,8 +13,6 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import static java.util.stream.Collectors.joining; - /** * LocalizedString implementation */ diff --git a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java index 1d1cc2f2780..fc61f044729 100644 --- a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java +++ b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java @@ -13,8 +13,6 @@ import com.commercetools.api.models.common.LocalizedString; import com.commercetools.api.models.common.LocalizedStringEntry; -import com.commercetools.api.models.common.LocalizedStringImpl; -import io.vrap.rmf.base.client.ModelBase; import io.vrap.rmf.base.client.utils.json.JsonUtils; import org.apache.commons.lang3.StringUtils; From bbb6a7f9386f73606c7b1950af8003dd82c44078 Mon Sep 17 00:00:00 2001 From: salander85 Date: Mon, 13 Nov 2023 14:04:53 +0100 Subject: [PATCH 3/7] Add toString method in LocalizedString --- .../api/models/common/LocalizedStringImpl.java | 11 ++++++++++- .../java/com/commercetools/LocalizedStringTest.java | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java index 5ea86b6b813..c79bafe525e 100644 --- a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java +++ b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java @@ -13,6 +13,8 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import static java.util.stream.Collectors.joining; + /** * LocalizedString implementation */ @@ -59,7 +61,14 @@ public int hashCode() { @Override public String toString() { - return reflectionString(); + return "LocalizedStringImpl(" + + values + .entrySet() + .stream() + .sorted(Comparator.comparing(Map.Entry::getKey)) + .map(entry -> entry.getKey() + " -> " + entry.getValue()) + .collect(joining(", ")) + + ")"; } } diff --git a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java index fc61f044729..b02bed75a25 100644 --- a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java +++ b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java @@ -13,6 +13,7 @@ import com.commercetools.api.models.common.LocalizedString; import com.commercetools.api.models.common.LocalizedStringEntry; +import io.vrap.rmf.base.client.ModelBase; import io.vrap.rmf.base.client.utils.json.JsonUtils; import org.apache.commons.lang3.StringUtils; @@ -185,8 +186,10 @@ public void returnPresentLocales() throws Exception { @Test public void implementToString() throws Exception { - assertThat(LOCALIZED_STRING.toString()) + assertThat(((ModelBase) LOCALIZED_STRING).reflectionString()) .isEqualTo(format("LocalizedStringImpl[values={de=%s, en=%s}]", DEFAULT_STRING_1, DEFAULT_STRING_2)); + assertThat(LOCALIZED_STRING.toString()) + .isEqualTo(format("LocalizedStringImpl(de->%s, en->%s)", DEFAULT_STRING_1, DEFAULT_STRING_2)); } @Test From bfbc003aac1e66c5b92ed84afbbb2e46dcfcc5f0 Mon Sep 17 00:00:00 2001 From: Auto Mation Date: Mon, 13 Nov 2023 13:07:27 +0000 Subject: [PATCH 4/7] spotless: Fix code style --- .../api/models/common/LocalizedStringImpl.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java index c79bafe525e..2bb68018832 100644 --- a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java +++ b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java @@ -1,6 +1,8 @@ package com.commercetools.api.models.common; +import static java.util.stream.Collectors.joining; + import java.time.*; import java.util.*; @@ -13,8 +15,6 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import static java.util.stream.Collectors.joining; - /** * LocalizedString implementation */ @@ -61,14 +61,11 @@ public int hashCode() { @Override public String toString() { - return "LocalizedStringImpl(" + - values - .entrySet() - .stream() - .sorted(Comparator.comparing(Map.Entry::getKey)) - .map(entry -> entry.getKey() + " -> " + entry.getValue()) - .collect(joining(", ")) - + ")"; + return "LocalizedStringImpl(" + values.entrySet() + .stream() + .sorted(Comparator.comparing(Map.Entry::getKey)) + .map(entry -> entry.getKey() + " -> " + entry.getValue()) + .collect(joining(", ")) + ")"; } } From 600df35a7e99627ff4a3a04888cf27a99d6af3e4 Mon Sep 17 00:00:00 2001 From: salander85 Date: Mon, 13 Nov 2023 14:22:18 +0100 Subject: [PATCH 5/7] Correct test --- .../src/test/java/com/commercetools/LocalizedStringTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java index b02bed75a25..021dbf046b7 100644 --- a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java +++ b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java @@ -189,7 +189,7 @@ public void implementToString() throws Exception { assertThat(((ModelBase) LOCALIZED_STRING).reflectionString()) .isEqualTo(format("LocalizedStringImpl[values={de=%s, en=%s}]", DEFAULT_STRING_1, DEFAULT_STRING_2)); assertThat(LOCALIZED_STRING.toString()) - .isEqualTo(format("LocalizedStringImpl(de->%s, en->%s)", DEFAULT_STRING_1, DEFAULT_STRING_2)); + .isEqualTo(format("LocalizedStringImpl(de -> %s, en -> %s)", DEFAULT_STRING_1, DEFAULT_STRING_2)); } @Test From 8dddfb764545db466e5214547463eeb88a691ec5 Mon Sep 17 00:00:00 2001 From: salander85 Date: Mon, 13 Nov 2023 14:26:47 +0100 Subject: [PATCH 6/7] Use ToStringBuilder --- .../api/models/common/LocalizedStringImpl.java | 10 +++++----- .../java/com/commercetools/LocalizedStringTest.java | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java index 2bb68018832..b8c5f58d4fe 100644 --- a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java +++ b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java @@ -14,6 +14,8 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; /** * LocalizedString implementation @@ -61,11 +63,9 @@ public int hashCode() { @Override public String toString() { - return "LocalizedStringImpl(" + values.entrySet() - .stream() - .sorted(Comparator.comparing(Map.Entry::getKey)) - .map(entry -> entry.getKey() + " -> " + entry.getValue()) - .collect(joining(", ")) + ")"; + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + .append("values", values) + .build(); } } diff --git a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java index 021dbf046b7..297f153dfbd 100644 --- a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java +++ b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java @@ -186,10 +186,8 @@ public void returnPresentLocales() throws Exception { @Test public void implementToString() throws Exception { - assertThat(((ModelBase) LOCALIZED_STRING).reflectionString()) - .isEqualTo(format("LocalizedStringImpl[values={de=%s, en=%s}]", DEFAULT_STRING_1, DEFAULT_STRING_2)); assertThat(LOCALIZED_STRING.toString()) - .isEqualTo(format("LocalizedStringImpl(de -> %s, en -> %s)", DEFAULT_STRING_1, DEFAULT_STRING_2)); + .isEqualTo(format("LocalizedStringImpl[values={de=%s, en=%s}]", DEFAULT_STRING_1, DEFAULT_STRING_2)); } @Test From 3f1808b6d7f3d22b5472a38a4bf2972077e3182c Mon Sep 17 00:00:00 2001 From: Auto Mation Date: Mon, 13 Nov 2023 13:29:18 +0000 Subject: [PATCH 7/7] spotless: Fix code style --- .../api/models/common/LocalizedStringImpl.java | 6 +----- .../test/java/com/commercetools/LocalizedStringTest.java | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java index b8c5f58d4fe..a70872a232d 100644 --- a/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java +++ b/commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/models/common/LocalizedStringImpl.java @@ -1,8 +1,6 @@ package com.commercetools.api.models.common; -import static java.util.stream.Collectors.joining; - import java.time.*; import java.util.*; @@ -63,9 +61,7 @@ public int hashCode() { @Override public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) - .append("values", values) - .build(); + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("values", values).build(); } } diff --git a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java index 297f153dfbd..fc61f044729 100644 --- a/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java +++ b/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/LocalizedStringTest.java @@ -13,7 +13,6 @@ import com.commercetools.api.models.common.LocalizedString; import com.commercetools.api.models.common.LocalizedStringEntry; -import io.vrap.rmf.base.client.ModelBase; import io.vrap.rmf.base.client.utils.json.JsonUtils; import org.apache.commons.lang3.StringUtils;