DisplayData implements Serializable { public static DisplayData from(HasDisplayData component) { checkNotNull(component, "component argument cannot be null"); InternalBuilder builder = new InternalBuilder(); builder.include(Path.root(), component); return builder.build(); } private  DisplayData(Map<Identifier, Item> entries); static DisplayData none(); static DisplayData from(HasDisplayData component); static @Nullable Type inferType(@Nullable Object value); @JsonValue Collection<Item> items(); Map<Identifier, Item> asMap(); @Override int hashCode(); @Override boolean equals(@Nullable Object obj); @Override String toString(); static ItemSpec<String> item(String key, @Nullable String value); static ItemSpec<?> item(String key, @Nullable ValueProvider<?> value); static ItemSpec<Integer> item(String key, @Nullable Integer value); static ItemSpec<Long> item(String key, @Nullable Long value); static ItemSpec<Float> item(String key, @Nullable Float value); static ItemSpec<Double> item(String key, @Nullable Double value); static ItemSpec<Boolean> item(String key, @Nullable Boolean value); static ItemSpec<Instant> item(String key, @Nullable Instant value); static ItemSpec<Duration> item(String key, @Nullable Duration value); static ItemSpec<Class<T>> item(String key, @Nullable Class<T> value); static ItemSpec<T> item(String key, Type type, @Nullable T value);  }
@Test public void testIncludesComponentsAtSamePath() { HasDisplayData component = new HasDisplayData() { @Override public void populateDisplayData(Builder builder) { builder.include("p", new NoopDisplayData()).include("p", new NoopDisplayData()); } }; thrown.expectCause(isA(IllegalArgumentException.class)); DisplayData.from(component); }
@Test public void testFromNull() { thrown.expect(NullPointerException.class); DisplayData.from(null); }
@Test public void testIncludeNull() { thrown.expectCause(isA(NullPointerException.class)); DisplayData.from( new HasDisplayData() { @Override public void populateDisplayData(Builder builder) { builder.include("p", null); } }); }
@Test public void testIncludeNullPath() { thrown.expectCause(isA(NullPointerException.class)); DisplayData.from( new HasDisplayData() { @Override public void populateDisplayData(Builder builder) { builder.include(null, new NoopDisplayData()); } }); }
@Test public void testIncludeEmptyPath() { thrown.expectCause(isA(IllegalArgumentException.class)); DisplayData.from( new HasDisplayData() { @Override public void populateDisplayData(Builder builder) { builder.include("", new NoopDisplayData()); } }); }
@Test public void testExceptionMessage() { final RuntimeException cause = new RuntimeException("oh noes!"); HasDisplayData component = new HasDisplayData() { @Override public void populateDisplayData(Builder builder) { throw cause; } }; thrown.expectMessage(component.getClass().getName()); thrown.expectCause(is(cause)); DisplayData.from(component); }
@Test public void testExceptionsNotWrappedRecursively() { final RuntimeException cause = new RuntimeException("oh noes!"); HasDisplayData component = new HasDisplayData() { @Override public void populateDisplayData(Builder builder) { builder.include( "p", new HasDisplayData() { @Override public void populateDisplayData(Builder builder) { throw cause; } }); } }; thrown.expectCause(is(cause)); DisplayData.from(component); }