X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FStringUtilsTest.java;h=0308f729f1da28fb6ca09a9f1cf2fe7d66827a51;hb=f0fd407e5fad67185a9813c57bfc50aacaf1de6e;hp=4dc44d4d7f52b91ee63d3fd96e7d5b9e1a423977;hpb=13e9dc5c4c6b9b343c5bc2bcef49d54a296f03f5;p=jalview.git diff --git a/test/jalview/util/StringUtilsTest.java b/test/jalview/util/StringUtilsTest.java index 4dc44d4..0308f72 100644 --- a/test/jalview/util/StringUtilsTest.java +++ b/test/jalview/util/StringUtilsTest.java @@ -21,18 +21,30 @@ package jalview.util; import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertTrue; +import static org.testng.AssertJUnit.fail; + +import jalview.gui.JvOptionPane; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class StringUtilsTest { + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + @Test(groups = { "Functional" }) public void testInsertCharAt() { @@ -135,7 +147,7 @@ public class StringUtilsTest public void testListToDelimitedString() { assertEquals("", StringUtils.listToDelimitedString(null, ";")); - List list = new ArrayList(); + List list = new ArrayList<>(); assertEquals("", StringUtils.listToDelimitedString(list, ";")); list.add("now"); assertEquals("now", StringUtils.listToDelimitedString(list, ";")); @@ -218,4 +230,42 @@ public class StringUtilsTest assertEquals("", StringUtils.toSentenceCase("")); assertNull(StringUtils.toSentenceCase(null)); } + + @Test(groups = { "Functional" }) + public void testStripHtmlTags() + { + assertNull(StringUtils.stripHtmlTags(null)); + assertEquals("", StringUtils.stripHtmlTags("")); + assertEquals( + "label", + StringUtils + .stripHtmlTags("label")); + + // if no "" tag, < and > get html-encoded (not sure why) + assertEquals("<a href=\"something\">label</href>", + StringUtils.stripHtmlTags("label")); + + // gets removed but not (is this intentional?) + assertEquals("

hello", + StringUtils.stripHtmlTags("

hello")); + + assertEquals("kdHydro < 12.53", + StringUtils.stripHtmlTags("kdHydro < 12.53")); + } + + @Test(groups = { "Functional" }) + public void testIsHexString() + { + assertFalse(StringUtils.isHexString("")); + assertTrue(StringUtils.isHexString("0123456789abcdefABCDEF")); + assertFalse(StringUtils.isHexString("g")); + try + { + StringUtils.isHexString(null); + fail("expected exception"); + } catch (NullPointerException e) + { + // expected + } + } }