JAL-2371 tests added
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 5 Jan 2017 09:21:49 +0000 (09:21 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 5 Jan 2017 09:21:49 +0000 (09:21 +0000)
src/jalview/datamodel/SequenceGroup.java
src/jalview/gui/ColourMenuHelper.java
test/jalview/datamodel/SequenceGroupTest.java [new file with mode: 0644]

index 90adafe..aa2e1c5 100755 (executable)
@@ -1369,6 +1369,10 @@ public class SequenceGroup implements AnnotatedCollectionI
 
   public void setColourScheme(ColourSchemeI scheme)
   {
+    if (cs == null)
+    {
+      cs = new CollectionColourScheme();
+    }
     cs.setColourScheme(scheme);
   }
 
index 52abfe1..31780d6 100644 (file)
@@ -77,7 +77,7 @@ public class ColourMenuHelper
 
     /*
      * scan registered colour schemes (built-in or user-defined
-     * and add them to the menu (in the order they were added)
+     * and add them to the menu (in the order they were registered)
      */
     Iterable<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
             .getColourSchemes();
diff --git a/test/jalview/datamodel/SequenceGroupTest.java b/test/jalview/datamodel/SequenceGroupTest.java
new file mode 100644 (file)
index 0000000..53ac181
--- /dev/null
@@ -0,0 +1,82 @@
+package jalview.datamodel;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+
+import jalview.schemes.NucleotideColourScheme;
+
+import org.testng.annotations.Test;
+
+public class SequenceGroupTest
+{
+  @Test
+  public void testAddSequence()
+  {
+    SequenceGroup sg = new SequenceGroup();
+    assertTrue(sg.getSequences().isEmpty());
+
+    SequenceI seq1 = new Sequence("seq1", "abc");
+    SequenceI seq2 = new Sequence("seq2", "abc");
+    SequenceI seq3 = new Sequence(seq1);
+
+    sg.addSequence(null, false);
+    assertTrue(sg.getSequences().isEmpty());
+    sg.addSequence(seq1, false);
+    assertEquals(sg.getSequences().size(), 1);
+    assertTrue(sg.getSequences().contains(seq1));
+    // adding the same sequence again does nothing
+    sg.addSequence(seq1, false);
+    assertEquals(sg.getSequences().size(), 1);
+    assertTrue(sg.getSequences().contains(seq1));
+    sg.addSequence(seq2, false);
+    sg.addSequence(seq2, false);
+    sg.addSequence(seq3, false);
+    assertEquals(sg.getSequences().size(), 3);
+    assertTrue(sg.getSequences().contains(seq1));
+    assertTrue(sg.getSequences().contains(seq2));
+    assertTrue(sg.getSequences().contains(seq3));
+  }
+
+  @Test
+  public void testAddOrRemove()
+  {
+    SequenceGroup sg = new SequenceGroup();
+    assertTrue(sg.getSequences().isEmpty());
+  
+    SequenceI seq1 = new Sequence("seq1", "abc");
+    SequenceI seq2 = new Sequence("seq2", "abc");
+    SequenceI seq3 = new Sequence(seq1);
+  
+    sg.addOrRemove(seq1, false);
+    assertEquals(sg.getSequences().size(), 1);
+    sg.addOrRemove(seq2, false);
+    assertEquals(sg.getSequences().size(), 2);
+    sg.addOrRemove(seq3, false);
+    assertEquals(sg.getSequences().size(), 3);
+    assertTrue(sg.getSequences().contains(seq1));
+    assertTrue(sg.getSequences().contains(seq2));
+    assertTrue(sg.getSequences().contains(seq3));
+    sg.addOrRemove(seq1, false);
+    assertEquals(sg.getSequences().size(), 2);
+    assertFalse(sg.getSequences().contains(seq1));
+  }
+
+  @Test
+  public void testGetColourScheme()
+  {
+    SequenceGroup sg = new SequenceGroup();
+    assertNotNull(sg.getGroupColourScheme());
+    assertNull(sg.getColourScheme());
+
+    sg.setGroupColourScheme(null);
+    assertNull(sg.getColourScheme());
+
+    NucleotideColourScheme scheme = new NucleotideColourScheme();
+    sg.setColourScheme(scheme);
+    assertSame(scheme, sg.getColourScheme());
+  }
+}