From 51e723f6fdb9f758b0b5841cb4a686c03d3459a3 Mon Sep 17 00:00:00 2001 From: Lyes Date: Tue, 15 Mar 2022 11:22:26 +0100 Subject: [PATCH 01/30] fix: remove Magic number in CollectionTest --- .../com/google/gson/functional/CollectionTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gson/src/test/java/com/google/gson/functional/CollectionTest.java b/gson/src/test/java/com/google/gson/functional/CollectionTest.java index 8d831a63e9..b1009c13ea 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -128,14 +128,16 @@ public void testQueueDeserialization() { } public void testPriorityQueue() throws Exception { + int[] value = {10, 20, 22}; + String stringToSerialize = value.toString(); Type type = new TypeToken>(){}.getType(); - PriorityQueue queue = gson.fromJson("[10, 20, 22]", type); - assertEquals(3, queue.size()); + PriorityQueue queue = gson.fromJson(stringToSerialize, type); + assertEquals(value.length, queue.size()); String json = gson.toJson(queue); - assertEquals(10, queue.remove().intValue()); - assertEquals(20, queue.remove().intValue()); - assertEquals(22, queue.remove().intValue()); - assertEquals("[10,20,22]", json); + for (int i = 0; i< value.length; i++){ + assertEquals(value[i], queue.remove().intValue()); + } + assertEquals(stringToSerialize, json); } public void testVector() { From 996eca1df017ce4123af123a17985c8fcd7c9dc8 Mon Sep 17 00:00:00 2001 From: Lyes Date: Tue, 15 Mar 2022 11:36:42 +0100 Subject: [PATCH 02/30] fix: remove Magic number in CollectionTest --- .../gson/functional/CollectionTest.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/gson/src/test/java/com/google/gson/functional/CollectionTest.java b/gson/src/test/java/com/google/gson/functional/CollectionTest.java index b1009c13ea..6a883eff9d 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -134,32 +134,36 @@ public void testPriorityQueue() throws Exception { PriorityQueue queue = gson.fromJson(stringToSerialize, type); assertEquals(value.length, queue.size()); String json = gson.toJson(queue); - for (int i = 0; i< value.length; i++){ + for (int i = 0; i < value.length; i++){ assertEquals(value[i], queue.remove().intValue()); } assertEquals(stringToSerialize, json); } public void testVector() { + int[] value = {10, 20, 31}; + String stringToSerialize = value.toString(); Type type = new TypeToken>(){}.getType(); - Vector target = gson.fromJson("[10, 20, 31]", type); - assertEquals(3, target.size()); - assertEquals(10, target.get(0).intValue()); - assertEquals(20, target.get(1).intValue()); - assertEquals(31, target.get(2).intValue()); + Vector target = gson.fromJson(stringToSerialize, type); + assertEquals(value.length, target.size()); + for (int i = 0; i < value.length; i++){ + assertEquals(value[i], target.get(i).intValue()); + } String json = gson.toJson(target); - assertEquals("[10,20,31]", json); + assertEquals(stringToSerialize, json); } public void testStack() { + int[] value = {11, 13, 17}; + String stringToSerialize = value.toString(); Type type = new TypeToken>(){}.getType(); - Stack target = gson.fromJson("[11, 13, 17]", type); - assertEquals(3, target.size()); + Stack target = gson.fromJson(stringToSerialize, type); + assertEquals(value.length, target.size()); String json = gson.toJson(target); - assertEquals(17, target.pop().intValue()); - assertEquals(13, target.pop().intValue()); - assertEquals(11, target.pop().intValue()); - assertEquals("[11,13,17]", json); + for (int i = 3; i > 0; i--){ + assertEquals(value[i], target.pop().intValue()); + } + assertEquals(stringToSerialize, json); } public void testNullsInListSerialization() { From abf30d5439395eae90c2778830b511bfb6bdf9ac Mon Sep 17 00:00:00 2001 From: Lyes Date: Tue, 22 Mar 2022 10:51:20 +0100 Subject: [PATCH 03/30] fix: remove Magic number in CollectionTest --- .../google/gson/functional/CollectionTest.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/gson/src/test/java/com/google/gson/functional/CollectionTest.java b/gson/src/test/java/com/google/gson/functional/CollectionTest.java index 6a883eff9d..553a24bb28 100644 --- a/gson/src/test/java/com/google/gson/functional/CollectionTest.java +++ b/gson/src/test/java/com/google/gson/functional/CollectionTest.java @@ -129,41 +129,38 @@ public void testQueueDeserialization() { public void testPriorityQueue() throws Exception { int[] value = {10, 20, 22}; - String stringToSerialize = value.toString(); Type type = new TypeToken>(){}.getType(); - PriorityQueue queue = gson.fromJson(stringToSerialize, type); + PriorityQueue queue = gson.fromJson("[10, 20, 22]", type); assertEquals(value.length, queue.size()); String json = gson.toJson(queue); for (int i = 0; i < value.length; i++){ assertEquals(value[i], queue.remove().intValue()); } - assertEquals(stringToSerialize, json); + assertEquals("[10,20,22]", json); } public void testVector() { int[] value = {10, 20, 31}; - String stringToSerialize = value.toString(); Type type = new TypeToken>(){}.getType(); - Vector target = gson.fromJson(stringToSerialize, type); + Vector target = gson.fromJson("[10, 20, 31]", type); assertEquals(value.length, target.size()); for (int i = 0; i < value.length; i++){ assertEquals(value[i], target.get(i).intValue()); } String json = gson.toJson(target); - assertEquals(stringToSerialize, json); + assertEquals("[10,20,31]", json); } public void testStack() { int[] value = {11, 13, 17}; - String stringToSerialize = value.toString(); Type type = new TypeToken>(){}.getType(); - Stack target = gson.fromJson(stringToSerialize, type); + Stack target = gson.fromJson("[11, 13, 17]", type); assertEquals(value.length, target.size()); String json = gson.toJson(target); - for (int i = 3; i > 0; i--){ + for (int i = 2; i > 0; i--){ assertEquals(value[i], target.pop().intValue()); } - assertEquals(stringToSerialize, json); + assertEquals("[11,13,17]", json); } public void testNullsInListSerialization() { From f776d6cc6825765846f4d025f1cc462b936e8555 Mon Sep 17 00:00:00 2001 From: Lyes Date: Sun, 10 Apr 2022 18:02:09 +0200 Subject: [PATCH 04/30] JUnit assertion to Truth assertion in CollectionTest.testCollectionOfStringsDeserialization and CollectionTest.testRawCollectionDeserializationNotAlllowed --- gson/pom.xml | 8 ++++++++ .../com/google/gson/functional/CollectionTest.java | 11 +++++++---- pom.xml | 7 +++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gson/pom.xml b/gson/pom.xml index a6eb1f80eb..0ac3c75dd9 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -23,6 +23,10 @@ junit test + + com.google.truth + truth + @@ -41,6 +45,10 @@ + + 9 + 9 +