@Test public void testScanTable() { File mockFile = mock(File.class); Store mockStore = mock(Store.class); AsciidocImporter asciidocImporter = new AsciidocImporter(mockFile, mockStore, 5); final Map<String, Object> parameters = new HashMap<>(); parameters.put(Asciidoctor.STRUCTURE_MAX_LEVEL, 10); Asciidoctor asciidoctor = Asciidoctor.Factory.create(); String content = ".Description of de.kontext_e.jqassistant.plugin.plantuml packages\n" + "[options=\"header\", myAttribute, architecture=\"packages\"]\n" + "|====\n" + "| Package | Purpose\n" + "| scanner | Scan a text file and create Neo4j nodes for packages and relationships for links.\n" + "| store | contains jQAssistant compliant descriptors for Neo4j nodes.\n" + "|====\n"; Document document = asciidoctor.load(content, parameters); final BlockContainer mockBlockContainer = mock(BlockContainer.class); final Set<AsciidocBlockDescriptor> asciidocBlocks = new HashSet<>(); when(mockBlockContainer.getAsciidocBlocks()).thenReturn(asciidocBlocks); final AsciidocTableDescriptor mockTableDescriptor = mock(AsciidocTableDescriptor.class); when(mockStore.create(AsciidocTableDescriptor.class)).thenReturn(mockTableDescriptor); final AsciidocTableColumnDescriptor mockTableColumnDescriptor = mock(AsciidocTableColumnDescriptor.class); when(mockStore.create(AsciidocTableColumnDescriptor.class)).thenReturn(mockTableColumnDescriptor); final AsciidocAttribute mockAttribute = mock(AsciidocAttribute.class); when(mockStore.create(AsciidocAttribute.class)).thenReturn(mockAttribute); final AsciidocTableCellDescriptor mockAsciidocTableCellDescriptor = mock(AsciidocTableCellDescriptor.class); when(mockStore.create(AsciidocTableCellDescriptor.class)).thenReturn(mockAsciidocTableCellDescriptor); final AsciidocTableRowDescriptor mockAsciidocTableRowDescriptor = mock(AsciidocTableRowDescriptor.class); when(mockStore.create(AsciidocTableRowDescriptor.class)).thenReturn(mockAsciidocTableRowDescriptor); when(mockTableDescriptor.getAttributes()).thenReturn(new HashSet<>()); List<AsciidocTableColumnDescriptor> columns = new ArrayList<>(); when(mockTableDescriptor.getAsciidocTableColumns()).thenReturn(columns); asciidocImporter.scanBlocks(document.blocks(), mockBlockContainer); verify(mockAsciidocTableCellDescriptor).setText("Package"); verify(mockAsciidocTableCellDescriptor).setText("Purpose"); verify(mockAsciidocTableCellDescriptor).setText("scanner"); verify(mockAsciidocTableCellDescriptor).setText("store"); verify(mockAttribute).setName("options"); verify(mockAttribute).setValue("header"); verify(mockAttribute).setValue("myAttribute"); verify(mockAttribute).setName("architecture"); verify(mockAttribute).setValue("packages"); }
void scanBlocks(List<AbstractBlock> blocks, BlockContainer blockContainer) { for (Object o: blocks) { if(o instanceof AbstractBlock) { AbstractBlock block = (AbstractBlock) o; if (block instanceof ListItem) continue; try { AsciidocBlockDescriptor blockDescriptor = scanOneBlock(block); blockContainer.getAsciidocBlocks().add(blockDescriptor); scanBlocks(block.getBlocks(), blockDescriptor); } catch (Exception e) { LOGGER.warn("Error while scanning Asciidoc block " + block.getNodeName() + "; reason is: " + e, e); } } } }
AsciidocImporter { void scanBlocks(List<AbstractBlock> blocks, BlockContainer blockContainer) { for (Object o: blocks) { if(o instanceof AbstractBlock) { AbstractBlock block = (AbstractBlock) o; if (block instanceof ListItem) continue; try { AsciidocBlockDescriptor blockDescriptor = scanOneBlock(block); blockContainer.getAsciidocBlocks().add(blockDescriptor); scanBlocks(block.getBlocks(), blockDescriptor); } catch (Exception e) { LOGGER.warn("Error while scanning Asciidoc block " + block.getNodeName() + "; reason is: " + e, e); } } } } }
AsciidocImporter { void scanBlocks(List<AbstractBlock> blocks, BlockContainer blockContainer) { for (Object o: blocks) { if(o instanceof AbstractBlock) { AbstractBlock block = (AbstractBlock) o; if (block instanceof ListItem) continue; try { AsciidocBlockDescriptor blockDescriptor = scanOneBlock(block); blockContainer.getAsciidocBlocks().add(blockDescriptor); scanBlocks(block.getBlocks(), blockDescriptor); } catch (Exception e) { LOGGER.warn("Error while scanning Asciidoc block " + block.getNodeName() + "; reason is: " + e, e); } } } } AsciidocImporter(final File file, final Store store, int structureMaxLevel); }
AsciidocImporter { void scanBlocks(List<AbstractBlock> blocks, BlockContainer blockContainer) { for (Object o: blocks) { if(o instanceof AbstractBlock) { AbstractBlock block = (AbstractBlock) o; if (block instanceof ListItem) continue; try { AsciidocBlockDescriptor blockDescriptor = scanOneBlock(block); blockContainer.getAsciidocBlocks().add(blockDescriptor); scanBlocks(block.getBlocks(), blockDescriptor); } catch (Exception e) { LOGGER.warn("Error while scanning Asciidoc block " + block.getNodeName() + "; reason is: " + e, e); } } } } AsciidocImporter(final File file, final Store store, int structureMaxLevel); static void main(String[] args); }
AsciidocImporter { void scanBlocks(List<AbstractBlock> blocks, BlockContainer blockContainer) { for (Object o: blocks) { if(o instanceof AbstractBlock) { AbstractBlock block = (AbstractBlock) o; if (block instanceof ListItem) continue; try { AsciidocBlockDescriptor blockDescriptor = scanOneBlock(block); blockContainer.getAsciidocBlocks().add(blockDescriptor); scanBlocks(block.getBlocks(), blockDescriptor); } catch (Exception e) { LOGGER.warn("Error while scanning Asciidoc block " + block.getNodeName() + "; reason is: " + e, e); } } } } AsciidocImporter(final File file, final Store store, int structureMaxLevel); static void main(String[] args);  }