X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fschemes%2FColourSchemesTest.java;h=0184f128bf5c345e3d3f4051bad817d246588caa;hb=refs%2Fheads%2Fimprovement%2FJAL-3847_some_attempts_to_set_gradle_and_groovy_versions;hp=1bc63482114158cccdd896b38dfe8f376665da98;hpb=8fe4fae3160ab519459a41976255a4b022c39a2e;p=jalview.git
diff --git a/test/jalview/schemes/ColourSchemesTest.java b/test/jalview/schemes/ColourSchemesTest.java
index 1bc6348..0184f12 100644
--- a/test/jalview/schemes/ColourSchemesTest.java
+++ b/test/jalview/schemes/ColourSchemesTest.java
@@ -1,29 +1,51 @@
+/*
+ * 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 .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.schemes;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
+import java.awt.Color;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import jalview.api.AlignViewportI;
import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
-import jalview.gui.AlignViewport;
import jalview.gui.Desktop;
import jalview.gui.SequenceRenderer;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
import jalview.schemes.ClustalxColourScheme.ClustalColour;
-import java.awt.Color;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
public class ColourSchemesTest
{
/*
@@ -32,67 +54,74 @@ public class ColourSchemesTest
*/
class Stripy extends ResidueColourScheme
{
- @Override
- public ColourSchemeI getInstance(AnnotatedCollectionI sg,
- Map hiddenRepSequences)
+ private ResidueColourScheme odd;
+
+ private ResidueColourScheme even;
+
+ private Stripy()
{
- final ColourSchemeI odd = ColourSchemes.getInstance()
- .getColourScheme(JalviewColourScheme.Taylor.toString(),
- (AnnotatedCollectionI) null);
- final ColourSchemeI even = ColourSchemes.getInstance()
- .getColourScheme(JalviewColourScheme.Zappo.toString(),
- (AnnotatedCollectionI) null);
- return new ResidueColourScheme() {
- @Override
- public Color findColour(char c, int j, SequenceI seq)
- {
- if (j % 2 == 1)
- {
- return odd.findColour(c, j, seq);
- }
- else
- {
- return even.findColour(c, j, seq);
- }
- }
+ }
- @Override
- public ColourSchemeI getInstance(AnnotatedCollectionI sg,
- Map hiddenRepSequences)
- {
- return null;
- }
+ /**
+ * constructor given colours for odd and even columns
+ *
+ * @param odd
+ * @param even
+ */
+ private Stripy(ColourSchemeI cs1, ColourSchemeI cs2)
+ {
+ odd = (ResidueColourScheme) cs1;
+ even = (ResidueColourScheme) cs2;
+ }
- @Override
- public String getSchemeName()
- {
- return Stripy.this.getSchemeName();
- }
-
- };
+ @Override
+ public ColourSchemeI getInstance(AlignViewportI view,
+ AnnotatedCollectionI sg)
+ {
+ final ColourSchemeI cs1 = ColourSchemes.getInstance().getColourScheme(
+ JalviewColourScheme.Taylor.toString(),
+ (AnnotatedCollectionI) null);
+ final ColourSchemeI cs2 = ColourSchemes.getInstance().getColourScheme(
+ JalviewColourScheme.Zappo.toString(),
+ (AnnotatedCollectionI) null);
+ return new Stripy(cs1, cs2);
}
-
+
+ @Override
+ public Color findColour(char c, int j, SequenceI seq)
+ {
+ if (j % 2 == 1)
+ {
+ return odd.findColour(c, j, seq);
+ }
+ else
+ {
+ return even.findColour(c, j, seq);
+ }
+ }
+
@Override
public String getSchemeName()
{
return "stripy";
}
};
-
+
/*
* a colour scheme that is Clustal but using AWT colour equivalents
*/
class MyClustal extends ResidueColourScheme
{
- ColourSchemeI delegate;
+ ClustalxColourScheme delegate;
- public MyClustal()
+ private MyClustal()
{
}
- public MyClustal(ColourSchemeI scheme)
+ private MyClustal(AnnotatedCollectionI sg,
+ Map hiddenRepSequences)
{
- delegate = scheme;
+ delegate = new ClustalxColourScheme(sg, hiddenRepSequences);
}
@Override
@@ -136,11 +165,10 @@ public class ColourSchemesTest
}
@Override
- public ColourSchemeI getInstance(AnnotatedCollectionI sg,
- Map hiddenRepSequences)
+ public ColourSchemeI getInstance(AlignViewportI view,
+ AnnotatedCollectionI sg)
{
- return new MyClustal(new ClustalxColourScheme().getInstance(sg,
- hiddenRepSequences));
+ return new MyClustal(sg, view.getHiddenRepSequences());
}
@Override
@@ -164,7 +192,8 @@ public class ColourSchemesTest
@AfterClass(alwaysRun = true)
public static void tearDownAfterClass() throws Exception
{
- Desktop.instance.closeAll_actionPerformed(null);
+ if (Desktop.instance != null)
+ Desktop.instance.closeAll_actionPerformed(null);
}
@Test(groups = "Functional")
@@ -175,7 +204,8 @@ public class ColourSchemesTest
* in the order in which they are declared in the JalviewColourScheme enum
* (this also determines their order in Colour menus)
*/
- Iterator schemes = ColourSchemes.getInstance().getColourSchemes().iterator();
+ Iterator schemes = ColourSchemes.getInstance()
+ .getColourSchemes().iterator();
JalviewColourScheme[] jalviewSchemes = JalviewColourScheme.values();
int i = 0;
while (schemes.hasNext() && i < jalviewSchemes.length)
@@ -187,79 +217,22 @@ public class ColourSchemesTest
}
@Test(groups = "Functional")
- public void testGetColourScheme_forViewport()
+ public void testGetColourScheme()
{
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
">seq1\nAGLRTWQU", DataSourceType.PASTE);
- ColourSchemes cs = ColourSchemes.getInstance();
-
- AlignViewport viewport = af.getViewport();
- assertTrue(cs.getColourScheme(JalviewColourScheme.Blosum62.toString(),
- viewport) instanceof Blosum62ColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Buried.toString(),
- viewport) instanceof BuriedColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Clustal.toString(),
- viewport) instanceof ClustalxColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Helix.toString(),
- viewport) instanceof HelixColourScheme);
- assertTrue(cs.getColourScheme(
- JalviewColourScheme.Hydrophobic.toString(), viewport) instanceof HydrophobicColourScheme);
- assertTrue(cs.getColourScheme(
- JalviewColourScheme.Nucleotide.toString(), viewport) instanceof NucleotideColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.PID.toString(),
- viewport) instanceof PIDColourScheme);
- assertTrue(cs.getColourScheme(
- JalviewColourScheme.PurinePyrimidine.toString(), viewport) instanceof PurinePyrimidineColourScheme);
- assertTrue(cs.getColourScheme(
- JalviewColourScheme.RNAHelices.toString(), viewport) instanceof RNAHelicesColour);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Strand.toString(),
- viewport) instanceof StrandColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Taylor.toString(),
- viewport) instanceof TaylorColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.TCoffee.toString(),
- viewport) instanceof TCoffeeColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Turn.toString(),
- viewport) instanceof TurnColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Zappo.toString(),
- viewport) instanceof ZappoColourScheme);
- af.closeMenuItem_actionPerformed(true);
- }
-
- @Test(groups = "Functional")
- public void testGetColourScheme_forAnnotatedCollection()
- {
- AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
- ">seq1\nAGLRTWQU", DataSourceType.PASTE);
- ColourSchemes cs = ColourSchemes.getInstance();
+ ColourSchemes schemes = ColourSchemes.getInstance();
AnnotatedCollectionI al = af.getViewport().getAlignment();
- assertTrue(cs.getColourScheme(JalviewColourScheme.Blosum62.toString(),
- al) instanceof Blosum62ColourScheme);
- assertTrue(cs
- .getColourScheme(JalviewColourScheme.Buried.toString(), al) instanceof BuriedColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Clustal.toString(),
- al) instanceof ClustalxColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Helix.toString(), al) instanceof HelixColourScheme);
- assertTrue(cs.getColourScheme(
- JalviewColourScheme.Hydrophobic.toString(), al) instanceof HydrophobicColourScheme);
- assertTrue(cs.getColourScheme(
- JalviewColourScheme.Nucleotide.toString(), al) instanceof NucleotideColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.PID.toString(), al) instanceof PIDColourScheme);
- assertTrue(cs.getColourScheme(
- JalviewColourScheme.PurinePyrimidine.toString(), al) instanceof PurinePyrimidineColourScheme);
- assertTrue(cs.getColourScheme(
- JalviewColourScheme.RNAHelices.toString(), al) instanceof RNAHelicesColour);
- assertTrue(cs
- .getColourScheme(JalviewColourScheme.Strand.toString(), al) instanceof StrandColourScheme);
- assertTrue(cs
- .getColourScheme(JalviewColourScheme.Taylor.toString(), al) instanceof TaylorColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.TCoffee.toString(),
- al) instanceof TCoffeeColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Turn.toString(), al) instanceof TurnColourScheme);
- assertTrue(cs.getColourScheme(JalviewColourScheme.Zappo.toString(), al) instanceof ZappoColourScheme);
+
+ for (JalviewColourScheme cs : JalviewColourScheme.values())
+ {
+ ColourSchemeI registered = schemes.getColourScheme(cs.toString(), al);
+ assertSame(registered.getClass(), cs.getSchemeClass());
+ }
af.closeMenuItem_actionPerformed(true);
}
-
+
@Test(groups = "Functional")
public void testRegisterColourScheme()
{
@@ -278,9 +251,9 @@ public class ColourSchemesTest
* set and check Taylor colours
*/
af.changeColour_actionPerformed(JalviewColourScheme.Taylor.toString());
- Color taylor1 = sr.getResidueBoxColour(seq, 88); // E 255,0,102
- Color taylor2 = sr.getResidueBoxColour(seq, 89); // A 204,255,0
- Color taylor3 = sr.getResidueBoxColour(seq, 90); // G 255,153,0
+ Color taylor1 = sr.getResidueColour(seq, 88, null); // E 255,0,102
+ Color taylor2 = sr.getResidueColour(seq, 89, null); // A 204,255,0
+ Color taylor3 = sr.getResidueColour(seq, 90, null); // G 255,153,0
assertEquals(taylor1, new Color(255, 0, 102));
assertEquals(taylor2, new Color(204, 255, 0));
assertEquals(taylor3, new Color(255, 153, 0));
@@ -289,9 +262,9 @@ public class ColourSchemesTest
* set and check Zappo colours
*/
af.changeColour_actionPerformed(JalviewColourScheme.Zappo.toString());
- Color zappo1 = sr.getResidueBoxColour(seq, 88); // E red
- Color zappo2 = sr.getResidueBoxColour(seq, 89); // A pink
- Color zappo3 = sr.getResidueBoxColour(seq, 90); // G magenta
+ Color zappo1 = sr.getResidueColour(seq, 88, null); // E red
+ Color zappo2 = sr.getResidueColour(seq, 89, null); // A pink
+ Color zappo3 = sr.getResidueColour(seq, 90, null); // G magenta
assertEquals(zappo1, Color.red);
assertEquals(zappo2, Color.pink);
assertEquals(zappo3, Color.magenta);
@@ -300,9 +273,9 @@ public class ColourSchemesTest
* set 'stripy' colours - odd columns are Taylor and even are Zappo
*/
af.changeColour_actionPerformed("stripy");
- Color stripy1 = sr.getResidueBoxColour(seq, 88);
- Color stripy2 = sr.getResidueBoxColour(seq, 89);
- Color stripy3 = sr.getResidueBoxColour(seq, 90);
+ Color stripy1 = sr.getResidueColour(seq, 88, null);
+ Color stripy2 = sr.getResidueColour(seq, 89, null);
+ Color stripy3 = sr.getResidueColour(seq, 90, null);
assertEquals(stripy1, zappo1);
assertEquals(stripy2, taylor2);
assertEquals(stripy3, zappo3);
@@ -311,9 +284,9 @@ public class ColourSchemesTest
* set and check Clustal colours
*/
af.changeColour_actionPerformed(JalviewColourScheme.Clustal.toString());
- Color clustal1 = sr.getResidueBoxColour(seq, 88);
- Color clustal2 = sr.getResidueBoxColour(seq, 89);
- Color clustal3 = sr.getResidueBoxColour(seq, 90);
+ Color clustal1 = sr.getResidueColour(seq, 88, null);
+ Color clustal2 = sr.getResidueColour(seq, 89, null);
+ Color clustal3 = sr.getResidueColour(seq, 90, null);
assertEquals(clustal1, ClustalColour.MAGENTA.colour);
assertEquals(clustal2, ClustalColour.BLUE.colour);
assertEquals(clustal3, ClustalColour.ORANGE.colour);
@@ -322,11 +295,28 @@ public class ColourSchemesTest
* set 'MyClustal' colours - uses AWT colour equivalents
*/
af.changeColour_actionPerformed("MyClustal");
- Color myclustal1 = sr.getResidueBoxColour(seq, 88);
- Color myclustal2 = sr.getResidueBoxColour(seq, 89);
- Color myclustal3 = sr.getResidueBoxColour(seq, 90);
+ Color myclustal1 = sr.getResidueColour(seq, 88, null);
+ Color myclustal2 = sr.getResidueColour(seq, 89, null);
+ Color myclustal3 = sr.getResidueColour(seq, 90, null);
assertEquals(myclustal1, Color.MAGENTA);
assertEquals(myclustal2, Color.BLUE);
assertEquals(myclustal3, Color.ORANGE);
}
+
+ /**
+ * Tests for check if scheme name exists. Built-in scheme names are the
+ * toString() values of enum JalviewColourScheme.
+ */
+ @Test(groups = "Functional")
+ public void testNameExists()
+ {
+ ColourSchemes cs = ColourSchemes.getInstance();
+ assertFalse(cs.nameExists(null));
+ assertFalse(cs.nameExists(""));
+ assertTrue(cs.nameExists("Clustal"));
+ assertTrue(cs.nameExists("CLUSTAL"));
+ assertFalse(cs.nameExists("CLUSTAL "));
+ assertTrue(cs.nameExists("% Identity"));
+ assertFalse(cs.nameExists("PID"));
+ }
}