X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fschemes%2FUserColourSchemeTest.java;h=497014ea1a2d9c25f38f8517814f13f99c73f864;hb=136c0793b90b72b928c4d77dc109dd5c644e00d3;hp=f3f72f61bc20a050e9fe860cc475f96b75eea3b4;hpb=528c0f1815bc67b54618ad5b16c2162946974caf;p=jalview.git diff --git a/test/jalview/schemes/UserColourSchemeTest.java b/test/jalview/schemes/UserColourSchemeTest.java index f3f72f6..497014e 100644 --- a/test/jalview/schemes/UserColourSchemeTest.java +++ b/test/jalview/schemes/UserColourSchemeTest.java @@ -1,51 +1,83 @@ +/* + * 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.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertNull; -import static org.testng.AssertJUnit.assertSame; + +import jalview.gui.JvOptionPane; import java.awt.Color; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class UserColourSchemeTest { + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + @Test(groups = "Functional") + public void testParseAppletParameter() + { + UserColourScheme cs = new UserColourScheme("white"); + cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30"); + assertEquals(Color.RED, cs.findColour('D')); + assertEquals(Color.RED, cs.findColour('d')); + assertEquals(Color.RED, cs.findColour('E')); + assertEquals(Color.RED, cs.findColour('e')); + Color c1 = new Color(0x0022ff); + assertEquals(c1, cs.findColour('K')); + assertEquals(c1, cs.findColour('R')); + assertEquals(c1, cs.findColour('h')); + Color c2 = new Color(10, 20, 30); + assertEquals(c2, cs.findColour('c')); + + cs = new UserColourScheme("white"); + cs.parseAppletParameter("D,E=red; K,R,H=0022FF; c=10 , 20,30;t=orange;lowercase=blue;s=pink"); + assertEquals(Color.RED, cs.findColour('D')); + assertEquals(Color.blue, cs.findColour('d')); + assertEquals(Color.RED, cs.findColour('E')); + assertEquals(Color.blue, cs.findColour('e')); + assertEquals(c1, cs.findColour('K')); + assertEquals(c1, cs.findColour('R')); + assertEquals(Color.blue, cs.findColour('h')); + assertEquals(c2, cs.findColour('c')); + // 'lowercase' sets all lower-case not already set to the given colour + assertEquals(Color.orange, cs.findColour('t')); + assertEquals(Color.blue, cs.findColour('k')); + assertEquals(Color.blue, cs.findColour('a')); + assertEquals(Color.pink, cs.findColour('s')); + } + @Test(groups = "Functional") - public void testGetColourFromString() + public void testToAppletParameter() { - /* - * by colour name - if known to AWT, and included in - * - * @see ColourSchemeProperty.getAWTColorFromName() - */ - assertSame(Color.RED, UserColourScheme.getColourFromString("red")); - assertSame(Color.RED, UserColourScheme.getColourFromString("Red")); - assertSame(Color.RED, UserColourScheme.getColourFromString(" RED ")); - - /* - * by RGB hex code - */ - String hexColour = Integer.toHexString(Color.RED.getRGB() & 0xffffff); - assertEquals(Color.RED, UserColourScheme.getColourFromString(hexColour)); - // 'hex' prefixes _not_ wanted here - assertNull(UserColourScheme.getColourFromString("0x" + hexColour)); - assertNull(UserColourScheme.getColourFromString("#" + hexColour)); - - /* - * by RGB triplet - */ - String rgb = String.format("%d,%d,%d", Color.red.getRed(), - Color.red.getGreen(), Color.red.getBlue()); - assertEquals(Color.RED, UserColourScheme.getColourFromString(rgb)); - - /* - * odds and ends - */ - assertNull(UserColourScheme.getColourFromString(null)); - assertNull(UserColourScheme.getColourFromString("rubbish")); - assertEquals(Color.WHITE, UserColourScheme.getColourFromString("-1")); - assertNull(UserColourScheme.getColourFromString(String - .valueOf(Integer.MAX_VALUE))); + UserColourScheme cs = new UserColourScheme( + "E,D=red; K,R,H=0022FF; c=10 , 20,30"); + String param = cs.toAppletParameter(); + assertEquals("D,E=ff0000;H,K,R=0022ff;c=0a141e", param); } }