StacktraceLines { public List<String> getFirstLines(int firstSize) { int size = 0; int i = 0; while (size < firstSize && i < lines.size()) { size += lines.get(i).length(); i++; } return lines.subList(0, i - 1); } StacktraceLines(List<String> lines); List<String> getLines(); int getTotalLineLength(); List<String> getFirstLines(int firstSize); List<String> getLastLines(int lastSize);  }
@Test public void testStacktraceLinesGetFirstLines() { int maxSizeOfFirstPart = 25; StacktraceLines stackTraceLines = new StacktraceLines(this.lines); List<String> extractedLines = stackTraceLines.getFirstLines(maxSizeOfFirstPart); int size = 0; for (String line: extractedLines) { size += line.length(); } assertThat(extractedLines, hasItem(containsString("this is the first line"))); assertThat(extractedLines, not(hasItem(containsString("this is the second line")))); assertThat(size, lessThan(maxSizeOfFirstPart)); }
@Test public void testStacktraceLinesGetFirstLinesUnderestimatingSizeOfFirstLine() { int maxSizeOfFirstPart = 10; StacktraceLines stackTraceLines = new StacktraceLines(lines); List<String> extractedLines = stackTraceLines.getFirstLines(maxSizeOfFirstPart); assertThat(extractedLines.size(), equalTo(0)); }
@Test(timeout = 1000) public void testStacktraceLinesGetFirstLinesOverEstimatingTotalSizeOfLines() { int maxSizeOfFirstPart = 2500; StacktraceLines stackTraceLines = new StacktraceLines(lines); stackTraceLines.getFirstLines(maxSizeOfFirstPart); }