From 6dde04eed2aed746f5240c020159e9ac9a44525e Mon Sep 17 00:00:00 2001 From: Yavuz Tas Date: Sat, 30 Nov 2019 08:33:51 +0100 Subject: [PATCH] condense a little bit the code of test data --- .../PrintingBinaryTreeModelUnitTest.java | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/binarytree/PrintingBinaryTreeModelUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/binarytree/PrintingBinaryTreeModelUnitTest.java index de4e3dfa01..8ea0bdd5ba 100644 --- a/core-java-modules/core-java/src/test/java/com/baeldung/binarytree/PrintingBinaryTreeModelUnitTest.java +++ b/core-java-modules/core-java/src/test/java/com/baeldung/binarytree/PrintingBinaryTreeModelUnitTest.java @@ -32,34 +32,29 @@ public class PrintingBinaryTreeModelUnitTest { public void tearDown() { System.setOut(System.out); } - + private BinaryTreeModel createBalancedTree() { - + BinaryTreeModel root = new BinaryTreeModel("root"); - + BinaryTreeModel node1 = new BinaryTreeModel("node1"); BinaryTreeModel node2 = new BinaryTreeModel("node2"); root.setLeft(node1); root.setRight(node2); - + BinaryTreeModel node3 = new BinaryTreeModel("node3"); BinaryTreeModel node4 = new BinaryTreeModel("node4"); node1.setLeft(node3); node1.setRight(node4); - - BinaryTreeModel node5 = new BinaryTreeModel("node5"); - BinaryTreeModel node6 = new BinaryTreeModel("node6"); - node2.setLeft(node5); - node2.setRight(node6); - + + node2.setLeft(new BinaryTreeModel("node5")); + node2.setRight(new BinaryTreeModel("node6")); + BinaryTreeModel node7 = new BinaryTreeModel("node7"); node3.setLeft(node7); - - BinaryTreeModel node8 = new BinaryTreeModel("node8"); - BinaryTreeModel node9 = new BinaryTreeModel("node9"); - node7.setLeft(node8); - node7.setRight(node9); - + node7.setLeft(new BinaryTreeModel("node8")); + node7.setRight(new BinaryTreeModel("node9")); + return root; } @@ -68,9 +63,8 @@ public class PrintingBinaryTreeModelUnitTest { BinaryTreeModel root = new BinaryTreeModel("root"); BinaryTreeModel node1 = new BinaryTreeModel("node1"); - BinaryTreeModel node2 = new BinaryTreeModel("node2"); root.setLeft(node1); - root.setRight(node2); + root.setRight(new BinaryTreeModel("node2")); BinaryTreeModel node3 = new BinaryTreeModel("node3"); node1.setLeft(node3); @@ -87,8 +81,7 @@ public class PrintingBinaryTreeModelUnitTest { BinaryTreeModel node7 = new BinaryTreeModel("node7"); node6.setLeft(node7); - BinaryTreeModel node8 = new BinaryTreeModel("node8"); - node7.setLeft(node8); + node7.setLeft(new BinaryTreeModel("node8")); return root; } @@ -97,9 +90,8 @@ public class PrintingBinaryTreeModelUnitTest { BinaryTreeModel root = new BinaryTreeModel("root"); - BinaryTreeModel node1 = new BinaryTreeModel("node1"); BinaryTreeModel node2 = new BinaryTreeModel("node2"); - root.setLeft(node1); + root.setLeft(new BinaryTreeModel("node1")); root.setRight(node2); BinaryTreeModel node3 = new BinaryTreeModel("node3"); @@ -117,8 +109,7 @@ public class PrintingBinaryTreeModelUnitTest { BinaryTreeModel node7 = new BinaryTreeModel("node7"); node6.setRight(node7); - BinaryTreeModel node8 = new BinaryTreeModel("node8"); - node7.setRight(node8); + node7.setRight(new BinaryTreeModel("node8")); return root; }