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

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

Merged
merged 6 commits into from
Jan 17, 2023

Conversation

MaicolAntali
Copy link
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
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
Contributor Author

Most welcome!

Only minor comments...

What comments?

Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

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!

gson/src/test/java/com/google/gson/GsonBuilderTest.java Outdated Show resolved Hide resolved
gson/src/test/java/com/google/gson/GsonTest.java Outdated Show resolved Hide resolved
gson/src/test/java/com/google/gson/JsonPrimitiveTest.java Outdated Show resolved Hide resolved
JsonPrimitive p2 = new JsonPrimitive(Short.valueOf((short)10));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
JsonPrimitive p1 = new JsonPrimitive((byte) 10);
Copy link
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
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.

@eamonnmcmanus
Copy link
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