Skip to content

Commit

Permalink
Stabilize JSON serialization of potentially flakey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joschi committed May 14, 2020
1 parent 818fbb9 commit c231ba3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.dropwizard.jackson;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import javax.annotation.Nullable;
import java.util.UUID;

@JsonPropertyOrder(alphabetic = true) // For deterministic serialization
public class Issue1627 {

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,8 @@ private void testValidatedCollectionType(Class<?> klass, Type type) throws IOExc
new MultivaluedHashMap<>(),
entity);

assertThat(obj)
.isInstanceOf(klass);

Iterator<Example> iterator = ((Iterable<Example>) obj).iterator();
assertThat(iterator.next().id).isEqualTo(1);
assertThat(iterator.next().id).isEqualTo(2);
assertThat(obj).isInstanceOf(klass);
assertThat((Iterable<Example>) obj).extracting(item -> item.id).contains(1 , 2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import static org.assertj.core.api.Assertions.assertThat;

public class JsonFormatterTest {

private final Map<String, Object> map = Maps.of(
private final SortedMap<String, Object> map = new TreeMap<>(Maps.of(
"name", "Jim",
"hobbies", Arrays.asList("Reading", "Biking", "Snorkeling"));
"hobbies", Arrays.asList("Reading", "Biking", "Snorkeling")));
private final ObjectMapper objectMapper = Jackson.newObjectMapper();

@Test
Expand Down

0 comments on commit c231ba3

Please sign in to comment.