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

Fix flaky test in CustomTypeAdaptersTest #2523

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -125,7 +125,8 @@ public void testCustomNestedSerializers() {
}
}).create();
ClassWithCustomTypeConverter target = new ClassWithCustomTypeConverter();
assertThat(gson.toJson(target)).isEqualTo("{\"bag\":6,\"value\":10}");
String targetStr = gson.toJson(target);
assertThat(targetStr.equals("{\"bag\":6,\"value\":10}") || targetStr.equals("{\"value\":10,\"bag\":6}")).isTrue();
Comment on lines +128 to +129
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, instead of using .equals()s, you can you the .isAnyOf(obj1, obj2) method.
According with the .isAnyOf() documentation:

Fails unless the subject is equal to any of the given elements.

The assert could be something like:

Suggested change
String targetStr = gson.toJson(target);
assertThat(targetStr.equals("{\"bag\":6,\"value\":10}") || targetStr.equals("{\"value\":10,\"bag\":6}")).isTrue();
assertThat(gson.toJson(target)).isAnyOf("{\"bag\":6,\"value\":10}", "{\"value\":10,\"bag\":6}");

Note: I am not a maintainer of the project, please wait for a maintainer's review

}

@Test
Expand Down