diff --git a/src/main/java/parser/FileVisitor.java b/src/main/java/parser/FileVisitor.java index 2a3a2f4..9ae4587 100644 --- a/src/main/java/parser/FileVisitor.java +++ b/src/main/java/parser/FileVisitor.java @@ -37,6 +37,9 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import static parser.tree.ModifierType.PACKAGE_PRIVATE; +import static parser.tree.NodeType.ENUM; + /** * This class is responsible for the creation of the AST of a Java source file using {@link JavaParser}. * Using the different visitors, it parses the file's inheritance declarations, @@ -183,11 +186,12 @@ public void visit(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, Void .setImplementedInterface(innerImplementedInterfaces) .build(); innerClasses.add(innerClass); + return; } nodeName = classOrInterfaceDeclaration.getNameAsString(); - NodeType localNodeType = classOrInterfaceDeclaration.isInterface() ? + nodeType = classOrInterfaceDeclaration.isInterface() ? NodeType.INTERFACE : NodeType.CLASS; @@ -196,8 +200,7 @@ public void visit(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, Void baseClass = classOrInterfaceDeclaration.getExtendedTypes().get(0).getNameAsString(); } - nodeType = localNodeType; - ArrayList implementedTypes = + List implementedTypes = classOrInterfaceDeclaration.getImplementedTypes() .stream() .map(NodeWithSimpleName::getNameAsString) @@ -215,12 +218,13 @@ public void visit(ConstructorDeclaration constructorDeclaration, Void arg) super.visit(constructorDeclaration, arg); ModifierType modifierType = constructorDeclaration.getModifiers().isEmpty() ? - ModifierType.PACKAGE_PRIVATE : + PACKAGE_PRIVATE : ModifierType.get(constructorDeclaration.getModifiers().get(0).toString()); Map parameters = constructorDeclaration.getParameters().stream() .collect(Collectors.toMap(NodeWithSimpleName::getNameAsString, parameter -> getType(parameter.getTypeAsString()))); + methods.add(new LeafNode.Method(constructorDeclaration.getNameAsString(), "Constructor", modifierType, @@ -239,7 +243,7 @@ public void visit(FieldDeclaration fieldDeclaration, Void arg) for (VariableDeclarator variable : fieldDeclaration.getVariables()) { ModifierType modifierType = fieldDeclaration.getModifiers().isEmpty() ? - ModifierType.PACKAGE_PRIVATE : + PACKAGE_PRIVATE : ModifierType.get(fieldDeclaration.getModifiers().get(0).toString()); fields.add(new LeafNode.Field(variable.getNameAsString(), @@ -277,7 +281,7 @@ public void visit(MethodDeclaration methodDeclaration, Void arg) super.visit(methodDeclaration, arg); ModifierType modifierType = methodDeclaration.getModifiers().isEmpty() ? - ModifierType.PACKAGE_PRIVATE : + PACKAGE_PRIVATE : ModifierType.get(methodDeclaration.getModifiers().get(0).toString()); Map parameters = methodDeclaration.getParameters().stream() @@ -312,7 +316,7 @@ public void visit(EnumDeclaration enumDeclaration, Void arg) super.visit(enumDeclaration, arg); nodeName = enumDeclaration.getNameAsString(); - nodeType = NodeType.ENUM; + nodeType = ENUM; } } diff --git a/src/test/java/manager/ClassDiagramManagerTest.java b/src/test/java/manager/ClassDiagramManagerTest.java index 8cc090a..46a9da8 100644 --- a/src/test/java/manager/ClassDiagramManagerTest.java +++ b/src/test/java/manager/ClassDiagramManagerTest.java @@ -17,12 +17,20 @@ import org.junit.jupiter.api.Test; import parser.Interpreter; import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -34,25 +42,11 @@ public class ClassDiagramManagerTest void createSourceProjectTest() { ClassDiagramManager classDiagramManager = new ClassDiagramManager(); + SourceProject sourceProject = classDiagramManager.createSourceProject(LatexEditor.SRC.path); - SourceProject sourceProject = classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - Map vertices = sourceProject.getInterpreter().getVertices(); - Interpreter interpreter = new Interpreter(); - interpreter.parseProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + Map vertices = sourceProject.getInterpreter().getVertices(); + Interpreter interpreter = new Interpreter(); + interpreter.parseProject(LatexEditor.SRC.path); interpreter.convertTreeToGraph(); ArrayList interpreterVertices = new ArrayList<>(interpreter.getVertices().values()); @@ -60,27 +54,22 @@ void createSourceProjectTest() for (Map.Entry vertexEntry : vertices.entrySet()) { PackageVertex optionalPackageVertex = interpreterVertices.stream() - .filter(vertex -> - vertex.getName().equals(vertexEntry.getValue().getName()) && - vertex.getParentVertex().getName().equals(vertexEntry.getValue().getParentVertex().getName())) + .filter(it -> it.getName().equals(vertexEntry.getValue().getName()) && + it.getParentVertex().getName().equals(vertexEntry.getValue().getParentVertex().getName())) .findFirst().orElseGet(Assertions::fail); assertEquals(vertexEntry.getValue().getNeighbourVertices().size(), optionalPackageVertex.getNeighbourVertices().size()); for (PackageVertex neighbourPackageVertex : vertexEntry.getValue().getNeighbourVertices()) { - Optional optionalNeighbourVertex = optionalPackageVertex.getNeighbourVertices().stream() - .filter(neighbour -> neighbour.getName().equals(neighbourPackageVertex.getName())) - .findAny(); - assertTrue(optionalNeighbourVertex.isPresent()); + assertTrue(optionalPackageVertex.getNeighbourVertices().stream() + .anyMatch(it -> it.getName().equals(neighbourPackageVertex.getName()))); } assertEquals(vertexEntry.getValue().getSinkVertices().size(), optionalPackageVertex.getSinkVertices().size()); for (ClassifierVertex classifierVertex : vertexEntry.getValue().getSinkVertices()) { - Optional optionalSinkVertex = optionalPackageVertex.getSinkVertices().stream() - .filter(sinkVertex1 -> sinkVertex1.getName().equals(classifierVertex.getName())) - .findAny(); - assertTrue(optionalSinkVertex.isPresent()); + assertTrue(optionalPackageVertex.getSinkVertices().stream() + .anyMatch(it -> it.getName().equals(classifierVertex.getName()))); } } } @@ -90,14 +79,8 @@ void createSourceProjectTest() void populateGraphNodesTest() { ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - SourceProject sourceProject = classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + SourceProject sourceProject = classDiagramManager.createSourceProject(LatexEditor.SRC.path); + classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", "ChangeVersionsStrategyCommand", "Command", @@ -111,40 +94,22 @@ void populateGraphNodesTest() "SaveCommand")); Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); + assertEquals(sourceProject.getInterpreter().getVertices().get(LatexEditor.COMMANDS.path).getSinkVertices().size(), graphNodes.size()); + + List l1 = sourceProject.getInterpreter().getVertices().get(LatexEditor.COMMANDS.path).getSinkVertices().stream() + .map(ClassifierVertex::getName) + .collect(Collectors.toCollection(ArrayList::new)); + + List l2 = graphNodes.keySet().stream() + .map(ClassifierVertex::getName) + .collect(Collectors.toCollection(ArrayList::new)); - List l1 = new ArrayList<>(); - List l2 = new ArrayList<>(); - assertEquals(sourceProject.getInterpreter().getVertices().get( - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))) - .getSinkVertices().size(), graphNodes.size()); - - Iterator iter1 = sourceProject.getInterpreter().getVertices() - .get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))) - .getSinkVertices().iterator(); - Iterator> iter2 = graphNodes.entrySet().iterator(); - while (iter1.hasNext() || iter2.hasNext()) - { - ClassifierVertex e1 = iter1.next(); - Map.Entry e2 = iter2.next(); - l1.add(e1.getName()); - l2.add(e2.getKey().getName()); - } Collections.sort(l1); Collections.sort(l2); - assertTrue(l1.size() == l2.size() && l1.containsAll(l2) && l2.containsAll(l1)); + + assertEquals(l1.size(), l2.size()); + assertTrue(l1.containsAll(l2)); + assertTrue(l2.containsAll(l1)); } @@ -155,20 +120,14 @@ void createDiagramTest() List chosenFiles = Arrays.asList("MainWindow", "LatexEditorView", "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); Map>> testingCreatedDiagram = classDiagramManager.getClassDiagram().getDiagram(); Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(graphNodes.keySet()); classDiagramManager.getClassDiagram().setDiagram(graphClassDiagramConverter.convertGraphToClassDiagram()); + ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); Map>> adjacencyList = shadowCleaner.shadowWeakRelationships(); @@ -185,14 +144,7 @@ void exportDiagramToGraphMLTest() List chosenFiles = Arrays.asList("MainWindow", "LatexEditorView", "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); classDiagramManager.arrangeDiagram(); File actualFile = classDiagramManager.exportDiagramToGraphML(Paths.get(String.format("%s%s%s", @@ -236,19 +188,24 @@ void saveDiagramTest() List chosenFiles = Arrays.asList("MainWindow", "LatexEditorView", "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); - File testingSavedFile = classDiagramManager.saveDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingSavedFile.txt"))); - DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); - assertTrue(FileUtils.contentEquals(javaFXExporter.exportDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.txt"))), testingSavedFile)); + File testingSavedFile = classDiagramManager.saveDiagram(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingSavedFile.txt")))); + DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); + assertTrue(FileUtils.contentEquals(javaFXExporter.exportDiagram(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))), testingSavedFile)); } catch (IOException e) { @@ -264,14 +221,7 @@ void loadDiagramTest() List chosenFiles = Arrays.asList("MainWindow", "LatexEditorView", "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); Map>> createdDiagram = classDiagramManager.getClassDiagram().getDiagram(); classDiagramManager.saveDiagram(Paths.get(String.format("%s%s%s", @@ -294,7 +244,7 @@ void loadDiagramTest() { Optional optionalSinkVertex = loadedDiagram.keySet() .stream() - .filter(sinkVertex1 -> sinkVertex1.getName().equals(classifierVertex.getName())).findFirst(); + .filter(it -> it.getName().equals(classifierVertex.getName())).findFirst(); assertTrue(optionalSinkVertex.isPresent()); assertEquals(createdDiagram.get(classifierVertex).size(), loadedDiagram.get(optionalSinkVertex.get()).size()); @@ -302,10 +252,9 @@ void loadDiagramTest() { assertTrue(loadedDiagram.get(optionalSinkVertex.get()) .stream() - .anyMatch(a -> - a.sourceVertex().getName().equals(arc.sourceVertex().getName()) && - a.targetVertex().getName().equals(arc.targetVertex().getName()) && - a.arcType().equals(arc.arcType()))); + .anyMatch(it -> it.sourceVertex().getName().equals(arc.sourceVertex().getName()) && + it.targetVertex().getName().equals(arc.targetVertex().getName()) && + it.arcType().equals(arc.arcType()))); } } } diff --git a/src/test/java/manager/PackageDiagramManagerTest.java b/src/test/java/manager/PackageDiagramManagerTest.java index d7b996f..934c37a 100644 --- a/src/test/java/manager/PackageDiagramManagerTest.java +++ b/src/test/java/manager/PackageDiagramManagerTest.java @@ -2,16 +2,14 @@ import model.graph.PackageVertex; import org.junit.jupiter.api.Test; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -23,15 +21,8 @@ public class PackageDiagramManagerTest void populateGraphMLPackageNodeTest() { PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); + SourceProject sourceProject = packageDiagramManager.createSourceProject(LatexEditor.SRC.path); - SourceProject sourceProject = packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); packageDiagramManager.convertTreeToDiagram(List.of("src.view", "src.model", "src.model.strategies", @@ -39,29 +30,22 @@ void populateGraphMLPackageNodeTest() "src.controller")); Map graphNodes = packageDiagramManager.getPackageDiagram().getGraphNodes(); Map packageNodes = sourceProject.getInterpreter().getVertices(); - packageNodes.remove(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + packageNodes.remove(LatexEditor.SRC.path); assertEquals(packageNodes.size(), graphNodes.size()); - Iterator> iter1 = packageNodes.entrySet().iterator(); - Iterator> iter2 = graphNodes.entrySet().iterator(); - List l1 = new ArrayList<>(); - List l2 = new ArrayList<>(); - while (iter1.hasNext() || iter2.hasNext()) - { - Map.Entry e1 = iter1.next(); - Map.Entry e2 = iter2.next(); - l1.add(e1.getValue().getName()); - l2.add(e2.getKey().getName()); - } + List l1 = packageNodes.values().stream() + .map(PackageVertex::getName) + .collect(Collectors.toCollection(ArrayList::new)); + + List l2 = graphNodes.keySet().stream() + .map(PackageVertex::getName) + .collect(Collectors.toCollection(ArrayList::new)); + Collections.sort(l1); Collections.sort(l2); - assertTrue(l1.size() == l2.size() && l1.containsAll(l2) && l2.containsAll(l1)); + + assertEquals(l1.size(), l2.size()); + assertTrue(l1.containsAll(l2)); + assertTrue(l2.containsAll(l1)); } } diff --git a/src/test/java/model/GraphClassDiagramConverterTest.java b/src/test/java/model/GraphClassDiagramConverterTest.java index 4cc82bd..e91c6f7 100644 --- a/src/test/java/model/GraphClassDiagramConverterTest.java +++ b/src/test/java/model/GraphClassDiagramConverterTest.java @@ -6,16 +6,16 @@ import model.graph.Arc; import model.graph.ClassifierVertex; import org.junit.jupiter.api.Test; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -30,47 +30,32 @@ void convertGraphToClassDiagramTest() List chosenFiles = Arrays.asList("MainWindow", "LatexEditorView", "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); + Set graphNodes = classDiagramManager.getClassDiagram().getGraphNodes().keySet(); Map>> diagram = classDiagramManager.getClassDiagram().getDiagram(); - List> arcs = new ArrayList<>(); - for (Set> arcSet : diagram.values()) - { - arcs.addAll(arcSet); - } + List> arcs = diagram.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toCollection(ArrayList::new)); GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(diagram.keySet()); Map>> adjacencyList = graphClassDiagramConverter.convertGraphToClassDiagram(); classDiagramManager.getClassDiagram().setDiagram(adjacencyList); ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); - adjacencyList = shadowCleaner.shadowWeakRelationships(); + adjacencyList = shadowCleaner.shadowWeakRelationships(); - Set> actualArcs = new HashSet<>(); - for (Set> value : adjacencyList.values()) - { - actualArcs.addAll(value); - } + Set> actualArcs = adjacencyList.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toCollection(HashSet::new)); assertEquals(arcs.size(), actualArcs.size()); - for (Arc arc : actualArcs) - { - assertTrue(arcs.contains(arc)); - } + assertTrue(actualArcs.containsAll(arcs)); assertEquals(graphNodes.size(), adjacencyList.keySet().size()); - for (ClassifierVertex classifierVertex : adjacencyList.keySet()) - { - assertTrue(graphNodes.contains(classifierVertex)); - } + assertTrue(graphNodes.containsAll(adjacencyList.keySet())); } } diff --git a/src/test/java/model/GraphPackageDiagramConverterTest.java b/src/test/java/model/GraphPackageDiagramConverterTest.java index 92163a2..4112c94 100644 --- a/src/test/java/model/GraphPackageDiagramConverterTest.java +++ b/src/test/java/model/GraphPackageDiagramConverterTest.java @@ -5,15 +5,15 @@ import model.graph.Arc; import model.graph.PackageVertex; import org.junit.jupiter.api.Test; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; -import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -25,14 +25,7 @@ public class GraphPackageDiagramConverterTest void convertGraphToPackageDiagramTest() { PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + packageDiagramManager.createSourceProject(LatexEditor.SRC.path); packageDiagramManager.convertTreeToDiagram(List.of("src.view", "src.model", "src.model.strategies", @@ -40,25 +33,18 @@ void convertGraphToPackageDiagramTest() "src.controller")); Map>> diagram = packageDiagramManager.getPackageDiagram().getDiagram(); - List> arcs = new ArrayList<>(); - for (Set> arcSet : diagram.values()) - { - arcs.addAll(arcSet); - } + List> arcs = diagram.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toCollection(ArrayList::new)); GraphPackageDiagramConverter graphPackageDiagramConverter = new GraphPackageDiagramConverter(diagram.keySet()); Map>> adjacencyList = graphPackageDiagramConverter.convertGraphToPackageDiagram(); - Set> actualArcs = new HashSet<>(); - for (Set> value : adjacencyList.values()) - { - actualArcs.addAll(value); - } + Set> actualArcs = adjacencyList.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toCollection(HashSet::new)); assertEquals(arcs.size(), actualArcs.size()); - for (Arc vertexArc : actualArcs) - { - assertTrue(arcs.contains(vertexArc)); - } + assertTrue(arcs.containsAll(actualArcs)); } } diff --git a/src/test/java/model/ShadowCleanerTest.java b/src/test/java/model/ShadowCleanerTest.java index ea9593a..9bc24c5 100644 --- a/src/test/java/model/ShadowCleanerTest.java +++ b/src/test/java/model/ShadowCleanerTest.java @@ -4,20 +4,21 @@ import model.diagram.GraphClassDiagramConverter; import model.diagram.ShadowCleaner; import model.graph.Arc; -import model.graph.ArcType; import model.graph.ClassifierVertex; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import static model.graph.ArcType.AGGREGATION; +import static model.graph.ArcType.ASSOCIATION; import static org.junit.jupiter.api.Assertions.assertEquals; public class ShadowCleanerTest @@ -34,123 +35,107 @@ void shadowWeakRelationshipsTest() "VersionsManager", "DocumentManager", "Document"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(graphNodes.keySet()); Map>> shadowedDiagram = graphClassDiagramConverter.convertGraphToClassDiagram(); classDiagramManager.getClassDiagram().setDiagram(shadowedDiagram); - int numberOfArcsBeforeShadowCleaner = 0; - for (Set> arcs : shadowedDiagram.values()) - { - numberOfArcsBeforeShadowCleaner += arcs.size(); - } + + long numberOfArcsBeforeShadowCleaner = shadowedDiagram.values().stream() + .mapToLong(Collection::size) + .sum(); + ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram()); Map>> diagram = shadowCleaner.shadowWeakRelationships(); - int numberOfArcsAfterShadowCleaner = 0; - for (Set> arcs : diagram.values()) - { - numberOfArcsAfterShadowCleaner += arcs.size(); - } + + long numberOfArcsAfterShadowCleaner = diagram.values().stream() + .mapToLong(Collection::size) + .sum(); + assertEquals(numberOfArcsAfterShadowCleaner + 7, numberOfArcsBeforeShadowCleaner); - ClassifierVertex chooseTemplate = diagram.keySet().stream().filter(sinkVertex -> sinkVertex.getName().equals("ChooseTemplate")).findFirst().orElseGet(Assertions::fail); - List> chooseTemplateLatexEditorViewArc = diagram.get(chooseTemplate) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) + ClassifierVertex chooseTemplate = diagram.keySet().stream() + .filter(it -> it.getName() + .equals("ChooseTemplate")) + .findFirst() + .orElseGet(Assertions::fail); + + List> chooseTemplateLatexEditorViewArc = diagram.get(chooseTemplate).stream() + .filter(it -> it.targetVertex().getName().equals("LatexEditorView")) .toList(); + assertEquals(1, chooseTemplateLatexEditorViewArc.size()); - assertEquals(ArcType.ASSOCIATION, chooseTemplateLatexEditorViewArc.get(0).arcType()); + assertEquals(ASSOCIATION, chooseTemplateLatexEditorViewArc.get(0).arcType()); - ClassifierVertex latexEditorView = diagram - .keySet() - .stream() - .filter(sinkVertex -> - sinkVertex.getName().equals("LatexEditorView")) + ClassifierVertex latexEditorView = diagram.keySet().stream() + .filter(it -> it.getName().equals("LatexEditorView")) .findFirst() .orElseGet(Assertions::fail); + List> latexEditorViewVersionsManagerArc = diagram.get(latexEditorView) .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("VersionsManager")) + .filter(it -> it.targetVertex().getName().equals("VersionsManager")) .toList(); + assertEquals(1, latexEditorViewVersionsManagerArc.size()); - assertEquals(ArcType.ASSOCIATION, latexEditorViewVersionsManagerArc.get(0).arcType()); + assertEquals(ASSOCIATION, latexEditorViewVersionsManagerArc.get(0).arcType()); List> LatexEditorViewLatexEditorControllerArc = diagram.get(latexEditorView) .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("LatexEditorController")) + .filter(it -> it.targetVertex().getName().equals("LatexEditorController")) .toList(); + assertEquals(1, LatexEditorViewLatexEditorControllerArc.size()); - assertEquals(ArcType.ASSOCIATION, LatexEditorViewLatexEditorControllerArc.get(0).arcType()); - - List> LatexEditorViewDocumentArc = new ArrayList<>(); - for (Arc classifierVertexArc : diagram.get(latexEditorView)) - { - if (classifierVertexArc.targetVertex().getName().equals("Document")) - { - LatexEditorViewDocumentArc.add(classifierVertexArc); - } - } + assertEquals(ASSOCIATION, LatexEditorViewLatexEditorControllerArc.get(0).arcType()); + + List> LatexEditorViewDocumentArc = diagram.get(latexEditorView).stream() + .filter(it -> it.targetVertex().getName().equals("Document")) + .collect(Collectors.toCollection(ArrayList::new)); + assertEquals(1, LatexEditorViewDocumentArc.size()); - assertEquals(ArcType.ASSOCIATION, LatexEditorViewDocumentArc.get(0).arcType()); + assertEquals(ASSOCIATION, LatexEditorViewDocumentArc.get(0).arcType()); ClassifierVertex mainWindow = diagram .keySet() .stream() - .filter(sinkVertex -> - sinkVertex.getName().equals("MainWindow")) + .filter(it -> it.getName().equals("MainWindow")) .findFirst() .orElseGet(Assertions::fail); + List> mainWindowLatexEditorViewArc = diagram .get(mainWindow) .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) + .filter(it -> it.targetVertex().getName().equals("LatexEditorView")) .toList(); + assertEquals(1, mainWindowLatexEditorViewArc.size()); - assertEquals(ArcType.ASSOCIATION, mainWindowLatexEditorViewArc.get(0).arcType()); + assertEquals(ASSOCIATION, mainWindowLatexEditorViewArc.get(0).arcType()); - ClassifierVertex versionsManager = diagram - .keySet() - .stream() - .filter(sinkVertex -> - sinkVertex.getName().equals("VersionsManager")) + ClassifierVertex versionsManager = diagram.keySet().stream() + .filter(it -> it.getName().equals("VersionsManager")) .findFirst() .orElseGet(Assertions::fail); - List> versionsManagerLatexEditorViewArc = diagram - .get(versionsManager) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("LatexEditorView")) + + List> versionsManagerLatexEditorViewArc = diagram.get(versionsManager).stream() + .filter(it -> it.targetVertex().getName().equals("LatexEditorView")) .toList(); + assertEquals(1, versionsManagerLatexEditorViewArc.size()); - assertEquals(ArcType.ASSOCIATION, versionsManagerLatexEditorViewArc.get(0).arcType()); + assertEquals(ASSOCIATION, versionsManagerLatexEditorViewArc.get(0).arcType()); - ClassifierVertex documentManager = diagram - .keySet() - .stream() - .filter(sinkVertex -> - sinkVertex.getName().equals("DocumentManager")) + ClassifierVertex documentManager = diagram.keySet().stream() + .filter(it -> it.getName().equals("DocumentManager")) .findFirst() .orElseGet(Assertions::fail); - List> documentManagerDocumentArc = diagram - .get(documentManager) - .stream() - .filter(sinkVertexArc -> - sinkVertexArc.targetVertex().getName().equals("Document")) + + List> documentManagerDocumentArc = diagram.get(documentManager).stream() + .filter(it -> it.targetVertex().getName().equals("Document")) .toList(); + assertEquals(1, documentManagerDocumentArc.size()); - assertEquals(ArcType.AGGREGATION, documentManagerDocumentArc.get(0).arcType()); + assertEquals(AGGREGATION, documentManagerDocumentArc.get(0).arcType()); } } diff --git a/src/test/java/model/exportation/GraphMLClassDiagramExporterTest.java b/src/test/java/model/exportation/GraphMLClassDiagramExporterTest.java index 920730d..467307c 100644 --- a/src/test/java/model/exportation/GraphMLClassDiagramExporterTest.java +++ b/src/test/java/model/exportation/GraphMLClassDiagramExporterTest.java @@ -11,6 +11,7 @@ import org.javatuples.Pair; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.io.IOException; @@ -36,19 +37,15 @@ void exportDiagramTest() List chosenFiles = Arrays.asList("MainWindow", "LatexEditorView", "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); classDiagramManager.arrangeDiagram(); + DiagramArrangementManagerInterface classDiagramArrangement = new ClassDiagramArrangementManager(classDiagramManager.getClassDiagram()); Map> nodesGeometry = classDiagramArrangement.arrangeGraphMLDiagram(); classDiagramManager.getClassDiagram().setGraphMLDiagramGeometry(nodesGeometry); + DiagramExporter graphMLExporter = new GraphMLClassDiagramExporter(classDiagramManager.getClassDiagram()); File exportedFile = graphMLExporter.exportDiagram(Paths.get(String.format("%s%s%s", PathConstructor.getCurrentPath(), diff --git a/src/test/java/model/exportation/JavaFXClassDiagramExporterTest.java b/src/test/java/model/exportation/JavaFXClassDiagramExporterTest.java index c4bdf66..4bc64d2 100644 --- a/src/test/java/model/exportation/JavaFXClassDiagramExporterTest.java +++ b/src/test/java/model/exportation/JavaFXClassDiagramExporterTest.java @@ -8,6 +8,8 @@ import model.diagram.exportation.JavaFXClassDiagramExporter; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.io.IOException; @@ -33,14 +35,7 @@ void exportDiagramTest() List chosenFiles = Arrays.asList("MainWindow", "LatexEditorView", "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); File actualFile = javaFXExporter.exportDiagram(Path.of(String.format("%s%s%s", @@ -59,10 +54,8 @@ void exportDiagramTest() { for (JsonElement actualElement : actualJsonArray) { - if (!actualElement.getAsJsonObject().get("name").equals(element.getAsJsonObject().get("name"))) - { - continue; - } + if (!actualElement.getAsJsonObject().get("name").equals(element.getAsJsonObject().get("name"))) continue; + assertEquals(element.getAsJsonObject().size(), actualElement.getAsJsonObject().size()); JsonArray expectedMethods = JsonParser.parseString(element.getAsJsonObject().get("methods").toString()).getAsJsonArray(); diff --git a/src/test/java/model/exportation/JavaFXPackageDiagramExporterTest.java b/src/test/java/model/exportation/JavaFXPackageDiagramExporterTest.java index 687d9e8..1482ac8 100644 --- a/src/test/java/model/exportation/JavaFXPackageDiagramExporterTest.java +++ b/src/test/java/model/exportation/JavaFXPackageDiagramExporterTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.io.IOException; @@ -46,18 +47,17 @@ void exportDiagramTest() try { PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))); + packageDiagramManager.createSourceProject(LatexEditor.SRC.path); packageDiagramManager.convertTreeToDiagram(getPackages()); DiagramExporter javaFXExporter = new JavaFXPackageDiagramExporter(packageDiagramManager.getPackageDiagram()); - File actualFile = javaFXExporter.exportDiagram(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", - "test", - "resources", - "testingExportedFile.txt"))); + File actualFile = javaFXExporter.exportDiagram(Path.of(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))); JsonArray expectedJsonArray = getJsonArray(); JsonArray actualJsonArray = JsonParser.parseString(Files.readAllLines(actualFile.toPath()).get(0)).getAsJsonArray(); @@ -94,12 +94,12 @@ void exportDiagramTest() } for (ClassifierVertex classifierVertex : expSinkVertices) { - Optional optionalSinkVertex = actSinkVertices.stream().filter(sinkVertex1 -> - sinkVertex1.getName().equals(classifierVertex.getName()) && - sinkVertex1.getVertexType().equals(classifierVertex.getVertexType()) && - sinkVertex1.getArcs().size() == classifierVertex.getArcs().size() && - sinkVertex1.getMethods().size() == classifierVertex.getMethods().size() && - sinkVertex1.getFields().size() == classifierVertex.getFields().size()) + Optional optionalSinkVertex = actSinkVertices.stream() + .filter(it -> it.getName().equals(classifierVertex.getName()) && + it.getVertexType().equals(classifierVertex.getVertexType()) && + it.getArcs().size() == classifierVertex.getArcs().size() && + it.getMethods().size() == classifierVertex.getMethods().size() && + it.getFields().size() == classifierVertex.getFields().size()) .findFirst(); assertTrue(optionalSinkVertex.isPresent()); @@ -107,24 +107,18 @@ void exportDiagramTest() for (ClassifierVertex.Field field : classifierVertex.getFields()) { assertTrue(fields.stream() - .anyMatch(field1 -> - field1.name().equals(field.name()) && - field1.type().equals(field.type()) && - field1.modifier().equals(field.modifier()) - ) - ); + .anyMatch(it -> it.name().equals(field.name()) && + it.type().equals(field.type()) && + it.modifier().equals(field.modifier()))); } List methods = optionalSinkVertex.get().getMethods(); for (ClassifierVertex.Method method : classifierVertex.getMethods()) { assertTrue(methods.stream() - .anyMatch(method1 -> - method1.name().equals(method.name()) && - method1.returnType().equals(method.returnType()) && - method1.parameters().equals(method.parameters()) - ) - ); + .anyMatch(it -> it.name().equals(method.name()) && + it.returnType().equals(method.returnType()) && + it.parameters().equals(method.parameters()))); } List> arcs = optionalSinkVertex.get().getArcs(); @@ -134,9 +128,7 @@ void exportDiagramTest() .anyMatch(sinkVertexArc -> sinkVertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && sinkVertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && - sinkVertexArc.arcType().equals(arc.arcType()) - ) - ); + sinkVertexArc.arcType().equals(arc.arcType()))); } } diff --git a/src/test/java/model/exportation/PlantUMLClassDiagramImageExporterTest.java b/src/test/java/model/exportation/PlantUMLClassDiagramImageExporterTest.java index 5c76779..5044d25 100644 --- a/src/test/java/model/exportation/PlantUMLClassDiagramImageExporterTest.java +++ b/src/test/java/model/exportation/PlantUMLClassDiagramImageExporterTest.java @@ -12,6 +12,7 @@ import net.sourceforge.plantuml.SourceStringReader; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -36,11 +37,14 @@ void exportDiagramTest() try { ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); - classDiagramManager.convertTreeToDiagram(List.of( - "StableVersionsStrategy", "VersionsStrategy", "VersionsStrategyFactory", "VolatileVersionsStrategy", - "VersionsManager", "Document", "DocumentManager") - ); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); + classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", + "VersionsStrategy", + "VersionsStrategyFactory", + "VolatileVersionsStrategy", + "VersionsManager", + "Document", + "DocumentManager")); PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(classDiagramManager.getClassDiagram()); String sinkVertexBuffer = plantUMLClassifierVertex.convertSinkVertex().toString(); @@ -48,15 +52,39 @@ void exportDiagramTest() String sinkVertexArcBuffer = plantUMLEdge.convertSinkVertexArc().toString(); DiagramExporter plantUMLExporter = new PlantUMLClassDiagramImageExporter(classDiagramManager.getClassDiagram()); - plantUMLExporter.exportDiagram(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.png"))); + plantUMLExporter.exportDiagram(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.png")))); InputStream in = getExpectedInputStream(sinkVertexBuffer, sinkVertexArcBuffer); BufferedImage convImg = ImageIO.read(in); - ImageIO.write(convImg, "png", Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "actualExportedFile.png")).toFile()); + ImageIO.write(convImg, "png", Path.of(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "actualExportedFile.png"))).toFile()); - BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.png")).toString()); - BufferedImage actualImage = ImageComparisonUtil.readImageFromResources(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "actualExportedFile.png")).toString()); + BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources(Path.of(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.png"))).toString()); + BufferedImage actualImage = ImageComparisonUtil.readImageFromResources(Path.of(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "actualExportedFile.png"))).toString()); ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).compareImages(); assertEquals(ImageComparisonState.MATCH, imageComparisonResult.getImageComparisonState()); } diff --git a/src/test/java/model/exportation/PlantUMLClassDiagramTextExporterTest.java b/src/test/java/model/exportation/PlantUMLClassDiagramTextExporterTest.java index 627ffd8..0e9ee24 100644 --- a/src/test/java/model/exportation/PlantUMLClassDiagramTextExporterTest.java +++ b/src/test/java/model/exportation/PlantUMLClassDiagramTextExporterTest.java @@ -7,6 +7,7 @@ import model.diagram.plantuml.PlantUMLClassifierVertexArc; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.io.IOException; @@ -27,14 +28,7 @@ void exportDiagramTest() try { ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", "VersionsStrategy", "VersionsStrategyFactory", diff --git a/src/test/java/model/graphml/GraphMLPackageVertexArcTest.java b/src/test/java/model/graphml/GraphMLPackageVertexArcTest.java index 457e238..88ba6db 100644 --- a/src/test/java/model/graphml/GraphMLPackageVertexArcTest.java +++ b/src/test/java/model/graphml/GraphMLPackageVertexArcTest.java @@ -5,13 +5,12 @@ import model.graph.Arc; import model.graph.PackageVertex; import org.junit.jupiter.api.Test; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; -import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import java.util.Set; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -22,14 +21,7 @@ public class GraphMLPackageVertexArcTest void convertVertexArcsToGraphMLTest() { PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + packageDiagramManager.createSourceProject(LatexEditor.SRC.path); packageDiagramManager.convertTreeToDiagram(List.of("src.view", "src.model", "src.model.strategies", @@ -39,13 +31,11 @@ void convertVertexArcsToGraphMLTest() StringBuilder actual = graphMLPackageVertexArc.convertVertexArc(); StringBuilder expected = new StringBuilder(); - List> arcs = new ArrayList<>(); - for (Set> arcSet : packageDiagramManager.getPackageDiagram().getDiagram().values()) - { - arcs.addAll(arcSet); - } - int edgeId = 0; + List> arcs = packageDiagramManager.getPackageDiagram().getDiagram().values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toCollection(ArrayList::new)); + int edgeId = 0; for (Arc e : arcs) { expected.append(String.format(""" @@ -61,11 +51,11 @@ void convertVertexArcsToGraphMLTest() \ """, - edgeId, + edgeId++, packageDiagramManager.getPackageDiagram().getGraphNodes().get(e.sourceVertex()), packageDiagramManager.getPackageDiagram().getGraphNodes().get(e.targetVertex()))); - edgeId++; } + assertEquals(expected.toString(), actual.toString()); } } diff --git a/src/test/java/model/graphml/GraphMLPackageVertexTest.java b/src/test/java/model/graphml/GraphMLPackageVertexTest.java index 4fadd3f..06f4d72 100644 --- a/src/test/java/model/graphml/GraphMLPackageVertexTest.java +++ b/src/test/java/model/graphml/GraphMLPackageVertexTest.java @@ -6,6 +6,8 @@ import org.javatuples.Pair; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.nio.file.Paths; @@ -21,7 +23,7 @@ class GraphMLPackageVertexTest void convertVerticesToGraphMLTest() { PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); + packageDiagramManager.createSourceProject(LatexEditor.SRC.path); packageDiagramManager.convertTreeToDiagram(List.of("src.view", "src.model", "src.model.strategies", diff --git a/src/test/java/model/graphml/GraphMLSinkPackageVertexArcTest.java b/src/test/java/model/graphml/GraphMLSinkPackageVertexArcTest.java index 379b092..7af9f95 100644 --- a/src/test/java/model/graphml/GraphMLSinkPackageVertexArcTest.java +++ b/src/test/java/model/graphml/GraphMLSinkPackageVertexArcTest.java @@ -6,6 +6,8 @@ import model.graph.ClassifierVertex; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.nio.file.Paths; @@ -23,13 +25,7 @@ public class GraphMLSinkPackageVertexArcTest void convertSinkVertexArcsToGraphMLTest() { ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s".formatted(PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", "ChangeVersionsStrategyCommand", "Command", diff --git a/src/test/java/model/graphml/GraphMLSinkPackageVertexTest.java b/src/test/java/model/graphml/GraphMLSinkPackageVertexTest.java index c9f7e80..4c6e1d3 100644 --- a/src/test/java/model/graphml/GraphMLSinkPackageVertexTest.java +++ b/src/test/java/model/graphml/GraphMLSinkPackageVertexTest.java @@ -7,6 +7,8 @@ import org.javatuples.Pair; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.nio.file.Paths; @@ -22,14 +24,7 @@ public class GraphMLSinkPackageVertexTest void convertSinkVerticesToGraphMLTest() { ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(List.of("AddLatexCommand", "ChangeVersionsStrategyCommand", "Command", @@ -91,10 +86,8 @@ void convertSinkVerticesToGraphMLTest() private String getNodesFields(ClassifierVertex l) { - if (l.getFields().isEmpty()) - { - return ""; - } + if (l.getFields().isEmpty()) return ""; + StringBuilder fields = new StringBuilder(); for (ClassifierVertex.Field field : l.getFields()) { @@ -106,10 +99,8 @@ private String getNodesFields(ClassifierVertex l) private String getNodesMethods(ClassifierVertex l) { - if ((l).getMethods().isEmpty()) - { - return ""; - } + if ((l).getMethods().isEmpty()) return ""; + StringBuilder methods = new StringBuilder(); for (ClassifierVertex.Method method : l.getMethods()) { @@ -121,11 +112,9 @@ private String getNodesMethods(ClassifierVertex l) private String getNodesColor(ClassifierVertex l) { - if (l.getVertexType().equals(VertexType.INTERFACE)) - { - return "#3366FF"; - } - return "#FF9900"; + return l.getVertexType().equals(VertexType.INTERFACE) ? + "#3366FF" : + "#FF9900"; } } diff --git a/src/test/java/model/javafx/JavaFXClassDiagramLoaderTest.java b/src/test/java/model/javafx/JavaFXClassDiagramLoaderTest.java index 142f344..9fbe046 100644 --- a/src/test/java/model/javafx/JavaFXClassDiagramLoaderTest.java +++ b/src/test/java/model/javafx/JavaFXClassDiagramLoaderTest.java @@ -9,10 +9,10 @@ import model.graph.ClassifierVertex; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -33,13 +33,7 @@ void loadDiagramTest() "LatexEditorView", "OpeningWindow"); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s".formatted(PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(chosenFiles); Map graphNodes = classDiagramManager.getClassDiagram().getGraphNodes(); @@ -47,7 +41,13 @@ void loadDiagramTest() Map>> createdDiagram = graphClassDiagramConverter.convertGraphToClassDiagram(); DiagramExporter javaFXExporter = new JavaFXClassDiagramExporter(classDiagramManager.getClassDiagram()); - File actualFile = javaFXExporter.exportDiagram(Path.of(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "testingExportedFile.txt"))); + File actualFile = javaFXExporter.exportDiagram(Path.of(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "testingExportedFile.txt")))); JavaFXClassDiagramLoader javaFXClassDiagramLoader = new JavaFXClassDiagramLoader(actualFile.toPath()); Set loadedDiagram = javaFXClassDiagramLoader.loadDiagram(); @@ -56,9 +56,8 @@ void loadDiagramTest() { Optional optionalSinkVertex = loadedDiagram .stream() - .filter(sinkVertex1 -> - sinkVertex1.getName().equals(classifierVertex.getName()) && - sinkVertex1.getVertexType().equals(classifierVertex.getVertexType())) + .filter(it -> it.getName().equals(classifierVertex.getName()) && + it.getVertexType().equals(classifierVertex.getVertexType())) .findFirst(); assertTrue(optionalSinkVertex.isPresent()); @@ -66,36 +65,30 @@ void loadDiagramTest() assertEquals(createdDiagram.get(classifierVertex).size(), arcs.size()); for (Arc arc : createdDiagram.get(classifierVertex)) { - assertTrue(arcs - .stream() - .anyMatch(sinkVertexArc -> - sinkVertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && - sinkVertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && - sinkVertexArc.arcType().equals(arc.arcType()))); + assertTrue(arcs.stream() + .anyMatch(it -> it.sourceVertex().getName().equals(arc.sourceVertex().getName()) && + it.targetVertex().getName().equals(arc.targetVertex().getName()) && + it.arcType().equals(arc.arcType()))); } List methods = optionalSinkVertex.get().getMethods(); assertEquals(classifierVertex.getMethods().size(), methods.size()); for (ClassifierVertex.Method method : classifierVertex.getMethods()) { - assertTrue(methods - .stream() - .anyMatch(method1 -> - method1.name().equals(method.name()) && - method1.returnType().equals(method.returnType()) && - method1.modifier().equals(method.modifier()))); + assertTrue(methods.stream() + .anyMatch(it -> it.name().equals(method.name()) && + it.returnType().equals(method.returnType()) && + it.modifier().equals(method.modifier()))); } List fields = optionalSinkVertex.get().getFields(); assertEquals(classifierVertex.getFields().size(), fields.size()); for (ClassifierVertex.Field field : classifierVertex.getFields()) { - assertTrue(fields - .stream() - .anyMatch(field1 -> - field1.name().equals(field.name()) && - field1.type().equals(field.type()) && - field1.modifier().equals(field.modifier()))); + assertTrue(fields.stream() + .anyMatch(it -> it.name().equals(field.name()) && + it.type().equals(field.type()) && + it.modifier().equals(field.modifier()))); } } } diff --git a/src/test/java/model/javafx/JavaFXPackageDiagramLoaderTest.java b/src/test/java/model/javafx/JavaFXPackageDiagramLoaderTest.java index 0800d10..e674e32 100644 --- a/src/test/java/model/javafx/JavaFXPackageDiagramLoaderTest.java +++ b/src/test/java/model/javafx/JavaFXPackageDiagramLoaderTest.java @@ -10,10 +10,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.Optional; @@ -29,14 +29,7 @@ public class JavaFXPackageDiagramLoaderTest void loadDiagramTest() { PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + packageDiagramManager.createSourceProject(LatexEditor.SRC.path); packageDiagramManager.convertTreeToDiagram(List.of("src.view", "src.model", "src.model.strategies", @@ -58,11 +51,9 @@ void loadDiagramTest() assertEquals(createdDiagram.size(), loadedDiagram.size()); for (PackageVertex vertex : createdDiagram.keySet()) { - Optional optionalVertex = loadedDiagram - .stream() - .filter(vertex1 -> - vertex1.getName().equals(vertex.getName()) && - vertex1.getVertexType().equals(vertex.getVertexType())) + Optional optionalVertex = loadedDiagram.stream() + .filter(it -> it.getName().equals(vertex.getName()) && + it.getVertexType().equals(vertex.getVertexType())) .findFirst(); assertTrue(optionalVertex.isPresent()); @@ -70,12 +61,10 @@ void loadDiagramTest() assertEquals(createdDiagram.get(vertex).size(), arcs.size()); for (Arc arc : createdDiagram.get(vertex)) { - arcs - .stream() - .filter(vertexArc -> - vertexArc.sourceVertex().getName().equals(arc.sourceVertex().getName()) && - vertexArc.targetVertex().getName().equals(arc.targetVertex().getName()) && - vertexArc.arcType().equals(arc.arcType())) + arcs.stream() + .filter(it -> it.sourceVertex().getName().equals(arc.sourceVertex().getName()) && + it.targetVertex().getName().equals(arc.targetVertex().getName()) && + it.arcType().equals(arc.arcType())) .findFirst() .orElseGet(Assertions::fail); } @@ -84,11 +73,9 @@ void loadDiagramTest() assertEquals(vertex.getSinkVertices().size(), sinkVertices.size()); for (ClassifierVertex classifierVertex : vertex.getSinkVertices()) { - sinkVertices - .stream() - .filter(sinkVertex1 -> - sinkVertex1.getName().equals(classifierVertex.getName()) && - sinkVertex1.getVertexType().equals(classifierVertex.getVertexType())) + sinkVertices.stream() + .filter(it -> it.getName().equals(classifierVertex.getName()) && + it.getVertexType().equals(classifierVertex.getVertexType())) .findFirst() .orElseGet(Assertions::fail); } @@ -97,11 +84,9 @@ void loadDiagramTest() assertEquals(vertex.getNeighbourVertices().size(), neighbours.size()); for (PackageVertex neighbour : vertex.getNeighbourVertices()) { - neighbours - .stream() - .filter(vertex1 -> - vertex1.getName().equals(neighbour.getName()) && - vertex1.getVertexType().equals(neighbour.getVertexType())) + neighbours.stream() + .filter(it -> it.getName().equals(neighbour.getName()) && + it.getVertexType().equals(neighbour.getVertexType())) .findFirst() .orElseGet(Assertions::fail); } diff --git a/src/test/java/model/plantuml/PlantUMLClassifierVertexArcTest.java b/src/test/java/model/plantuml/PlantUMLClassifierVertexArcTest.java index 3cc2d96..43fd92e 100644 --- a/src/test/java/model/plantuml/PlantUMLClassifierVertexArcTest.java +++ b/src/test/java/model/plantuml/PlantUMLClassifierVertexArcTest.java @@ -4,6 +4,8 @@ import model.diagram.plantuml.PlantUMLClassifierVertexArc; import org.junit.jupiter.api.Test; import utils.PathConstructor; +import utils.PathTemplate; +import utils.PathTemplate.LatexEditor; import java.io.File; import java.nio.file.Paths; @@ -34,13 +36,7 @@ void convertSinkVertexArcTest() """; ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s".formatted(PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", "VersionsStrategy", "VersionsStrategyFactory", diff --git a/src/test/java/model/plantuml/PlantUMLClassifierVertexTest.java b/src/test/java/model/plantuml/PlantUMLClassifierVertexTest.java index 59e3b9f..fb271ed 100644 --- a/src/test/java/model/plantuml/PlantUMLClassifierVertexTest.java +++ b/src/test/java/model/plantuml/PlantUMLClassifierVertexTest.java @@ -3,10 +3,8 @@ import manager.ClassDiagramManager; import model.diagram.plantuml.PlantUMLClassifierVertex; import org.junit.jupiter.api.Test; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -21,14 +19,7 @@ void convertSinkVertexTest() { ClassDiagramManager classDiagramManager = new ClassDiagramManager(); - classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + classDiagramManager.createSourceProject(LatexEditor.SRC.path); classDiagramManager.convertTreeToDiagram(List.of("StableVersionsStrategy", "VersionsStrategy", "VersionsStrategyFactory", diff --git a/src/test/java/model/plantuml/PlantUMLPackageVertexArcTest.java b/src/test/java/model/plantuml/PlantUMLPackageVertexArcTest.java index 47762af..0ec17cb 100644 --- a/src/test/java/model/plantuml/PlantUMLPackageVertexArcTest.java +++ b/src/test/java/model/plantuml/PlantUMLPackageVertexArcTest.java @@ -3,10 +3,8 @@ import manager.PackageDiagramManager; import model.diagram.plantuml.PlantUMLPackageVertexArc; import org.junit.jupiter.api.Test; -import utils.PathConstructor; +import utils.PathTemplate; -import java.io.File; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -32,22 +30,9 @@ class PlantUMLPackageVertexArcTest @Test void convertVertexArcTest() { - // - // Given - // PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + packageDiagramManager.createSourceProject(PathTemplate.LatexEditor.SRC.path); - // - // When - // packageDiagramManager.convertTreeToDiagram(List.of("src.view", "src.model", "src.model.strategies", @@ -56,9 +41,6 @@ void convertVertexArcTest() PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(packageDiagramManager.getPackageDiagram()); String actualBuffer = plantUMLEdge.convertVertexArc().toString(); - // - // Then - // List expectedRelationship = Arrays.asList(EXPECTED_BUFFER.split("\n")); List actualRelationship = Arrays.asList(actualBuffer.split("\n")); Collections.sort(expectedRelationship); diff --git a/src/test/java/model/plantuml/PlantUMLPackageVertexTest.java b/src/test/java/model/plantuml/PlantUMLPackageVertexTest.java index 412d4bc..67fd7f9 100644 --- a/src/test/java/model/plantuml/PlantUMLPackageVertexTest.java +++ b/src/test/java/model/plantuml/PlantUMLPackageVertexTest.java @@ -3,10 +3,8 @@ import manager.PackageDiagramManager; import model.diagram.plantuml.PlantUMLPackageVertex; import org.junit.jupiter.api.Test; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -21,7 +19,7 @@ void convertVertexTest() { PackageDiagramManager packageDiagramManager = new PackageDiagramManager(); - packageDiagramManager.createSourceProject(Paths.get(PathConstructor.getCurrentPath() + File.separator + PathConstructor.constructPath("src", "test", "resources", "LatexEditor", "src"))); + packageDiagramManager.createSourceProject(LatexEditor.SRC.path); packageDiagramManager.convertTreeToDiagram(List.of("src", "src.view", "src.model", diff --git a/src/test/java/parser/FileVisitorTest.java b/src/test/java/parser/FileVisitorTest.java index 961a07c..9c117e5 100644 --- a/src/test/java/parser/FileVisitorTest.java +++ b/src/test/java/parser/FileVisitorTest.java @@ -7,11 +7,10 @@ import parser.tree.LeafNode; import parser.tree.NodeType; import parser.tree.PackageNode; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; +import utils.PathTemplate.ParserTesting; -import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -21,6 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static parser.tree.NodeType.CLASS; +import static parser.tree.NodeType.INTERFACE; public class FileVisitorTest { @@ -32,34 +33,20 @@ public class FileVisitorTest void methodReturnTypesTest() { Parser parser = ProjectParserFactory.createProjectParser(parserType); + Map packages = parser.parseSourcePackage(LatexEditor.SRC.path); - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath().toString(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); + PackageNode commandPackage = packages.get(LatexEditor.COMMANDS.path); LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); - List methodReturnTypesExpected = new ArrayList<>(Arrays.asList("Constructor", - "void")); + List methodReturnTypesExpected = new ArrayList<>(Arrays.asList("Constructor", "void")); List methodReturnTypesActual = addLatexCommand.getMethodReturnTypes(); Collections.sort(methodReturnTypesActual); Collections.sort(methodReturnTypesExpected); - assertTrue(methodReturnTypesActual.size() == methodReturnTypesExpected.size() && - methodReturnTypesExpected.containsAll(methodReturnTypesActual) && - methodReturnTypesActual.containsAll(methodReturnTypesExpected)); + + assertEquals(methodReturnTypesExpected.size(), methodReturnTypesActual.size()); + assertTrue(methodReturnTypesExpected.containsAll(methodReturnTypesActual)); + assertTrue(methodReturnTypesActual.containsAll(methodReturnTypesExpected)); } @@ -68,22 +55,8 @@ void methodParameterTypesTest() { Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); + Map packages = parser.parseSourcePackage(LatexEditor.SRC.path); + PackageNode commandPackage = packages.get(LatexEditor.COMMANDS.path); LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); List methodParameterTypes = new ArrayList<>(List.of("VersionsManager")); @@ -91,9 +64,10 @@ void methodParameterTypesTest() Collections.sort(methodParameterTypesTest); Collections.sort(methodParameterTypes); - assertTrue(methodParameterTypesTest.size() == methodParameterTypes.size() && - methodParameterTypes.containsAll(methodParameterTypesTest) && - methodParameterTypesTest.containsAll(methodParameterTypes)); + + assertEquals(methodParameterTypes.size(), methodParameterTypesTest.size()); + assertTrue(methodParameterTypes.containsAll(methodParameterTypesTest)); + assertTrue(methodParameterTypesTest.containsAll(methodParameterTypes)); } @@ -102,22 +76,8 @@ void fieldTypesTest() { Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); + Map packages = parser.parseSourcePackage(LatexEditor.SRC.path); + PackageNode commandPackage = packages.get(LatexEditor.COMMANDS.path); LeafNode addLatexCommand = commandPackage.getLeafNodes().get("AddLatexCommand"); List fieldTypes = new ArrayList<>(List.of("VersionsManager")); List fieldTypesTest = addLatexCommand @@ -128,9 +88,10 @@ void fieldTypesTest() .collect(Collectors.toCollection(ArrayList::new)); Collections.sort(fieldTypes); - assertTrue(fieldTypesTest.size() == fieldTypes.size() && - fieldTypes.containsAll(fieldTypesTest) && - fieldTypesTest.containsAll(fieldTypes)); + + assertEquals(fieldTypes.size(), fieldTypesTest.size()); + assertTrue(fieldTypes.containsAll(fieldTypesTest)); + assertTrue(fieldTypesTest.containsAll(fieldTypes)); } @@ -139,16 +100,8 @@ void variableTypesTest() { Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - "/src/test/resources/LatexEditor/src/controller")); + Map packages = parser.parseSourcePackage(LatexEditor.SRC.path); + PackageNode commandPackage = packages.get(LatexEditor.CONTROLLER.path); LeafNode latexEditorController = commandPackage.getLeafNodes().get("LatexEditorController"); List variablesTypes = new ArrayList<>(List.of("CommandFactory")); @@ -156,9 +109,10 @@ void variableTypesTest() Collections.sort(variablesTypesTest); Collections.sort(variablesTypes); - assertTrue(variablesTypesTest.size() == variablesTypes.size() && - variablesTypes.containsAll(variablesTypesTest) && - variablesTypesTest.containsAll(variablesTypes)); + + assertEquals(variablesTypes.size(), variablesTypesTest.size()); + assertTrue(variablesTypes.containsAll(variablesTypesTest)); + assertTrue(variablesTypesTest.containsAll(variablesTypes)); } @@ -167,18 +121,8 @@ void objectCreationTest() { Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting")))); - PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting"))); + Map packages = parser.parseSourcePackage(ParserTesting.SRC.path); + PackageNode sourcePackage = packages.get(ParserTesting.SRC.path); LeafNode objectCreationSample = sourcePackage.getLeafNodes().get("ObjectCreationSample"); List objectsCreatedExpected = new ArrayList<>(List.of("ImplementingClass", @@ -189,9 +133,10 @@ void objectCreationTest() Collections.sort(objectsCreatedActual); Collections.sort(objectsCreatedExpected); - assertTrue(objectsCreatedActual.size() == objectsCreatedExpected.size() && - objectsCreatedExpected.containsAll(objectsCreatedActual) && - objectsCreatedActual.containsAll(objectsCreatedExpected)); + + assertEquals(objectsCreatedExpected.size(), objectsCreatedActual.size()); + assertTrue(objectsCreatedExpected.containsAll(objectsCreatedActual)); + assertTrue(objectsCreatedActual.containsAll(objectsCreatedExpected)); } @@ -200,45 +145,49 @@ void leafNodeTypesTest() { Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting")))); - PackageNode inheritancePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting"))); + Map packages = parser.parseSourcePackage(ParserTesting.SRC.path); + PackageNode inheritancePackage = packages.get(ParserTesting.SRC.path); + List classLeafs = new ArrayList<>(); - List interfaceLeafs = new ArrayList<>(); classLeafs.add(inheritancePackage.getLeafNodes().get("ImplementingClass")); classLeafs.add(inheritancePackage.getLeafNodes().get("ExtensionClass")); + + List interfaceLeafs = new ArrayList<>(); interfaceLeafs.add(inheritancePackage.getLeafNodes().get("TestingInterface")); interfaceLeafs.add(inheritancePackage.getLeafNodes().get("TestingInterface2")); - for (LeafNode l : classLeafs) - { - assertEquals(NodeType.CLASS, l.nodeType()); - } - for (LeafNode l : interfaceLeafs) - { - assertEquals(NodeType.INTERFACE, l.nodeType()); - } - - PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting"))); + long classCount = classLeafs.stream() + .filter(it -> it.nodeType().equals(CLASS)) + .count(); + assertEquals(classCount, classLeafs.size()); + long interfaceCount = interfaceLeafs.stream() + .filter(it -> it.nodeType().equals(INTERFACE)) + .count(); + assertEquals(interfaceCount, interfaceLeafs.size()); + + PackageNode sourcePackage = packages.get(ParserTesting.SRC.path); LeafNode enumTest = sourcePackage.getLeafNodes().get("EnumSample"); assertEquals(NodeType.ENUM, enumTest.nodeType()); LeafNode objectCreationTest = sourcePackage.getLeafNodes().get("ObjectCreationSample"); - assertEquals(NodeType.CLASS, objectCreationTest.nodeType()); + assertEquals(CLASS, objectCreationTest.nodeType()); + } + + @Test + void inheritanceTest() + { + Parser parser = ProjectParserFactory.createProjectParser(parserType); + + Map packages = parser.parseSourcePackage(ParserTesting.SRC.path); + PackageNode inheritancePackage = packages.get(ParserTesting.SRC.path); + + LeafNode implementingClass = inheritancePackage.getLeafNodes().get("ImplementingClass"); + assertEquals(2, implementingClass.implementedInterfaces().size()); + assertTrue(implementingClass.implementedInterfaces().contains("TestingInterface")); + assertTrue(implementingClass.implementedInterfaces().contains("TestingInterface2")); + + assertEquals("ExtensionClass", implementingClass.baseClass()); } @@ -247,21 +196,16 @@ void innerMembersTest() { Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting")))); - PackageNode sourcePackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "ParserTesting"))); + Map packages = parser.parseSourcePackage(ParserTesting.SRC.path); + PackageNode sourcePackage = packages.get(ParserTesting.SRC.path); + LeafNode innerClassSample = sourcePackage.getLeafNodes().get("InnerClassSample"); - assertEquals(innerClassSample.innerClasses().get(0).nodeName(), "InnerClass"); - assertEquals(innerClassSample.records().get(0), "RecordSample"); + + assertEquals(innerClassSample.innerClasses().size(), 1); + assertEquals("InnerClass", innerClassSample.innerClasses().get(0).nodeName()); + + assertEquals(innerClassSample.records().size(), 1); + assertEquals("RecordSample", innerClassSample.records().get(0)); } @@ -276,16 +220,8 @@ void importsTest() Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packages = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - PackageNode commandPackage = packages.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - "/src/test/resources/LatexEditor/src/model")); + Map packages = parser.parseSourcePackage(LatexEditor.SRC.path); + PackageNode commandPackage = packages.get(LatexEditor.MODEL.path); LeafNode versionsManager = commandPackage.getLeafNodes().get("VersionsManager"); List imports = versionsManager.imports(); assertEquals(expectedImports, imports); diff --git a/src/test/java/parser/InterpreterTest.java b/src/test/java/parser/InterpreterTest.java index fb18622..5824a41 100644 --- a/src/test/java/parser/InterpreterTest.java +++ b/src/test/java/parser/InterpreterTest.java @@ -8,11 +8,9 @@ import parser.tree.LeafNode; import parser.tree.PackageNode; import parser.tree.Relationship; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.Set; @@ -27,14 +25,7 @@ public class InterpreterTest public void convertTreeToGraphTest() { Interpreter interpreter = new Interpreter(); - interpreter.parseProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); + interpreter.parseProject(LatexEditor.SRC.path); interpreter.convertTreeToGraph(); Map packageNodes = interpreter.getPackageNodes(); Map vertices = interpreter.getVertices(); @@ -54,12 +45,10 @@ public void convertTreeToGraphTest() assertEquals(subNodes.size(), neighbours.size()); for (Map.Entry subNode : subNodes.entrySet()) { - assertTrue(neighbours - .stream() - .anyMatch(it -> - it.getPath().toString().equals(subNode.getKey().toString()) && - it.getName().equals(subNode.getValue().getNodeName()) && - it.getVertexType().toString().equals(subNode.getValue().getNodeType().toString()))); + assertTrue(neighbours.stream() + .anyMatch(it -> it.getPath().toString().equals(subNode.getKey().toString()) && + it.getName().equals(subNode.getValue().getNodeName()) && + it.getVertexType().toString().equals(subNode.getValue().getNodeType().toString()))); } Map>> packageNodeRelationships = interpreter.getPackageNodeRelationships(); @@ -74,12 +63,10 @@ public void convertTreeToGraphTest() assertEquals(relationships.size(), arcs.size()); for (Relationship relationship : relationships) { - assertTrue(arcs - .stream() - .anyMatch(a -> - a.arcType().toString().equals(relationship.relationshipType().toString()) && - a.sourceVertex().getPath().equals(relationship.startingNode().getPath()) && - a.targetVertex().getPath().equals(relationship.endingNode().getPath()))); + assertTrue(arcs.stream() + .anyMatch(it -> it.arcType().toString().equals(relationship.relationshipType().toString()) && + it.sourceVertex().getPath().equals(relationship.startingNode().getPath()) && + it.targetVertex().getPath().equals(relationship.endingNode().getPath()))); } Map leafNodes = packageNode.getLeafNodes(); @@ -98,26 +85,22 @@ public void convertTreeToGraphTest() List vertexMethods = classifierVertex.getMethods(); for (LeafNode.Method leafMethod : leafMethods) { - assertTrue(vertexMethods - .stream() - .anyMatch(it -> - it.name().equals(leafMethod.methodName()) && - it.parameters().size() == leafMethod.parameters().size() && - it.parameters().equals(leafMethod.parameters()) && - it.returnType().equals(leafMethod.returnType()) && - it.modifier().toString().equals(leafMethod.modifierType().toString()))); + assertTrue(vertexMethods.stream() + .anyMatch(it -> it.name().equals(leafMethod.methodName()) && + it.parameters().size() == leafMethod.parameters().size() && + it.parameters().equals(leafMethod.parameters()) && + it.returnType().equals(leafMethod.returnType()) && + it.modifier().toString().equals(leafMethod.modifierType().toString()))); } List leafFields = leafNodeEntry.getValue().fields(); List vertexFields = classifierVertex.getFields(); for (LeafNode.Field leafField : leafFields) { - assertTrue(vertexFields - .stream() - .anyMatch(it -> - it.name().equals(leafField.fieldNames()) && - it.type().equals(leafField.fieldType()) && - it.modifier().toString().equals(leafField.modifierType().toString()))); + assertTrue(vertexFields.stream() + .anyMatch(it -> it.name().equals(leafField.fieldNames()) && + it.type().equals(leafField.fieldType()) && + it.modifier().toString().equals(leafField.modifierType().toString()))); } Map>> leafNodeRelationships = interpreter.getLeafNodeRelationships(); @@ -132,12 +115,10 @@ public void convertTreeToGraphTest() assertEquals(subNodeRelationships.size(), sinkVertexArcs.size()); for (Relationship relationship : subNodeRelationships) { - assertTrue(sinkVertexArcs - .stream() - .anyMatch(it -> - it.arcType().toString().equals(relationship.relationshipType().toString()) && - it.sourceVertex().getPath().equals(relationship.startingNode().path()) && - it.targetVertex().getPath().equals(relationship.endingNode().path()))); + assertTrue(sinkVertexArcs.stream() + .anyMatch(it -> it.arcType().toString().equals(relationship.relationshipType().toString()) && + it.sourceVertex().getPath().equals(relationship.startingNode().path()) && + it.targetVertex().getPath().equals(relationship.endingNode().path()))); } } } diff --git a/src/test/java/parser/PackageNodeCleanerTest.java b/src/test/java/parser/PackageNodeCleanerTest.java index ba48796..b937254 100644 --- a/src/test/java/parser/PackageNodeCleanerTest.java +++ b/src/test/java/parser/PackageNodeCleanerTest.java @@ -2,11 +2,9 @@ import org.junit.jupiter.api.Test; import parser.tree.PackageNode; -import utils.PathConstructor; +import utils.PathTemplate.BookstoreAdvanced; -import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -16,123 +14,37 @@ public class PackageNodeCleanerTest { + + public static final int NON_VALID_NODES = 5; + + @Test void removeNonPackageNodesTest() { Interpreter interpreter = new Interpreter(); - interpreter.parseProject(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01")))); + interpreter.parseProject(BookstoreAdvanced.SRC_ROOT.path); Map packageNodes = interpreter.getPackageNodes(); Map validPackageNodes = PackageNodeCleaner.removeNonPackageNodes(packageNodes); - assertEquals(packageNodes.size(), validPackageNodes.size() + 5); + assertEquals(packageNodes.size(), validPackageNodes.size() + NON_VALID_NODES); - // Valid Package Nodes - assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src"))))); - assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "bookstore"))))); - assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "gui"))))); - assertTrue(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01"))))); + // Valid Package Nodes. + assertTrue(validPackageNodes.containsKey(BookstoreAdvanced.SRC.path)); + assertTrue(validPackageNodes.containsKey(BookstoreAdvanced.BOOKSTORE.path)); + assertTrue(validPackageNodes.containsKey(BookstoreAdvanced.GUI.path)); + assertTrue(validPackageNodes.containsKey(BookstoreAdvanced.SRC_ROOT.path)); - // Non Valid Package Nodes - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - ".settings"))))); - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "bin"))))); - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "bin", - "bookstore"))))); - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "bin", - "gui"))))); - assertFalse(validPackageNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src", - "lib"))))); + // Non Valid Package Nodes. + assertFalse(validPackageNodes.containsKey(BookstoreAdvanced.DOT_SETTINGS.path)); + assertFalse(validPackageNodes.containsKey(BookstoreAdvanced.BIN.path)); + assertFalse(validPackageNodes.containsKey(BookstoreAdvanced.BIN_BOOKSTORE.path)); + assertFalse(validPackageNodes.containsKey(BookstoreAdvanced.BIN_GUI.path)); + assertFalse(validPackageNodes.containsKey(BookstoreAdvanced.LIB.path)); - PackageNode sourcePackage = validPackageNodes.get(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01")))); + PackageNode sourcePackage = validPackageNodes.get(BookstoreAdvanced.SRC_ROOT.path); Map sourcePackageSubNodes = sourcePackage.getSubNodes(); assertEquals(sourcePackageSubNodes.size(), 1); - assertTrue(sourcePackageSubNodes.containsKey(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "BookstoreAdvancedV01", - "src"))))); + assertTrue(sourcePackageSubNodes.containsKey(BookstoreAdvanced.SRC.path)); } } diff --git a/src/test/java/parser/ProjectParserTest.java b/src/test/java/parser/ProjectParserTest.java index fb9b069..5d09109 100644 --- a/src/test/java/parser/ProjectParserTest.java +++ b/src/test/java/parser/ProjectParserTest.java @@ -6,9 +6,8 @@ import parser.factory.ProjectParserFactory; import parser.tree.LeafNode; import parser.tree.PackageNode; -import utils.PathConstructor; +import utils.PathTemplate.LatexEditor; -import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -16,6 +15,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -26,113 +26,71 @@ public class ProjectParserTest ParserType parserType = ParserType.JAVAPARSER; + public static final List SOURCES_SUB_PACKAGES = new ArrayList<>(Arrays.asList(LatexEditor.CONTROLLER.path, + LatexEditor.MODEL.path, + LatexEditor.VIEW.path)); + + public static final List VIEWS_LEAF_NODES = new ArrayList<>(Arrays.asList(LatexEditor.CHOOSE_TEMPLATE.path, + LatexEditor.LATEX_EDITOR.path, + LatexEditor.MAIN_WINDOW.path, + LatexEditor.OPENING_WINDOW.path)); + + public static final List CONTROLLERS_LEAF_NODES = new ArrayList<>(List.of(LatexEditor.LATEX_EDITOR_CONTROLLER.path)); + + public static final List STRATEGIES_LEAF_NODES = new ArrayList<>(Arrays.asList(LatexEditor.STABLE_VERSIONS_STRATEGY.path, + LatexEditor.VERSIONS_STRATEGY.path, + LatexEditor.VOLATILE_VERSIONS_STRATEGY.path, + LatexEditor.VERSIONS_STRATEGY_FACTORY.path)); + public static final List MODELS_LEAF_NODES = new ArrayList<>(Arrays.asList(LatexEditor.DOCUMENT.path, + LatexEditor.DOCUMENT_MANAGER.path, + LatexEditor.VERSIONS_MANAGER.path)); + + public static final List COMMANDS_LEAF_NODES = new ArrayList<>(Arrays.asList(LatexEditor.ADD_LATEX_COMMAND.path, + LatexEditor.COMMAND.path, + LatexEditor.COMMAND_FACTORY.path, + LatexEditor.CREATE_COMMAND.path, + LatexEditor.EDIT_COMMAND.path, + LatexEditor.LOAD_COMMAND.path, + LatexEditor.SAVE_COMMAND.path, + LatexEditor.CHANGE_VERSIONS_STRATEGY_COMMAND.path, + LatexEditor.DISABLE_VERSIONS_MANAGER_COMMAND.path, + LatexEditor.ENABLE_VERSIONS_MANAGE_COMMAND.path, + LatexEditor.ROLLBACK_TO_PREVIOUS_VERSION_COMMAND.path)); @Test void parsingTest() { Parser parser = ProjectParserFactory.createProjectParser(parserType); - Map packageNodes = parser.parseSourcePackage(Paths.get(String.format("%s%s%s", - PathConstructor.getCurrentPath(), - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - - PackageNode controllerPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller"))); + Map packageNodes = parser.parseSourcePackage(LatexEditor.SRC.path); + + PackageNode controllerPackage = packageNodes.get(LatexEditor.CONTROLLER.path); List testingLeafNodes = new ArrayList<>(); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller")), - controllerPackage.getPath()); - - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))), - controllerPackage.getParentNode().getPath()); + assertEquals(LatexEditor.CONTROLLER.path, controllerPackage.getPath()); + + assertEquals(LatexEditor.SRC.path, controllerPackage.getParentNode().getPath()); assertTrue(controllerPackage.isValid(), "message"); Map subNodes = controllerPackage.getSubNodes(); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands")), - subNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))).getPath()); + assertEquals(LatexEditor.COMMANDS.path, subNodes.get(LatexEditor.COMMANDS.path).getPath()); for (LeafNode l : controllerPackage.getLeafNodes().values()) { testingLeafNodes.add(l.path()); - assertEquals(l.parentNode().getPath(), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller"))); + assertEquals(l.parentNode().getPath(), LatexEditor.CONTROLLER.path); } Collections.sort(testingLeafNodes); Collections.sort(CONTROLLERS_LEAF_NODES); - assertTrue(testingLeafNodes.size() == CONTROLLERS_LEAF_NODES.size() && - CONTROLLERS_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(CONTROLLERS_LEAF_NODES)); + + assertEquals(CONTROLLERS_LEAF_NODES.size(), testingLeafNodes.size()); + assertTrue(CONTROLLERS_LEAF_NODES.containsAll(testingLeafNodes)); + assertTrue(testingLeafNodes.containsAll(CONTROLLERS_LEAF_NODES)); testingLeafNodes.clear(); - PackageNode commandsPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands")), - commandsPackage.getPath()); - - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller")), - commandsPackage.getParentNode().getPath()); + PackageNode commandsPackage = packageNodes.get(LatexEditor.COMMANDS.path); + assertEquals(LatexEditor.COMMANDS.path, commandsPackage.getPath()); + assertEquals(LatexEditor.CONTROLLER.path, commandsPackage.getParentNode().getPath()); assertTrue(commandsPackage.isValid()); subNodes = commandsPackage.getSubNodes(); @@ -140,443 +98,97 @@ void parsingTest() for (LeafNode l : commandsPackage.getLeafNodes().values()) { testingLeafNodes.add(l.path()); - assertEquals(l.parentNode().getPath(), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands"))); + assertEquals(l.parentNode().getPath(), LatexEditor.COMMANDS.path); } Collections.sort(testingLeafNodes); Collections.sort(COMMANDS_LEAF_NODES); - assertTrue(testingLeafNodes.size() == COMMANDS_LEAF_NODES.size() && - COMMANDS_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(COMMANDS_LEAF_NODES)); + + assertEquals(COMMANDS_LEAF_NODES.size(), testingLeafNodes.size()); + assertTrue(COMMANDS_LEAF_NODES.containsAll(testingLeafNodes)); + assertTrue(testingLeafNodes.containsAll(COMMANDS_LEAF_NODES)); testingLeafNodes.clear(); - PackageNode modelPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model"))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model")), - modelPackage.getPath()); - - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))), - modelPackage.getParentNode().getPath()); + PackageNode modelPackage = packageNodes.get(LatexEditor.MODEL.path); + assertEquals(LatexEditor.MODEL.path, modelPackage.getPath()); + + assertEquals(LatexEditor.SRC.path, modelPackage.getParentNode().getPath()); assertTrue(modelPackage.isValid()); subNodes = modelPackage.getSubNodes(); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies")), - subNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies"))).getPath()); + assertEquals(LatexEditor.STRATEGIES.path, subNodes.get(LatexEditor.STRATEGIES.path).getPath()); + for (LeafNode l : modelPackage.getLeafNodes().values()) { - assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model"))); + assertEquals(l.parentNode().getPath(), LatexEditor.MODEL.path); testingLeafNodes.add(l.path()); } Collections.sort(testingLeafNodes); Collections.sort(MODELS_LEAF_NODES); - assertTrue(testingLeafNodes.size() == MODELS_LEAF_NODES.size() && - MODELS_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(MODELS_LEAF_NODES)); + + assertEquals(MODELS_LEAF_NODES.size(), testingLeafNodes.size()); + assertTrue(MODELS_LEAF_NODES.containsAll(testingLeafNodes)); + assertTrue(testingLeafNodes.containsAll(MODELS_LEAF_NODES)); testingLeafNodes.clear(); - PackageNode strategiesPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies"))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies")), - strategiesPackage.getPath()); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model")), - strategiesPackage.getParentNode().getPath()); + PackageNode strategiesPackage = packageNodes.get(LatexEditor.STRATEGIES.path); + assertEquals(LatexEditor.STRATEGIES.path, strategiesPackage.getPath()); + assertEquals(LatexEditor.MODEL.path, strategiesPackage.getParentNode().getPath()); assertTrue(strategiesPackage.isValid()); subNodes = strategiesPackage.getSubNodes(); assertEquals(0, subNodes.size()); for (LeafNode l : strategiesPackage.getLeafNodes().values()) { - assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies"))); + assertEquals(l.parentNode().getPath(), LatexEditor.STRATEGIES.path); testingLeafNodes.add(l.path()); } Collections.sort(testingLeafNodes); Collections.sort(STRATEGIES_LEAF_NODES); - assertTrue(testingLeafNodes.size() == STRATEGIES_LEAF_NODES.size() && - STRATEGIES_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(STRATEGIES_LEAF_NODES)); + + assertEquals(STRATEGIES_LEAF_NODES.size(), testingLeafNodes.size()); + assertTrue(STRATEGIES_LEAF_NODES.containsAll(testingLeafNodes)); + assertTrue(testingLeafNodes.containsAll(STRATEGIES_LEAF_NODES)); testingLeafNodes.clear(); - PackageNode viewPackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view"))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view")), - viewPackage.getPath()); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))), - viewPackage.getParentNode().getPath()); + PackageNode viewPackage = packageNodes.get(LatexEditor.VIEW.path); + assertEquals(LatexEditor.VIEW.path, viewPackage.getPath()); + assertEquals(LatexEditor.SRC.path, viewPackage.getParentNode().getPath()); assertTrue(viewPackage.isValid()); subNodes = viewPackage.getSubNodes(); assertEquals(0, subNodes.size()); for (LeafNode l : viewPackage.getLeafNodes().values()) { - assertEquals(l.parentNode().getPath(), Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view"))); + assertEquals(l.parentNode().getPath(), LatexEditor.VIEW.path); testingLeafNodes.add(l.path()); } + Collections.sort(testingLeafNodes); Collections.sort(VIEWS_LEAF_NODES); - assertTrue(testingLeafNodes.size() == VIEWS_LEAF_NODES.size() && - VIEWS_LEAF_NODES.containsAll(testingLeafNodes) && - testingLeafNodes.containsAll(VIEWS_LEAF_NODES)); + + assertEquals(VIEWS_LEAF_NODES.size(), testingLeafNodes.size()); + assertTrue(VIEWS_LEAF_NODES.containsAll(testingLeafNodes)); + assertTrue(testingLeafNodes.containsAll(VIEWS_LEAF_NODES)); + testingLeafNodes.clear(); - PackageNode sourcePackage = packageNodes.get(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src")))); - assertEquals(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - String.format("%s%s", - File.separator, - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src"))), - sourcePackage.getPath()); + PackageNode sourcePackage = packageNodes.get(LatexEditor.SRC.path); + assertEquals(LatexEditor.SRC.path, sourcePackage.getPath()); assertEquals(Paths.get(""), sourcePackage.getParentNode().getPath()); assertFalse(sourcePackage.isValid()); subNodes = sourcePackage.getSubNodes(); - List testingSubPackages = new ArrayList<>(); - for (PackageNode subP : subNodes.values()) - { - testingSubPackages.add(subP.getPath()); - } - Collections.sort(testingSubPackages); + List testingSubPackages = subNodes.values().stream() + .map(PackageNode::getPath) + .sorted() + .collect(Collectors.toCollection(ArrayList::new)); + Collections.sort(SOURCES_SUB_PACKAGES); - assertTrue(testingSubPackages.size() == SOURCES_SUB_PACKAGES.size() && - SOURCES_SUB_PACKAGES.containsAll(testingSubPackages) && - testingSubPackages.containsAll(SOURCES_SUB_PACKAGES)); + + assertEquals(SOURCES_SUB_PACKAGES.size(), testingSubPackages.size()); + assertTrue(SOURCES_SUB_PACKAGES.containsAll(testingSubPackages)); + assertTrue(testingSubPackages.containsAll(SOURCES_SUB_PACKAGES)); assertEquals(0, sourcePackage.getLeafNodes().size()); } - - - public static final List SOURCES_SUB_PACKAGES = - new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view")))); - - public static final List VIEWS_LEAF_NODES = - new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view", - "ChooseTemplate.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view", - "LatexEditorView.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view", - "MainWindow.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "view", - "OpeningWindow.java")))); - - public static final List CONTROLLERS_LEAF_NODES = - new ArrayList<>(List.of(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "LatexEditorController.java")))); - - public static final List STRATEGIES_LEAF_NODES = - new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies", - "StableVersionsStrategy.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies", - "VersionsStrategy.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies", - "VolatileVersionsStrategy.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "strategies", - "VersionsStrategyFactory.java")))); - - public static final List MODELS_LEAF_NODES = - new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "Document.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "DocumentManager.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "model", - "VersionsManager.java")))); - - public static final List COMMANDS_LEAF_NODES = - new ArrayList<>(Arrays.asList(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "AddLatexCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "Command.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "CommandFactory.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "CreateCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "EditCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "LoadCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "SaveCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "ChangeVersionsStrategyCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "DisableVersionsManagementCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "EnableVersionsManagementCommand.java")), - Paths.get(PathConstructor.getCurrentPath().normalize().toString(), - PathConstructor.constructPath("src", - "test", - "resources", - "LatexEditor", - "src", - "controller", - "commands", - "RollbackToPreviousVersionCommand.java")))); } diff --git a/src/test/java/utils/PathConstructor.java b/src/test/java/utils/PathConstructor.java index 3288d41..7d636ac 100644 --- a/src/test/java/utils/PathConstructor.java +++ b/src/test/java/utils/PathConstructor.java @@ -10,27 +10,20 @@ public class PathConstructor public static String constructPath(String... strings) { - StringBuilder path = new StringBuilder(); - for (String string : strings) - { - path.append(File.separator).append(string); - } - return path.toString(); + return String.join(File.separator, strings); } public static Path getCurrentPath() { - Path currentDirectory; try { - currentDirectory = Path.of(".").toRealPath(); + return Path.of(".").toRealPath(); } catch (IOException e) { throw new RuntimeException(e); } - return currentDirectory; } diff --git a/src/test/java/utils/PathTemplate.java b/src/test/java/utils/PathTemplate.java new file mode 100644 index 0000000..8d45454 --- /dev/null +++ b/src/test/java/utils/PathTemplate.java @@ -0,0 +1,399 @@ +package utils; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class PathTemplate +{ + public enum LatexEditor + { + SRC(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src")))), + + COMMANDS(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands"))), + + STRATEGIES(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies"))), + + CONTROLLER(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller"))), + + MODEL(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model"))), + + VIEW(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view"))), + + CHOOSE_TEMPLATE(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view", + "ChooseTemplate.java"))), + + LATEX_EDITOR(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view", + "LatexEditorView.java"))), + MAIN_WINDOW(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view", + "MainWindow.java"))), + + OPENING_WINDOW(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "view", + "OpeningWindow.java"))), + + LATEX_EDITOR_CONTROLLER(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "LatexEditorController.java"))), + + STABLE_VERSIONS_STRATEGY(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies", + "StableVersionsStrategy.java"))), + + VERSIONS_STRATEGY(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies", + "VersionsStrategy.java"))), + + VOLATILE_VERSIONS_STRATEGY(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies", + "VolatileVersionsStrategy.java"))), + + VERSIONS_STRATEGY_FACTORY(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "strategies", + "VersionsStrategyFactory.java"))), + + DOCUMENT(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "Document.java"))), + + DOCUMENT_MANAGER(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "DocumentManager.java"))), + + VERSIONS_MANAGER(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "model", + "VersionsManager.java"))), + + ADD_LATEX_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "AddLatexCommand.java"))), + + COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "Command.java"))), + + COMMAND_FACTORY(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "CommandFactory.java"))), + + CREATE_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "CreateCommand.java"))), + + EDIT_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "EditCommand.java"))), + + LOAD_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "LoadCommand.java"))), + SAVE_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "SaveCommand.java"))), + + CHANGE_VERSIONS_STRATEGY_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "ChangeVersionsStrategyCommand.java"))), + + DISABLE_VERSIONS_MANAGER_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "DisableVersionsManagementCommand.java"))), + + ENABLE_VERSIONS_MANAGE_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "EnableVersionsManagementCommand.java"))), + + ROLLBACK_TO_PREVIOUS_VERSION_COMMAND(Paths.get(PathConstructor.getCurrentPath().normalize().toString(), + PathConstructor.constructPath("src", + "test", + "resources", + "LatexEditor", + "src", + "controller", + "commands", + "RollbackToPreviousVersionCommand.java"))); + + public final Path path; + + LatexEditor(Path path) + { + this.path = path; + } + + } + + public enum ParserTesting + { + SRC(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "ParserTesting")))); + + public final Path path; + + ParserTesting(Path path) + { + this.path = path; + } + } + + public enum BookstoreAdvanced + { + SRC_ROOT(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", "BookstoreAdvancedV01")))), + SRC(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src")))), + BOOKSTORE(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "bookstore")))), + GUI(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "gui")))), + DOT_SETTINGS(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + ".settings")))), + BIN(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "bin")))), + LIB(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "lib")))), + BIN_GUI(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "bin", + "gui")))), + BIN_BOOKSTORE(Paths.get(String.format("%s%s%s", + PathConstructor.getCurrentPath(), + File.separator, + PathConstructor.constructPath("src", + "test", + "resources", + "BookstoreAdvancedV01", + "src", + "bin", + "bookstore")))); + + public final Path path; + + BookstoreAdvanced(Path path) + { + this.path = path; + } + } + +} diff --git a/src/test/resources/ParserTesting/EnumSample.java b/src/test/resources/ParserTesting/EnumSample.java index 93fb0c6..c2b3d43 100644 --- a/src/test/resources/ParserTesting/EnumSample.java +++ b/src/test/resources/ParserTesting/EnumSample.java @@ -1,3 +1,2 @@ -public enum EnumSample -{} \ No newline at end of file +public enum EnumSample {} diff --git a/src/test/resources/ParserTesting/ExtensionClass.java b/src/test/resources/ParserTesting/ExtensionClass.java index ec37b3d..5359433 100644 --- a/src/test/resources/ParserTesting/ExtensionClass.java +++ b/src/test/resources/ParserTesting/ExtensionClass.java @@ -1,5 +1,2 @@ -public class ExtensionClass -{ - -} +public class ExtensionClass {} diff --git a/src/test/resources/ParserTesting/ImplementingClass.java b/src/test/resources/ParserTesting/ImplementingClass.java index 0fa2d7d..64c263d 100644 --- a/src/test/resources/ParserTesting/ImplementingClass.java +++ b/src/test/resources/ParserTesting/ImplementingClass.java @@ -1,5 +1,4 @@ -public class ImplementingClass extends ExtensionClass implements TestingInterface, TestingInterface2 -{ - -} +public class ImplementingClass extends ExtensionClass + implements TestingInterface, + TestingInterface2 {} diff --git a/src/test/resources/ParserTesting/InnerClassSample.java b/src/test/resources/ParserTesting/InnerClassSample.java index 62aa3fc..069a286 100644 --- a/src/test/resources/ParserTesting/InnerClassSample.java +++ b/src/test/resources/ParserTesting/InnerClassSample.java @@ -7,7 +7,5 @@ private class InnerClass extends ObjectCreationSample implements TestingInterfac private ObjectCreationSample e = new ObjectCreationSample(); } - public record RecordSample(ObjectCreationSample objectCreationSample) - { - } -} \ No newline at end of file + public record RecordSample(ObjectCreationSample objectCreationSample) {} +} diff --git a/src/test/resources/ParserTesting/ObjectCreationSample.java b/src/test/resources/ParserTesting/ObjectCreationSample.java index ae6a860..10798b5 100644 --- a/src/test/resources/ParserTesting/ObjectCreationSample.java +++ b/src/test/resources/ParserTesting/ObjectCreationSample.java @@ -26,7 +26,6 @@ private void createMapWithObject() } - private enum EnumSample - {} + private enum EnumSample {} -} \ No newline at end of file +} diff --git a/src/test/resources/ParserTesting/TestingInterface.java b/src/test/resources/ParserTesting/TestingInterface.java index 3f61971..0612b3a 100644 --- a/src/test/resources/ParserTesting/TestingInterface.java +++ b/src/test/resources/ParserTesting/TestingInterface.java @@ -1,5 +1,2 @@ -public interface TestingInterface -{ - -} +public interface TestingInterface {} diff --git a/src/test/resources/ParserTesting/TestingInterface2.java b/src/test/resources/ParserTesting/TestingInterface2.java index 8c19143..e7143fa 100644 --- a/src/test/resources/ParserTesting/TestingInterface2.java +++ b/src/test/resources/ParserTesting/TestingInterface2.java @@ -1,5 +1,2 @@ -public interface TestingInterface2 -{ - -} +public interface TestingInterface2 {}