JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / analysis / AlignmentAnnotationUtilsTest.java
index b68842a..cdb950e 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 jalview.analysis;
 
 import static org.testng.AssertJUnit.assertEquals;
@@ -8,7 +28,9 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.SequenceI;
-import jalview.io.AppletFormatAdapter;
+import jalview.gui.JvOptionPane;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -18,11 +40,20 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 public class AlignmentAnnotationUtilsTest
 {
+
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
   // 4 sequences x 13 positions
   final static String EOL = "\n";
 
@@ -45,14 +76,14 @@ public class AlignmentAnnotationUtilsTest
   /**
    * Test method that converts a (possibly null) array to a list.
    */
-  @Test(groups ={ "Functional" })
+  @Test(groups = { "Functional" })
   public void testAsList()
   {
     // null array
     Collection<AlignmentAnnotation> c1 = AlignmentAnnotationUtils
             .asList(null);
     assertTrue(c1.isEmpty());
-    
+
     // empty array
     AlignmentAnnotation[] anns = new AlignmentAnnotation[0];
     c1 = AlignmentAnnotationUtils.asList(anns);
@@ -118,12 +149,12 @@ public class AlignmentAnnotationUtilsTest
    * 
    * @throws IOException
    */
- @BeforeMethod(alwaysRun = true)
+  @BeforeMethod(alwaysRun = true)
   public void setUp() throws IOException
   {
     alignment = new jalview.io.FormatAdapter().readFile(TEST_DATA,
-            AppletFormatAdapter.PASTE, "FASTA");
-  
+            DataSourceType.PASTE, FileFormat.Fasta);
+
     AlignmentAnnotation[] anns = new AlignmentAnnotation[SEQ_ANN_COUNT];
     for (int i = 0; i < anns.length; i++)
     {
@@ -132,8 +163,7 @@ public class AlignmentAnnotationUtilsTest
        * array)
        */
       anns[i] = new AlignmentAnnotation("Label" + i, "Desc " + i,
-              new Annotation[]
-              {});
+              new Annotation[] {});
       anns[i].setCalcId("CalcId" + i);
       anns[i].visible = true;
       alignment.addAnnotation(anns[i]);
@@ -143,14 +173,14 @@ public class AlignmentAnnotationUtilsTest
   /**
    * Test a mixture of show/hidden annotations in/outside selection group.
    */
-  @Test(groups ={ "Functional" })
+  @Test(groups = { "Functional" })
   public void testGetShownHiddenTypes_forSelectionGroup()
   {
     Map<String, List<List<String>>> shownTypes = new HashMap<String, List<List<String>>>();
     Map<String, List<List<String>>> hiddenTypes = new HashMap<String, List<List<String>>>();
     AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
     SequenceI[] seqs = alignment.getSequencesArray();
-  
+
     /*
      * Configure annotation properties for test
      */
@@ -160,7 +190,7 @@ public class AlignmentAnnotationUtilsTest
     anns[4].visible = false;
     anns[7].sequenceRef = seqs[1];
     anns[7].visible = true;
-  
+
     /*
      * in selection group, hidden:
      */
@@ -184,12 +214,11 @@ public class AlignmentAnnotationUtilsTest
     anns[6].visible = true;
     anns[9].sequenceRef = seqs[3]; // CalcId9/Label9
     anns[9].visible = true;
-  
+
     List<SequenceI> selected = selectSequences(0, 3);
     AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
-            AlignmentAnnotationUtils.asList(anns),
-            selected);
-  
+            AlignmentAnnotationUtils.asList(anns), selected);
+
     // check results; note CalcId9/Label9 is both hidden and shown (for
     // different sequences) so should be in both
     // shown: CalcId6/Label6 and CalcId9/Label9
@@ -200,7 +229,7 @@ public class AlignmentAnnotationUtilsTest
     assertEquals(1, shownTypes.get("CalcId9").size());
     assertEquals(1, shownTypes.get("CalcId9").get(0).size());
     assertEquals("Label9", shownTypes.get("CalcId9").get(0).get(0));
-  
+
     // hidden: CalcId2/Label2, CalcId2/Label3, CalcId3/Label2, CalcId9/Label9
     assertEquals(3, hiddenTypes.size());
     assertEquals(2, hiddenTypes.get("CalcId2").size());
@@ -214,7 +243,7 @@ public class AlignmentAnnotationUtilsTest
     assertEquals(1, hiddenTypes.get("CalcId9").size());
     assertEquals(1, hiddenTypes.get("CalcId9").get(0).size());
     assertEquals("Label9", hiddenTypes.get("CalcId9").get(0).get(0));
-  
+
     consoleDebug(shownTypes, hiddenTypes);
   }
 
@@ -222,19 +251,19 @@ public class AlignmentAnnotationUtilsTest
    * Test case where there are 'grouped' annotations, visible and hidden, within
    * and without the selection group.
    */
-  @Test(groups ={ "Functional" })
+  @Test(groups = { "Functional" })
   public void testGetShownHiddenTypes_withGraphGroups()
   {
     final int GROUP_3 = 3;
     final int GROUP_4 = 4;
     final int GROUP_5 = 5;
     final int GROUP_6 = 6;
-  
+
     Map<String, List<List<String>>> shownTypes = new HashMap<String, List<List<String>>>();
     Map<String, List<List<String>>> hiddenTypes = new HashMap<String, List<List<String>>>();
     AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
     SequenceI[] seqs = alignment.getSequencesArray();
-  
+
     /*
      * Annotations for selection group and graph group
      * 
@@ -263,7 +292,7 @@ public class AlignmentAnnotationUtilsTest
     anns[11].graphGroup = GROUP_3;
     anns[11].label = "Label2";
     anns[11].setCalcId("CalcId2");
-  
+
     // annotations Label1 (hidden), Label5 (visible) in group 6 (visible)
     anns[1].sequenceRef = seqs[3];
     // being in a visible group should take precedence over this visibility
@@ -293,7 +322,7 @@ public class AlignmentAnnotationUtilsTest
     anns[0].graphGroup = GROUP_4;
     anns[0].label = "Label5";
     anns[0].setCalcId("CalcId1");
-  
+
     /*
      * Annotations outwith selection group - should be ignored.
      */
@@ -316,7 +345,7 @@ public class AlignmentAnnotationUtilsTest
     anns[9].visible = true;
     anns[9].graph = AlignmentAnnotation.LINE_GRAPH;
     anns[9].graphGroup = GROUP_4;
-  
+
     /*
      * Generate annotations[] arrays to match aligned columns
      */
@@ -324,11 +353,10 @@ public class AlignmentAnnotationUtilsTest
 
     List<SequenceI> selected = selectSequences(0, 3);
     AlignmentAnnotationUtils.getShownHiddenTypes(shownTypes, hiddenTypes,
-            AlignmentAnnotationUtils.asList(anns),
-            selected);
-  
+            AlignmentAnnotationUtils.asList(anns), selected);
+
     consoleDebug(shownTypes, hiddenTypes);
-  
+
     // CalcId1 / Label1, Label5 (only) should be 'shown', once, as a compound
     // type
     assertEquals(1, shownTypes.size());
@@ -336,7 +364,7 @@ public class AlignmentAnnotationUtilsTest
     assertEquals(2, shownTypes.get("CalcId1").get(0).size());
     assertEquals("Label1", shownTypes.get("CalcId1").get(0).get(0));
     assertEquals("Label5", shownTypes.get("CalcId1").get(0).get(1));
-  
+
     // CalcId2 / Label2, Label3 (only) should be 'hidden'
     assertEquals(1, hiddenTypes.size());
     assertEquals(1, hiddenTypes.get("CalcId2").size());
@@ -348,7 +376,7 @@ public class AlignmentAnnotationUtilsTest
   /**
    * Test method that determines visible graph groups.
    */
-  @Test(groups ={ "Functional" })
+  @Test(groups = { "Functional" })
   public void testGetVisibleGraphGroups()
   {
     AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
@@ -358,7 +386,7 @@ public class AlignmentAnnotationUtilsTest
     anns[0].graph = AlignmentAnnotation.BAR_GRAPH;
     anns[0].graphGroup = 1;
     anns[0].visible = true;
-  
+
     /*
      * a line graph group is included as long as one of its members is visible
      */
@@ -368,22 +396,21 @@ public class AlignmentAnnotationUtilsTest
     anns[2].graph = AlignmentAnnotation.LINE_GRAPH;
     anns[2].graphGroup = 5;
     anns[2].visible = true;
-  
+
     /*
      * a line graph group with no visible rows is not included
      */
     anns[3].graph = AlignmentAnnotation.LINE_GRAPH;
     anns[3].graphGroup = 3;
     anns[3].visible = false;
-  
+
     // a visible line graph with no graph group is not included
     anns[4].graph = AlignmentAnnotation.LINE_GRAPH;
     anns[4].graphGroup = -1;
     anns[4].visible = true;
-  
-    BitSet result = AlignmentAnnotationUtils
-            .getVisibleLineGraphGroups(AlignmentAnnotationUtils
-                    .asList(anns));
+
+    BitSet result = AlignmentAnnotationUtils.getVisibleLineGraphGroups(
+            AlignmentAnnotationUtils.asList(anns));
     assertTrue(result.get(5));
     assertFalse(result.get(0));
     assertFalse(result.get(1));
@@ -395,7 +422,7 @@ public class AlignmentAnnotationUtilsTest
    * Test for case where no sequence is selected. Shouldn't normally arise but
    * check it handles it gracefully.
    */
-  @Test(groups ={ "Functional" })
+  @Test(groups = { "Functional" })
   public void testGetShownHiddenTypes_noSequenceSelected()
   {
     Map<String, List<List<String>>> shownTypes = new HashMap<String, List<List<String>>>();