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
Changes from 4 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
27 changes: 15 additions & 12 deletions gson/src/test/java/com/google/gson/functional/CollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,38 @@ public void testQueueDeserialization() {
}

public void testPriorityQueue() throws Exception {
int[] value = {10, 20, 22};
Type type = new TypeToken<PriorityQueue<Integer>>(){}.getType();
PriorityQueue<Integer> queue = gson.fromJson("[10, 20, 22]", type);
assertEquals(3, queue.size());
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());
for (int i = 0; i < value.length; i++){
assertEquals(value[i], queue.remove().intValue());
}
assertEquals("[10,20,22]", json);
}

public void testVector() {
int[] value = {10, 20, 31};
Type type = new TypeToken<Vector<Integer>>(){}.getType();
Vector<Integer> 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());
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);
}

public void testStack() {
int[] value = {11, 13, 17};
Type type = new TypeToken<Stack<Integer>>(){}.getType();
Stack<Integer> target = gson.fromJson("[11, 13, 17]", type);
assertEquals(3, target.size());
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());
for (int i = 2; i > 0; i--){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be >= 0, otherwise it misses the element at value[0]. Maybe would also be good to to replace the 2 with value.length - 1.

assertEquals(value[i], target.pop().intValue());
}
assertEquals("[11,13,17]", json);
}

Expand Down