@Test public void thatNoLinksToLeafsWereAddedIfNoLinksInDiagram() { String[] lines = ("The Backend is structured with Domain Components in the first level. Could look like this:\n" + "\n" + "[\"plantuml\",\"Backend\",\"png\"]\n" + "-----\n" + "title First Level Components\n" + "caption Level 1 Building Blocks\n" + "\n" + "legend right\n" + " | Element | Description |\n" + " |<#42788e>| Component |\n" + " | A --> B | A depends on B |\n" + "endlegend\n" + "\n" + "component TechnicalService [\n" + " componentName(TechnicalService)\n" + "\n" + "]\n" + "\n" + "component Application [\n" + " componentName(Application)\n" + "\n" + "]\n" + "\n" + "component A1 [\n" + "]\n" + "component A2 [\n" + "]\n" + "component A3 [\n" + "]\n" + "component A4 [\n" + "]\n" + "component A5 [\n" + "]\n" + "component A6 [\n" + "]\n" + "\n" + "-----\n" + "\n") .split("\\n"); pumlLineParser = new PumlLineParser(mockStore, plantUmlFileDescriptor, ParsingState.IGNORING); final PlantUmlClassDiagramDescriptor mockDescriptionDiagramDescriptor = mock(PlantUmlClassDiagramDescriptor.class); when(mockStore.create(PlantUmlClassDiagramDescriptor.class)).thenReturn(mockDescriptionDiagramDescriptor); final PlantUmlLeafDescriptor mockPlantUmlLeafDescriptor = mock(PlantUmlLeafDescriptor.class); when(mockStore.create(PlantUmlLeafDescriptor.class)).thenReturn(mockPlantUmlLeafDescriptor); final Set<PlantUmlElement> leafs = new HashSet<>(); when(mockDescriptionDiagramDescriptor.getLeafs()).thenReturn(leafs); stream(lines).forEach(line -> pumlLineParser.parseLine(line)); verify(mockStore).create(PlantUmlClassDiagramDescriptor.class); verify(mockStore, times(8)).create(PlantUmlLeafDescriptor.class); verify(mockDescriptionDiagramDescriptor).setTitle("first level components"); verify(mockDescriptionDiagramDescriptor).setCaption("level 1 building blocks"); verify(mockDescriptionDiagramDescriptor, times(8)).getLeafs(); verify(mockPlantUmlLeafDescriptor, times(1)).setFullName("technicalservice"); verify(mockPlantUmlLeafDescriptor, times(1)).setFullName("application"); verify(mockPlantUmlLeafDescriptor, times(0)).getLinkTargets(); assertEquals(1, leafs.size()); }
void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } }
PumlLineParser { void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } } }
PumlLineParser { void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } } PumlLineParser(final Store store, final PlantUmlFileDescriptor plantUmlFileDescriptor, final ParsingState parsingState); }
PumlLineParser { void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } } PumlLineParser(final Store store, final PlantUmlFileDescriptor plantUmlFileDescriptor, final ParsingState parsingState);  }
PumlLineParser { void parseLine(final String line) { if(line == null) return; String normalizedLine = line.trim().toLowerCase(); if(normalizedLine.startsWith("!include")) { return; } if(parsingState == ParsingState.IGNORING && normalizedLine.startsWith("[\"plantuml\"")) { parsingState = ParsingState.PLANTUMLFOUND; final String[] parts = normalizedLine .replaceAll("\\[", "") .replaceAll("]", "") .replaceAll("\"", "") .replaceAll("\n", "") .split(","); if(parts!= null && parts.length >= 3) { pictureFileName = parts[1]; pictureFileType = parts[2]; } } if(parsingState == ParsingState.ACCEPTING && (normalizedLine.startsWith("----") || normalizedLine.startsWith("@enduml"))) { parsingState = ParsingState.IGNORING; lineBuffer.append("\n"); lineBuffer.append("@enduml"); storeDiagram(); pictureFileName = null; pictureFileType = null; } if(parsingState == ParsingState.PLANTUMLFOUND && normalizedLine.startsWith("----")) { parsingState = ParsingState.ACCEPTING; lineBuffer = new StringBuilder(); lineBuffer.append("@startuml"); lineBuffer.append("\n"); return; } if(parsingState == ParsingState.ACCEPTING) { lineBuffer.append(normalizedLine); lineBuffer.append("\n"); } } PumlLineParser(final Store store, final PlantUmlFileDescriptor plantUmlFileDescriptor, final ParsingState parsingState);   }