JAL-2326 added setup method for JvOptionPane in all Jalveiw test classes to enable...
[jalview.git] / test / jalview / util / MapListTest.java
index c442b6f..a2f38e2 100644 (file)
@@ -27,15 +27,25 @@ import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
 
+import jalview.gui.JvOptionPane;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 public class MapListTest
 {
 
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
   @Test(groups = { "Functional" })
   public void testSomething()
   {
@@ -535,8 +545,7 @@ public class MapListTest
     MapList ml = new MapList(new int[] { 1, 5, 10, 15, 25, 20 }, new int[] {
         51, 1 }, 1, 3);
     String s = ml.toString();
-    assertEquals("[ [1, 5] [10, 15] [25, 20] ] To [ [51, 1] ]",
-            s);
+    assertEquals("[ [1, 5] [10, 15] [25, 20] ] 1:3 to [ [51, 1] ]", s);
   }
 
   @Test(groups = { "Functional" })
@@ -559,10 +568,25 @@ public class MapListTest
 
     String s = ml.toString();
     assertEquals(
-            "[ [11, 15] [20, 25] [35, 30] [2, 4] [37, 40] ] To [ [72, 22] [12, 17] [78, 83] [88, 96] ]",
+            "[ [11, 15] [20, 25] [35, 30] [2, 4] [37, 40] ] 1:3 to [ [72, 22] [12, 17] [78, 83] [88, 96] ]",
             s);
   }
 
+  /**
+   * Test that confirms adding a map twice does nothing
+   */
+  @Test(groups = { "Functional" })
+  public void testAddMapList_sameMap()
+  {
+    MapList ml = new MapList(new int[] { 11, 15, 20, 25, 35, 30 },
+            new int[] { 72, 22 }, 1, 3);
+    String before = ml.toString();
+    ml.addMapList(ml);
+    assertEquals(before, ml.toString());
+    ml.addMapList(new MapList(ml));
+    assertEquals(before, ml.toString());
+  }
+
   @Test(groups = { "Functional" })
   public void testAddMapList_contiguous()
   {
@@ -572,7 +596,7 @@ public class MapListTest
     MapList ml2 = new MapList(new int[] { 15, 16 }, new int[] { 58, 53 },
             1, 3);
     ml.addMapList(ml2);
-    assertEquals("[ [11, 16] ] To [ [72, 53] ]", ml.toString());
+    assertEquals("[ [11, 16] ] 1:3 to [ [72, 53] ]", ml.toString());
   }
 
   @Test(groups = "Functional")
@@ -655,14 +679,17 @@ public class MapListTest
   @Test(groups = { "Functional" })
   public void testIsFromForwardStrand()
   {
-    MapList ml = new MapList(new int[] { 2, 2, 3, 9, 12, 11 },
-            new int[] { 20, 11 }, 1, 1);
+    // [3-9] declares forward strand
+    MapList ml = new MapList(new int[] { 2, 2, 3, 9, 12, 11 }, new int[] {
+        20, 11 }, 1, 1);
     assertTrue(ml.isFromForwardStrand());
 
+    // [11-5] declares reverse strand ([13-14] is ignored)
     ml = new MapList(new int[] { 2, 2, 11, 5, 13, 14 },
             new int[] { 20, 11 }, 1, 1);
     assertFalse(ml.isFromForwardStrand());
 
+    // all single position ranges - defaults to forward strand
     ml = new MapList(new int[] { 2, 2, 4, 4, 6, 6 }, new int[] { 3, 1 }, 1,
             1);
     assertTrue(ml.isFromForwardStrand());