/* * 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 java.awt.Color; import org.testng.annotations.Test; public class UserColourSchemeTest { @Test(groups = "Functional") public void testGetColourFromString() { /* * 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))); } }