TableDataConverter implements Converter { @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String colspanText = reader.getAttribute(DocumentationXmlReader.XML_TD_ATTRIBUTE_COLSPAN); int colspan = colspanText != null ? Integer.valueOf(colspanText) : 1; Footnote footnote = null; if(reader.hasMoreChildren()) { reader.moveDown(); String positionString = reader.getAttribute(DocumentationXmlReader.XML_FOOTNOTE_ATTRIBUTE_POSITION); footnote = new Footnote(reader.getValue(),Integer.valueOf(positionString)); reader.moveUp(); } StringBuffer value = new StringBuffer(reader.getValue()); boolean isHeader = DocumentationXmlReader.XML_TH_ELEMENT.equalsIgnoreCase(reader.getNodeName()); TableData td = new TableData(value.toString(), colspan,isHeader,footnote); log.trace("Created TableData {}", td); return td; }  @Override boolean canConvert(@SuppressWarnings("rawtypes") Class type); @Override void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context); @Override Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context);  }
@Test public void testUnmarshal_withColspan() { setUpReaderMock("2", text, null, null, DocumentationXmlReader.XML_TD_ELEMENT); TableData td = (TableData) this.converter.unmarshal(readerMock, null); assertEquals(2, td.getColspan()); assertEquals(text, td.getText()); assertNull(td.getFootnote()); assertFalse(td.isHeader()); }
@Test public void testUnmarshal_isHeader() { setUpReaderMock(null, text, null, null, DocumentationXmlReader.XML_TH_ELEMENT); TableData td = (TableData) this.converter.unmarshal(readerMock, null); assertEquals(1, td.getColspan()); assertEquals(text, td.getText()); assertNull(td.getFootnote()); assertTrue(td.isHeader()); }
@Test public void testUnmarshal_textWithFootnote() { setUpReaderMock(null, text, "*", "8", DocumentationXmlReader.XML_TD_ELEMENT); TableData td = (TableData) this.converter.unmarshal(readerMock, null); assertEquals(1, td.getColspan()); assertEquals(text, td.getText()); assertEquals("*", td.getFootnote().getSymbol()); assertEquals(8, td.getFootnote().getPosition()); assertFalse(td.isHeader()); }
@Test public void testUnmarshal_footnoteOnly() { setUpReaderMock(null, null, "*", "0", DocumentationXmlReader.XML_TD_ELEMENT); TableData td = (TableData) this.converter.unmarshal(readerMock, null); assertEquals(1, td.getColspan()); assertEquals("", td.getText()); assertEquals("*", td.getFootnote().getSymbol()); assertEquals(0, td.getFootnote().getPosition()); assertFalse(td.isHeader()); }
@Test public void testUnmarshal_emptyElement() { setUpReaderMock(null, null, null, null, DocumentationXmlReader.XML_TD_ELEMENT); TableData td = (TableData) this.converter.unmarshal(readerMock, null); assertEquals(1, td.getColspan()); assertEquals("", td.getText()); assertNull(td.getFootnote()); assertFalse(td.isHeader()); }