You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/07/31 23:32:47 UTC
cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang CharSetUtilsTest.java
scolebourne 2003/07/31 14:32:47
Modified: lang/src/java/org/apache/commons/lang CharSetUtils.java
CharSet.java
lang/src/test/org/apache/commons/lang CharSetUtilsTest.java
Log:
Fix CharSetUtils to not throw NPE all the time
Revision Changes Path
1.18 +112 -54 jakarta-commons/lang/src/java/org/apache/commons/lang/CharSetUtils.java
Index: CharSetUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/CharSetUtils.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- CharSetUtils.java 31 Jul 2003 20:38:26 -0000 1.17
+++ CharSetUtils.java 31 Jul 2003 21:32:47 -0000 1.18
@@ -56,8 +56,8 @@
/**
* <p>Numerous routines to manipulate a <code>CharSet</code>.</p>
*
- * <p>This class tries to handle <code>null</code> input gracefully.
- * An exception will generally not be thrown for a <code>null</code> input.
+ * <p>This class handles <code>null</code> input gracefully.
+ * An exception will not be thrown for a <code>null</code> input.
* Each method documents its behaviour in more detail.</p>
*
* @author <a href="bayard@generationjava.com">Henri Yandell</a>
@@ -77,6 +77,7 @@
public CharSetUtils() {
}
+ //-----------------------------------------------------------------------
/**
* <p>Creates a <code>CharSetUtils</code> object which allows a certain amount of
* set logic to be performed.</p>
@@ -87,33 +88,72 @@
* a set in itself due to the size of that set in unicode.</li>
* <li>"ej-m" implies e,j->m. e,j,k,l,m.</li>
* </ul>
+ *
+ * <pre>
+ * CharSetUtils.evaluateSet(null) = null
+ * CharSetUtils.evaluateSet("") = CharSet matching nothing
+ * CharSetUtils.evaluateSet("a-e") = CharSet matching a,b,c,d,e
+ * </pre>
*
- * @param set the set, must not be null
- * @return a CharSet instance
- * @throws NullPointerException if any of set[i] is null or if set is null
+ * @param set the set, may be null
+ * @return a CharSet instance, <code>null</code> if null input
+ */
+ public static CharSet evaluateSet(String set) {
+ if (set == null) {
+ return null;
+ }
+ return new CharSet(new String[] {set});
+ }
+
+ /**
+ * <p>Creates a <code>CharSetUtils</code> object which allows a certain amount of
+ * set logic to be performed.</p>
+ * <p>The syntax is:</p>
+ * <ul>
+ * <li>"aeio" which implies 'a','e',..</li>
+ * <li>"^e" implies not e. However it only negates, it's not
+ * a set in itself due to the size of that set in unicode.</li>
+ * <li>"ej-m" implies e,j->m. e,j,k,l,m.</li>
+ * </ul>
+ *
+ * <pre>
+ * CharSetUtils.evaluateSet(null) = null
+ * CharSetUtils.evaluateSet([]) = CharSet matching nothing
+ * CharSetUtils.evaluateSet(["a-e"]) = CharSet matching a,b,c,d,e
+ * </pre>
+ *
+ * @param set the set, may be null
+ * @return a CharSet instance, <code>null</code> if null input
*/
public static CharSet evaluateSet(String[] set) {
+ if (set == null) {
+ return null;
+ }
return new CharSet(set);
}
+ //-----------------------------------------------------------------------
/**
* <p>Squeezes any repititions of a character that is mentioned in the
* supplied set.</p>
*
- * <p>An example is:</p>
- * <ul>
- * <li>squeeze("hello", "el") => "helo"</li>
- * </ul>
- * @see #evaluateSet(java.lang.String[]) for set-syntax.
+ * <pre>
+ * CharSetUtils.squeeze(null, *) = null
+ * CharSetUtils.squeeze("", *) = ""
+ * CharSetUtils.squeeze(*, null) = *
+ * CharSetUtils.squeeze(*, "") = *
+ * CharSetUtils.squeeze("hello", "k-p") = "helo"
+ * CharSetUtils.squeeze("hello", "a-e") = "hello"
+ * </pre>
*
+ * @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str the string to squeeze, may be null
- * @param set the character set to use for manipulation, must not be null
+ * @param set the character set to use for manipulation, may be null
* @return modified String, <code>null</code> if null string input
- * @throws NullPointerException if <code>set</code> is <code>null</code>
*/
public static String squeeze(String str, String set) {
- if (str == null) {
- return null;
+ if (str == null || str.length() == 0 || set == null || set.length() == 0) {
+ return str;
}
String[] strs = new String[1];
strs[0] = set;
@@ -128,17 +168,15 @@
* <ul>
* <li>squeeze("hello", {"el"}) => "helo"</li>
* </ul>
- * @see #evaluateSet(java.lang.String[]) for set-syntax.
*
+ * @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str the string to squeeze, may be null
- * @param set the character set to use for manipulation, must not be null
+ * @param set the character set to use for manipulation, may be null
* @return modified String, <code>null</code> if null string input
- * @throws NullPointerException if <code>set</code> is <code>null</code>
- * or any element is <code>null</code>
*/
public static String squeeze(String str, String[] set) {
- if (str == null) {
- return null;
+ if (str == null || str.length() == 0 || set == null || set.length == 0) {
+ return str;
}
CharSet chars = evaluateSet(set);
StringBuffer buffer = new StringBuffer(str.length());
@@ -159,22 +197,27 @@
return buffer.toString();
}
+ //-----------------------------------------------------------------------
/**
* <p>Takes an argument in set-syntax, see evaluateSet,
* and returns the number of characters present in the specified string.</p>
*
- * <p>An example would be:</p>
- * <ul>
- * <li>count("hello", {"c-f", "o"}) returns 2.</li>
- * </ul>
+ * <pre>
+ * CharSetUtils.count(null, *) = 0
+ * CharSetUtils.count("", *) = 0
+ * CharSetUtils.count(*, null) = 0
+ * CharSetUtils.count(*, "") = 0
+ * CharSetUtils.count("hello", "k-p") = 3
+ * CharSetUtils.count("hello", "a-e") = 1
+ * </pre>
*
+ * @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to count characters in, may be null
- * @param set String set of characters to count, must not be null
+ * @param set String set of characters to count, may be null
* @return character count, zero if null string input
- * @throws NullPointerException if <code>set</code> is <code>null</code>
*/
public static int count(String str, String set) {
- if (str == null) {
+ if (str == null || str.length() == 0 || set == null || set.length() == 0) {
return 0;
}
String[] strs = new String[1];
@@ -191,14 +234,13 @@
* <li>count("hello", {"c-f", "o"}) returns 2.</li>
* </ul>
*
+ * @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to count characters in, may be null
- * @param set String[] set of characters to count, must not be null
+ * @param set String[] set of characters to count, may be null
* @return character count, zero if null string input
- * @throws NullPointerException if <code>set</code> is <code>null</code>
- * or any element is <code>null</code>
*/
public static int count(String str, String[] set) {
- if (str == null) {
+ if (str == null || str.length() == 0 || set == null || set.length == 0) {
return 0;
}
CharSet chars = evaluateSet(set);
@@ -213,24 +255,32 @@
return count;
}
+ //-----------------------------------------------------------------------
/**
* <p>Takes an argument in set-syntax, see evaluateSet,
* and keeps any of characters present in the specified string.</p>
*
- * <p>An example would be:</p>
- * <ul>
- * <li>keep("hello", {"c-fo"}) returns "hll"</li>
- * </ul>
+ * <pre>
+ * CharSetUtils.keep(null, *) = null
+ * CharSetUtils.keep("", *) = ""
+ * CharSetUtils.keep(*, null) = ""
+ * CharSetUtils.keep(*, "") = ""
+ * CharSetUtils.keep("hello", "hl") = "hll"
+ * CharSetUtils.keep("hello", "le") = "ell"
+ * </pre>
*
+ * @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to keep characters from, may be null
- * @param set String set of characters to keep, must not be null
+ * @param set String set of characters to keep, may be null
* @return modified String, <code>null</code> if null string input
- * @throws NullPointerException if <code>set</code> is <code>null</code>
*/
public static String keep(String str, String set) {
if (str == null) {
return null;
}
+ if (str.length() == 0 || set == null || set.length() == 0) {
+ return "";
+ }
String[] strs = new String[1];
strs[0] = set;
return keep(str, strs);
@@ -246,36 +296,43 @@
* returns "hll"</li>
* </ul>
*
+ * @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to keep characters from, may be null
- * @param set String[] set of characters to keep, must not be null
+ * @param set String[] set of characters to keep, may be null
* @return modified String, <code>null</code> if null string input
- * @throws NullPointerException if <code>set</code> is <code>null</code>
- * or any element is <code>null</code>
*/
public static String keep(String str, String[] set) {
if (str == null) {
return null;
}
+ if (str.length() == 0 || set == null || set.length == 0) {
+ return "";
+ }
return modify(str, set, true);
}
+ //-----------------------------------------------------------------------
/**
* <p>Takes an argument in set-syntax, see evaluateSet,
* and deletes any of characters present in the specified string.</p>
*
- * <p>An example would be:</p>
- * <ul>
- * <li>delete("hello", {"c-fo"}) returns "hll"</li>
- * </ul>
+ * <pre>
+ * CharSetUtils.delete(null, *) = null
+ * CharSetUtils.delete("", *) = ""
+ * CharSetUtils.delete(*, null) = *
+ * CharSetUtils.delete(*, "") = *
+ * CharSetUtils.delete("hello", "hl") = "hll"
+ * CharSetUtils.delete("hello", "le") = "ell"
+ * </pre>
*
+ * @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to delete characters from, may be null
- * @param set String set of characters to delete, must not be null
+ * @param set String set of characters to delete, may be null
* @return modified String, <code>null</code> if null string input
- * @throws NullPointerException if <code>set</code> is <code>null</code>
*/
public static String delete(String str, String set) {
- if (str == null) {
- return null;
+ if (str == null || str.length() == 0 || set == null || set.length() == 0) {
+ return str;
}
String[] strs = new String[1];
strs[0] = set;
@@ -292,19 +349,19 @@
* "hll"</li>
* </ul>
*
+ * @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to delete characters from, may be null
- * @param set String[] set of characters to delete, must not be null
+ * @param set String[] set of characters to delete, may be null
* @return modified String, <code>null</code> if null string input
- * @throws NullPointerException if <code>set</code> is <code>null</code>
- * or any element is <code>null</code>
*/
public static String delete(String str, String[] set) {
- if (str == null) {
- return null;
+ if (str == null || str.length() == 0 || set == null || set.length == 0) {
+ return str;
}
return modify(str, set, false);
}
+ //-----------------------------------------------------------------------
// Implementation of delete and keep
private static String modify(String str, String[] set, boolean expect) {
CharSet chars = evaluateSet(set);
@@ -319,6 +376,7 @@
return buffer.toString();
}
+ //-----------------------------------------------------------------------
/**
* <p>Translate characters in a String.
* This is a multi character search and replace routine.</p>
1.9 +22 -12 jakarta-commons/lang/src/java/org/apache/commons/lang/CharSet.java
Index: CharSet.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/CharSet.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- CharSet.java 23 Mar 2003 17:59:09 -0000 1.8
+++ CharSet.java 31 Jul 2003 21:32:47 -0000 1.9
@@ -58,8 +58,7 @@
import java.util.List;
/**
- * <p>A set of characters. You can iterate over the characters in the
- * set.</p>
+ * <p>A set of characters.</p>
*
* @author <a href="bayard@generationjava.com">Henri Yandell</a>
* @author Stephen Colebourne
@@ -75,9 +74,18 @@
*
* <p>Use the factory method
* {@link CharSetUtils#evaluateSet(java.lang.String[])}.</p>
+ */
+ protected CharSet(String set) {
+ add(set);
+ }
+
+ /**
+ * <p>Restricted constructor.</p>
+ *
+ * <p>Use the factory method
+ * {@link CharSetUtils#evaluateSet(java.lang.String[])}.</p>
*
- * @throws NullPointerException if any of set[i] is <code>null</code>
- * or if set is <code>null</code>
+ * @throws NullPointerException if set is <code>null</code>
*/
protected CharSet(String[] set) {
int sz = set.length;
@@ -116,31 +124,33 @@
* <p>Add a set definition string to the <code>CharSet</code>.</p>
*
* @param str set definition string
- * @throws NullPointerException if <code>str</code> is <code>null</code>
*/
protected void add(String str) {
+ if (str == null) {
+ return;
+ }
int sz = str.length();
CharRange range = null;
- if("-".equals(str)) {
+ if ("-".equals(str)) {
range = new CharRange('-');
set.add(range);
return;
- }
+ }
boolean end = false;
boolean negated = false;
- for(int i=0; i<sz; i++) {
+ for (int i = 0; i < sz; i++) {
char ch = str.charAt(i);
- if(ch == '-') {
+ if (ch == '-') {
end = true;
continue;
}
- if(end) {
+ if (end) {
range.setEnd(ch);
continue;
}
- if(ch == '^') {
+ if (ch == '^') {
negated = true;
continue;
}
1.11 +139 -51 jakarta-commons/lang/src/test/org/apache/commons/lang/CharSetUtilsTest.java
Index: CharSetUtilsTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/CharSetUtilsTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CharSetUtilsTest.java 30 Jul 2003 22:21:39 -0000 1.10
+++ CharSetUtilsTest.java 31 Jul 2003 21:32:47 -0000 1.11
@@ -104,72 +104,167 @@
}
//-----------------------------------------------------------------------
- public void testSqueeze() {
- assertEquals(null, CharSetUtils.squeeze(null, (String[]) null));
+ public void testEvaluateSet_String() {
+ assertEquals(null, CharSetUtils.evaluateSet((String) null));
+ assertEquals("[]", CharSetUtils.evaluateSet("").toString());
+ assertEquals("[a-e]", CharSetUtils.evaluateSet("a-e").toString());
+ }
+
+ public void testEvaluateSet_Stringarray() {
+ assertEquals(null, CharSetUtils.evaluateSet((String[]) null));
+ assertEquals("[]", CharSetUtils.evaluateSet(new String[0]).toString());
+ assertEquals("[]", CharSetUtils.evaluateSet(new String[] {null}).toString());
+ assertEquals("[a-e]", CharSetUtils.evaluateSet(new String[] {"a-e"}).toString());
+ }
+
+ //-----------------------------------------------------------------------
+ public void testSqueeze_StringString() {
assertEquals(null, CharSetUtils.squeeze(null, (String) null));
- assertEquals(null, CharSetUtils.squeeze(null, new String[] { "el" }));
- assertEquals("helo", CharSetUtils.squeeze("hello", new String[] { "el" }));
+ assertEquals(null, CharSetUtils.squeeze(null, ""));
+
+ assertEquals("", CharSetUtils.squeeze("", (String) null));
+ assertEquals("", CharSetUtils.squeeze("", ""));
+ assertEquals("", CharSetUtils.squeeze("", "a-e"));
+
+ assertEquals("hello", CharSetUtils.squeeze("hello", (String) null));
assertEquals("hello", CharSetUtils.squeeze("hello", ""));
- assertEquals("", CharSetUtils.squeeze("", new String[] { "el" }));
+ assertEquals("hello", CharSetUtils.squeeze("hello", "a-e"));
+ assertEquals("helo", CharSetUtils.squeeze("hello", "l-p"));
+ }
+
+ public void testSqueeze_StringStringarray() {
+ assertEquals(null, CharSetUtils.squeeze(null, (String[]) null));
+ assertEquals(null, CharSetUtils.squeeze(null, new String[0]));
+ assertEquals(null, CharSetUtils.squeeze(null, new String[] {null}));
+ assertEquals(null, CharSetUtils.squeeze(null, new String[] {"el"}));
+
+ assertEquals("", CharSetUtils.squeeze("", (String[]) null));
+ assertEquals("", CharSetUtils.squeeze("", new String[0]));
+ assertEquals("", CharSetUtils.squeeze("", new String[] {null}));
+ assertEquals("", CharSetUtils.squeeze("", new String[] {"a-e"}));
+
+ assertEquals("hello", CharSetUtils.squeeze("hello", (String[]) null));
+ assertEquals("hello", CharSetUtils.squeeze("hello", new String[0]));
+ assertEquals("hello", CharSetUtils.squeeze("hello", new String[] {null}));
+ assertEquals("hello", CharSetUtils.squeeze("hello", new String[] {"a-e"}));
+
+ assertEquals("helo", CharSetUtils.squeeze("hello", new String[] { "el" }));
assertEquals("hello", CharSetUtils.squeeze("hello", new String[] { "e" }));
assertEquals("fofof", CharSetUtils.squeeze("fooffooff", new String[] { "of" }));
assertEquals("fof", CharSetUtils.squeeze("fooooff", new String[] { "fo" }));
- try {
- CharSetUtils.squeeze("hello", (String[]) null);
- fail("Expecting NullPointerException");
- } catch (NullPointerException ex) {}
- try {
- CharSetUtils.squeeze("hello", new String[] { "", null });
- fail("Expecting NullPointerException");
- } catch (NullPointerException ex) {}
}
- public void testCount() {
- assertEquals(0, CharSetUtils.count(null, (String[]) null));
+ //-----------------------------------------------------------------------
+ public void testCount_StringString() {
assertEquals(0, CharSetUtils.count(null, (String) null));
- assertEquals(0, CharSetUtils.count(null, new String[] { "el" }));
+ assertEquals(0, CharSetUtils.count(null, ""));
+
+ assertEquals(0, CharSetUtils.count("", (String) null));
+ assertEquals(0, CharSetUtils.count("", ""));
+ assertEquals(0, CharSetUtils.count("", "a-e"));
+
+ assertEquals(0, CharSetUtils.count("hello", (String) null));
+ assertEquals(0, CharSetUtils.count("hello", ""));
+ assertEquals(1, CharSetUtils.count("hello", "a-e"));
+ assertEquals(3, CharSetUtils.count("hello", "l-p"));
+ }
+
+ public void testCount_StringStringarray() {
+ assertEquals(0, CharSetUtils.count(null, (String[]) null));
+ assertEquals(0, CharSetUtils.count(null, new String[0]));
+ assertEquals(0, CharSetUtils.count(null, new String[] {null}));
+ assertEquals(0, CharSetUtils.count(null, new String[] {"a-e"}));
+
+ assertEquals(0, CharSetUtils.count("", (String[]) null));
+ assertEquals(0, CharSetUtils.count("", new String[0]));
+ assertEquals(0, CharSetUtils.count("", new String[] {null}));
+ assertEquals(0, CharSetUtils.count("", new String[] {"a-e"}));
+
+ assertEquals(0, CharSetUtils.count("hello", (String[]) null));
+ assertEquals(0, CharSetUtils.count("hello", new String[0]));
+ assertEquals(0, CharSetUtils.count("hello", new String[] {null}));
+ assertEquals(1, CharSetUtils.count("hello", new String[] {"a-e"}));
+
assertEquals(3, CharSetUtils.count("hello", new String[] { "el" }));
- assertEquals(0, CharSetUtils.count("", new String[] { "el" }));
assertEquals(0, CharSetUtils.count("hello", new String[] { "x" }));
assertEquals(2, CharSetUtils.count("hello", new String[] { "e-i" }));
assertEquals(5, CharSetUtils.count("hello", new String[] { "a-z" }));
assertEquals(0, CharSetUtils.count("hello", new String[] { "" }));
- assertEquals(0, CharSetUtils.count("hello", ""));
- try {
- CharSetUtils.count("hello", (String[]) null);
- fail("Expecting NullPointerException");
- } catch (NullPointerException ex) {}
- try {
- CharSetUtils.count("hello", new String[] { "", null });
- fail("Expecting NullPointerException");
- } catch (NullPointerException ex) {}
}
- public void testKeep() {
- assertEquals(null, CharSetUtils.keep(null, (String[]) null));
+ //-----------------------------------------------------------------------
+ public void testKeep_StringString() {
assertEquals(null, CharSetUtils.keep(null, (String) null));
- assertEquals(null, CharSetUtils.keep(null, new String[] { "el" }));
+ assertEquals(null, CharSetUtils.keep(null, ""));
+
+ assertEquals("", CharSetUtils.keep("", (String) null));
+ assertEquals("", CharSetUtils.keep("", ""));
+ assertEquals("", CharSetUtils.keep("", "a-e"));
+
+ assertEquals("", CharSetUtils.keep("hello", (String) null));
+ assertEquals("", CharSetUtils.keep("hello", ""));
+ assertEquals("", CharSetUtils.keep("hello", "xyz"));
+ assertEquals("hello", CharSetUtils.keep("hello", "a-z"));
+ assertEquals("hello", CharSetUtils.keep("hello", "oleh"));
+ assertEquals("ell", CharSetUtils.keep("hello", "el"));
+ }
+
+ public void testKeep_StringStringarray() {
+ assertEquals(null, CharSetUtils.keep(null, (String[]) null));
+ assertEquals(null, CharSetUtils.keep(null, new String[0]));
+ assertEquals(null, CharSetUtils.keep(null, new String[] {null}));
+ assertEquals(null, CharSetUtils.keep(null, new String[] {"a-e"}));
+
+ assertEquals("", CharSetUtils.keep("", (String[]) null));
+ assertEquals("", CharSetUtils.keep("", new String[0]));
+ assertEquals("", CharSetUtils.keep("", new String[] {null}));
+ assertEquals("", CharSetUtils.keep("", new String[] {"a-e"}));
+
+ assertEquals("", CharSetUtils.keep("hello", (String[]) null));
+ assertEquals("", CharSetUtils.keep("hello", new String[0]));
+ assertEquals("", CharSetUtils.keep("hello", new String[] {null}));
+ assertEquals("e", CharSetUtils.keep("hello", new String[] {"a-e"}));
+
+ assertEquals("e", CharSetUtils.keep("hello", new String[] { "a-e" }));
assertEquals("ell", CharSetUtils.keep("hello", new String[] { "el" }));
assertEquals("hello", CharSetUtils.keep("hello", new String[] { "elho" }));
- assertEquals("", CharSetUtils.keep("hello", new String[] { "" }));
- assertEquals("", CharSetUtils.keep("hello", ""));
assertEquals("hello", CharSetUtils.keep("hello", new String[] { "a-z" }));
assertEquals("----", CharSetUtils.keep("----", new String[] { "-" }));
assertEquals("ll", CharSetUtils.keep("hello", new String[] { "l" }));
- try {
- CharSetUtils.keep("hello", (String[]) null);
- fail("Expecting NullPointerException");
- } catch (NullPointerException ex) {}
- try {
- CharSetUtils.keep("hello", new String[] { "", null});
- fail("Expecting NullPointerException");
- } catch (NullPointerException ex) {}
}
- public void testDelete() {
+ //-----------------------------------------------------------------------
+ public void testDelete_StringString() {
+ assertEquals(null, CharSetUtils.delete(null, (String) null));
+ assertEquals(null, CharSetUtils.delete(null, ""));
+
+ assertEquals("", CharSetUtils.delete("", (String) null));
+ assertEquals("", CharSetUtils.delete("", ""));
+ assertEquals("", CharSetUtils.delete("", "a-e"));
+
+ assertEquals("hello", CharSetUtils.delete("hello", (String) null));
+ assertEquals("hello", CharSetUtils.delete("hello", ""));
+ assertEquals("hllo", CharSetUtils.delete("hello", "a-e"));
+ assertEquals("he", CharSetUtils.delete("hello", "l-p"));
+ assertEquals("hello", CharSetUtils.delete("hello", "z"));
+ }
+
+ public void testDelete_StringStringarray() {
assertEquals(null, CharSetUtils.delete(null, (String[]) null));
- assertEquals(null, CharSetUtils.delete(null,(String) null));
- assertEquals(null, CharSetUtils.delete(null, new String[] { "el" }));
+ assertEquals(null, CharSetUtils.delete(null, new String[0]));
+ assertEquals(null, CharSetUtils.delete(null, new String[] {null}));
+ assertEquals(null, CharSetUtils.delete(null, new String[] {"el"}));
+
+ assertEquals("", CharSetUtils.delete("", (String[]) null));
+ assertEquals("", CharSetUtils.delete("", new String[0]));
+ assertEquals("", CharSetUtils.delete("", new String[] {null}));
+ assertEquals("", CharSetUtils.delete("", new String[] {"a-e"}));
+
+ assertEquals("hello", CharSetUtils.delete("hello", (String[]) null));
+ assertEquals("hello", CharSetUtils.delete("hello", new String[0]));
+ assertEquals("hello", CharSetUtils.delete("hello", new String[] {null}));
+ assertEquals("hello", CharSetUtils.delete("hello", new String[] {"xyz"}));
+
assertEquals("ho", CharSetUtils.delete("hello", new String[] { "el" }));
assertEquals("", CharSetUtils.delete("hello", new String[] { "elho" }));
assertEquals("hello", CharSetUtils.delete("hello", new String[] { "" }));
@@ -177,16 +272,9 @@
assertEquals("", CharSetUtils.delete("hello", new String[] { "a-z" }));
assertEquals("", CharSetUtils.delete("----", new String[] { "-" }));
assertEquals("heo", CharSetUtils.delete("hello", new String[] { "l" }));
- try {
- CharSetUtils.delete("hello", (String[]) null);
- fail("Expecting NullPointerException");
- } catch (NullPointerException ex) {}
- try {
- CharSetUtils.delete("hello", new String[] { "-", null });
- fail("Expecting NullPointerException");
- } catch (NullPointerException ex) {}
}
+ //-----------------------------------------------------------------------
public void testTranslate() {
assertEquals(null, CharSetUtils.translate(null, null, null));
assertEquals("", CharSetUtils.translate("","a", "b"));
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org