DefaultBlameManager implements BlameManager { @Override public <R, E> AnnotatedContent<R, E> blame(AnnotatedContent<R, E> content, R revision, List<E> previous) { if (content == null) { if (previous == null || revision == null) { return null; } return new DefaultAnnotatedContent<>(revision, previous); } if (!(content instanceof DefaultAnnotatedContent)) { throw new IllegalArgumentException("Incompatible annotated content type provided"); } ((DefaultAnnotatedContent<R, E>) content).analyseRevision(revision, previous); return content; }  @Override AnnotatedContent<R, E> blame(AnnotatedContent<R, E> content, R revision, List<E> previous);  }
@Test void blameNullRevision() { assertThat(blameManager.blame(null, null, null), nullValue()); assertThat(blameManager.blame(null, null, Collections.<String>emptyList()), nullValue()); assertThat(blameManager.blame(null, new Object(), null), nullValue()); }
@Test void blame() { Revision rev1 = new Revision("rev1"); Revision rev2 = new Revision("rev2"); Revision rev3 = new Revision("rev3"); AnnotatedContent<Revision, String> annotatedContent = blameManager.blame(null, rev3, Arrays.asList( "Jackdaws love my big sphinx of quartz.", "Cozy lummox gives smart squid who asks for job pen.", "The quick red fox", "jumps over", "the lazy dog")); assertThat(annotatedContent.isEntirelyAnnotated(), is(false)); assertThat(annotatedContent.getOldestRevision(), sameInstance(rev3)); annotatedContent = blameManager.blame(annotatedContent, rev2, Arrays.asList( "Cozy lummox gives smart squid who asks for job pen.", "The quick red fox", "jumps over the lazy dog")); assertThat(annotatedContent.isEntirelyAnnotated(), is(false)); assertThat(annotatedContent.getOldestRevision(), sameInstance(rev2)); annotatedContent = blameManager.blame(annotatedContent, rev1, Arrays.asList( "Cozy lummox gives smart squid who asks for job pen.", "The quick brown fox", "jumps over the lazy dog.")); assertThat(annotatedContent.isEntirelyAnnotated(), is(false)); assertThat(annotatedContent.getOldestRevision(), sameInstance(rev1)); annotatedContent = blameManager.blame(annotatedContent, null, null); assertThat(annotatedContent.isEntirelyAnnotated(), is(true)); assertThat(annotatedContent.getOldestRevision(), nullValue()); Iterator<AnnotatedElement<Revision, String>> iter = annotatedContent.iterator(); assertThat(iter.hasNext(), is(true)); AnnotatedElement<Revision, String> annotatedElement = iter.next(); assertThat(annotatedElement.getElement(), is("Jackdaws love my big sphinx of quartz.")); assertThat(annotatedElement.getRevision(), sameInstance(rev3)); assertThat(iter.hasNext(), is(true)); annotatedElement = iter.next(); assertThat(annotatedElement.getElement(), is("Cozy lummox gives smart squid who asks for job pen.")); assertThat(annotatedElement.getRevision(), sameInstance(rev1)); assertThat(iter.hasNext(), is(true)); annotatedElement = iter.next(); assertThat(annotatedElement.getElement(), is("The quick red fox")); assertThat(annotatedElement.getRevision(), sameInstance(rev2)); assertThat(iter.hasNext(), is(true)); annotatedElement = iter.next(); assertThat(annotatedElement.getElement(), is("jumps over")); assertThat(annotatedElement.getRevision(), sameInstance(rev3)); assertThat(iter.hasNext(), is(true)); annotatedElement = iter.next(); assertThat(annotatedElement.getElement(), is("the lazy dog")); assertThat(annotatedElement.getRevision(), sameInstance(rev3)); assertThat(iter.hasNext(), is(false)); Throwable exception = assertThrows(NoSuchElementException.class, () -> { iter.next(); }); assertEquals("No more annotated content", exception.getMessage()); }