JAL-3368 removed parsing web colours (now on a separate branch)
[jalview.git] / test / jalview / util / StringUtilsTest.java
index b6f8a25..0308f72 100644 (file)
 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;
 
@@ -145,7 +147,7 @@ public class StringUtilsTest
   public void testListToDelimitedString()
   {
     assertEquals("", StringUtils.listToDelimitedString(null, ";"));
-    List<String> list = new ArrayList<String>();
+    List<String> list = new ArrayList<>();
     assertEquals("", StringUtils.listToDelimitedString(list, ";"));
     list.add("now");
     assertEquals("now", StringUtils.listToDelimitedString(list, ";"));
@@ -228,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(
+            "<a href=\"something\">label</href>",
+            StringUtils
+                    .stripHtmlTags("<html><a href=\"something\">label</href></html>"));
+
+    // if no "<html>" tag, < and > get html-encoded (not sure why)
+    assertEquals("&lt;a href=\"something\"&gt;label&lt;/href&gt;",
+            StringUtils.stripHtmlTags("<a href=\"something\">label</href>"));
+
+    // </body> gets removed but not <body> (is this intentional?)
+    assertEquals("<body><p>hello",
+            StringUtils.stripHtmlTags("<html><body><p>hello</body></html>"));
+
+    assertEquals("kdHydro &lt; 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
+    }
+  }
 }