X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FJvSwingUtilsTest.java;h=5e65cc24eaa2de7554b8c072d26f09f73858cc60;hb=29c183b0d0de9f6f9f94d2b528d10e20b1891684;hp=11e6ea5ed5fd1d4c9e41a6b0bd94ceef6e247831;hpb=be32c14cd8e48fe0a207cd7030cb9cd46f894678;p=jalview.git diff --git a/test/jalview/gui/JvSwingUtilsTest.java b/test/jalview/gui/JvSwingUtilsTest.java index 11e6ea5..5e65cc2 100644 --- a/test/jalview/gui/JvSwingUtilsTest.java +++ b/test/jalview/gui/JvSwingUtilsTest.java @@ -1,15 +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.junit.Assert.assertEquals; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; import javax.swing.JScrollBar; -import org.junit.Test; +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() { /* @@ -24,7 +53,7 @@ public class JvSwingUtilsTest assertEquals(0.25f, JvSwingUtils.getScrollBarProportion(sb), 0.001f); } - @Test + @Test(groups = { "Functional" }) public void testGetScrollValueForProportion() { /* @@ -38,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)); + } }