@Test public void testEmptyLines() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8); AsciiTableFormatter formatter = new AsciiTableFormatter(writer, null, config, new Column("column1").setColspan(4), new Column("column2").setColspan(2))) { formatter.writeCell("Line:1 Cell:1") .writeCell("Line:1 Cell:2") .writeCell("Line:1 Cell:3") .writeEmptyLine(); } assertEquals("+--------------------------------------------------+---------+\n" + "| column1 | column2 |\n" + "+--------------------------------------------------+---------+\n" + "| Line:1 Cell:1 | Line:1 Cell:2 | Line:1 Cell:3 | | | |\n" + "+---------------+---------------+---------------+--+--+------+" + System.lineSeparator(), new String(bos.toByteArray(), StandardCharsets.UTF_8)); } }
@Test public void testAsciiTableFormatter1() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8); try (AsciiTableFormatter formatter = new AsciiTableFormatter(writer, null, config, new Column("column1").setColspan(2).setHorizontalAlignment(HorizontalAlignment.CENTER).setTitleHorizontalAlignment(HorizontalAlignment.CENTER), new Column("column2").setHorizontalAlignment(HorizontalAlignment.CENTER).setTitleHorizontalAlignment(HorizontalAlignment.CENTER))) { formatter.writeCell("Line:1 Cell:1", 2) .writeCell("Line:1 Cell:2", 1) .writeCell("Line:2 Cell:1", 1) .writeCell("Line:2 Cell:2", 1) .writeCell("Line:2 Cell:3", 1); } assertEquals("+-------------------------------+---------------+\n" + "| column1 | column2 |\n" + "+-------------------------------+---------------+\n" + "| Line:1 Cell:1 | Line:1 Cell:2 |\n" + "| Line:2 Cell:1 | Line:2 Cell:2 | Line:2 Cell:3 |\n" + "+---------------+---------------+---------------+" + System.lineSeparator(), new String(bos.toByteArray(), StandardCharsets.UTF_8)); writer.close(); }
@Test public void testAsciiTableFormatter2() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8); try (AsciiTableFormatter formatter = new AsciiTableFormatter(writer, null, config, new Column("column1").setColspan(4).setHorizontalAlignment(HorizontalAlignment.CENTER).setTitleHorizontalAlignment(HorizontalAlignment.CENTER), new Column("column2").setColspan(2).setHorizontalAlignment(HorizontalAlignment.CENTER).setTitleHorizontalAlignment(HorizontalAlignment.CENTER))) { formatter.writeCell("Line:1 Cell:1", 1) .writeCell("Line:1 Cell:2", 1) .writeCell("Line:1 Cell:3", 1) .writeCell("Line:1 Cell:4", 1) .writeCell("Line:1 Cell:5", 1) .writeCell("Line:1 Cell:6", 1); } assertEquals("+---------------------------------------------------------------+-------------------------------+\n" + "| column1 | column2 |\n" + "+---------------------------------------------------------------+-------------------------------+\n" + "| Line:1 Cell:1 | Line:1 Cell:2 | Line:1 Cell:3 | Line:1 Cell:4 | Line:1 Cell:5 | Line:1 Cell:6 |\n" + "+---------------+---------------+---------------+---------------+---------------+---------------+" + System.lineSeparator(), new String(bos.toByteArray(), StandardCharsets.UTF_8)); writer.close(); }
@Test public void testUnauthorizedColspan() throws IOException { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("You have exceded the authorized colspan"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8); AsciiTableFormatter formatter = new AsciiTableFormatter(writer, null, config, new Column("column1").setColspan(4).setHorizontalAlignment(HorizontalAlignment.CENTER), new Column("column2").setColspan(2).setHorizontalAlignment(HorizontalAlignment.CENTER))) { formatter.writeCell("Line:1 Cell:1", 1) .writeCell("Line:1 Cell:2", 1) .writeCell("Line:1 Cell:3", 1) .writeCell("Line:1 Cell:4", 2) .writeCell("Line:1 Cell:5", 1); } }