@Test public void thatStateDiagramIsRead() { final String puml = "@startuml\n" + "\n" + "[*] --> State1\n" + "State1 --> [*]\n" + "State1 : this is a string\n" + "State1 : this is another string\n" + "\n" + "State1 -> State2\n" + "State2 --> [*]\n" + "\n" + "@enduml"; String[] lines = puml.split("\\n"); pumlLineParser = new PumlLineParser(mockStore, plantUmlFileDescriptor, ParsingState.ACCEPTING); final PlantUmlStateDiagramDescriptor mockDescriptor = mock(PlantUmlStateDiagramDescriptor.class); when(mockStore.create(PlantUmlStateDiagramDescriptor.class)).thenReturn(mockDescriptor); final PlantUmlLeafDescriptor mockPlantUmlLeafDescriptor = mock(PlantUmlLeafDescriptor.class); when(mockStore.create(PlantUmlLeafDescriptor.class)).thenReturn(mockPlantUmlLeafDescriptor); for (String line : lines) { pumlLineParser.parseLine(line); } verify(mockStore).create(PlantUmlStateDiagramDescriptor.class); verify(mockStore, times(4)).create(PlantUmlLeafDescriptor.class); verify(mockDescriptor).setType("STATEDIAGRAM"); verify(mockPlantUmlLeafDescriptor, times(1)).setType("CIRCLE_START"); verify(mockPlantUmlLeafDescriptor, times(2)).setType("STATE"); verify(mockPlantUmlLeafDescriptor, times(1)).setType("CIRCLE_END"); verify(mockPlantUmlLeafDescriptor, times(1)).setFullName("*start"); verify(mockPlantUmlLeafDescriptor, times(1)).setFullName("state1"); verify(mockPlantUmlLeafDescriptor, times(1)).setFullName("state2"); verify(mockPlantUmlLeafDescriptor, times(1)).setFullName("*end"); verify(mockPlantUmlLeafDescriptor, times(4)).getLinkTargets(); }
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);   }