@Test public void testFormatWithEmpty() { GameMatrix matrix = gameMatrixFactory.newGameMatrix(); String actual = newInstance().format(matrix); assertEquals( "| | | | | | | | | |\n"+ "|---|---|---|---|---|---|---|---|---|\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| . | . | . | . | . | . | . | . | . |\n"+ "| | | | | | | | | |\n" , actual); }
@Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); }
MarkdownTableFormatter extends AbstractTextFormatter { @Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); } }
MarkdownTableFormatter extends AbstractTextFormatter { @Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); }  }
MarkdownTableFormatter extends AbstractTextFormatter { @Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); }  @Override String format(final GameMatrix matrix); }
MarkdownTableFormatter extends AbstractTextFormatter { @Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); }  @Override String format(final GameMatrix matrix);  }