Skip to content

Commit

Permalink
fix flaky EnumTest
Browse files Browse the repository at this point in the history
  • Loading branch information
219sansim committed Nov 3, 2023
1 parent e685705 commit 6979450
Showing 1 changed file with 8 additions and 4 deletions.
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

0 comments on commit 6979450

Please sign in to comment.