Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of magic numbers in CollectionTest #2091

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
999e279
Merge pull request #1 from google/master
Lhandi29 Mar 1, 2022
51e723f
fix: remove Magic number in CollectionTest
Lhandi29 Mar 15, 2022
996eca1
fix: remove Magic number in CollectionTest
Lhandi29 Mar 15, 2022
abf30d5
fix: remove Magic number in CollectionTest
Lhandi29 Mar 22, 2022
f776d6c
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
feefe22
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
10ea6e8
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
1c359de
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
e8776a2
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
3c7feb8
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
38b729d
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
e9e9e67
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
f443276
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
3cafb34
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
0c660b4
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
a3e6cd7
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
1d50e3a
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
49e355d
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
7819e74
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
372852b
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
8fa2869
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
098d7bb
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
d879fe5
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
2a25a9a
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
5cfcda6
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
0a4dfb9
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
3d83b70
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
7b5b11d
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
9f491ec
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
3bc33d9
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
62dd893
JUnit assertion to Truth assertion
Lhandi29 Apr 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
</dependency>
</dependencies>

<build>
Expand All @@ -41,6 +45,10 @@
</configuration>
</execution>
</executions>
<configuration>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required for your change to work?

<source>9</source>
<target>9</target>
</configuration>
</plugin>
<!-- Note: Javadoc plugin has to be run in combination with >= `package`
phase, e.g. `mvn package javadoc:javadoc`, otherwise it fails with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import com.google.gson.reflect.TypeToken;

import junit.framework.TestCase;

import static org.junit.Assert.assertArrayEquals;
import static com.google.common.truth.Truth.assertThat;

/**
* Functional tests for Json serialization and deserialization of collections.
Expand Down Expand Up @@ -157,7 +159,7 @@ public void testStack() {
Stack<Integer> target = gson.fromJson("[11, 13, 17]", type);
assertEquals(value.length, target.size());
String json = gson.toJson(target);
for (int i = 2; i > 0; i--){
for (int i = (value.length - 1); i >= 0; i--){
assertEquals(value[i], target.pop().intValue());
}
assertEquals("[11,13,17]", json);
Expand Down Expand Up @@ -235,13 +237,14 @@ public void testCollectionOfStringsDeserialization() {
Type collectionType = new TypeToken<Collection<String>>() { }.getType();
Collection<String> target = gson.fromJson(json, collectionType);

assertTrue(target.contains("Hello"));
assertTrue(target.contains("World"));
//assertTrue(target.contains("Hello"));
assertThat(target.contains("Hello")).isTrue();
assertThat(target.contains("World")).isTrue();
}

public void testRawCollectionOfIntegersSerialization() {
Collection<Integer> target = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
assertEquals("[1,2,3,4,5,6,7,8,9]", gson.toJson(target));
assertThat(gson.toJson(target)).contains("[1,2,3,4,5,6,7,8,9]");
}

@SuppressWarnings("rawtypes")
Expand All @@ -257,7 +260,7 @@ public void testRawCollectionDeserializationNotAlllowed() {
String json = "[0,1,2,3,4,5,6,7,8,9]";
Collection integers = gson.fromJson(json, Collection.class);
// JsonReader converts numbers to double by default so we need a floating point comparison
assertEquals(Arrays.asList(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0), integers);
assertThat(integers).containsAtLeast(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);

json = "[\"Hello\", \"World\"]";
Collection strings = gson.fromJson(json, Collection.class);
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down