X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Futil%2FStringUtilsTest.java;h=084219ad661026893a57e9597a75e63fe0c321a8;hb=9bcdd1d38988de350482acfd1a21628f73cdbd6d;hp=dc2555bcf8e9c5ced387293f124e41f281ed5cb0;hpb=8f920d337154e092f5f9056ffde3cdf2735eca43;p=jalview.git diff --git a/test/jalview/util/StringUtilsTest.java b/test/jalview/util/StringUtilsTest.java index dc2555b..084219a 100644 --- a/test/jalview/util/StringUtilsTest.java +++ b/test/jalview/util/StringUtilsTest.java @@ -24,15 +24,25 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertTrue; +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() { @@ -165,4 +175,79 @@ public class StringUtilsTest assertEquals(0, StringUtils.parseInt(String.valueOf(Integer.MAX_VALUE) + "1")); } + + @Test(groups = { "Functional" }) + public void testCompareVersions() + { + assertEquals(0, StringUtils.compareVersions(null, null)); + assertEquals(0, StringUtils.compareVersions("2.8.3", null)); + + /* + * same version returns 0 + */ + assertEquals(0, StringUtils.compareVersions("2.8", "2.8")); + assertEquals(0, StringUtils.compareVersions("2.8.3", "2.8.3")); + assertEquals(0, StringUtils.compareVersions("2.8.3b1", "2.8.3b1", "b")); + assertEquals(0, StringUtils.compareVersions("2.8.3B1", "2.8.3b1", "b")); + assertEquals(0, StringUtils.compareVersions("2.8.3b1", "2.8.3B1", "b")); + + /* + * v1 < v2 returns -1 + */ + assertEquals(-1, StringUtils.compareVersions("2.8.3", "2.8.4")); + assertEquals(-1, StringUtils.compareVersions("2.8.3", "2.9")); + assertEquals(-1, StringUtils.compareVersions("2.8.3", "2.9.2")); + assertEquals(-1, StringUtils.compareVersions("2.8", "2.8.3")); + assertEquals(-1, StringUtils.compareVersions("2.8.3", "2.8.3b1", "b")); + assertEquals(-1, StringUtils.compareVersions("2.8.3b1", "2.8.3b2", "b")); + assertEquals(-1, StringUtils.compareVersions("2.8", "2.8.0", "b")); + assertEquals(-1, StringUtils.compareVersions("2", "12")); + assertEquals(-1, StringUtils.compareVersions("3.2.4", "3.12.11")); + + /* + * v1 > v2 returns +1 + */ + assertEquals(1, StringUtils.compareVersions("2.8.3", "2.8")); + assertEquals(1, StringUtils.compareVersions("2.8.0", "2.8")); + assertEquals(1, StringUtils.compareVersions("2.8.4", "2.8.3")); + assertEquals(1, StringUtils.compareVersions("2.8.3b1", "2.8.3", "b")); + assertEquals(1, StringUtils.compareVersions("2.8.3", "2.8.2b1", "b")); + assertEquals(1, StringUtils.compareVersions("2.8.0b2", "2.8.0b1", "b")); + assertEquals(1, StringUtils.compareVersions("12", "2")); + assertEquals(1, StringUtils.compareVersions("3.12.11", "3.2.4")); + } + + @Test(groups = { "Functional" }) + public void testToSentenceCase() + { + assertEquals("John", StringUtils.toSentenceCase("john")); + assertEquals("John", StringUtils.toSentenceCase("JOHN")); + assertEquals("John and james", + StringUtils.toSentenceCase("JOHN and JAMES")); + assertEquals("J", StringUtils.toSentenceCase("j")); + 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")); + } }
hello", + StringUtils.stripHtmlTags("
hello")); + + assertEquals("kdHydro < 12.53", + StringUtils.stripHtmlTags("kdHydro < 12.53")); + } }