From 902a15eeb7361608e4b0b8b421a5435d21b1ee63 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 5 Jan 2017 09:21:49 +0000 Subject: [PATCH] JAL-2371 tests added --- src/jalview/datamodel/SequenceGroup.java | 4 ++ src/jalview/gui/ColourMenuHelper.java | 2 +- test/jalview/datamodel/SequenceGroupTest.java | 82 +++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 test/jalview/datamodel/SequenceGroupTest.java diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 90adafe..aa2e1c5 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1369,6 +1369,10 @@ public class SequenceGroup implements AnnotatedCollectionI public void setColourScheme(ColourSchemeI scheme) { + if (cs == null) + { + cs = new CollectionColourScheme(); + } cs.setColourScheme(scheme); } diff --git a/src/jalview/gui/ColourMenuHelper.java b/src/jalview/gui/ColourMenuHelper.java index 52abfe1..31780d6 100644 --- a/src/jalview/gui/ColourMenuHelper.java +++ b/src/jalview/gui/ColourMenuHelper.java @@ -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 colourSchemes = ColourSchemes.getInstance() .getColourSchemes(); diff --git a/test/jalview/datamodel/SequenceGroupTest.java b/test/jalview/datamodel/SequenceGroupTest.java new file mode 100644 index 0000000..53ac181 --- /dev/null +++ b/test/jalview/datamodel/SequenceGroupTest.java @@ -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()); + } +} -- 1.7.10.2