### Question:
SelectionCalculator { public Block getSelectionFor(Revision r, Progress p) { return doGetSelectionFor(r, p); } SelectionCalculator(IdeaGateway gw, List<Revision> rr, int fromLine, int toLine); boolean canCalculateFor(Revision r, Progress p); Block getSelectionFor(Revision r, Progress p);  }### Answer:
@Test public void testNormalizingLineEnds() { List<Revision> rr = createRevisions("abc\ndef\nghi", "abc\r\ndef\r\nghi"); SelectionCalculator c = new SelectionCalculator(gw, rr, 0, 1); Block b0 = c.getSelectionFor(rr.get(0), new NullProgress()); Block b1 = c.getSelectionFor(rr.get(1), new NullProgress()); assertBlock(0, 1, "abc\ndef", b0); assertBlock(0, 1, "abc\ndef", b1); }
@Test public void testSelectionWasNotChanged() { List<Revision> rr = createRevisions("abc\ndef\nghi", "abc1\ndef1\nghi1"); SelectionCalculator c = new SelectionCalculator(gw, rr, 0, 2); Block b0 = c.getSelectionFor(rr.get(0), new NullProgress()); Block b1 = c.getSelectionFor(rr.get(1), new NullProgress()); assertBlock(0, 2, "abc1\ndef1\nghi1", b0); assertBlock(0, 2, "abc\ndef\nghi", b1); }
@Test public void testSelectionWasMoved() { List<Revision> rr = createRevisions("abc\ndef\nghi", "def\nghi"); SelectionCalculator c = new SelectionCalculator(gw, rr, 0, 1); Block b0 = c.getSelectionFor(rr.get(0), new NullProgress()); Block b1 = c.getSelectionFor(rr.get(1), new NullProgress()); assertBlock(0, 1, "def\nghi", b0); assertBlock(1, 2, "def\nghi", b1); }
@Test public void testSelectionForVeryOldRevisionTakenBackward() { List<Revision> rr = createRevisions("ghi\nabc\ndef", "abc\nghi\ndef", "abc\ndef\nghi"); SelectionCalculator c = new SelectionCalculator(gw, rr, 0, 1); Block b2 = c.getSelectionFor(rr.get(2), new NullProgress()); Block b1 = c.getSelectionFor(rr.get(1), new NullProgress()); Block b0 = c.getSelectionFor(rr.get(0), new NullProgress()); assertBlock(0, 1, "abc\ndef", b0); assertBlock(0, 2, "abc\nghi\ndef", b1); assertBlock(1, 2, "abc\ndef", b2); }
@Test public void testNormailingLineEnds() { List<Revision> rr = createRevisions("abc\ndef\nghi", "abc\r\ndef\r\nghi"); SelectionCalculator c = new SelectionCalculator(gw, rr, 0, 1); Block b0 = c.getSelectionFor(rr.get(0), new NullProgress()); Block b1 = c.getSelectionFor(rr.get(1), new NullProgress()); assertBlock(0, 1, "abc\ndef", b0); assertBlock(0, 1, "abc\ndef", b1); }
@Test public void testProgressOnGetSelection() { List<Revision> rr = createRevisions("one", "two", "three", "four"); SelectionCalculator c = new SelectionCalculator(gw, rr, 0, 0); Progress p = createStrictMock(Progress.class); p.processed(25); p.processed(50); p.processed(75); p.processed(100); replay(p); c.getSelectionFor(rr.get(3), p); verify(p); }