assertThat(e.content()).isEqualTo("foo"); assertThat(e.contentAsText()).isEqualTo("foo"); assertThat(e.contentAsPrettyText()).isEqualTo("foo"); assertThatThrownBy(e::contentAsJson).isInstanceOf(JsonParseException.class); assertThatThrownBy(() -> e.contentAsJson(JsonNode.class)).isInstanceOf(JsonParseException.class);
@Test public void ofJson() throws Exception { final Entry<JsonNode> e = Entry.ofJson(new Revision(1), "/a.json", "{ \"foo\": \"bar\" }"); assertThat(e.revision()).isEqualTo(new Revision(1)); assertThat(e.hasContent()).isTrue(); e.ifHasContent(content -> assertThatJson(content).isEqualTo("{ \"foo\": \"bar\" }")); assertThatJson(e.content()).isEqualTo("{ \"foo\": \"bar\" }"); assertThat(e.contentAsText()).isEqualTo("{\"foo\":\"bar\"}"); assertThat(e.contentAsPrettyText()).isEqualTo("{\n \"foo\": \"bar\"\n}"); assertThat(e.content()).isSameAs(e.contentAsJson()); assertThat(e.content()).isEqualTo(e.contentAsJson(JsonNode.class)); // JSON file vs. JSON file final Entry<JsonNode> e2 = Entry.ofJson(new Revision(1), "/a.json", "{ \"foo\": \"bar\" }"); assertThat(e).isEqualTo(e2); assertThat(e.hashCode()).isEqualTo(e2.hashCode()); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(2), "/a.json", "{ \"foo\": \"bar\" }")); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(1), "/b.json", "{ \"foo\": \"bar\" }")); assertThat(e).isNotEqualTo(Entry.ofJson(new Revision(1), "/a.json", "null")); // JSON file vs. text file final Entry<String> e3 = Entry.ofText(new Revision(1), "/a.json", "{\"foo\":\"bar\"}"); assertThat(e).isNotEqualTo(e3); assertThat(e.hashCode()).isNotEqualTo(e3.hashCode()); // JSON file vs. directory final Entry<Void> e4 = Entry.ofDirectory(new Revision(1), "/foo"); assertThat(e).isNotEqualTo(e4); assertThat(e.hashCode()).isNotEqualTo(e4.hashCode()); }