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 tests in guava. #1

Open
wants to merge 1 commit into
base: 2.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.common.collect.Sets;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONException;
import org.skyscreamer.jsonassert.JSONAssert;

/**
* Unit tests to verify serialization of {@link FluentIterable}s.
Expand All @@ -25,6 +27,13 @@ static FluentIterable<Integer> createFluentIterable() {
* or Guava's implementation of FluentIterable changes.
* @throws Exception
*/
private void assertJsonEqualsNonStrict(String json0, String json1) {
try {
JSONAssert.assertEquals(json0, json1, false);
} catch (JSONException jse) {
throw new IllegalArgumentException(jse.getMessage());
}
}
public void testSerializationWithoutModule() throws Exception {
ObjectMapper mapper = new ObjectMapper();
FluentHolder holder = new FluentHolder();
Expand All @@ -34,13 +43,13 @@ public void testSerializationWithoutModule() throws Exception {

public void testSerialization() throws Exception {
String json = MAPPER.writeValueAsString(createFluentIterable());
assertEquals("[1,2,3]", json);
assertJsonEqualsNonStrict("[1,2,3]", json);
}

public void testWrappedSerialization() throws Exception {
FluentHolder holder = new FluentHolder();
String json = MAPPER.writeValueAsString(holder);
assertEquals("{\"value\":[1,2,3]}", json);
assertJsonEqualsNonStrict("{\"value\":[1,2,3]}", json);
}

}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
</scm>

<dependencies>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down