X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FJvSwingUtilsTest.java;h=e6f40419e809b2126ed254a9611e953404e5d23d;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=868fe38134e1f05932fd3d026de159faa3fac8df;hpb=3412b273e964fb1a9d22564b04a5f0c827ec2461;p=jalview.git diff --git a/test/jalview/gui/JvSwingUtilsTest.java b/test/jalview/gui/JvSwingUtilsTest.java index 868fe38..e6f4041 100644 --- a/test/jalview/gui/JvSwingUtilsTest.java +++ b/test/jalview/gui/JvSwingUtilsTest.java @@ -1,13 +1,44 @@ +/* + * 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.gui; import static org.testng.AssertJUnit.assertEquals; -import org.testng.annotations.Test; +import static org.testng.AssertJUnit.assertFalse; + import javax.swing.JScrollBar; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + public class JvSwingUtilsTest { - @Test + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + @Test(groups = { "Functional" }) public void testGetScrollBarProportion() { /* @@ -22,7 +53,7 @@ public class JvSwingUtilsTest assertEquals(0.25f, JvSwingUtils.getScrollBarProportion(sb), 0.001f); } - @Test + @Test(groups = { "Functional" }) public void testGetScrollValueForProportion() { /* @@ -36,4 +67,56 @@ public class JvSwingUtilsTest */ assertEquals(125, JvSwingUtils.getScrollValueForProportion(sb, 0.25f)); } + + /** + * Test wrap tooltip where it is less than or equal to 60 characters long - no + * wrap should be applied + */ + @Test(groups = { "Functional" }) + public void testWrapTooltip_shortText() + { + String tip = "hello world"; + assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); + assertEquals("" + tip + "", + JvSwingUtils.wrapTooltip(true, tip)); + + tip = "012345678901234567890123456789012345678901234567890123456789"; // 60 + assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); + assertEquals("" + tip + "", + JvSwingUtils.wrapTooltip(true, tip)); + + tip = "0123456789012345678901234567890123456789012345678901234567890"; // 61 + assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip))); + assertFalse(("" + tip + "") + .equals(JvSwingUtils.wrapTooltip(true, tip))); + } + + /** + * Test wrap tooltip where it is more than one line (separated by <br> + * tags) of less than or equal to 60 characters long - no wrap should be + * applied + */ + @Test(groups = { "Functional" }) + public void testWrapTooltip_multilineShortText() + { + String tip = "Now is the winter of our discontent
Made glorious summer by this sun of York"; + assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); + assertEquals("" + tip + "", + JvSwingUtils.wrapTooltip(true, tip)); + } + + /** + * Test wrap tooltip where it is more than 60 characters long - word break and + * word wrap styling should be applied + */ + @Test(groups = { "Functional" }) + public void testWrapTooltip_longText() + { + String tip = "Now is the winter of our discontent made glorious summer by this sun of York"; + String expected = "" + + "
" + tip + "
"; + assertEquals("" + expected + "", + JvSwingUtils.wrapTooltip(true, tip)); + assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip)); + } }