TableData { public String toHtml() { String element = "td"; String spanTxt = ""; if(header) { element = "th"; } if(colspan > 1) { spanTxt = " colspan=\"" + colspan + "\""; } StringBuffer sb = new StringBuffer(text != null ? text : ""); if(footnote != null) { sb.insert(footnote.getPosition(), footnote.toHtml()); } return String.format("<%s%s>%s</%s>", element, spanTxt, sb.toString(), element); } TableData();  TableData(String text);  TableData(String text, int colspan);  TableData(String text, int colspan, boolean header, Footnote footnote); int getColspan(); Footnote getFootnote(); String getText(); boolean isHeader(); void setColspan(int colspan); void setFootnote(Footnote footnote); void setHeader(boolean header); void setText(String text); String toHtml(); @Override String toString();  }
@Test public void testToHtml() { TableData td = new TableData(); assertEquals("<td></td>",td.toHtml()); td.setHeader(true); assertEquals("<th></th>",td.toHtml()); td.setHeader(false); td.setColspan(2); assertEquals("<td colspan=\"2\"></td>",td.toHtml()); td.setColspan(1); td.setText("blah note"); assertEquals("<td>blah note</td>",td.toHtml()); td.setFootnote(footnote); assertEquals("<td>blah <sup>*</sup>note</td>",td.toHtml()); }