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 EnumTest #2522

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
12 changes: 8 additions & 4 deletions gson/src/test/java/com/google/gson/functional/EnumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -93,7 +94,7 @@ public void testCollectionOfEnumsDeserialization() {
@Test
public void testClassWithEnumFieldSerialization() {
ClassWithEnumFields target = new ClassWithEnumFields();
assertThat(gson.toJson(target)).isEqualTo(target.getExpectedJson());
assertThat(target.getExpectedJson().contains(gson.toJson(target))).isTrue();;
}

@Test
Expand All @@ -111,9 +112,12 @@ private static enum MyEnum {
private static class ClassWithEnumFields {
private final MyEnum value1 = MyEnum.VALUE1;
private final MyEnum value2 = MyEnum.VALUE2;
public String getExpectedJson() {
return "{\"value1\":\"" + value1 + "\",\"value2\":\"" + value2 + "\"}";
}
public Set<String> getExpectedJson() {
Set<String> possiblejsonvalues = new HashSet<String>();
possiblejsonvalues.add("{\"value1\":\"" + value1 + "\",\"value2\":\"" + value2 + "\"}");
possiblejsonvalues.add("{\"value2\":\"" + value2 + "\",\"value1\":\"" + value1 + "\"}");
return possiblejsonvalues;
}
}

/**
Expand Down