JAL-2799 rearranged AptxInit code
[jalview.git] / test / jalview / ext / archaeopteryx / AptxPhylogenyTreeTest.java
index 6e324d7..8975d83 100644 (file)
@@ -3,10 +3,9 @@ package jalview.ext.archaeopteryx;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
-import jalview.bin.Jalview;
 import jalview.gui.Desktop;
-import jalview.gui.JvOptionPane;
 
+import org.forester.archaeopteryx.Archaeopteryx;
 import org.forester.archaeopteryx.MainFrame;
 import org.forester.archaeopteryx.TreePanel;
 import org.forester.phylogeny.Phylogeny;
@@ -14,7 +13,7 @@ import org.forester.phylogeny.PhylogenyNode;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-public class AptxPhylogenyTreeTest
+public class AptxPhylogenyTreeTest extends TreeViewTest
 {
   final Phylogeny inputTree = new Phylogeny();
 
@@ -22,7 +21,7 @@ public class AptxPhylogenyTreeTest
 
   final PhylogenyNode ancestor1Node = new PhylogenyNode("ancestor 1");
 
-  final PhylogenyNode ancestor2Node = new PhylogenyNode("ancestor 2");
+  final PhylogenyNode ancestor2Node = new PhylogenyNode("leaf 2");
 
   final PhylogenyNode leaf1aNode = new PhylogenyNode("leaf 1a");
 
@@ -30,14 +29,14 @@ public class AptxPhylogenyTreeTest
 
   final PhylogenyNode leaf1cNode = new PhylogenyNode("leaf 1c");
 
-  TreePanel treePanel;
-
   Phylogeny tree;
 
+  TreePanel treePanel;
+
   MainFrame aptx;
 
-  Jalview jalview;
 
+  @Override
   @BeforeClass(alwaysRun = true)
   public void setUpTree()
   {
@@ -55,91 +54,91 @@ public class AptxPhylogenyTreeTest
     ancestor1Node.setDistanceToParent(36);
     ancestor2Node.setDistanceToParent(42);
 
+    inputTree.setName("test");
     inputTree.setRoot(rootNode);
     inputTree.setRooted(true);
 
   }
 
-  @BeforeClass(dependsOnMethods = { "setUpTree" })
-  public void setUpJalview()
+  @Override
+  @BeforeClass(dependsOnMethods = { "setUpJalview", "setUpTree" })
+  public void createTreeView()
   {
-    String[] args = new String[0];
-    Jalview.main(args);
-    aptx = ArchaeopteryxInit.createInstance(inputTree);
-
+    treeView = Archaeopteryx.createApplication(inputTree);
+    aptx = (MainFrame) treeView; // pretty ugly
     treePanel = aptx.getMainPanel().getCurrentTreePanel();
     tree = treePanel.getPhylogeny();
-  }
 
+    Desktop.addInternalFrame(aptx, "Archaeopteryx", 500, 500);
 
-  @BeforeClass(alwaysRun = true)
-  public void setUpJvOptionPane()
-  {
-    JvOptionPane.setInteractiveMode(false);
-    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
   }
 
+
+
   @Test(groups = "Functional")
-  public void testAptxExists()
+  public void testMainPanelExists()
   {
-    assertTrue(aptx != null);
+    assertTrue(aptx.getMainPanel() != null);
   }
 
-
   @Test(groups = "Functional")
-  public void testAptxBoundToJalview()
+  public void testTreePanelExists()
   {
-    assertTrue(aptx.getTopLevelAncestor() instanceof Desktop);
+    assertTrue(treePanel != null);
   }
 
-  @Test(groups = "Functional")
-  public void testShowingAptx()
+  @Override
+  public void testTreeTitle()
   {
-    assertTrue(aptx.isShowing());
+    assertTrue(tree.getName().equals("test"));
 
   }
 
-  @Test(groups = "Functional")
-  public void testMainPanelExists()
+  @Test(
+    groups = "Functional",
+    expectedExceptions = IllegalArgumentException.class)
+  public void testInvalidBranchName()
   {
-    assertTrue(aptx.getMainPanel() != null);
+    tree.getNode("I shouldn't exist");
+
   }
 
-  @Test(groups = "Functional")
-  public void testTreePanelExists()
+  @Override
+  public void testExistingBranchName()
   {
-    assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
+    tree.getNode("leaf 2");
+
   }
 
-  @Test(groups = "Functional")
+  @Override
   public void testTreeLoaded()
   {
-    assertTrue(aptx.getMainPanel().getCurrentTreePanel() != null);
+    assertTrue(tree != null);
   }
 
-  @Test(groups = "Functional")
+  @Override
   public void testChildNodesCount()
   {
     assertEquals(tree.getNode("ancestor 1").getNumberOfExternalNodes(), 3);
 
   }
 
-  @Test(groups = "Functional")
-  public void testCorrectLeafToParentBranchLength()
+  @Override
+  public void testChildToParentBranchLength()
   {
     assertEquals(tree.getNode("leaf 1a").getDistanceToParent(), 2.0);
 
   }
 
-  @Test(groups = "Functional")
-  public void testCorrectAncestorLeafToRootBranchLength()
+  @Override
+  public void testNodeToRootBranchLength()
   {
-    assertEquals(tree.getNode("ancestor 2").getDistanceToParent(), 42.0);
+    assertEquals(tree.getNode("leaf 2").getDistanceToParent(), 42.0);
 
   }
 
-  @Test(groups = "Functional")
-  public void testCorrectLeafToRootBranchLength()
+  @Override
+  public void testDistantNodeToRootBranchLength()
   {
     assertEquals(tree.getNode("leaf 1c").calculateDistanceToRoot(),
             4.0 + 36.0);
@@ -150,4 +149,6 @@ public class AptxPhylogenyTreeTest
 
 
 
+
+
 }