JAL-2527 Unit test
authorkiramt <k.mourao@dundee.ac.uk>
Thu, 31 Aug 2017 13:27:50 +0000 (14:27 +0100)
committerkiramt <k.mourao@dundee.ac.uk>
Thu, 31 Aug 2017 13:27:50 +0000 (14:27 +0100)
test/jalview/renderer/OverviewResColourFinderTest.java

index 649a0bf..d7ce4a8 100644 (file)
@@ -22,12 +22,14 @@ package jalview.renderer;
 
 import static org.testng.AssertJUnit.assertEquals;
 
+import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
 import jalview.gui.JvOptionPane;
+import jalview.gui.Preferences;
 import jalview.schemes.UserColourScheme;
 import jalview.schemes.ZappoColourScheme;
 
@@ -158,4 +160,74 @@ public class OverviewResColourFinderTest
     assertEquals(Color.pink, rcf.getResidueColour(false,
             av.getResidueShading(), null, seq, 3, null));
   }
+
+  @Test
+  public void testGetBoxColour()
+  {
+    Cache.loadProperties("test/jalview/io/testProps.jvprops");
+
+    SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
+                                                            // gap
+    AlignmentI al = new Alignment(new SequenceI[] { seq });
+    final AlignViewport av = new AlignViewport(al);
+
+    // non-legacy colouring
+    ResidueColourFinder rcf = new OverviewResColourFinder();
+    ResidueShaderI shader = new ResidueShader();
+
+    // residues white
+    Color c = rcf.getBoxColour(shader, seq, 0);
+    assertEquals(Color.white, c);
+
+    // gaps gap colour
+    c = rcf.getBoxColour(shader, seq, 3);
+    assertEquals(Preferences.OVERVIEW_DEFAULT_GAP, c);
+
+    // legacy colouring set explicitly via constructor
+    rcf = new OverviewResColourFinder(true, Color.blue, Color.red);
+    shader = new ResidueShader();
+
+    // residues light gray
+    c = rcf.getBoxColour(shader, seq, 0);
+    assertEquals(Color.lightGray, c);
+
+    // gaps white
+    c = rcf.getBoxColour(shader, seq, 3);
+    assertEquals(Color.white, c);
+
+    // legacy colouring off
+    rcf = new OverviewResColourFinder();
+    shader = new ResidueShader();
+
+    // residues white
+    c = rcf.getBoxColour(shader, seq, 0);
+    assertEquals(Color.white, c);
+
+    // gaps gap colour
+    c = rcf.getBoxColour(shader, seq, 3);
+    assertEquals(Preferences.OVERVIEW_DEFAULT_GAP, c);
+
+    // non legacy colouring with colour scheme
+    rcf = new OverviewResColourFinder(false, Color.blue, Color.red);
+    shader = new ResidueShader(new ZappoColourScheme());
+
+    // M residue pink
+    c = rcf.getBoxColour(shader, seq, 0);
+    assertEquals(Color.pink, c);
+
+    // gaps blue
+    c = rcf.getBoxColour(shader, seq, 3);
+    assertEquals(Color.blue, c);
+
+    // legacy colouring with colour scheme
+    rcf = new OverviewResColourFinder(true, Color.blue, Color.red);
+
+    // M residue pink
+    c = rcf.getBoxColour(shader, seq, 0);
+    assertEquals(Color.pink, c);
+
+    // gaps white
+    c = rcf.getBoxColour(shader, seq, 3);
+    assertEquals(Color.white, c);
+  }
 }