2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.renderer;
23 import static org.testng.AssertJUnit.assertEquals;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.AlignViewport;
30 import jalview.gui.JvOptionPane;
31 import jalview.schemes.UserColourScheme;
32 import jalview.schemes.ZappoColourScheme;
34 import java.awt.Color;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.Test;
39 public class ResidueColourFinderTest
42 @BeforeClass(alwaysRun = true)
43 public void setUpJvOptionPane()
45 JvOptionPane.setInteractiveMode(false);
46 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
49 @Test(groups = { "Functional" })
50 public void testGetResidueColour_zappo()
52 SequenceI seq = new Sequence("name", "MATVLGSPRAPAFF"); // FER1_MAIZE...
53 AlignmentI al = new Alignment(new SequenceI[] { seq });
54 final AlignViewport av = new AlignViewport(al);
55 ResidueColourFinder rcf = new ResidueColourFinder();
56 av.setGlobalColourScheme(new ZappoColourScheme());
58 // @see ResidueProperties.zappo
59 assertEquals(Color.pink,
60 rcf.getResidueColour(true, av.getResidueShading(), null, seq, 0,
62 assertEquals(Color.green,
63 rcf.getResidueColour(true, av.getResidueShading(), null, seq, 2,
65 assertEquals(Color.magenta,
66 rcf.getResidueColour(true, av.getResidueShading(), null, seq, 5,
68 assertEquals(Color.orange,
69 rcf.getResidueColour(true, av.getResidueShading(), null, seq,
73 // everything is white if showBoxes is false
74 assertEquals(Color.white, rcf.getResidueColour(false,
75 av.getResidueShading(), null, seq, 0, null)); // M
76 assertEquals(Color.white, rcf.getResidueColour(false,
77 av.getResidueShading(), null, seq, 2, null)); // T
78 assertEquals(Color.white, rcf.getResidueColour(false,
79 av.getResidueShading(), null, seq, 5, null)); // G
80 assertEquals(Color.white, rcf.getResidueColour(false,
81 av.getResidueShading(), null, seq, 12, null)); // F
84 @Test(groups = { "Functional" })
85 public void testGetResidueColour_none()
87 SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
88 AlignmentI al = new Alignment(new SequenceI[] { seq });
89 final AlignViewport av = new AlignViewport(al);
90 ResidueColourFinder rcf = new ResidueColourFinder();
92 assertEquals(Color.white,
93 rcf.getResidueColour(true, av.getResidueShading(),
95 assertEquals(Color.white,
96 rcf.getResidueColour(true, av.getResidueShading(),
99 // no change if showBoxes is false
100 assertEquals(Color.white, rcf.getResidueColour(false,
101 av.getResidueShading(), null, seq, 0, null));
102 assertEquals(Color.white, rcf.getResidueColour(false,
103 av.getResidueShading(), null, seq, 2, null));
106 @Test(groups = { "Functional" })
107 public void testGetResidueColour_userdef()
109 SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
111 AlignmentI al = new Alignment(new SequenceI[] { seq });
112 final AlignViewport av = new AlignViewport(al);
113 ResidueColourFinder rcf = new ResidueColourFinder();
115 Color[] newColours = new Color[24];
116 for (int i = 0; i < 24; i++)
118 newColours[i] = null;
121 av.setGlobalColourScheme(new UserColourScheme(newColours));
123 // gap colour not specified so gap colour is null
124 // this is consistent with previous behaviour, but may not be correct?
125 assertEquals(null, rcf.getResidueColour(true, av.getResidueShading(),
126 null, seq, 3, null));
128 newColours[23] = Color.pink;
129 av.setGlobalColourScheme(new UserColourScheme(newColours));
131 // gap colour specified as pink
132 assertEquals(Color.pink, rcf.getResidueColour(true,
133 av.getResidueShading(),
134 null, seq, 3, null));
136 // everything is white if showBoxes is false
137 newColours[23] = null;
138 assertEquals(Color.white, rcf.getResidueColour(false,
139 av.getResidueShading(),
140 null, seq, 3, null));
142 newColours[23] = Color.pink;
143 av.setGlobalColourScheme(new UserColourScheme(newColours));
145 // gap colour specified as pink
146 assertEquals(Color.white, rcf.getResidueColour(false,
147 av.getResidueShading(), null, seq, 3, null));
150 // TODO more tests for getResidueColour covering groups, feature rendering...