From a29326254cf21aa7633d1485c1621ffd0fee1097 Mon Sep 17 00:00:00 2001 From: hansonr Date: Tue, 27 Aug 2019 23:51:43 -0500 Subject: [PATCH] JAL-3253-applet JAL-3423 Windows TestNG Bug found in wrap tool tip (also in Jalview-Develop) due to some messages having only one of or and some having neither but still having
(potentially) --- src/jalview/gui/JvSwingUtils.java | 16 +++++++++++++-- test/jalview/gui/JvSwingUtilsTest.java | 34 ++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index b25b2c8..7dd8e6c 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -58,6 +58,7 @@ public final class JvSwingUtils { public static final String HTML_PREFIX = "
"; + /** * wrap a bare html safe string to around 60 characters per line using a CSS * style class specifying word-wrap and break-word @@ -75,8 +76,19 @@ public final class JvSwingUtils "Tootip text to format must not be null!"); ttext = ttext.trim(); boolean maxLengthExceeded = false; - - if (ttext.contains("
")) + boolean isHTML = ttext.startsWith(""); + if (isHTML) + { + ttext = ttext.substring(6); + } + if (ttext.endsWith("")) + { + isHTML = true; + ttext = ttext.substring(0, ttext.length() - 7); + } + boolean hasBR = ttext.contains("
"); + enclose |= isHTML || hasBR; + if (hasBR) { String[] htmllines = ttext.split("
"); for (String line : htmllines) diff --git a/test/jalview/gui/JvSwingUtilsTest.java b/test/jalview/gui/JvSwingUtilsTest.java index 5a8fba7..d46972a 100644 --- a/test/jalview/gui/JvSwingUtilsTest.java +++ b/test/jalview/gui/JvSwingUtilsTest.java @@ -20,8 +20,8 @@ */ package jalview.gui; +import static org.junit.Assert.assertTrue; import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; import javax.swing.JScrollBar; @@ -86,9 +86,17 @@ public class JvSwingUtilsTest JvSwingUtils.wrapTooltip(true, tip)); tip = "0123456789012345678901234567890123456789012345678901234567890"; // 61 - assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip))); - assertFalse(("" + tip + "").equals(JvSwingUtils + assertTrue(tip.equals(JvSwingUtils.wrapTooltip(false, tip))); + assertTrue((JvSwingUtils.HTML_PREFIX + tip + "
") + .equals(JvSwingUtils .wrapTooltip(true, tip))); + +// was: +// +// assertFalse(tip.equals(JvSwingUtils.wrapTooltip(false, tip))); +// assertFalse(("" + tip + "").equals(JvSwingUtils +// .wrapTooltip(true, tip))); + } /** @@ -100,9 +108,23 @@ public class JvSwingUtilsTest 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)); + + // System.out.println( + // JvSwingUtils.wrapTooltip(false, "" + tip + "")); + // System.out.println(JvSwingUtils.wrapTooltip(true, tip)); + + assertEquals("" + tip + "", + JvSwingUtils.wrapTooltip(false, "" + tip + "")); assertEquals("" + tip + "", JvSwingUtils.wrapTooltip(true, tip)); + +// was: +// +// assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); +// assertEquals("" + tip + "", +// JvSwingUtils.wrapTooltip(true, tip)); +// + } /** @@ -113,9 +135,9 @@ public class JvSwingUtilsTest public void testWrapTooltip_longText() { String tip = "Now is the winter of our discontent made glorious summer by this sun of York"; - String expected = JvSwingUtils.HTML_PREFIX + tip + " "; + String expected = JvSwingUtils.HTML_PREFIX + tip + ""; assertEquals(expected, JvSwingUtils.wrapTooltip(true, tip)); - assertEquals(expected, JvSwingUtils.wrapTooltip(false, tip)); + assertEquals(tip, JvSwingUtils.wrapTooltip(false, tip)); } } -- 1.7.10.2