/** * Combined the current summary with another summary, by summing up individual fields. * * @param other The other summary to be combined with. */ public void combine(AnswerSummary other) { if (other != null) { _notes = (Strings.isNullOrEmpty(_notes)) ? other.getNotes() : _notes + "; " + other.getNotes(); _numFailed += other.getNumFailed(); _numPassed += other.getNumPassed(); _numResults += other.getNumResults(); } }
@Test public void deserializationTest() throws IOException { String summaryStr = "{\"notes\" : \"notes1\", \"numFailed\" : 21, \"numPassed\" : 23, " + "\"numResults\": 42}"; AnswerSummary summary = BatfishObjectMapper.mapper().readValue(summaryStr, AnswerSummary.class); assertThat(summary.getNotes(), equalTo("notes1")); assertThat(summary.getNumFailed(), equalTo(21)); assertThat(summary.getNumPassed(), equalTo(23)); assertThat(summary.getNumResults(), equalTo(42)); }
@Test public void serializationTest() throws IOException { AnswerSummary summary = new AnswerSummary("notes1", 21, 23, 42); // The summary should survive cloning through JSON. AnswerSummary summaryAfter = BatfishObjectMapper.clone(summary, AnswerSummary.class); assertThat(summaryAfter.getNotes(), equalTo("notes1")); assertThat(summaryAfter.getNumFailed(), equalTo(21)); assertThat(summaryAfter.getNumPassed(), equalTo(23)); assertThat(summaryAfter.getNumResults(), equalTo(42)); } }
@Test public void combineTest() { AnswerSummary summary = new AnswerSummary("notes1", 1, 2, 3); AnswerSummary summaryOther = new AnswerSummary("notes2", 4, 5, 6); summary.combine(summaryOther); assertThat(summary.getNotes(), equalTo("notes1; notes2")); assertThat(summary.getNumFailed(), equalTo(5)); assertThat(summary.getNumPassed(), equalTo(7)); assertThat(summary.getNumResults(), equalTo(9)); }