elharo commented on code in PR #391:
URL: 
https://github.com/apache/maven-dependency-plugin/pull/391#discussion_r1610551901


##########
src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java:
##########
@@ -137,6 +147,74 @@ public void testTreeTGFSerializing() throws Exception {
         assertTrue(findString(contents, 
"testGroupId:release:jar:1.0:compile"));
     }
 
+    /**
+     * Test the JSON format serialization on DependencyNodes with circular 
dependence
+     */
+    public void testTreeJsonCircularDependency() throws Exception {

Review Comment:
   can you declare a more specific exception?



##########
src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java:
##########
@@ -137,6 +147,74 @@ public void testTreeTGFSerializing() throws Exception {
         assertTrue(findString(contents, 
"testGroupId:release:jar:1.0:compile"));
     }
 
+    /**
+     * Test the JSON format serialization on DependencyNodes with circular 
dependence
+     */
+    public void testTreeJsonCircularDependency() throws Exception {
+        String outputFileName = testDir.getAbsolutePath() + "tree1.json";
+        File outputFile = new File(outputFileName);
+        Files.createDirectories(outputFile.getParentFile().toPath());
+        outputFile.createNewFile();
+
+        Artifact artifact1 = this.stubFactory.createArtifact("testGroupId", 
"project1", "1.0");
+        Artifact artifact2 = this.stubFactory.createArtifact("testGroupId", 
"project2", "1.0");
+        DefaultDependencyNode node1 = new DefaultDependencyNode(artifact1);
+        DefaultDependencyNode node2 = new DefaultDependencyNode(artifact2);
+
+        node1.setChildren(new ArrayList<DependencyNode>());
+        node2.setChildren(new ArrayList<DependencyNode>());
+
+        node1.getChildren().add(node2);
+        node2.getChildren().add(node1);
+
+        JsonDependencyNodeVisitor jsonDependencyNodeVisitor =
+                new JsonDependencyNodeVisitor(new OutputStreamWriter(new 
FileOutputStream(outputFile)));
+
+        jsonDependencyNodeVisitor.visit(node1);
+    }
+
+    /*
+     * Test parsing of Json output and verify all key-value pairs
+     */
+    public void testTreeJsonParsing() throws Exception {
+        List<String> contents = runTreeMojo("tree2.json", "json");
+
+        JsonReader reader = Json.createReader(new 
StringReader(String.join("\n", contents)));
+        JsonObject root = reader.readObject();
+        reader.close();

Review Comment:
   I think you can use try with resources to autoclose this.



##########
src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java:
##########
@@ -137,6 +147,74 @@ public void testTreeTGFSerializing() throws Exception {
         assertTrue(findString(contents, 
"testGroupId:release:jar:1.0:compile"));
     }
 
+    /**
+     * Test the JSON format serialization on DependencyNodes with circular 
dependence
+     */
+    public void testTreeJsonCircularDependency() throws Exception {
+        String outputFileName = testDir.getAbsolutePath() + "tree1.json";
+        File outputFile = new File(outputFileName);
+        Files.createDirectories(outputFile.getParentFile().toPath());
+        outputFile.createNewFile();
+
+        Artifact artifact1 = this.stubFactory.createArtifact("testGroupId", 
"project1", "1.0");
+        Artifact artifact2 = this.stubFactory.createArtifact("testGroupId", 
"project2", "1.0");
+        DefaultDependencyNode node1 = new DefaultDependencyNode(artifact1);
+        DefaultDependencyNode node2 = new DefaultDependencyNode(artifact2);
+
+        node1.setChildren(new ArrayList<DependencyNode>());
+        node2.setChildren(new ArrayList<DependencyNode>());
+
+        node1.getChildren().add(node2);
+        node2.getChildren().add(node1);
+
+        JsonDependencyNodeVisitor jsonDependencyNodeVisitor =
+                new JsonDependencyNodeVisitor(new OutputStreamWriter(new 
FileOutputStream(outputFile)));
+
+        jsonDependencyNodeVisitor.visit(node1);
+    }
+
+    /*
+     * Test parsing of Json output and verify all key-value pairs
+     */
+    public void testTreeJsonParsing() throws Exception {

Review Comment:
   can you declare a more specific exception?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to