Skip to content

Commit d2f70a7

Browse files
author
sandhu5
committed
fix flaky EnumTest
1 parent e685705 commit d2f70a7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

gson/src/test/java/com/google/gson/functional/EnumTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.EnumSet;
3939
import java.util.Map;
4040
import java.util.Set;
41+
import java.util.HashSet;
4142
import org.junit.Before;
4243
import org.junit.Test;
4344

@@ -93,7 +94,7 @@ public void testCollectionOfEnumsDeserialization() {
9394
@Test
9495
public void testClassWithEnumFieldSerialization() {
9596
ClassWithEnumFields target = new ClassWithEnumFields();
96-
assertThat(gson.toJson(target)).isEqualTo(target.getExpectedJson());
97+
assertThat(target.getExpectedJson().contains(gson.toJson(target))).isTrue();;
9798
}
9899

99100
@Test
@@ -111,9 +112,12 @@ private static enum MyEnum {
111112
private static class ClassWithEnumFields {
112113
private final MyEnum value1 = MyEnum.VALUE1;
113114
private final MyEnum value2 = MyEnum.VALUE2;
114-
public String getExpectedJson() {
115-
return "{\"value1\":\"" + value1 + "\",\"value2\":\"" + value2 + "\"}";
116-
}
115+
public Set<String> getExpectedJson() {
116+
Set<String> possiblejsonvalues = new HashSet<String>();
117+
possiblejsonvalues.add("{\"value1\":\"" + value1 + "\",\"value2\":\"" + value2 + "\"}");
118+
possiblejsonvalues.add("{\"value2\":\"" + value2 + "\",\"value1\":\"" + value1 + "\"}");
119+
return possiblejsonvalues;
120+
}
117121
}
118122

119123
/**

0 commit comments

Comments
 (0)