Skip to content

Port Junit test to Truth in the package com.google.gson of the module gson - #2299

Merged
eamonnmcmanus merged 6 commits into
google:masterfrom
MaicolAntali:truth-asserts
Jan 17, 2023
Merged

Port Junit test to Truth in the package com.google.gson of the module gson#2299
eamonnmcmanus merged 6 commits into
google:masterfrom
MaicolAntali:truth-asserts

Conversation

@MaicolAntali

Copy link
Copy Markdown
Contributor

I have port Junit test to Truth in the package com.google.gson of the module gson

The port doesn't involve the nested packages:

  • com.google.gson.common
  • com.google.gson.functional
  • com.google.gson.internal
  • com.google.gson.metrics
  • com.google.gson.reflect
  • com.google.gson.regression
  • com.google.gson.stream

Note: I also cleanup the code (For example: remove unnecessary unboxing & remove unused throws clausole)

@eamonnmcmanus

Copy link
Copy Markdown
Member

This is fantastic! Thanks very much for doing it. I hope you were able to automate most of the transformations.

Only minor comments...

@MaicolAntali

Copy link
Copy Markdown
Contributor Author

Most welcome!

Only minor comments...

What comments?

@eamonnmcmanus eamonnmcmanus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would help if I published the comments!

Comment thread gson/src/test/java/com/google/gson/GsonBuilderTest.java Outdated
Comment thread gson/src/test/java/com/google/gson/GsonTest.java Outdated
Comment thread gson/src/test/java/com/google/gson/JsonObjectAsMapTest.java Outdated
Comment thread gson/src/test/java/com/google/gson/JsonPrimitiveTest.java Outdated
JsonPrimitive p2 = new JsonPrimitive(Short.valueOf((short)10));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
JsonPrimitive p1 = new JsonPrimitive((byte) 10);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not in this PR, but I think it might make sense to introduce a test-scoped dependency on com.google.guava:guava-testlib. A large number of the assertions in this class could be reduced to a single large call to EqualsTester. It checks that test objects in the same "equality group" are all pairwise equal and have equal hash-codes, and that objects not in the same "equality group" are not equal.

We could also use guava-testlib to simplify JsonArrayAsListTest and JsonObjectAsMapTest and probably some other tests, via ListTestSuiteBuilder and the like, though the JUnit 3 API is unfortunate. Again, not in this PR, but worth thinking about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, make sense. Probably the next step would be implement Truth in all of the nested packages. After that we could think to implement guava and simplify some tests.

Comment thread gson/src/test/java/com/google/gson/FieldNamingPolicyTest.java Outdated
@eamonnmcmanus

Copy link
Copy Markdown
Member

Thanks again!

@eamonnmcmanus
eamonnmcmanus merged commit be87c3f into google:master Jan 17, 2023
@MaicolAntali
MaicolAntali deleted the truth-asserts branch January 18, 2023 14:14
tibor-universe pushed a commit to getuniverse/gson that referenced this pull request Sep 14, 2024
…le `gson` (google#2299)

* Add the Truth dependency

* Port Junit test to Truth in the package `com.google.gson` of the module `gson`

* Replace the `assertThat(e.getMessage()).isEqualTo(...)"` with `assertThat(e).hasMessageThat().isEqualTo(...)`

* Minor fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants