JAL-3763 failsafe check for null
[jalview.git] / test / MCview / PDBChainTest.java
index 07f9bd5..533c0af 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package MCview;
 
 import static org.testng.AssertJUnit.assertEquals;
@@ -10,17 +30,29 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.gui.JvOptionPane;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.TaylorColourScheme;
+import jalview.structure.StructureImportSettings;
 
 import java.awt.Color;
+import java.util.List;
 import java.util.Vector;
 
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 public class PDBChainTest
 {
+
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
   PDBChain c;
 
   final Atom a1 = new Atom(1f, 2f, 3f);
@@ -31,14 +63,15 @@ public class PDBChainTest
 
   final Atom a4 = new Atom(2f, 1f, 7f);
 
-  @BeforeMethod
+  @BeforeMethod(alwaysRun = true)
   public void setUp()
   {
     System.out.println("setup");
+    StructureImportSettings.setShowSeqFeatures(true);
     c = new PDBChain("1GAQ", "A");
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testGetNewlineString()
   {
     assertEquals(System.lineSeparator(), c.getNewlineString());
@@ -46,7 +79,7 @@ public class PDBChainTest
     assertEquals("gaga", c.getNewlineString());
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testPrint()
   {
     c.offset = 7;
@@ -58,7 +91,7 @@ public class PDBChainTest
     a3.resName = "ASP";
     a3.resNumber = 41;
 
-    Vector<Bond> v = new Vector<Bond>();
+    Vector<Bond> v = new Vector<>();
     v.add(new Bond(a1, a2));
     v.add(new Bond(a2, a3));
     v.add(new Bond(a3, a1));
@@ -74,7 +107,7 @@ public class PDBChainTest
    * Test the method that constructs a Bond between two atoms and adds it to the
    * chain's list of bonds
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void testMakeBond()
   {
     /*
@@ -109,7 +142,7 @@ public class PDBChainTest
     assertEquals(3f, b2.end[2], 0.0001f);
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testSetChainColours_colour()
   {
     c.makeBond(a1, a2);
@@ -126,7 +159,7 @@ public class PDBChainTest
    * Test setting bond start/end colours based on a colour scheme i.e. colour by
    * residue
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void testSetChainColours_colourScheme()
   {
     Color alaColour = new Color(204, 255, 0);
@@ -154,7 +187,7 @@ public class PDBChainTest
     assertEquals(Color.gray, b.endCol);
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testGetChargeColour()
   {
     assertEquals(Color.red, PDBChain.getChargeColour("ASP"));
@@ -169,7 +202,7 @@ public class PDBChainTest
   /**
    * Test the method that sets bond start/end colours by residue charge property
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void testSetChargeColours()
   {
     a1.resName = "ASP"; // red
@@ -198,10 +231,10 @@ public class PDBChainTest
   /**
    * Test the method that converts the raw list of atoms to a list of residues
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void testMakeResidueList_noAnnotation()
   {
-    Vector<Atom> atoms = new Vector<Atom>();
+    Vector<Atom> atoms = new Vector<>();
     c.atoms = atoms;
     c.isNa = true;
     atoms.add(makeAtom(4, "N", "MET"));
@@ -226,19 +259,19 @@ public class PDBChainTest
     /*
      * check sequence features
      */
-    SequenceFeature[] sfs = c.sequence.getSequenceFeatures();
-    assertEquals(3, sfs.length);
-    assertEquals("RESNUM", sfs[0].type);
-    assertEquals("MET:4 1gaqA", sfs[0].description);
-    assertEquals(4, sfs[0].begin);
-    assertEquals(4, sfs[0].end);
-    assertEquals("RESNUM", sfs[0].type);
-    assertEquals("LYS:5 1gaqA", sfs[1].description);
-    assertEquals(5, sfs[1].begin);
-    assertEquals(5, sfs[1].end);
-    assertEquals("LEU:6 1gaqA", sfs[2].description);
-    assertEquals(6, sfs[2].begin);
-    assertEquals(6, sfs[2].end);
+    List<SequenceFeature> sfs = c.sequence.getSequenceFeatures();
+    assertEquals(3, sfs.size());
+    assertEquals("RESNUM", sfs.get(0).type);
+    assertEquals("MET:4 1gaqA", sfs.get(0).description);
+    assertEquals(4, sfs.get(0).begin);
+    assertEquals(4, sfs.get(0).end);
+    assertEquals("RESNUM", sfs.get(0).type);
+    assertEquals("LYS:5 1gaqA", sfs.get(1).description);
+    assertEquals(5, sfs.get(1).begin);
+    assertEquals(5, sfs.get(1).end);
+    assertEquals("LEU:6 1gaqA", sfs.get(2).description);
+    assertEquals(6, sfs.get(2).begin);
+    assertEquals(6, sfs.get(2).end);
   }
 
   private Atom makeAtom(int resnum, String name, String resname)
@@ -256,38 +289,38 @@ public class PDBChainTest
    * Test the method that converts the raw list of atoms to a list of residues,
    * including parsing of tempFactor to an alignment annotation
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void testMakeResidueList_withTempFactor()
   {
-    Vector<Atom> atoms = new Vector<Atom>();
+    Vector<Atom> atoms = new Vector<>();
     c.atoms = atoms;
     atoms.add(makeAtom(4, "N", "MET"));
-    atoms.get(atoms.size()-1).tfactor = 1f;
+    atoms.get(atoms.size() - 1).tfactor = 1f;
     atoms.add(makeAtom(4, "CA", "MET"));
-    atoms.get(atoms.size()-1).tfactor = 2f;
+    atoms.get(atoms.size() - 1).tfactor = 2f;
     atoms.add(makeAtom(4, "C", "MET"));
-    atoms.get(atoms.size()-1).tfactor = 3f;
+    atoms.get(atoms.size() - 1).tfactor = 3f;
     atoms.add(makeAtom(5, "O", "LYS"));
-    atoms.get(atoms.size()-1).tfactor = 7f;
+    atoms.get(atoms.size() - 1).tfactor = 7f;
     atoms.add(makeAtom(5, "N", "LYS"));
-    atoms.get(atoms.size()-1).tfactor = 8f;
+    atoms.get(atoms.size() - 1).tfactor = 8f;
     atoms.add(makeAtom(5, "CA", "LYS"));
-    atoms.get(atoms.size()-1).tfactor = 9f;
+    atoms.get(atoms.size() - 1).tfactor = 9f;
     atoms.add(makeAtom(6, "O", "LEU"));
-    atoms.get(atoms.size()-1).tfactor = 4f;
+    atoms.get(atoms.size() - 1).tfactor = -4f;
     atoms.add(makeAtom(6, "N", "LEU"));
-    atoms.get(atoms.size()-1).tfactor = 5f;
+    atoms.get(atoms.size() - 1).tfactor = 5f;
     atoms.add(makeAtom(6, "CA", "LEU"));
-    atoms.get(atoms.size()-1).tfactor = 6f;
-  
+    atoms.get(atoms.size() - 1).tfactor = 6f;
+
     /*
      * make residues including temp factor annotation
      */
     c.makeResidueList(true);
-    
+
     /*
      * Verify annotations; note the tempFactor is read from the first atom in
-     * each residue i.e. we expect values 1, 7, 4 for the residues
+     * each residue i.e. we expect values 1, 7, -4 for the residues
      */
     AlignmentAnnotation[] ann = c.sequence.getAnnotation();
     assertEquals(1, ann.length);
@@ -295,23 +328,23 @@ public class PDBChainTest
     assertEquals("Temperature Factor for 1gaqA", ann[0].description);
     assertSame(c.sequence, ann[0].sequenceRef);
     assertEquals(AlignmentAnnotation.LINE_GRAPH, ann[0].graph);
-    assertEquals(0f, ann[0].graphMin, 0.001f);
+    assertEquals(-4f, ann[0].graphMin, 0.001f);
     assertEquals(7f, ann[0].graphMax, 0.001f);
     assertEquals(3, ann[0].annotations.length);
     assertEquals(1f, ann[0].annotations[0].value, 0.001f);
     assertEquals(7f, ann[0].annotations[1].value, 0.001f);
-    assertEquals(4f, ann[0].annotations[2].value, 0.001f);
+    assertEquals(-4f, ann[0].annotations[2].value, 0.001f);
   }
 
   /**
    * Test the method that constructs bonds between successive residues' CA or P
    * atoms
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void testMakeCaBondList()
   {
     c.isNa = true;
-    Vector<Atom> atoms = new Vector<Atom>();
+    Vector<Atom> atoms = new Vector<>();
     c.atoms = atoms;
     atoms.add(makeAtom(4, "N", "MET"));
     atoms.add(makeAtom(4, "CA", "MET"));
@@ -338,11 +371,11 @@ public class PDBChainTest
     assertTrue(c.isNa);
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testMakeCaBondList_nucleotide()
   {
     c.isNa = false;
-    Vector<Atom> atoms = new Vector<Atom>();
+    Vector<Atom> atoms = new Vector<>();
     c.atoms = atoms;
     atoms.add(makeAtom(4, "N", "G"));
     atoms.add(makeAtom(4, "P", "G"));
@@ -370,10 +403,10 @@ public class PDBChainTest
   /**
    * Test the method that updates atoms with their alignment positions
    */
-  @Test
+  @Test(groups = { "Functional" })
   public void testMakeExactMapping()
   {
-    Vector<Atom> atoms = new Vector<Atom>();
+    Vector<Atom> atoms = new Vector<>();
     c.atoms = atoms;
     atoms.add(makeAtom(4, "N", "MET"));
     atoms.add(makeAtom(4, "CA", "MET"));