use of org.hamcrest.CustomTypeSafeMatcher in project beam by apache.
the class DisplayDataTest method testJsonSerializationAnonymousClassNamespace.
@Test
public void testJsonSerializationAnonymousClassNamespace() throws IOException {
HasDisplayData component = new HasDisplayData() {
@Override
public void populateDisplayData(Builder builder) {
builder.add(DisplayData.item("foo", "bar"));
}
};
DisplayData data = DisplayData.from(component);
JsonNode json = MAPPER.readTree(MAPPER.writeValueAsBytes(data));
String namespace = json.elements().next().get("namespace").asText();
final Pattern anonClassRegex = Pattern.compile(Pattern.quote(DisplayDataTest.class.getName()) + "\\$\\d+$");
assertThat(namespace, new CustomTypeSafeMatcher<String>("anonymous class regex: " + anonClassRegex) {
@Override
protected boolean matchesSafely(String item) {
java.util.regex.Matcher m = anonClassRegex.matcher(item);
return m.matches();
}
});
}
Aggregations