JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / test / jalview / util / StringUtilsTest.java
index ece1fda..4dc44d4 100644 (file)
@@ -1,10 +1,32 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.util;
 
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertTrue;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 import org.testng.annotations.Test;
 
@@ -108,4 +130,92 @@ public class StringUtilsTest
     assertEquals("a*b*c*cde", StringUtils.arrayToSeparatorList(new String[]
     { "a", "b*c", "cde" }, "*"));
   }
+
+  @Test(groups = { "Functional" })
+  public void testListToDelimitedString()
+  {
+    assertEquals("", StringUtils.listToDelimitedString(null, ";"));
+    List<String> list = new ArrayList<String>();
+    assertEquals("", StringUtils.listToDelimitedString(list, ";"));
+    list.add("now");
+    assertEquals("now", StringUtils.listToDelimitedString(list, ";"));
+    list.add("is");
+    assertEquals("now;is", StringUtils.listToDelimitedString(list, ";"));
+    assertEquals("now ; is", StringUtils.listToDelimitedString(list, " ; "));
+    list.add("the");
+    list.add("winter");
+    list.add("of");
+    list.add("our");
+    list.add("discontent");
+    assertEquals("now is the winter of our discontent",
+            StringUtils.listToDelimitedString(list, " "));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testParseInt()
+  {
+    assertEquals(0, StringUtils.parseInt(null));
+    assertEquals(0, StringUtils.parseInt(""));
+    assertEquals(0, StringUtils.parseInt("x"));
+    assertEquals(0, StringUtils.parseInt("1.2"));
+    assertEquals(33, StringUtils.parseInt("33"));
+    assertEquals(33, StringUtils.parseInt("+33"));
+    assertEquals(-123, StringUtils.parseInt("-123"));
+    // too big for an int:
+    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));
+  }
 }