### Question:
AsciiTable { public static String generate( List<String> headers, List<AsciiTableAlignment> alignments, List<? extends List<String>> cells) { int colCount = alignments.size(); int rowCount = cells.size(); ArgChecker.isTrue( headers.size() == colCount, "Number of headers {} must match number of alignments {}", headers.size(), colCount); int[] colLengths = new int[colCount]; for (int colIdx = 0; colIdx < colCount; colIdx++) { colLengths[colIdx] = headers.get(colIdx).length(); } for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) { List<String> row = cells.get(rowIdx); ArgChecker.isTrue( row.size() == colCount, "Table of cells has incorrect number of columns {} in row {}", row.size(), rowIdx); for (int colIdx = 0; colIdx < colCount; colIdx++) { colLengths[colIdx] = Math.max(colLengths[colIdx], row.get(colIdx).length()); } } int colTotalLength = 3; for (int colIdx = 0; colIdx < colCount; colIdx++) { colTotalLength += colLengths[colIdx] + 3; } StringBuilder buf = new StringBuilder((rowCount + 3) * colTotalLength); writeSeparatorLine(buf, colLengths); writeDataLine(buf, colLengths, alignments, headers); writeSeparatorLine(buf, colLengths); for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) { writeDataLine(buf, colLengths, alignments, cells.get(rowIdx)); } writeSeparatorLine(buf, colLengths); return buf.toString(); } private  AsciiTable(); static String generate(
      List<String> headers,
      List<AsciiTableAlignment> alignments,
      List<? extends List<String>> cells);  }### Answer:
@Test public void test_generate_padData() { List<AsciiTableAlignment> alignments = ImmutableList.of(AsciiTableAlignment.LEFT, AsciiTableAlignment.RIGHT); List<String> headers = ImmutableList.of("Alpha", "Beta"); List<List<String>> cells = ImmutableList.of(ImmutableList.of("12", "23"), ImmutableList.of("12345", "")); String test = AsciiTable.generate(headers, alignments, cells); String expected = "" + "+-------+------+" + LINE_SEPARATOR + "| Alpha | Beta |" + LINE_SEPARATOR + "+-------+------+" + LINE_SEPARATOR + "| 12 | 23 |" + LINE_SEPARATOR + "| 12345 | |" + LINE_SEPARATOR + "+-------+------+" + LINE_SEPARATOR; assertThat(test).isEqualTo(expected); }
@Test public void test_generate_padHeader() { List<AsciiTableAlignment> alignments = ImmutableList.of(AsciiTableAlignment.LEFT, AsciiTableAlignment.RIGHT); List<String> headers = ImmutableList.of("A", "B"); List<List<String>> cells = ImmutableList.of(ImmutableList.of("12", "23"), ImmutableList.of("12345", "")); String test = AsciiTable.generate(headers, alignments, cells); String expected = "" + "+-------+----+" + LINE_SEPARATOR + "| A | B |" + LINE_SEPARATOR + "+-------+----+" + LINE_SEPARATOR + "| 12 | 23 |" + LINE_SEPARATOR + "| 12345 | |" + LINE_SEPARATOR + "+-------+----+" + LINE_SEPARATOR; assertThat(test).isEqualTo(expected); }