@Test public void toStringContainsTheImportantFields() throws Exception { assertThat(newEmptyReference().toString()).isEqualTo("Reference{typeId='typeId', id='123', obj=null}"); assertThat(newFilledReference().toString()).isEqualTo("Reference{typeId='typeId', id='123', obj=TestEntity{foo='value'}}"); }
@Test public void serializationDoesNotContainReferencedObject() throws Exception { assertThat(newObjectMapper().writeValueAsString(newFilledReference())).isEqualTo("{\"typeId\":\"typeId\",\"id\":\"123\"}"); }
@Test public void deserializationCanContainExpandedObject() throws Exception { final String json = String.format("{\"typeId\":\"%s\",\"id\": \"%s\",\"obj\":{\"foo\":\"value\"}}", typeId, id); final Reference<TestEntity> actual = newObjectMapper().readValue(json, TypeReferenceTestImpl.of()); assertThat(actual).isEqualTo(newFilledReference()); }
@Test public void implementEquals() throws Exception { assertThat(newFilledReference()).isEqualTo(newFilledReference()); assertThat(newEmptyReference()).isEqualTo(newEmptyReference()); assertThat(newFilledReference()).isEqualTo(newEmptyReference()); assertThat(newFilledReference()).isEqualTo(newEmptyReference().filled(new TestEntity("other value"))); assertThat(Reference.<String>of(typeId, "Foo", "x")).isNotEqualTo(newEmptyReference()); assertThat(Reference.<String>ofResourceTypeIdAndIdAndObj(typeId, "Foo", "x")).isNotEqualTo(newEmptyReference()); }
@Test public void createFilledReference() throws Exception { final Reference<TestEntity> reference = newFilledReference(); assertThat(reference.getId()).isEqualTo(id); assertThat(reference.getTypeId()).isEqualTo(typeId); assertThat(reference.getObj()).isEqualTo(new TestEntity("value")); }