Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Vosburgh2015-11-16 10:49:32 -0500
committerBrian Vosburgh2015-11-16 10:49:32 -0500
commitdaa12d59035dae319977f67f4e53f933494cf50c (patch)
tree7cfd20289d2f5abbf6677b2ec2cb64b88f3798a8
parent0e48cf1a006be38c71c9477de0c96168affd78e6 (diff)
downloadwebtools.dali-daa12d59035dae319977f67f4e53f933494cf50c.tar.gz
webtools.dali-daa12d59035dae319977f67f4e53f933494cf50c.tar.xz
webtools.dali-daa12d59035dae319977f67f4e53f933494cf50c.zip
sync and improve test coverage of StringTools, CharArrayTools,
StringBuilderTools, StringBufferTools, and WriterTools
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CharArrayTools.java194
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBufferTools.java27
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBuilderTools.java27
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java148
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/io/WriterTools.java27
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AbstractStringBuilderToolsTests.java614
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AbstractStringToolsTests.java1109
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CharArrayToolsTests.java826
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBufferToolsTests.java593
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBuilderToolsTests.java610
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringToolsTests.java874
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/WriterToolsTests.java719
12 files changed, 3687 insertions, 2081 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CharArrayTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CharArrayTools.java
index 61084ecdad..8d1e3f5bc2 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CharArrayTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CharArrayTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,7 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Locale;
+import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate;
import org.eclipse.jpt.common.utility.predicate.Predicate;
import org.eclipse.jpt.common.utility.transformer.Transformer;
@@ -38,21 +39,40 @@ public final class CharArrayTools {
/** empty char array array */
public static final char[][] EMPTY_CHAR_ARRAY_ARRAY = new char[0][0];
+ public static final Transformer<char[], String> STRING_TRANSFORMER = new StringTransformer();
+ /* CU private */ static class StringTransformer
+ implements Transformer<char[], String>, Serializable
+ {
+ public String transform(char[] string) {
+ return String.valueOf(string);
+ }
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName();
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return STRING_TRANSFORMER;
+ }
+ }
+
// ********** reverse **********
/**
- * Return a new string with the reverse the characters of the specified string.
+ * @see StringTools#reverse(String)
*/
public static char[] reverse(char[] string) {
- return (string.length == 0) ? string : ArrayTools.reverse(string.clone());
+ int len = string.length;
+ return (len <= 1) ? string : ArrayTools.reverse(string.clone(), len);
}
// ********** last **********
/**
- * Return the last character of the specified string.
+ * @see StringTools#last(String)
*/
public static char last(char[] string) {
return string[string.length - 1];
@@ -62,9 +82,16 @@ public final class CharArrayTools {
// ********** concatenation **********
/**
- * Return a concatenation of the specified strings.
+ * @see StringTools#concatenate(String...)
*/
public static char[] concatenate(char[]... strings) {
+ return (strings.length == 0) ? EMPTY_CHAR_ARRAY : ((strings.length == 1) ? strings[0] : concatenate_(strings));
+ }
+
+ /**
+ * Pre-condition: array length > 1
+ */
+ private static char[] concatenate_(char[]... strings) {
int stringLength = 0;
for (char[] string : strings) {
stringLength += string.length;
@@ -85,20 +112,94 @@ public final class CharArrayTools {
}
/**
- * Return a concatenation of the specified strings.
+ * @see StringTools#concatenate(Iterable)
*/
public static char[] concatenate(Iterable<char[]> strings) {
return concatenate(strings.iterator());
}
/**
- * Return a concatenation of the specified strings.
+ * @see StringTools#concatenate(Iterator)
*/
public static char[] concatenate(Iterator<char[]> strings) {
+ return strings.hasNext() ? concatenate_(strings) : EMPTY_CHAR_ARRAY;
+ }
+
+ /**
+ * Pre-condition: iterator is not empty
+ */
+ private static char[] concatenate_(Iterator<char[]> strings) {
+ StringBuilder sb = new StringBuilder();
+ while (strings.hasNext()) {
+ sb.append(strings.next());
+ }
+ return sb.toString().toCharArray();
+ }
+
+ /**
+ * @see StringTools#concatenate(String[], String)
+ */
+ public static char[] concatenate(char[][] strings, char[] separator) {
+ int stringsLength = strings.length;
+ if (stringsLength == 0) {
+ return EMPTY_CHAR_ARRAY;
+ }
+ if (stringsLength == 1) {
+ return strings[0];
+ }
+ int separatorLength = separator.length;
+ if (separatorLength == 0) {
+ return concatenate_(strings);
+ }
+ int stringLength = 0;
+ for (char[] string : strings) {
+ stringLength += string.length;
+ }
+ stringLength += ((stringsLength - 1) * separatorLength);
+ char[] buffer = new char[stringLength];
+ int i = 0;
+ for (char[] string : strings) {
+ int len = string.length;
+ if (len > 0) {
+ System.arraycopy(string, 0, buffer, i, len);
+ i += len;
+ }
+ if (i < stringLength) {
+ System.arraycopy(separator, 0, buffer, i, separatorLength);
+ i += separatorLength;
+ }
+ }
+ return buffer;
+ }
+
+ /**
+ * @see StringTools#concatenate(Iterable, String)
+ */
+ public static char[] concatenate(Iterable<char[]> strings, char[] separator) {
+ return concatenate(strings.iterator(), separator);
+ }
+
+ /**
+ * @see StringTools#concatenate(Iterator, String)
+ */
+ public static char[] concatenate(Iterator<char[]> strings, char[] separator) {
+ return strings.hasNext() ? concatenate_(strings, separator) : EMPTY_CHAR_ARRAY;
+ }
+
+ /**
+ * Pre-condition: iterator is not empty
+ */
+ private static char[] concatenate_(Iterator<char[]> strings, char[] separator) {
+ int separatorLength = separator.length;
+ if (separatorLength == 0) {
+ return concatenate_(strings);
+ }
StringBuilder sb = new StringBuilder();
while (strings.hasNext()) {
sb.append(strings.next());
+ sb.append(separator);
}
+ sb.setLength(sb.length() - separatorLength); // chop off trailing separator
return sb.toString().toCharArray();
}
@@ -390,7 +491,7 @@ public final class CharArrayTools {
}
@Override
public String toString() {
- return ObjectTools.toString(this, this.delimiter);
+ return ObjectTools.toString(this, convertToJavaStringLiteral(this.delimiter));
}
}
@@ -466,7 +567,7 @@ public final class CharArrayTools {
int stringLength = string.length;
int resultLength = stringLength - 2;
if (resultLength < 0) {
- throw new IllegalArgumentException("invalid string: \"" + new String(string) + '"'); //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid string: \"" + String.valueOf(string) + '"'); //$NON-NLS-1$
}
if (resultLength == 0) {
return EMPTY_CHAR_ARRAY;
@@ -486,7 +587,7 @@ public final class CharArrayTools {
}
int resultLength = string.length - (2 * count);
if (resultLength < 0) {
- throw new IllegalArgumentException("invalid string: \"" + new String(string) + '"'); //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid string: \"" + String.valueOf(string) + '"'); //$NON-NLS-1$
}
if (resultLength == 0) {
return EMPTY_CHAR_ARRAY;
@@ -610,14 +711,20 @@ public final class CharArrayTools {
* @see StringTools#commonPrefixLength(String, String)
*/
public static int commonPrefixLength(char[] s1, char[] s2) {
- return commonPrefixLength(s1, s2, Math.min(s1.length, s2.length));
+ return commonPrefixLength_(s1, s2, Math.min(s1.length, s2.length));
}
/**
- * Return the length of the common prefix shared by the specified strings;
- * but limit the length to the specified maximum.
+ * @see StringTools#commonPrefixLength(String, String, int)
*/
public static int commonPrefixLength(char[] s1, char[] s2, int max) {
+ return commonPrefixLength_(s1, s2, Math.min(max, Math.min(s1.length, s2.length)));
+ }
+
+ /**
+ * no max check
+ */
+ private static int commonPrefixLength_(char[] s1, char[] s2, int max) {
for (int i = 0; i < max; i++) {
if (s1[i] != s2[i]) {
return i;
@@ -696,8 +803,7 @@ public final class CharArrayTools {
// if both the first and second characters are capitalized,
// return the string unchanged
if ((stringLength > 1)
- && Character.isUpperCase(string[1])
- && Character.isUpperCase(string[0])){
+ && Character.isUpperCase(string[1])){
return true;
}
return false;
@@ -765,6 +871,28 @@ public final class CharArrayTools {
}
/**
+ * @see #isBlank(char[])
+ */
+ public static final Predicate<char[]> IS_BLANK = new IsBlank();
+
+ /* CU private */ static class IsBlank
+ implements Predicate<char[]>, Serializable
+ {
+ public boolean evaluate(char[] string) {
+ return isBlank(string);
+ }
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName();
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return IS_BLANK;
+ }
+ }
+
+ /**
* @see StringTools#isNotBlank(String)
*/
public static boolean isNotBlank(char[] string) {
@@ -833,17 +961,31 @@ public final class CharArrayTools {
}
/**
+ * @see #startsWithIgnoreCase(char[], char[])
+ */
+ public static class StartsWithIgnoreCase
+ extends CriterionPredicate<char[], char[]>
+ {
+ public StartsWithIgnoreCase(char[] prefix) {
+ super(prefix);
+ }
+ public boolean evaluate(char[] string) {
+ return startsWithIgnoreCase(string, this.criterion);
+ }
+ }
+
+ /**
* @see StringTools#isUppercase(String)
*/
public static boolean isUppercase(char[] string) {
- return (string.length != 0) && StringTools.isUppercase_(new String(string));
+ return (string.length != 0) && StringTools.isUppercase_(String.valueOf(string));
}
/**
* @see StringTools#isLowercase(String)
*/
public static boolean isLowercase(char[] string) {
- return (string.length != 0) && StringTools.isLowercase_(new String(string));
+ return (string.length != 0) && StringTools.isLowercase_(String.valueOf(string));
}
@@ -858,7 +1000,7 @@ public final class CharArrayTools {
return ByteArrayTools.EMPTY_BYTE_ARRAY;
}
if (BitTools.isOdd(hexStringLength)) {
- throw new IllegalArgumentException("Odd-sized hexadecimal string: " + new String(hexString) + " (" + hexStringLength + " characters)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ throw new IllegalArgumentException("Odd-sized hexadecimal string: " + String.valueOf(hexString) + " (" + hexStringLength + " characters)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return convertHexStringToByteArray(hexString, hexStringLength);
}
@@ -883,7 +1025,7 @@ public final class CharArrayTools {
}
private static String buildIllegalHexCharMessage(char[] hexString, int index) {
- return StringTools.buildIllegalHexCharMessage(new String(hexString), index);
+ return StringTools.buildIllegalHexCharMessage(String.valueOf(hexString), index);
}
@@ -1139,9 +1281,9 @@ public final class CharArrayTools {
/**
* @see #convertToDoubleQuotedXmlAttributeValueContent(char[])
*/
- public static final Transformer<char[], char[]> XML_DOUBLE_QUOTED_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER = new XmlDoubleQuotedAttributeValueContentTransformer();
+ public static final Transformer<char[], char[]> DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER = new DoubleQuotedXmlAttributeValueContentTransformer();
- /* CU private */ static class XmlDoubleQuotedAttributeValueContentTransformer
+ /* CU private */ static class DoubleQuotedXmlAttributeValueContentTransformer
implements Transformer<char[], char[]>, Serializable
{
public char[] transform(char[] string) {
@@ -1154,7 +1296,7 @@ public final class CharArrayTools {
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
- return XML_DOUBLE_QUOTED_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
+ return DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
}
}
@@ -1211,9 +1353,9 @@ public final class CharArrayTools {
/**
* @see #convertToSingleQuotedXmlAttributeValueContent(char[])
*/
- public static final Transformer<char[], char[]> XML_SINGLE_QUOTED_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER = new XmlSingleQuotedAttributeValueContentTransformer();
+ public static final Transformer<char[], char[]> SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER = new SingleQuotedXmlAttributeValueContentTransformer();
- /* CU private */ static class XmlSingleQuotedAttributeValueContentTransformer
+ /* CU private */ static class SingleQuotedXmlAttributeValueContentTransformer
implements Transformer<char[], char[]>, Serializable
{
public char[] transform(char[] string) {
@@ -1226,7 +1368,7 @@ public final class CharArrayTools {
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
- return XML_SINGLE_QUOTED_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
+ return SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
}
}
@@ -1612,7 +1754,7 @@ public final class CharArrayTools {
* @see String#lastIndexOf(int)
*/
public static int lastIndexOf(char[] string, int c) {
- return indexOf(string, c, string.length - 1);
+ return lastIndexOf(string, c, string.length - 1);
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBufferTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBufferTools.java
index 6388c9be2c..5c6cae30b4 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBufferTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBufferTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -36,6 +36,27 @@ public final class StringBufferTools {
}
+ // ********** reverse **********
+
+ /**
+ * Reverse the specified string.
+ */
+ public static void reverse(StringBuffer sb, String string) {
+ for (int i = string.length(); i-- > 0; ) {
+ sb.append(string.charAt(i));
+ }
+ }
+
+ /**
+ * Reverse the specified string.
+ */
+ public static void reverse(StringBuffer sb, char[] string) {
+ for (int i = string.length; i-- > 0; ) {
+ sb.append(string[i]);
+ }
+ }
+
+
// ********** padding/truncating/centering/repeating **********
/**
@@ -678,7 +699,7 @@ public final class StringBufferTools {
int stringLength = string.length;
int resultLength = stringLength - 2;
if (resultLength < 0) {
- throw new IllegalArgumentException("invalid string: \"" + new String(string) + '"'); //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid string: \"" + String.valueOf(string) + '"'); //$NON-NLS-1$
}
if (resultLength == 0) {
return;
@@ -743,7 +764,7 @@ public final class StringBufferTools {
}
int resultLength = string.length - (2 * count);
if (resultLength < 0) {
- throw new IllegalArgumentException("invalid string: \"" + new String(string) + '"'); //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid string: \"" + String.valueOf(string) + '"'); //$NON-NLS-1$
}
if (resultLength == 0) {
return;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBuilderTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBuilderTools.java
index 349aa8758b..e06ab071d0 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBuilderTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringBuilderTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -38,6 +38,27 @@ public final class StringBuilderTools {
}
+ // ********** reverse **********
+
+ /**
+ * Reverse the specified string.
+ */
+ public static void reverse(StringBuilder sb, String string) {
+ for (int i = string.length(); i-- > 0; ) {
+ sb.append(string.charAt(i));
+ }
+ }
+
+ /**
+ * Reverse the specified string.
+ */
+ public static void reverse(StringBuilder sb, char[] string) {
+ for (int i = string.length; i-- > 0; ) {
+ sb.append(string[i]);
+ }
+ }
+
+
// ********** padding/truncating/centering/repeating **********
/**
@@ -680,7 +701,7 @@ public final class StringBuilderTools {
int stringLength = string.length;
int resultLength = stringLength - 2;
if (resultLength < 0) {
- throw new IllegalArgumentException("invalid string: \"" + new String(string) + '"'); //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid string: \"" + String.valueOf(string) + '"'); //$NON-NLS-1$
}
if (resultLength == 0) {
return;
@@ -745,7 +766,7 @@ public final class StringBuilderTools {
}
int resultLength = string.length - (2 * count);
if (resultLength < 0) {
- throw new IllegalArgumentException("invalid string: \"" + new String(string) + '"'); //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid string: \"" + String.valueOf(string) + '"'); //$NON-NLS-1$
}
if (resultLength == 0) {
return;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
index acf3d6cd68..d9f8fd94ca 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,6 @@ package org.eclipse.jpt.common.utility.internal;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Iterator;
-import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
import org.eclipse.jpt.common.utility.internal.predicate.CriterionPredicate;
import org.eclipse.jpt.common.utility.predicate.Predicate;
import org.eclipse.jpt.common.utility.transformer.Transformer;
@@ -36,14 +35,33 @@ public final class StringTools {
/** empty string array */
public static final String[] EMPTY_STRING_ARRAY = new String[0];
+ public static final Transformer<String, char[]> CHAR_ARRAY_TRANSFORMER = new CharArrayTransformer();
+ /* CU private */ static class CharArrayTransformer
+ implements Transformer<String, char[]>, Serializable
+ {
+ public char[] transform(String string) {
+ return string.toCharArray();
+ }
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName();
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return CHAR_ARRAY_TRANSFORMER;
+ }
+ }
+
// ********** reverse **********
/**
- * Reverse the characters of the specified string.
+ * Return a string with the reversed characters of the specified string.
*/
public static String reverse(String string) {
- return (string.length() == 0) ? string : new String(ArrayTools.reverse(string.toCharArray()));
+ int len = string.length();
+ return (len <= 1) ? string : String.valueOf(ArrayTools.reverse(string.toCharArray(), len));
}
@@ -63,7 +81,30 @@ public final class StringTools {
* Return a concatenation of the specified strings.
*/
public static String concatenate(String... strings) {
- return (strings.length != 0) ? concatenate_(IteratorTools.iterator(strings)) : EMPTY_STRING;
+ return (strings.length == 0) ? EMPTY_STRING : ((strings.length == 1) ? strings[0] : concatenate_(strings));
+ }
+
+ /**
+ * Pre-condition: array length > 1
+ */
+ private static String concatenate_(String... strings) {
+ int stringLength = 0;
+ for (String string : strings) {
+ stringLength += string.length();
+ }
+ if (stringLength == 0) {
+ return EMPTY_STRING;
+ }
+ char[] buffer = new char[stringLength];
+ int i = 0;
+ for (String string : strings) {
+ int len = string.length();
+ if (len > 0) {
+ string.getChars(0, len, buffer, i);
+ i += len;
+ }
+ }
+ return String.valueOf(buffer);
}
/**
@@ -96,7 +137,36 @@ public final class StringTools {
* inserting the specified separator between them.
*/
public static String concatenate(String[] strings, String separator) {
- return (strings.length != 0) ? concatenate_(IteratorTools.iterator(strings), separator) : EMPTY_STRING;
+ int stringsLength = strings.length;
+ if (stringsLength == 0) {
+ return EMPTY_STRING;
+ }
+ if (stringsLength == 1) {
+ return strings[0];
+ }
+ int separatorLength = separator.length();
+ if (separatorLength == 0) {
+ return concatenate_(strings);
+ }
+ int stringLength = 0;
+ for (String string : strings) {
+ stringLength += string.length();
+ }
+ stringLength += ((stringsLength - 1) * separatorLength);
+ char[] buffer = new char[stringLength];
+ int i = 0;
+ for (String string : strings) {
+ int len = string.length();
+ if (len > 0) {
+ string.getChars(0, len, buffer, i);
+ i += len;
+ }
+ if (i < stringLength) {
+ separator.getChars(0, separatorLength, buffer, i);
+ i += separatorLength;
+ }
+ }
+ return String.valueOf(buffer);
}
/**
@@ -171,7 +241,7 @@ public final class StringTools {
Arrays.fill(result, 0, begin, c);
string.getChars(0, stringLength, result, begin);
Arrays.fill(result, begin + stringLength, length, c);
- return new String(result);
+ return String.valueOf(result);
}
/**
@@ -244,7 +314,7 @@ public final class StringTools {
char[] result = new char[length];
string.getChars(0, stringLength, result, 0);
Arrays.fill(result, stringLength, length, c);
- return new String(result);
+ return String.valueOf(result);
}
/**
@@ -320,7 +390,7 @@ public final class StringTools {
int padLength = length - stringLength;
string.getChars(0, stringLength, result, padLength);
Arrays.fill(result, 0, padLength, c);
- return new String(result);
+ return String.valueOf(result);
}
/**
@@ -384,7 +454,7 @@ public final class StringTools {
segCount++;
result[j++] = c;
}
- return new String(result);
+ return String.valueOf(result);
}
@@ -461,7 +531,7 @@ public final class StringTools {
delimiter.getChars(0, delimiterLength, result, 0);
string.getChars(0, stringLength, result, delimiterLength);
delimiter.getChars(0, delimiterLength, result, delimiterLength+stringLength);
- return new String(result);
+ return String.valueOf(result);
}
/**
@@ -482,7 +552,7 @@ public final class StringTools {
}
@Override
public String toString() {
- return ObjectTools.toString(this, this.delimiter);
+ return ObjectTools.toString(this, convertToJavaStringLiteral(this.delimiter));
}
}
@@ -620,7 +690,7 @@ public final class StringTools {
private static String undelimit(String string, int count, int resultLength) {
char[] result = new char[resultLength];
string.getChars(count, count+resultLength, result, 0);
- return new String(result);
+ return String.valueOf(result);
}
@@ -721,7 +791,7 @@ public final class StringTools {
*/
public static String compressWhitespace(String string) {
int first = indexOfWhitespace(string);
- return (first == -1) ? string : new String(compressWhitespace(string, first));
+ return (first == -1) ? string : compressWhitespace(string, first);
}
/**
@@ -784,7 +854,7 @@ public final class StringTools {
char[] result = new char[stringLength];
result[0] = Character.toUpperCase(string.charAt(0));
string.getChars(1, stringLength, result, 1);
- return new String(result);
+ return String.valueOf(result);
}
/**
@@ -835,8 +905,7 @@ public final class StringTools {
// if both the first and second characters are capitalized,
// return the string unchanged
if ((stringLength > 1)
- && Character.isUpperCase(string.charAt(1))
- && Character.isUpperCase(string.charAt(0))){
+ && Character.isUpperCase(string.charAt(1))){
return true;
}
return false;
@@ -849,7 +918,7 @@ public final class StringTools {
char[] result = new char[stringLength];
result[0] = Character.toLowerCase(string.charAt(0));
string.getChars(1, stringLength, result, 1);
- return new String(result);
+ return String.valueOf(result);
}
/**
@@ -905,6 +974,28 @@ public final class StringTools {
}
/**
+ * @see #isBlank(String)
+ */
+ public static final Predicate<String> IS_BLANK = new IsBlank();
+
+ /* CU private */ static class IsBlank
+ implements Predicate<String>, Serializable
+ {
+ public boolean evaluate(String string) {
+ return isBlank(string);
+ }
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName();
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return IS_BLANK;
+ }
+ }
+
+ /**
* Return whether the specified string is non-<code>null</code>, non-empty,
* and does not contain only whitespace characters.
*/
@@ -951,6 +1042,9 @@ public final class StringTools {
return string.regionMatches(true, 0, prefix, 0, prefix.length());
}
+ /**
+ * @see #startsWithIgnoreCase(String, String)
+ */
public static class StartsWithIgnoreCase
extends CriterionPredicate<String, String>
{
@@ -972,7 +1066,7 @@ public final class StringTools {
/**
* no length check
*/
- static boolean isUppercase_(String string) {
+ /* package */ static boolean isUppercase_(String string) {
return string.equals(string.toUpperCase());
}
@@ -986,7 +1080,7 @@ public final class StringTools {
/**
* no length check
*/
- static boolean isLowercase_(String string) {
+ /* package */ static boolean isLowercase_(String string) {
return string.equals(string.toLowerCase());
}
@@ -1027,7 +1121,7 @@ public final class StringTools {
return bytes;
}
- static String buildIllegalHexCharMessage(String hexString, int index) {
+ /* package */ static String buildIllegalHexCharMessage(String hexString, int index) {
StringBuilder sb = new StringBuilder(hexString.length() + 40);
sb.append("Illegal hexadecimal character: "); //$NON-NLS-1$
sb.append(hexString, 0, index);
@@ -1359,9 +1453,9 @@ public final class StringTools {
/**
* @see #convertToDoubleQuotedXmlAttributeValueContent(String)
*/
- public static final Transformer<String, String> XML_DOUBLE_QUOTED_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER = new XmlDoubleQuotedAttributeValueContentTransformer();
+ public static final Transformer<String, String> DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER = new DoubleQuotedXmlAttributeValueContentTransformer();
- /* CU private */ static class XmlDoubleQuotedAttributeValueContentTransformer
+ /* CU private */ static class DoubleQuotedXmlAttributeValueContentTransformer
implements Transformer<String, String>, Serializable
{
public String transform(String string) {
@@ -1374,7 +1468,7 @@ public final class StringTools {
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
- return XML_DOUBLE_QUOTED_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
+ return DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
}
}
@@ -1435,9 +1529,9 @@ public final class StringTools {
/**
* @see #convertToSingleQuotedXmlAttributeValueContent(String)
*/
- public static final Transformer<String, String> XML_SINGLE_QUOTED_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER = new XmlSingleQuotedAttributeValueContentTransformer();
+ public static final Transformer<String, String> SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER = new SingleQuotedXmlAttributeValueContentTransformer();
- /* CU private */ static class XmlSingleQuotedAttributeValueContentTransformer
+ /* CU private */ static class SingleQuotedXmlAttributeValueContentTransformer
implements Transformer<String, String>, Serializable
{
public String transform(String string) {
@@ -1450,7 +1544,7 @@ public final class StringTools {
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
- return XML_SINGLE_QUOTED_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
+ return SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/io/WriterTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/io/WriterTools.java
index 83d2297844..79fcc1d8f2 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/io/WriterTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/io/WriterTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,6 +23,27 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
*/
public final class WriterTools {
+ // ********** reverse **********
+
+ /**
+ * Reverse the specified string.
+ */
+ public static void reverse(Writer writer, String string) throws IOException {
+ for (int i = string.length(); i-- > 0; ) {
+ writer.write(string.charAt(i));
+ }
+ }
+
+ /**
+ * Reverse the specified string.
+ */
+ public static void reverse(Writer writer, char[] string) throws IOException {
+ for (int i = string.length; i-- > 0; ) {
+ writer.write(string[i]);
+ }
+ }
+
+
// ********** padding/truncating/centering/repeating **********
/**
@@ -659,7 +680,7 @@ public final class WriterTools {
int stringLength = string.length;
int resultLength = stringLength - 2;
if (resultLength < 0) {
- throw new IllegalArgumentException("invalid string: \"" + new String(string) + '"'); //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid string: \"" + String.valueOf(string) + '"'); //$NON-NLS-1$
}
if (resultLength == 0) {
return;
@@ -724,7 +745,7 @@ public final class WriterTools {
}
int resultLength = string.length - (2 * count);
if (resultLength < 0) {
- throw new IllegalArgumentException("invalid string: \"" + new String(string) + '"'); //$NON-NLS-1$
+ throw new IllegalArgumentException("invalid string: \"" + String.valueOf(string) + '"'); //$NON-NLS-1$
}
if (resultLength == 0) {
return;
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AbstractStringBuilderToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AbstractStringBuilderToolsTests.java
new file mode 100644
index 0000000000..c855747f56
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AbstractStringBuilderToolsTests.java
@@ -0,0 +1,614 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import java.lang.reflect.InvocationTargetException;
+import org.eclipse.jpt.common.utility.internal.ClassTools;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public abstract class AbstractStringBuilderToolsTests
+ extends TestCase
+{
+ public AbstractStringBuilderToolsTests(String name) {
+ super(name);
+ }
+
+ // ********** char[] **********
+
+ public void testConvertToCharArray() throws Exception {
+ this.verifyConvertToCharArray("fred");
+ this.verifyConvertToCharArray("f");
+ this.verifyConvertToCharArray("");
+ }
+
+ protected abstract void verifyConvertToCharArray(String string) throws Exception;
+
+
+ // ********** reverse **********
+
+ public void testReverse() throws Exception {
+ this.verifyReverse("derf", "fred");
+ this.verifyReverse("wilma", "amliw");
+ this.verifyReverse("f", "f");
+ this.verifyReverse("", "");
+ }
+
+ protected abstract void verifyReverse(String expected, String string) throws Exception;
+
+ // ********** padding/truncating/centering/repeating **********
+
+ public void testCenter() throws Exception {
+ this.verifyCenter("fred", "fred", 4);
+ this.verifyCenter(" fred ", "fred", 6);
+ this.verifyCenter(" fred ", "fred", 7);
+ this.verifyCenter("re", "fred", 2);
+ this.verifyCenter("fre", "fred", 3);
+ this.verifyCenter("", "fred", 0);
+ }
+
+ protected abstract void verifyCenter(String expected, String s, int len) throws Exception;
+
+ public void testPad() throws Exception {
+ this.verifyPad("fred", "fred", 4);
+ this.verifyPad("fred ", "fred", 6);
+
+ boolean exCaught = false;
+ try {
+ this.verifyPad("BOGUS", "fred", 2);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ protected abstract void verifyPad(String expected, String string, int length) throws Exception;
+
+ public void testFit() throws Exception {
+ this.verifyFit("fred", "fred", 4);
+ this.verifyFit("fred ", "fred", 6);
+ this.verifyFit("fr", "fred", 2);
+ this.verifyFit("", "fred", 0);
+ }
+
+ protected abstract void verifyFit(String expected, String string, int length) throws Exception;
+
+ public void testZeroPad() throws Exception {
+ this.verifyZeroPad("1234", "1234", 4);
+ this.verifyZeroPad("001234", "1234", 6);
+
+ boolean exCaught = false;
+ try {
+ this.verifyZeroPad("BOGUS", "1234", 2);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ protected abstract void verifyZeroPad(String expected, String string, int length) throws Exception;
+
+ public void testZeroFit() throws Exception {
+ this.verifyZeroFit("1234", "1234", 4);
+ this.verifyZeroFit("001234", "1234", 6);
+ this.verifyZeroFit("34", "1234", 2);
+ this.verifyZeroFit("", "1234", 0);
+ }
+
+ protected abstract void verifyZeroFit(String expected, String string, int length) throws Exception;
+
+ public void testRepeat() throws Exception {
+ this.verifyRepeat("", "1234", 0);
+ this.verifyRepeat("12", "1234", 2);
+ this.verifyRepeat("1234", "1234", 4);
+ this.verifyRepeat("123412", "1234", 6);
+ this.verifyRepeat("12341234", "1234", 8);
+ this.verifyRepeat("123412341234123412341", "1234", 21);
+ }
+
+ protected abstract void verifyRepeat(String expected, String string, int length) throws Exception;
+
+ public void testSeparate() throws Exception {
+ this.verifySeparate("012345", "012345", '-', 22);
+ this.verifySeparate("012345", "012345", '-', 6);
+ this.verifySeparate("01234-5", "012345", '-', 5);
+ this.verifySeparate("0123-45", "012345", '-', 4);
+ this.verifySeparate("012-345", "012345", '-', 3);
+ this.verifySeparate("01-23-45", "012345", '-', 2);
+ this.verifySeparate("0-1-2-3-4-5", "012345", '-', 1);
+
+ boolean exCaught = false;
+ try {
+ this.verifySeparate("012345", "012345", '-', 0);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ protected abstract void verifySeparate(String expected, String string, char separator, int segmentLength) throws Exception;
+
+ public void testDelimit() throws Exception {
+ this.verifyDelimit("123Employee123", "Employee", "123");
+ this.verifyDelimit("123123123", "123", "123");
+ this.verifyDelimit("123123", "", "123");
+ this.verifyDelimit("", "", "");
+ this.verifyDelimit("123", "123", "");
+ this.verifyDelimit("x123x", "123", "x");
+ }
+
+ protected abstract void verifyDelimit(String expected, String string, String delimiter) throws Exception;
+
+ public void testQuote() throws Exception {
+ this.verifyQuote("\"Employee\"", "Employee");
+ this.verifyQuote("\"123\"", "123");
+ this.verifyQuote("\"\"", "");
+ this.verifyQuote("\"Emp\"\"loyee\"", "Emp\"loyee");
+ }
+
+ protected abstract void verifyQuote(String expected, String string) throws Exception;
+
+ public void testRemoveFirstOccurrence() throws Exception {
+ this.verifyRemoveFirstOccurrence("Employee", "Emplo&yee", '&');
+ this.verifyRemoveFirstOccurrence("Employee&", "Emplo&yee&", '&');
+ this.verifyRemoveFirstOccurrence("Employee Foo", "Employee &Foo", '&');
+ this.verifyRemoveFirstOccurrence("Employee", "Employee&", '&');
+ this.verifyRemoveFirstOccurrence("Employee", "&Employee", '&');
+ this.verifyRemoveFirstOccurrence("Employee", "Employee", '&');
+ }
+
+ protected abstract void verifyRemoveFirstOccurrence(String expected, String string, char charToRemove) throws Exception;
+
+ public void testRemoveAllOccurrences() throws Exception {
+ this.verifyRemoveAllOccurrences("EmployeeFred", "Employee Fred", ' ');
+ this.verifyRemoveAllOccurrences("Employee", " Employee ", ' ');
+ this.verifyRemoveAllOccurrences("EmployeeFoo", "Employee Foo", ' ');
+ this.verifyRemoveAllOccurrences("EmployeeFoo", " Emp loyee Foo", ' ');
+ this.verifyRemoveAllOccurrences(" Emp loyee Foo", " Emp loyee Foo", '&');
+ }
+
+ protected abstract void verifyRemoveAllOccurrences(String expected, String string, char charToRemove) throws Exception;
+
+ public void testRemoveAllSpaces() throws Exception {
+ this.verifyRemoveAllSpaces("EmployeeFred", "Employee Fred");
+ this.verifyRemoveAllSpaces("Employee", " Employee ");
+ this.verifyRemoveAllSpaces("EmployeeFoo", "Employee Foo");
+ this.verifyRemoveAllSpaces("EmployeeFoo", " Emp loyee Foo");
+ this.verifyRemoveAllSpaces("Employee", "Employee");
+ }
+
+ protected abstract void verifyRemoveAllSpaces(String expected, String string) throws Exception;
+
+ public void testRemoveAllWhitespace() throws Exception {
+ this.verifyRemoveAllWhitespace("EmployeeFred", "Employee Fred\t");
+ this.verifyRemoveAllWhitespace("Employee", "\tEmployee\n");
+ this.verifyRemoveAllWhitespace("EmployeeFoo", "Employee \t Foo");
+ this.verifyRemoveAllWhitespace("EmployeeFoo", " Emp\tloyee \n Foo");
+ this.verifyRemoveAllWhitespace("EmployeeFoo", "EmployeeFoo");
+ }
+
+ protected abstract void verifyRemoveAllWhitespace(String expected, String string) throws Exception;
+
+ public void testCompressWhitespace() throws Exception {
+ this.verifyCompressWhitespace("Employee Fred ", "Employee Fred\t");
+ this.verifyCompressWhitespace(" Employee ", "\tEmployee \n");
+ this.verifyCompressWhitespace("Employee Foo", "Employee \t Foo");
+ this.verifyCompressWhitespace(" Emp loyee Foo ", " Emp\tloyee \n Foo ");
+ this.verifyCompressWhitespace("EmployeeFoo", "EmployeeFoo");
+ }
+
+ protected abstract void verifyCompressWhitespace(String expected, String string) throws Exception;
+
+ public void testCapitalize() throws Exception {
+ this.verifyCapitalize("Oracle", "Oracle");
+ this.verifyCapitalize("Oracle", "oracle");
+ this.verifyCapitalize(" ", " ");
+ this.verifyCapitalize("ORACLE", "ORACLE");
+ this.verifyCapitalize("", "");
+ this.verifyCapitalize("A", "a");
+ this.verifyCapitalize("\u00C9cole", "\u00E9cole"); // e'cole -> E'cole
+ }
+
+ protected abstract void verifyCapitalize(String expected, String string) throws Exception;
+
+ public void testUncapitalize() throws Exception {
+ this.verifyUncapitalize("oracle", "Oracle");
+ this.verifyUncapitalize("oracle", "oracle");
+ this.verifyUncapitalize(" ", " ");
+ this.verifyUncapitalize("ORACLE", "ORACLE");
+ this.verifyUncapitalize("", "");
+ this.verifyUncapitalize("a", "A");
+ this.verifyUncapitalize("\u00E9cole", "\u00C9cole"); // E'cole -> e'cole
+ }
+
+ protected abstract void verifyUncapitalize(String expected, String string) throws Exception;
+
+ public void testConvertToHexString() throws Exception {
+ this.verifyConvertToHexString("74657374", "test"); // UTF-8 values
+ this.verifyConvertToHexString("", "");
+ }
+
+ public void testConvertToHexString_negative() throws Exception {
+ this.verifyConvertToHexString(this.getHexCafe(), "caf\u00E9"); // UTF-8 values
+ }
+
+ private String getHexCafe() {
+ return AbstractStringToolsTests.getHexCafe();
+ }
+
+ protected abstract void verifyConvertToHexString(String expected, String string) throws Exception;
+
+ public void testConvertCamelCaseToAllCaps() throws Exception {
+ this.verifyConvertCamelCaseToAllCaps("TEST", "test");
+ this.verifyConvertCamelCaseToAllCaps("TEST", "TEST");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "testTest");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "TestTest");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "testTESTTest");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "TestTESTTest");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST_T", "TestTESTTestT");
+ this.verifyConvertCamelCaseToAllCaps("", "");
+ }
+
+ protected abstract void verifyConvertCamelCaseToAllCaps(String expected, String string) throws Exception;
+
+ public void testConvertCamelCaseToAllCapsMaxLength() throws Exception {
+ this.verifyConvertCamelCaseToAllCapsMaxLength("", "test", 0);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 55);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TEST", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TEST", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TEST", 55);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "testTest", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_", "testTest", 5);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TES", "testTest", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "testTest", 55);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TestTest", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TES", "TestTest", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "TestTest", 55);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "testTESTTest", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TES", "testTESTTest", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST", "testTESTTest", 55);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TestTESTTest", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TES", "TestTESTTest", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST", "TestTESTTest", 55);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TestTESTTestT", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TES", "TestTESTTestT", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST_T", "TestTESTTestT", 55);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("", "", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("", "", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("", "", 55);
+ }
+
+ protected abstract void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int maxLength) throws Exception;
+
+ // ********** convert all-caps to camel case **********
+
+ public void testConvertAllCapsToCamelCase() throws Exception {
+ this.verifyConvertAllCapsToCamelCase("", "");
+ this.verifyConvertAllCapsToCamelCase("", "", true);
+ this.verifyConvertAllCapsToCamelCase("", "", false);
+ this.verifyConvertAllCapsToCamelCase("test", "TEST", false);
+ this.verifyConvertAllCapsToCamelCase("test", "TEST_", false);
+ this.verifyConvertAllCapsToCamelCase("test", "TEST____", false);
+ this.verifyConvertAllCapsToCamelCase("Test", "TEST");
+ this.verifyConvertAllCapsToCamelCase("Test", "TEST", true);
+ this.verifyConvertAllCapsToCamelCase("test", "TeST", false);
+ this.verifyConvertAllCapsToCamelCase("testTest", "TEST_TEST", false);
+ this.verifyConvertAllCapsToCamelCase("testTest", "TEST___TEST", false);
+ this.verifyConvertAllCapsToCamelCase("TestTest", "TEST_TEST");
+ this.verifyConvertAllCapsToCamelCase("TestTest", "TEST_TEST", true);
+ this.verifyConvertAllCapsToCamelCase("testTestTest", "TEST_TEST_TEST", false);
+ this.verifyConvertAllCapsToCamelCase("TestTestTest", "TEST_TEST_TEST");
+ this.verifyConvertAllCapsToCamelCase("TestTestTest", "TEST_TEST_TEST", true);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "TEST_TEST_TEST_T", false);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "_TEST_TEST_TEST_T", false);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "__TEST_TEST_TEST_T", false);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "TEST_TEST_TEST_T");
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "TEST_TEST_TEST_T", true);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "_TEST_TEST_TEST_T");
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "_TEST_TEST_TEST_T", true);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "__TEST_TEST_TEST_T");
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "__TEST_TEST_TEST_T", true);
+ }
+
+ protected abstract void verifyConvertAllCapsToCamelCase(String expected, String string) throws Exception;
+
+ protected abstract void verifyConvertAllCapsToCamelCase(String expected, String string, boolean capFirst) throws Exception;
+
+ public void testConvertAllCapsToCamelCaseLowercase() throws Exception {
+ this.verifyConvertAllCapsToCamelCase("test", "test", false);
+ this.verifyConvertAllCapsToCamelCase("test", "test_", false);
+ this.verifyConvertAllCapsToCamelCase("test", "test____", false);
+ this.verifyConvertAllCapsToCamelCase("Test", "test", true);
+ this.verifyConvertAllCapsToCamelCase("test", "test", false);
+ this.verifyConvertAllCapsToCamelCase("testTest", "test_test", false);
+ this.verifyConvertAllCapsToCamelCase("testTest", "test___test", false);
+ this.verifyConvertAllCapsToCamelCase("TestTest", "test_test", true);
+ this.verifyConvertAllCapsToCamelCase("testTestTest", "test_test_test", false);
+ this.verifyConvertAllCapsToCamelCase("TestTestTest", "test_test_test", true);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "test_test_test_t", false);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "_test_test_test_t", false);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "__test_test_test_t", false);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "test_test_test_t", true);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "_test_test_test_t", true);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "__test_test_test_t", true);
+ }
+
+ public void testUndelimit() throws Exception {
+ this.verifyUndelimit("foo", "\"foo\"");
+ this.verifyUndelimit("", "\"\"");
+ this.verifyUndelimit("foo", "'foo'");
+ this.verifyUndelimit("fo\"o", "\"fo\"\"o\"");
+ this.verifyUndelimit("foo\"", "\"foo\"\"\"");
+ this.verifyUndelimit("\"foo", "\"\"\"foo\"");
+ this.verifyUndelimit("foo", "[foo]");
+ this.verifyUndelimit("\"", "\"\"\"");
+ this.verifyUndelimit("foo\"", "\"foo\"bar\"");
+ this.verifyUndelimit("foo\"", "\"foo\"\"");
+
+ boolean exCaught = false;
+ try {
+ this.verifyUndelimit("BOGUS", "x");
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ protected abstract void verifyUndelimit(String expected, String s) throws Exception;
+
+ public void testUndelimitCount() throws Exception {
+ this.verifyUndelimitCount("o", "\"foo\"", 2);
+ this.verifyUndelimitCount("", "\"\"\"\"", 2);
+ this.verifyUndelimitCount("foo", "XXfooXX", 2);
+ this.verifyUndelimitCount("\"foo\"", "\"foo\"", 0);
+
+ boolean exCaught = false;
+ try {
+ this.verifyUndelimitCount("BOGUS", "XXXX", 5);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ protected abstract void verifyUndelimitCount(String expected, String s, int count) throws Exception;
+
+ public void testConvertToJavaStringLiteral() throws Exception {
+ this.verifyConvertToJavaStringLiteral("\"\"", "");
+ this.verifyConvertToJavaStringLiteral("\"\\\"\\\"\"", "\"\"");
+ this.verifyConvertToJavaStringLiteral("\"'foo'\"", "'foo'");
+ this.verifyConvertToJavaStringLiteral("\"foo\\bbar\"", "foo\bbar");
+ this.verifyConvertToJavaStringLiteral("\"foo\\n\\tbar\"", "foo\n\tbar");
+ this.verifyConvertToJavaStringLiteral("\"foo\\\"bar\"", "foo\"bar");
+ this.verifyConvertToJavaStringLiteral("\"foo\\\\bar\"", "foo\\bar");
+ this.verifyConvertToJavaStringLiteral("\"\\ffoo\\f\"", "\ffoo\f");
+ this.verifyConvertToJavaStringLiteral("\"\\rfoo\\r\"", "\rfoo\r");
+ }
+
+ protected abstract void verifyConvertToJavaStringLiteral(String expected, String s) throws Exception;
+
+ public void testConvertToJavaStringLiteralContent() throws Exception {
+ this.verifyConvertToJavaStringLiteralContent("", "");
+ this.verifyConvertToJavaStringLiteralContent("\\\"\\\"", "\"\"");
+ this.verifyConvertToJavaStringLiteralContent("'foo'", "'foo'");
+ this.verifyConvertToJavaStringLiteralContent("foo\\bbar", "foo\bbar");
+ this.verifyConvertToJavaStringLiteralContent("foo\\n\\tbar", "foo\n\tbar");
+ this.verifyConvertToJavaStringLiteralContent("foo\\\"bar", "foo\"bar");
+ this.verifyConvertToJavaStringLiteralContent("foo\\\\bar", "foo\\bar");
+ }
+
+ protected abstract void verifyConvertToJavaStringLiteralContent(String expected, String s) throws Exception;
+
+ // ********** converting to XML **********
+
+ public void testConvertToXmlAttributeValue() throws Exception {
+ this.verifyConvertToXmlAttributeValue("\"\"", "");
+ this.verifyConvertToXmlAttributeValue("'\"'", "\"");
+ this.verifyConvertToXmlAttributeValue("'\"\"'", "\"\"");
+ this.verifyConvertToXmlAttributeValue("\"'\"", "'");
+ this.verifyConvertToXmlAttributeValue("\"''\"", "''");
+ this.verifyConvertToXmlAttributeValue("\"&quot;'&quot;\"", "\"'\"");
+ this.verifyConvertToXmlAttributeValue("\"&quot;''&quot;\"", "\"''\"");
+ this.verifyConvertToXmlAttributeValue("\"'foo'\"", "'foo'");
+ this.verifyConvertToXmlAttributeValue("'\"foo\"'", "\"foo\"");
+ this.verifyConvertToXmlAttributeValue("\"&quot;foo&quot; 'bar'\"", "\"foo\" 'bar'");
+ this.verifyConvertToXmlAttributeValue("\"foo &amp; bar\"", "foo & bar");
+ this.verifyConvertToXmlAttributeValue("'\"foo &amp; bar\"'", "\"foo & bar\"");
+ this.verifyConvertToXmlAttributeValue("\"foo &lt;&lt;&lt; bar\"", "foo <<< bar");
+ this.verifyConvertToXmlAttributeValue("'\"foo &lt;&lt;&lt; bar\"'", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToXmlAttributeValue(String expected, String string) throws Exception;
+
+ public void testConvertToDoubleQuotedXmlAttributeValue() throws Exception {
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"\"", "");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;\"", "\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;&quot;\"", "\"\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"'\"", "'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"''\"", "''");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;'&quot;\"", "\"'\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;''&quot;\"", "\"''\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"'foo'\"", "'foo'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;foo&quot;\"", "\"foo\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;foo&quot; 'bar'\"", "\"foo\" 'bar'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"foo &amp; bar\"", "foo & bar");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;foo &amp; bar&quot;\"", "\"foo & bar\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"foo &lt;&lt;&lt; bar\"", "foo <<< bar");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;foo &lt;&lt;&lt; bar&quot;\"", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToDoubleQuotedXmlAttributeValue(String expected, String string) throws Exception;
+
+ public void testConvertToDoubleQuotedXmlAttributeValueContent() throws Exception {
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("", "");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;", "\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;&quot;", "\"\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("'", "'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("''", "''");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;'&quot;", "\"'\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;''&quot;", "\"''\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("'foo'", "'foo'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;foo&quot;", "\"foo\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;foo&quot; 'bar'", "\"foo\" 'bar'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("foo &amp; bar", "foo & bar");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;foo &amp; bar&quot;", "\"foo & bar\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("foo &lt;&lt;&lt; bar", "foo <<< bar");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;foo &lt;&lt;&lt; bar&quot;", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToDoubleQuotedXmlAttributeValueContent(String expected, String string) throws Exception;
+
+ public void testConvertToSingleQuotedXmlAttributeValue() throws Exception {
+ this.verifyConvertToSingleQuotedXmlAttributeValue("''", "");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"'", "\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"\"'", "\"\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'&apos;'", "'");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'&apos;&apos;'", "''");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"&apos;\"'", "\"'\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"&apos;&apos;\"'", "\"''\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'&apos;foo&apos;'", "'foo'");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"foo\"'", "\"foo\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"foo\" &apos;bar&apos;'", "\"foo\" 'bar'");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'foo &amp; bar'", "foo & bar");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"foo &amp; bar\"'", "\"foo & bar\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'foo &lt;&lt;&lt; bar'", "foo <<< bar");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"foo &lt;&lt;&lt; bar\"'", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToSingleQuotedXmlAttributeValue(String expected, String string) throws Exception;
+
+ public void testConvertToSingleQuotedXmlAttributeValueContent() throws Exception {
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("", "");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"", "\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"\"", "\"\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("&apos;", "'");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("&apos;&apos;", "''");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"&apos;\"", "\"'\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"&apos;&apos;\"", "\"''\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("&apos;foo&apos;", "'foo'");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"foo\"", "\"foo\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"foo\" &apos;bar&apos;", "\"foo\" 'bar'");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("foo &amp; bar", "foo & bar");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"foo &amp; bar\"", "\"foo & bar\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("foo &lt;&lt;&lt; bar", "foo <<< bar");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"foo &lt;&lt;&lt; bar\"", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToSingleQuotedXmlAttributeValueContent(String expected, String string) throws Exception;
+
+ public void testConvertToXmlElementText() throws Exception {
+ this.verifyConvertToXmlElementText("", "");
+ this.verifyConvertToXmlElementText("\"", "\"");
+ this.verifyConvertToXmlElementText("\"\"", "\"\"");
+ this.verifyConvertToXmlElementText("'", "'");
+ this.verifyConvertToXmlElementText("''", "''");
+ this.verifyConvertToXmlElementText("\"'\"", "\"'\"");
+ this.verifyConvertToXmlElementText("\"''\"", "\"''\"");
+ this.verifyConvertToXmlElementText("'foo'", "'foo'");
+ this.verifyConvertToXmlElementText("foo &amp; bar", "foo & bar");
+ this.verifyConvertToXmlElementText("foo &amp;", "foo &");
+ this.verifyConvertToXmlElementText("&amp; bar", "& bar");
+ this.verifyConvertToXmlElementText("\"foo &amp; bar\"", "\"foo & bar\"");
+ this.verifyConvertToXmlElementText("foo &lt;&lt;&lt; bar", "foo <<< bar");
+ this.verifyConvertToXmlElementText("\"foo &lt;&lt;&lt; bar\"", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToXmlElementText(String expected, String string) throws Exception;
+
+ public void testConvertToXmlElementCDATA() throws Exception {
+ String START = "<![CDATA[";
+ String END = "]]>";
+ this.verifyConvertToXmlElementCDATA(START + END, "");
+ this.verifyConvertToXmlElementCDATA(START + "\"" + END, "\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"\"" + END, "\"\"");
+ this.verifyConvertToXmlElementCDATA(START + "'" + END, "'");
+ this.verifyConvertToXmlElementCDATA(START + "''" + END, "''");
+ this.verifyConvertToXmlElementCDATA(START + "\"'\"" + END, "\"'\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"''\"" + END, "\"''\"");
+ this.verifyConvertToXmlElementCDATA(START + "'foo'" + END, "'foo'");
+ this.verifyConvertToXmlElementCDATA(START + "foo & bar" + END, "foo & bar");
+ this.verifyConvertToXmlElementCDATA(START + "foo &" + END, "foo &");
+ this.verifyConvertToXmlElementCDATA(START + "& bar" + END, "& bar");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo & bar\"" + END, "\"foo & bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "foo <<< bar" + END, "foo <<< bar");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <<< bar\"" + END, "\"foo <<< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <&< bar\"" + END, "\"foo <&< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <]< bar\"" + END, "\"foo <]< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <]]< bar\"" + END, "\"foo <]]< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <]]&gt;< bar\"" + END, "\"foo <]]>< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "foo <]" + END, "foo <]");
+ this.verifyConvertToXmlElementCDATA(START + "foo <]]" + END, "foo <]]");
+ this.verifyConvertToXmlElementCDATA(START + "foo <]]&gt;" + END, "foo <]]>");
+ this.verifyConvertToXmlElementCDATA(START + "]foo" + END, "]foo");
+ this.verifyConvertToXmlElementCDATA(START + "]]foo" + END, "]]foo");
+ this.verifyConvertToXmlElementCDATA(START + "]]&gt;foo" + END, "]]>foo");
+ }
+
+ protected abstract void verifyConvertToXmlElementCDATA(String expected, String string) throws Exception;
+
+ public void testConvertToXmlElementCDATAContent() throws Exception {
+ this.verifyConvertToXmlElementCDATAContent("", "");
+ this.verifyConvertToXmlElementCDATAContent("\"", "\"");
+ this.verifyConvertToXmlElementCDATAContent("\"\"", "\"\"");
+ this.verifyConvertToXmlElementCDATAContent("'", "'");
+ this.verifyConvertToXmlElementCDATAContent("''", "''");
+ this.verifyConvertToXmlElementCDATAContent("\"'\"", "\"'\"");
+ this.verifyConvertToXmlElementCDATAContent("\"''\"", "\"''\"");
+ this.verifyConvertToXmlElementCDATAContent("'foo'", "'foo'");
+ this.verifyConvertToXmlElementCDATAContent("foo & bar", "foo & bar");
+ this.verifyConvertToXmlElementCDATAContent("foo &", "foo &");
+ this.verifyConvertToXmlElementCDATAContent("& bar", "& bar");
+ this.verifyConvertToXmlElementCDATAContent("\"foo & bar\"", "\"foo & bar\"");
+ this.verifyConvertToXmlElementCDATAContent("foo <<< bar", "foo <<< bar");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <<< bar\"", "\"foo <<< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <&< bar\"", "\"foo <&< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <]< bar\"", "\"foo <]< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <]]< bar\"", "\"foo <]]< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <]]&gt;< bar\"", "\"foo <]]>< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("foo <]", "foo <]");
+ this.verifyConvertToXmlElementCDATAContent("foo <]]", "foo <]]");
+ this.verifyConvertToXmlElementCDATAContent("foo <]]&gt;", "foo <]]>");
+ this.verifyConvertToXmlElementCDATAContent("]foo", "]foo");
+ this.verifyConvertToXmlElementCDATAContent("]]foo", "]]foo");
+ this.verifyConvertToXmlElementCDATAContent("]]&gt;foo", "]]>foo");
+ }
+
+ protected abstract void verifyConvertToXmlElementCDATAContent(String expected, String string) throws Exception;
+
+ // ********** constructor **********
+
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object at = ClassTools.newInstance(this.getToolsClass());
+ fail("bogus: " + at); //$NON-NLS-1$
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+
+ protected String getSimpleToolsClassName() {
+ return this.getToolsClass().getSimpleName();
+ }
+
+ protected abstract Class<?> getToolsClass();
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AbstractStringToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AbstractStringToolsTests.java
new file mode 100644
index 0000000000..c37bff170f
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AbstractStringToolsTests.java
@@ -0,0 +1,1109 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import org.eclipse.jpt.common.utility.internal.ByteArrayTools;
+import org.eclipse.jpt.common.utility.internal.ClassTools;
+import org.eclipse.jpt.common.utility.internal.SystemTools;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public abstract class AbstractStringToolsTests
+ extends TestCase
+{
+ protected AbstractStringToolsTests(String name) {
+ super(name);
+ }
+
+ protected abstract String CR();
+
+ // ********** reverse **********
+
+ public void testReverse() {
+ this.verifyReverse("derf", "fred");
+ this.verifyReverse("wilma", "amliw");
+ this.verifyReverse("f", "f");
+ this.verifyReverse("", "");
+ }
+
+ protected abstract void verifyReverse(String expected, String string);
+
+ // ********** last **********
+
+ public void testLast() {
+ this.verifyLast('d', "fred");
+ this.verifyLast('a', "wilma");
+ this.verifyLast('f', "f");
+
+ boolean exCaught = false;
+ try {
+ this.verifyLast('X', "");
+ fail();
+ } catch (IndexOutOfBoundsException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ protected abstract void verifyLast(char expected, String string);
+
+ // ********** concatenate **********
+
+ public void testConcatenate_empty() throws Exception {
+ String[] array = new String[0];
+ this.verifyConcatenate("", array);
+ this.verifyConcatenate("", array, "");
+ this.verifyConcatenate("", array, ";");
+ }
+
+ public void testConcatenate_one() throws Exception {
+ String[] array = new String[] {"foo"};
+ this.verifyConcatenate("foo", array);
+ this.verifyConcatenate("foo", array, "");
+ this.verifyConcatenate("foo", array, ";");
+ }
+
+ public void testConcatenate_three() throws Exception {
+ String[] array = new String[] {"foo", "bar", "baz"};
+ this.verifyConcatenate("foobarbaz", array);
+ this.verifyConcatenate("foobarbaz", array, "");
+ this.verifyConcatenate("foo;bar;baz", array, ";");
+ }
+
+ public void testConcatenate_threeEmpty() throws Exception {
+ String[] array = new String[] {"", "", ""};
+ this.verifyConcatenate("", array);
+ this.verifyConcatenate("", array, "");
+ this.verifyConcatenate(";;", array, ";");
+ }
+
+ public void testConcatenate_oneEmpty() throws Exception {
+ String[] array = new String[] {"foo", "", "baz"};
+ this.verifyConcatenate("foobaz", array);
+ this.verifyConcatenate("foobaz", array, "");
+ this.verifyConcatenate("foo;;baz", array, ";");
+ }
+
+ protected abstract void verifyConcatenate(String expected, String[] array);
+
+ protected abstract void verifyConcatenate(String expected, String[] array, String delim);
+
+ // ********** padding/truncating/centering/repeating **********
+
+ public void testCenter() {
+ this.verifyCenter("", "fred", 0);
+ this.verifyCenter("fred", "fred", 4);
+ this.verifyCenter(" fred ", "fred", 6);
+ this.verifyCenter(" fred ", "fred", 7);
+ this.verifyCenter("re", "fred", 2);
+ this.verifyCenter("fre", "fred", 3);
+ }
+
+ protected abstract void verifyCenter(String expected, String string, int len);
+
+ public void testPad() {
+ this.verifyPad("fred", "fred", 4);
+ this.verifyPad("fred ", "fred", 6);
+
+ boolean exThrown = false;
+ try {
+ this.verifyPad("BOGUS", "fred", 2);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exThrown = true;
+ }
+ assertTrue(exThrown);
+ }
+
+ protected abstract void verifyPad(String expected, String string, int len);
+
+ public void testFit() {
+ this.verifyFit("", "fred", 0);
+ this.verifyFit("fred", "fred", 4);
+ this.verifyFit("fred ", "fred", 6);
+ this.verifyFit("fr", "fred", 2);
+ }
+
+ protected abstract void verifyFit(String expected, String string, int len);
+
+ public void testZeroPad() {
+ this.verifyZeroPad("1234", "1234", 4);
+ this.verifyZeroPad("001234", "1234", 6);
+
+ boolean exThrown = false;
+ try {
+ this.verifyZeroPad("BOGUS", "1234", 2);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exThrown = true;
+ }
+ assertTrue(exThrown);
+ }
+
+ protected abstract void verifyZeroPad(String expected, String string, int len);
+
+ public void testZeroFit() {
+ this.verifyZeroFit("", "1234", 0);
+ this.verifyZeroFit("1234", "1234", 4);
+ this.verifyZeroFit("001234", "1234", 6);
+ this.verifyZeroFit("34", "1234", 2);
+ }
+
+ protected abstract void verifyZeroFit(String expected, String string, int len);
+
+ public void testRepeat() {
+ this.verifyRepeat("", "1234", 0);
+ this.verifyRepeat("12", "1234", 2);
+ this.verifyRepeat("1234", "1234", 4);
+ this.verifyRepeat("123412", "1234", 6);
+ this.verifyRepeat("12341234", "1234", 8);
+ this.verifyRepeat("123412341234123412341", "1234", 21);
+ }
+
+ protected abstract void verifyRepeat(String expected, String string, int length);
+
+ // ********** separating **********
+
+ public void testSeparateCharInt() {
+ this.verifySeparate("012345", "012345", '-', 22);
+ this.verifySeparate("012345", "012345", '-', 6);
+ this.verifySeparate("01234-5", "012345", '-', 5);
+ this.verifySeparate("0123-45", "012345", '-', 4);
+ this.verifySeparate("012-345", "012345", '-', 3);
+ this.verifySeparate("01-23-45", "012345", '-', 2);
+ this.verifySeparate("0-1-2-3-4-5", "012345", '-', 1);
+ }
+
+ public void testSeparateCharInt_ex() {
+ this.verifySeparateCharInt_ex("012345", '-', 0);
+ this.verifySeparateCharInt_ex("012345", '-', -3);
+ }
+
+ private void verifySeparateCharInt_ex(String string, char separator, int segmentLength) {
+ boolean exThrown = false;
+ try {
+ this.verifySeparate("BOGUS", string, separator, segmentLength);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exThrown = true;
+ }
+ assertTrue(exThrown);
+ }
+
+ protected abstract void verifySeparate(String expected, String string, char separator, int segmentLength);
+
+ // ********** delimiting **********
+
+ public void testQuote() {
+ this.verifyQuote("\"Employee\"", "Employee");
+ this.verifyQuote("\"123\"", "123");
+ this.verifyQuote("\"\"", "");
+ this.verifyQuote("\"Emp\"\"loyee\"", "Emp\"loyee");
+ }
+
+ protected abstract void verifyQuote(String expected, String string);
+
+ public void testCharDelimiter() {
+ this.verifyCharDelimiter("\"Employee\"", "Employee", '"');
+ this.verifyCharDelimiter("_123_", "123", '_');
+ this.verifyCharDelimiter("XX", "", 'X');
+ this.verifyCharDelimiter("\"Emp\"\"loyee\"", "Emp\"loyee", '"');
+ }
+
+ protected abstract void verifyCharDelimiter(String expected, String string, char delimiter);
+
+ public void testCharDelimiter_toString() {
+ Object delimiter = this.buildCharDelimiter('"');
+ assertTrue(delimiter.toString(), delimiter.toString().startsWith(this.getSimpleToolsClassName() + ".CharDelimiter"));
+ assertTrue(delimiter.toString(), delimiter.toString().endsWith("(\")"));
+ }
+
+ protected abstract Object buildCharDelimiter(char c);
+
+ public void testDelimit() {
+ this.verifyDelimit("123Employee123", "Employee", "123");
+ this.verifyDelimit("123123123", "123", "123");
+ this.verifyDelimit("123123", "", "123");
+
+ this.verifyDelimit("Employee", "Employee", "");
+ this.verifyDelimit("123", "123", "");
+ this.verifyDelimit("", "", "");
+
+ this.verifyDelimit("XEmployeeX", "Employee", "X");
+ this.verifyDelimit("X123X", "123", "X");
+ this.verifyDelimit("XX", "", "X");
+ }
+
+ protected abstract void verifyDelimit(String expected, String string, String delimiter);
+
+ public void testStringDelimiter() {
+ this.verifyStringDelimiter("123Employee123", "Employee", "123");
+ this.verifyStringDelimiter("123123123", "123", "123");
+ this.verifyStringDelimiter("123123", "", "123");
+ }
+
+ protected abstract void verifyStringDelimiter(String expected, String string, String delimiter);
+
+ public void testStringDelimiter_toString() {
+ Object delimiter = this.buildStringDelimiter("123");
+ String simpleClassName = this.getSimpleToolsClassName();
+ String prefix = simpleClassName.substring(0, simpleClassName.length() - "Tools".length());
+ assertTrue(delimiter.toString(), delimiter.toString().startsWith(simpleClassName + "." + prefix + "Delimiter"));
+ assertTrue(delimiter.toString(), delimiter.toString().endsWith("(\"123\")"));
+ }
+
+ protected abstract Object buildStringDelimiter(String string);
+
+ // ********** removing characters **********
+
+ public void testRemoveFirstOccurrence() {
+ this.verifyRemoveFirstOccurrence("Employee", "Employee", '&');
+ this.verifyRemoveFirstOccurrence("Employee", "Emplo&yee", '&');
+ this.verifyRemoveFirstOccurrence("Employee&", "Emplo&yee&", '&');
+ this.verifyRemoveFirstOccurrence("Employee Foo", "Employee &Foo", '&');
+ this.verifyRemoveFirstOccurrence("Employee", "Employee&", '&');
+ this.verifyRemoveFirstOccurrence("Employee", "&Employee", '&');
+ }
+
+ protected abstract void verifyRemoveFirstOccurrence(String expected, String string, char charToRemove);
+
+ public void testRemoveAllOccurrences() {
+ this.verifyRemoveAllOccurrences("Employee", "Employee", ' ');
+ this.verifyRemoveAllOccurrences("EmployeeFred", "Employee Fred", ' ');
+ this.verifyRemoveAllOccurrences("Employee", " Employee ", ' ');
+ this.verifyRemoveAllOccurrences("EmployeeFoo", "Employee Foo", ' ');
+ this.verifyRemoveAllOccurrences("EmployeeFoo", " Emp loyee Foo", ' ');
+ }
+
+ protected abstract void verifyRemoveAllOccurrences(String expected, String string, char charToRemove);
+
+ public void testRemoveAllSpaces() {
+ this.verifyRemoveAllSpaces("Employee", "Employee");
+ this.verifyRemoveAllSpaces("EmployeeFred", "Employee Fred");
+ this.verifyRemoveAllSpaces("Employee", " Employee ");
+ this.verifyRemoveAllSpaces("EmployeeFoo", "Employee Foo");
+ this.verifyRemoveAllSpaces("EmployeeFoo", " Emp loyee Foo");
+ }
+
+ protected abstract void verifyRemoveAllSpaces(String expected, String string);
+
+ public void testRemoveAllWhitespace() {
+ this.verifyRemoveAllWhitespace("EmployeeFred", "EmployeeFred");
+ this.verifyRemoveAllWhitespace("EmployeeFred", "Employee Fred\t");
+ this.verifyRemoveAllWhitespace("Employee", "\tEmployee\n");
+ this.verifyRemoveAllWhitespace("EmployeeFoo", "Employee \t Foo");
+ this.verifyRemoveAllWhitespace("EmployeeFoo", " Emp\tloyee \n Foo");
+ }
+
+ protected abstract void verifyRemoveAllWhitespace(String expected, String string);
+
+ public void testCompressWhitespace() {
+ this.verifyCompressWhitespace("EmployeeFred", "EmployeeFred");
+ this.verifyCompressWhitespace("Employee Fred ", "Employee Fred\t");
+ this.verifyCompressWhitespace(" Employee ", "\tEmployee \n");
+ this.verifyCompressWhitespace("Employee Foo", "Employee \t Foo");
+ this.verifyCompressWhitespace(" Emp loyee Foo ", " Emp\tloyee \n Foo ");
+ }
+
+ protected abstract void verifyCompressWhitespace(String expected, String string);
+
+ // ********** common prefix **********
+
+ public void testCommonPrefixLength() {
+ this.verifyCommonPrefixLength(3, "fooZZZ", "fooBBB");
+ this.verifyCommonPrefixLength(3, "foo", "fooBBB");
+ this.verifyCommonPrefixLength(3, "fooZZZ", "foo");
+ this.verifyCommonPrefixLength(3, "foo", "foo");
+ }
+
+ protected abstract void verifyCommonPrefixLength(int expected, String string1, String string2);
+
+ public void testCommonPrefixLengthMax() {
+ this.verifyCommonPrefixLengthMax(2, "fooZZZ", "fooBBB", 2);
+ this.verifyCommonPrefixLengthMax(2, "foo", "fooBBB", 2);
+ this.verifyCommonPrefixLengthMax(2, "fooZZZ", "foo", 2);
+ this.verifyCommonPrefixLengthMax(2, "foo", "foo", 2);
+ }
+
+ protected abstract void verifyCommonPrefixLengthMax(int expected, String string1, String string2, int max);
+
+ // ********** capitalization **********
+
+ public void testCapitalize() {
+ this.verifyCapitalize("Oracle", "Oracle");
+ this.verifyCapitalize("Oracle", "oracle");
+ this.verifyCapitalize(" ", " ");
+ this.verifyCapitalize("ORACLE", "ORACLE");
+ this.verifyCapitalize("", "");
+ this.verifyCapitalize("A", "a");
+ this.verifyCapitalize("\u00C9cole", "\u00E9cole"); // e'cole -> E'cole
+ }
+
+ protected abstract void verifyCapitalize(String expected, String string);
+
+ public void testCapitalizer_methods() throws Exception {
+ Object capitalizer = this.getCapitalizer();
+ assertEquals("Capitalizer", capitalizer.toString());
+ assertSame(capitalizer, TestTools.serialize(capitalizer));
+ }
+
+ protected abstract Object getCapitalizer();
+
+ public void testUncapitalize() {
+ this.verifyUncapitalize("oracle", "Oracle");
+ this.verifyUncapitalize("oracle", "oracle");
+ this.verifyUncapitalize(" ", " ");
+ this.verifyUncapitalize("ORACLE", "ORACLE");
+ this.verifyUncapitalize("ORacle", "ORacle");
+ this.verifyUncapitalize("oRacle", "oRacle");
+ this.verifyUncapitalize("", "");
+ this.verifyUncapitalize("a", "A");
+ this.verifyUncapitalize("\u00E9cole", "\u00C9cole"); // E'cole -> e'cole
+ }
+
+ protected abstract void verifyUncapitalize(String expected, String string);
+
+ public void testUncapitalizer_methods() throws Exception {
+ Object uncapitalizer = this.getUncapitalizer();
+ assertEquals("Uncapitalizer", uncapitalizer.toString());
+ assertSame(uncapitalizer, TestTools.serialize(uncapitalizer));
+ }
+
+ protected abstract Object getUncapitalizer();
+
+ // ********** queries **********
+
+ public void testIsBlank() {
+ this.verifyIsBlank(true, (String) null);
+ this.verifyIsBlank(true, "");
+ this.verifyIsBlank(true, " ");
+ this.verifyIsBlank(true, " \t\t ");
+ this.verifyIsBlank(true, " \t\t " + this.CR());
+
+ this.verifyIsBlank(false, "XXX");
+ }
+
+ protected abstract void verifyIsBlank(boolean expected, String string);
+
+ public void testIsBlankPredicate_methods() throws Exception {
+ Object predicate = this.getIsBlankPredicate();
+ assertEquals("IsBlank", predicate.toString());
+ assertSame(predicate, TestTools.serialize(predicate));
+ }
+
+ protected abstract Object getIsBlankPredicate();
+
+ public void testIsNotBlank() {
+ this.verifyIsNotBlank(false, (String) null);
+ this.verifyIsNotBlank(false, "");
+ this.verifyIsNotBlank(false, " ");
+ this.verifyIsNotBlank(false, " \t\t ");
+ this.verifyIsNotBlank(false, " \t\t " + this.CR());
+
+ this.verifyIsNotBlank(true, "XXX");
+ }
+
+ protected abstract void verifyIsNotBlank(boolean expected, String string);
+
+ public void testIsNotBlankPredicate_methods() throws Exception {
+ Object predicate = this.getIsNotBlankPredicate();
+ assertEquals("IsNotBlank", predicate.toString());
+ assertSame(predicate, TestTools.serialize(predicate));
+ }
+
+ protected abstract Object getIsNotBlankPredicate();
+
+ public void testEqualsIgnoreCase() {
+ this.verifyEqualsIgnoreCase(true, (String) null, (String) null);
+ verifyEqualsIgnoreCase(false, null, "asdf");
+ verifyEqualsIgnoreCase(false, "asdf", null);
+ verifyEqualsIgnoreCase(true, "asdf", "asdf");
+ verifyEqualsIgnoreCase(true, "asdf", "ASDF");
+ verifyEqualsIgnoreCase(false, "asdf", "ASDD");
+ verifyEqualsIgnoreCase(false, "asdf", "ASDFF");
+ }
+
+ protected abstract void verifyEqualsIgnoreCase(boolean expected, String string1, String string2);
+
+ public void testStartsWithIgnoreCase() {
+ this.verifyStartsWithIgnoreCase(true, "asdf", "as");
+ this.verifyStartsWithIgnoreCase(true, "asdf", "aS");
+ this.verifyStartsWithIgnoreCase(true, "asdf", "");
+ this.verifyStartsWithIgnoreCase(true, "asdf", "A");
+
+ this.verifyStartsWithIgnoreCase(false, "asdf", "bsdf");
+ this.verifyStartsWithIgnoreCase(false, "asdf", "g");
+ this.verifyStartsWithIgnoreCase(false, "asdf", "asdg");
+ this.verifyStartsWithIgnoreCase(false, "asdf", "asdfg");
+ this.verifyStartsWithIgnoreCase(false, "asdf", "asdfgggggg");
+ }
+
+ protected abstract void verifyStartsWithIgnoreCase(boolean expected, String string, String prefix);
+
+ public void testIsUppercase() {
+ this.verifyIsUppercase("FOO");
+ this.verifyIsUppercase("FOO2");
+ this.verifyIsUppercase("F O O");
+ this.denyIsUppercase("Foo");
+ this.denyIsUppercase("");
+ }
+
+ protected abstract void verifyIsUppercase(String string);
+
+ protected abstract void denyIsUppercase(String string);
+
+ public void testIsLowercase() {
+ this.verifyIsLowercase("foo");
+ this.verifyIsLowercase("foo2");
+ this.verifyIsLowercase("f o o");
+ this.denyIsLowercase("Foo");
+ this.denyIsLowercase("");
+ }
+
+ protected abstract void verifyIsLowercase(String string);
+
+ protected abstract void denyIsLowercase(String string);
+
+ // ********** byte arrays **********
+
+ public void testConvertHexStringToByteArray_empty() throws Exception {
+ byte[] byteArray = this.convertHexStringToByteArray("");
+ assertEquals(0, byteArray.length);
+ assertTrue(Arrays.equals(ByteArrayTools.EMPTY_BYTE_ARRAY, byteArray));
+ }
+
+ protected abstract byte[] convertHexStringToByteArray(String string);
+
+ public void testConvertHexStringToByteArray_oddLength() throws Exception {
+ this.verifyConvertHexStringToByteArray_illegalCharacter("CAFEE");
+ }
+
+ public void testConvertHexStringToByteArray_illegalCharacter1() throws Exception {
+ this.verifyConvertHexStringToByteArray_illegalCharacter("CAFEX0CAFEX0");
+ }
+
+ public void testConvertHexStringToByteArray_illegalCharacter2() throws Exception {
+ this.verifyConvertHexStringToByteArray_illegalCharacter("CAFE0XCAFE0x");
+ }
+
+ protected void verifyConvertHexStringToByteArray_illegalCharacter(String string) throws Exception {
+ boolean exCaught = false;
+ try {
+ byte[] byteArray = this.convertHexStringToByteArray(string);
+ fail("bogus byte array: " + Arrays.toString(byteArray));
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testConvertHexStringToByteArray_ok() throws Exception {
+ String s = "74657374"; // UTF-8 values
+ assertEquals("test", new String(this.convertHexStringToByteArray(s)));
+ }
+
+ public void testConvertHexStringToByteArray_negative() throws Exception {
+ String s = getHexCafe();
+ assertEquals("caf\u00E9", new String(this.convertHexStringToByteArray(s)));
+ }
+
+ public void testConvertHexStringToByteArray_lowercase() throws Exception {
+ String s = getHexCafe().toLowerCase();
+ assertEquals("caf\u00E9", new String(this.convertHexStringToByteArray(s)));
+ }
+
+ public static String getHexCafe() {
+ if (SystemTools.fileEncodingIsWindows()) {
+ return "636166E9";
+ }
+ if (SystemTools.fileEncodingIsUTF8()) {
+ return "636166C3A9";
+ }
+ return null;
+ }
+
+ // ********** convert camel-case to all-caps **********
+
+ public void testConvertCamelCaseToAllCaps() {
+ this.verifyConvertCamelCaseToAllCaps("", "");
+ this.verifyConvertCamelCaseToAllCaps("TEST", "test");
+ this.verifyConvertCamelCaseToAllCaps("TEST", "TEST");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "testTest");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "TestTest");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "testTESTTest");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "TestTESTTest");
+ this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST_T", "TestTESTTestT");
+ }
+
+ protected abstract void verifyConvertCamelCaseToAllCaps(String expected, String string);
+
+ public void testConvertCamelCaseToAllCapsMaxLength() {
+ this.verifyConvertCamelCaseToAllCapsMaxLength("", "", 0);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("", "", 44);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("", "test", 0);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 44);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TES", "test", 3);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TEST", 5);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TE", "TEST", 2);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "testTest", 9);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TES", "testTest", 8);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_T", "testTest", 6);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_", "testTest", 5);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "testTest", 4);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "TestTest", 9);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "TestTest", 1100);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_", "testTESTTest", 10);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST", "TestTESTTest", 14);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST_T", "TestTESTTestT", 16);
+ this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST_", "TestTESTTestT", 15);
+ }
+
+ protected abstract void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int max);
+
+ // ********** convert all-caps to camel case **********
+
+ public void testConvertAllCapsToCamelCase() {
+ this.verifyConvertAllCapsToCamelCase("", "");
+ this.verifyConvertAllCapsToCamelCase("", "", true);
+ this.verifyConvertAllCapsToCamelCase("", "", false);
+ this.verifyConvertAllCapsToCamelCase("test", "TEST", false);
+ this.verifyConvertAllCapsToCamelCase("test", "TEST_", false);
+ this.verifyConvertAllCapsToCamelCase("test", "TEST____", false);
+ this.verifyConvertAllCapsToCamelCase("Test", "TEST");
+ this.verifyConvertAllCapsToCamelCase("Test", "TEST", true);
+ this.verifyConvertAllCapsToCamelCase("test", "TeST", false);
+ this.verifyConvertAllCapsToCamelCase("testTest", "TEST_TEST", false);
+ this.verifyConvertAllCapsToCamelCase("testTest", "TEST___TEST", false);
+ this.verifyConvertAllCapsToCamelCase("TestTest", "TEST_TEST");
+ this.verifyConvertAllCapsToCamelCase("TestTest", "TEST_TEST", true);
+ this.verifyConvertAllCapsToCamelCase("testTestTest", "TEST_TEST_TEST", false);
+ this.verifyConvertAllCapsToCamelCase("TestTestTest", "TEST_TEST_TEST");
+ this.verifyConvertAllCapsToCamelCase("TestTestTest", "TEST_TEST_TEST", true);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "TEST_TEST_TEST_T", false);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "_TEST_TEST_TEST_T", false);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "__TEST_TEST_TEST_T", false);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "TEST_TEST_TEST_T");
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "TEST_TEST_TEST_T", true);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "_TEST_TEST_TEST_T");
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "_TEST_TEST_TEST_T", true);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "__TEST_TEST_TEST_T");
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "__TEST_TEST_TEST_T", true);
+ }
+
+ protected abstract void verifyConvertAllCapsToCamelCase(String expected, String string);
+
+ protected abstract void verifyConvertAllCapsToCamelCase(String expected, String string, boolean capFirst);
+
+ public void testConvertAllCapsToCamelCaseLowercase() {
+ this.verifyConvertAllCapsToCamelCase("test", "test", false);
+ this.verifyConvertAllCapsToCamelCase("test", "test_", false);
+ this.verifyConvertAllCapsToCamelCase("test", "test____", false);
+ this.verifyConvertAllCapsToCamelCase("Test", "test", true);
+ this.verifyConvertAllCapsToCamelCase("test", "test", false);
+ this.verifyConvertAllCapsToCamelCase("testTest", "test_test", false);
+ this.verifyConvertAllCapsToCamelCase("testTest", "test___test", false);
+ this.verifyConvertAllCapsToCamelCase("TestTest", "test_test", true);
+ this.verifyConvertAllCapsToCamelCase("testTestTest", "test_test_test", false);
+ this.verifyConvertAllCapsToCamelCase("TestTestTest", "test_test_test", true);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "test_test_test_t", false);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "_test_test_test_t", false);
+ this.verifyConvertAllCapsToCamelCase("testTestTestT", "__test_test_test_t", false);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "test_test_test_t", true);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "_test_test_test_t", true);
+ this.verifyConvertAllCapsToCamelCase("TestTestTestT", "__test_test_test_t", true);
+ }
+
+ // ********** delimiting **********
+
+ public void testIsQuoted() {
+ this.denyIsQuoted("foo");
+ this.verifyIsQuoted("\"foo\"");
+
+ this.denyIsQuoted("");
+ this.verifyIsQuoted("\"\"");
+
+ this.denyIsQuoted("\"");
+ this.denyIsQuoted(" ");
+ this.denyIsQuoted("''");
+ this.denyIsQuoted("'foo'");
+ }
+
+ protected abstract void verifyIsQuoted(String string);
+
+ protected abstract void denyIsQuoted(String string);
+
+ public void testIsParenthetical() {
+ this.denyIsParenthetical("foo");
+ this.verifyIsParenthetical("(foo)");
+
+ this.denyIsParenthetical("");
+ this.verifyIsParenthetical("()");
+
+ this.denyIsParenthetical("(");
+ this.denyIsParenthetical(" ");
+ this.denyIsParenthetical("''");
+ this.denyIsParenthetical("'foo'");
+ }
+
+ protected abstract void verifyIsParenthetical(String string);
+
+ protected abstract void denyIsParenthetical(String string);
+
+ public void testIsBracketed() {
+ this.denyIsBracketed("foo");
+ this.verifyIsBracketed("[foo]");
+
+ this.denyIsBracketed("");
+ this.verifyIsBracketed("[]");
+
+ this.denyIsBracketed("[");
+ this.denyIsBracketed(" ");
+ this.denyIsBracketed("''");
+ this.denyIsBracketed("'foo'");
+ }
+
+ protected abstract void verifyIsBracketed(String string);
+
+ protected abstract void denyIsBracketed(String string);
+
+ public void testIsBraced() {
+ this.denyIsBraced("foo");
+ this.verifyIsBraced("{foo}");
+
+ this.denyIsBraced("");
+ this.verifyIsBraced("{}");
+
+ this.denyIsBraced("{");
+ this.denyIsBraced(" ");
+ this.denyIsBraced("''");
+ this.denyIsBraced("'foo'");
+ }
+
+ protected abstract void verifyIsBraced(String string);
+
+ protected abstract void denyIsBraced(String string);
+
+ public void testIsChevroned() {
+ this.denyIsChevroned("foo");
+ this.verifyIsChevroned("<foo>");
+
+ this.denyIsChevroned("");
+ this.verifyIsChevroned("<>");
+
+ this.denyIsChevroned("{");
+ this.denyIsChevroned(" ");
+ this.denyIsChevroned("''");
+ this.denyIsChevroned("'foo'");
+ }
+
+ protected abstract void verifyIsChevroned(String string);
+
+ protected abstract void denyIsChevroned(String string);
+
+ public void testIsDelimited() {
+ this.denyIsDelimited("foo", '?');
+ this.verifyIsDelimited("?foo?", '?');
+
+ this.denyIsDelimited("", '?');
+ this.verifyIsDelimited("\"\"", '"');
+ this.verifyIsDelimited("?xx?", '?');
+ this.denyIsDelimited("?xx]", '?');
+
+ this.denyIsDelimited("\"", '"');
+ this.denyIsDelimited(" ", ' ');
+ this.denyIsDelimited("''", '"');
+ this.denyIsDelimited("'foo'", '?');
+ }
+
+ protected abstract void verifyIsDelimited(String string, char c);
+
+ protected abstract void denyIsDelimited(String string, char c);
+
+ public void testIsDelimited2() {
+ this.denyIsDelimited2("foo", '[', ']');
+ this.verifyIsDelimited2("{foo}", '{', '}');
+
+ this.denyIsDelimited2("", '[', ']');
+ this.verifyIsDelimited2("[]", '[', ']');
+ this.verifyIsDelimited2("[xx]", '[', ']');
+ this.denyIsDelimited2("?xx]", '[', ']');
+
+ this.denyIsDelimited2("\"", '[', ']');
+ this.denyIsDelimited2(" ", '[', ']');
+ this.denyIsDelimited2("''", '[', ']');
+ this.denyIsDelimited2("'foo'", '[', ']');
+ }
+
+ protected abstract void verifyIsDelimited2(String string, char start, char end);
+
+ protected abstract void denyIsDelimited2(String string, char start, char end);
+
+ // ********** undelimiting **********
+
+ public void testUndelimit() {
+ this.verifyUndelimit("foo", "\"foo\"");
+ this.verifyUndelimit("", "\"\"");
+ this.verifyUndelimit("foo", "'foo'");
+ this.verifyUndelimit("fo\"o", "\"fo\"\"o\"");
+ this.verifyUndelimit("foo\"", "\"foo\"\"\"");
+ this.verifyUndelimit("\"foo", "\"\"\"foo\"");
+ this.verifyUndelimit("foo", "[foo]");
+ this.verifyUndelimit("\"", "\"\"\"");
+ this.verifyUndelimit("foo\"", "\"foo\"bar\"");
+ this.verifyUndelimit("foo\"", "\"foo\"\"");
+ }
+
+ public void testUndelimit_ex() {
+ boolean exCaught = false;
+ try {
+ this.verifyUndelimit("BOGUS", "x");
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ protected abstract void verifyUndelimit(String expected, String string);
+
+ public void testUndelimitInt() {
+ this.verifyUndelimitInt("\"foo\"", "\"foo\"", 0);
+ this.verifyUndelimitInt("o", "\"foo\"", 2);
+ this.verifyUndelimitInt("foo", "\"\"foo\"\"", 2);
+ this.verifyUndelimitInt("o", "'foo'", 2);
+ this.verifyUndelimitInt("", "foof", 2);
+ }
+
+ public void testUndelimitInt_ex() {
+ this.verifyUndelimitInt_ex("\"\"", 2);
+ this.verifyUndelimitInt_ex("'o'", 2);
+ }
+
+ protected void verifyUndelimitInt_ex(String string, int count) {
+ boolean exCaught = false;
+ try {
+ this.verifyUndelimitInt("BOGUS", string, count);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ protected abstract void verifyUndelimitInt(String expected, String string, int count);
+
+ // ********** converting to Java string literal **********
+
+ public void testConvertToJavaStringLiteral() {
+ this.verifyConvertToJavaStringLiteral("\"\"", "");
+ this.verifyConvertToJavaStringLiteral("\"\\\"\\\"\"", "\"\"");
+ this.verifyConvertToJavaStringLiteral("\"'foo'\"", "'foo'");
+ this.verifyConvertToJavaStringLiteral("\"foo\\bbar\"", "foo\bbar");
+ this.verifyConvertToJavaStringLiteral("\"foo\\n\\tbar\"", "foo\n\tbar");
+ this.verifyConvertToJavaStringLiteral("\"foo\\\"bar\"", "foo\"bar");
+ this.verifyConvertToJavaStringLiteral("\"foo\\\\bar\"", "foo\\bar");
+ }
+
+ protected abstract void verifyConvertToJavaStringLiteral(String expected, String string);
+
+ public void testConvertToJavaStringLiteralTransformer_methods() throws Exception {
+ Object transformer = this.getJavaStringLiteralTransformer();
+ assertEquals("JavaStringLiteralTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getJavaStringLiteralTransformer();
+
+ public void testConvertToJavaStringLiteralContent() {
+ this.verifyConvertToJavaStringLiteralContent("", "");
+ this.verifyConvertToJavaStringLiteralContent("\\\"\\\"", "\"\"");
+ this.verifyConvertToJavaStringLiteralContent("'foo'", "'foo'");
+ this.verifyConvertToJavaStringLiteralContent("foo\\bbar", "foo\bbar");
+ this.verifyConvertToJavaStringLiteralContent("foo\\n\\tbar", "foo\n\tbar");
+ this.verifyConvertToJavaStringLiteralContent("foo\\\"bar", "foo\"bar");
+ this.verifyConvertToJavaStringLiteralContent("foo\\\\bar", "foo\\bar");
+ }
+
+ protected abstract void verifyConvertToJavaStringLiteralContent(String expected, String string);
+
+ public void testConvertToJavaStringLiteralContentTransformer_methods() throws Exception {
+ Object transformer = this.getJavaStringLiteralContentTransformer();
+ assertEquals("JavaStringLiteralContentTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getJavaStringLiteralContentTransformer();
+
+ // ********** converting to XML **********
+
+ public void testConvertToXmlAttributeValue() {
+ this.verifyConvertToXmlAttributeValue("\"\"", "");
+ this.verifyConvertToXmlAttributeValue("'\"'", "\"");
+ this.verifyConvertToXmlAttributeValue("'\"\"'", "\"\"");
+ this.verifyConvertToXmlAttributeValue("\"'\"", "'");
+ this.verifyConvertToXmlAttributeValue("\"''\"", "''");
+ this.verifyConvertToXmlAttributeValue("\"&quot;'&quot;\"", "\"'\"");
+ this.verifyConvertToXmlAttributeValue("\"&quot;''&quot;\"", "\"''\"");
+ this.verifyConvertToXmlAttributeValue("\"'foo'\"", "'foo'");
+ this.verifyConvertToXmlAttributeValue("'\"foo\"'", "\"foo\"");
+ this.verifyConvertToXmlAttributeValue("\"&quot;foo&quot; 'bar'\"", "\"foo\" 'bar'");
+ this.verifyConvertToXmlAttributeValue("\"foo &amp; bar\"", "foo & bar");
+ this.verifyConvertToXmlAttributeValue("'\"foo &amp; bar\"'", "\"foo & bar\"");
+ this.verifyConvertToXmlAttributeValue("\"foo &lt;&lt;&lt; bar\"", "foo <<< bar");
+ this.verifyConvertToXmlAttributeValue("'\"foo &lt;&lt;&lt; bar\"'", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToXmlAttributeValue(String expected, String string);
+
+ public void testConvertToXmlAttributeValueTransformer_methods() throws Exception {
+ Object transformer = this.getXmlAttributeValueTransformer();
+ assertEquals("XmlAttributeValueTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getXmlAttributeValueTransformer();
+
+ public void testConvertToDoubleQuotedXmlAttributeValue() {
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"\"", "");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;\"", "\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;&quot;\"", "\"\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"'\"", "'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"''\"", "''");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;'&quot;\"", "\"'\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;''&quot;\"", "\"''\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"'foo'\"", "'foo'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;foo&quot;\"", "\"foo\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;foo&quot; 'bar'\"", "\"foo\" 'bar'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"foo &amp; bar\"", "foo & bar");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;foo &amp; bar&quot;\"", "\"foo & bar\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"foo &lt;&lt;&lt; bar\"", "foo <<< bar");
+ this.verifyConvertToDoubleQuotedXmlAttributeValue("\"&quot;foo &lt;&lt;&lt; bar&quot;\"", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToDoubleQuotedXmlAttributeValue(String expected, String string);
+
+ public void testConvertToDoubleQuotedXmlAttributeValueTransformer_methods() throws Exception {
+ Object transformer = this.getDoubleQuotedXmlAttributeValueTransformer();
+ assertEquals("DoubleQuotedXmlAttributeValueTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getDoubleQuotedXmlAttributeValueTransformer();
+
+ public void testConvertToDoubleQuotedXmlAttributeValueContent() {
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("", "");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;", "\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;&quot;", "\"\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("'", "'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("''", "''");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;'&quot;", "\"'\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;''&quot;", "\"''\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("'foo'", "'foo'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;foo&quot;", "\"foo\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;foo&quot; 'bar'", "\"foo\" 'bar'");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("foo &amp; bar", "foo & bar");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;foo &amp; bar&quot;", "\"foo & bar\"");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("foo &lt;&lt;&lt; bar", "foo <<< bar");
+ this.verifyConvertToDoubleQuotedXmlAttributeValueContent("&quot;foo &lt;&lt;&lt; bar&quot;", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToDoubleQuotedXmlAttributeValueContent(String expected, String string);
+
+ public void testConvertToDoubleQuotedXmlAttributeValueContentTransformer_methods() throws Exception {
+ Object transformer = this.getDoubleQuotedXmlAttributeValueContentTransformer();
+ assertEquals("DoubleQuotedXmlAttributeValueContentTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getDoubleQuotedXmlAttributeValueContentTransformer();
+
+ public void testConvertToSingleQuotedXmlAttributeValue() {
+ this.verifyConvertToSingleQuotedXmlAttributeValue("''", "");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"'", "\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"\"'", "\"\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'&apos;'", "'");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'&apos;&apos;'", "''");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"&apos;\"'", "\"'\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"&apos;&apos;\"'", "\"''\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'&apos;foo&apos;'", "'foo'");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"foo\"'", "\"foo\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"foo\" &apos;bar&apos;'", "\"foo\" 'bar'");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'foo &amp; bar'", "foo & bar");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"foo &amp; bar\"'", "\"foo & bar\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'foo &lt;&lt;&lt; bar'", "foo <<< bar");
+ this.verifyConvertToSingleQuotedXmlAttributeValue("'\"foo &lt;&lt;&lt; bar\"'", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToSingleQuotedXmlAttributeValue(String expected, String string);
+
+ public void testConvertToSingleQuotedXmlAttributeValueTransformer_methods() throws Exception {
+ Object transformer = this.getSingleQuotedXmlAttributeValueTransformer();
+ assertEquals("SingleQuotedXmlAttributeValueTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getSingleQuotedXmlAttributeValueTransformer();
+
+ public void testConvertToSingleQuotedXmlAttributeValueContent() {
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("", "");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"", "\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"\"", "\"\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("&apos;", "'");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("&apos;&apos;", "''");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"&apos;\"", "\"'\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"&apos;&apos;\"", "\"''\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("&apos;foo&apos;", "'foo'");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"foo\"", "\"foo\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"foo\" &apos;bar&apos;", "\"foo\" 'bar'");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("foo &amp; bar", "foo & bar");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"foo &amp; bar\"", "\"foo & bar\"");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("foo &lt;&lt;&lt; bar", "foo <<< bar");
+ this.verifyConvertToSingleQuotedXmlAttributeValueContent("\"foo &lt;&lt;&lt; bar\"", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToSingleQuotedXmlAttributeValueContent(String expected, String string);
+
+ public void testConvertToSingleQuotedXmlAttributeValueContentTransformer_methods() throws Exception {
+ Object transformer = this.getSingleQuotedXmlAttributeValueContentTransformer();
+ assertEquals("SingleQuotedXmlAttributeValueContentTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getSingleQuotedXmlAttributeValueContentTransformer();
+
+ public void testConvertToXmlElementText() {
+ this.verifyConvertToXmlElementText("", "");
+ this.verifyConvertToXmlElementText("\"", "\"");
+ this.verifyConvertToXmlElementText("\"\"", "\"\"");
+ this.verifyConvertToXmlElementText("'", "'");
+ this.verifyConvertToXmlElementText("''", "''");
+ this.verifyConvertToXmlElementText("\"'\"", "\"'\"");
+ this.verifyConvertToXmlElementText("\"''\"", "\"''\"");
+ this.verifyConvertToXmlElementText("'foo'", "'foo'");
+ this.verifyConvertToXmlElementText("foo &amp; bar", "foo & bar");
+ this.verifyConvertToXmlElementText("foo &amp;", "foo &");
+ this.verifyConvertToXmlElementText("&amp; bar", "& bar");
+ this.verifyConvertToXmlElementText("\"foo &amp; bar\"", "\"foo & bar\"");
+ this.verifyConvertToXmlElementText("foo &lt;&lt;&lt; bar", "foo <<< bar");
+ this.verifyConvertToXmlElementText("\"foo &lt;&lt;&lt; bar\"", "\"foo <<< bar\"");
+ }
+
+ protected abstract void verifyConvertToXmlElementText(String expected, String string);
+
+ public void testConvertToXmlElementTextTransformer_methods() throws Exception {
+ Object transformer = this.getXmlElementTextTransformer();
+ assertEquals("XmlElementTextTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getXmlElementTextTransformer();
+
+ public void testConvertToXmlElementCDATA() {
+ String START = "<![CDATA[";
+ String END = "]]>";
+ this.verifyConvertToXmlElementCDATA(START + END, "");
+ this.verifyConvertToXmlElementCDATA(START + "\"" + END, "\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"\"" + END, "\"\"");
+ this.verifyConvertToXmlElementCDATA(START + "'" + END, "'");
+ this.verifyConvertToXmlElementCDATA(START + "''" + END, "''");
+ this.verifyConvertToXmlElementCDATA(START + "\"'\"" + END, "\"'\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"''\"" + END, "\"''\"");
+ this.verifyConvertToXmlElementCDATA(START + "'foo'" + END, "'foo'");
+ this.verifyConvertToXmlElementCDATA(START + "foo & bar" + END, "foo & bar");
+ this.verifyConvertToXmlElementCDATA(START + "foo &" + END, "foo &");
+ this.verifyConvertToXmlElementCDATA(START + "& bar" + END, "& bar");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo & bar\"" + END, "\"foo & bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "foo <<< bar" + END, "foo <<< bar");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <<< bar\"" + END, "\"foo <<< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <&< bar\"" + END, "\"foo <&< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <]< bar\"" + END, "\"foo <]< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <]]< bar\"" + END, "\"foo <]]< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "\"foo <]]&gt;< bar\"" + END, "\"foo <]]>< bar\"");
+ this.verifyConvertToXmlElementCDATA(START + "foo <]" + END, "foo <]");
+ this.verifyConvertToXmlElementCDATA(START + "foo <]]" + END, "foo <]]");
+ this.verifyConvertToXmlElementCDATA(START + "foo <]]&gt;" + END, "foo <]]>");
+ this.verifyConvertToXmlElementCDATA(START + "]foo" + END, "]foo");
+ this.verifyConvertToXmlElementCDATA(START + "]]foo" + END, "]]foo");
+ this.verifyConvertToXmlElementCDATA(START + "]]&gt;foo" + END, "]]>foo");
+ }
+
+ protected abstract void verifyConvertToXmlElementCDATA(String expected, String string);
+
+ public void testConvertToXmlElementCDATATransformer_methods() throws Exception {
+ Object transformer = this.getXmlElementCDATATransformer();
+ assertEquals("XmlElementCDATATransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getXmlElementCDATATransformer();
+
+ public void testConvertToXmlElementCDATAContent() throws Exception {
+ this.verifyConvertToXmlElementCDATAContent("", "");
+ this.verifyConvertToXmlElementCDATAContent("\"", "\"");
+ this.verifyConvertToXmlElementCDATAContent("\"\"", "\"\"");
+ this.verifyConvertToXmlElementCDATAContent("'", "'");
+ this.verifyConvertToXmlElementCDATAContent("''", "''");
+ this.verifyConvertToXmlElementCDATAContent("\"'\"", "\"'\"");
+ this.verifyConvertToXmlElementCDATAContent("\"''\"", "\"''\"");
+ this.verifyConvertToXmlElementCDATAContent("'foo'", "'foo'");
+ this.verifyConvertToXmlElementCDATAContent("foo & bar", "foo & bar");
+ this.verifyConvertToXmlElementCDATAContent("foo &", "foo &");
+ this.verifyConvertToXmlElementCDATAContent("& bar", "& bar");
+ this.verifyConvertToXmlElementCDATAContent("\"foo & bar\"", "\"foo & bar\"");
+ this.verifyConvertToXmlElementCDATAContent("foo <<< bar", "foo <<< bar");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <<< bar\"", "\"foo <<< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <&< bar\"", "\"foo <&< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <]< bar\"", "\"foo <]< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <]]< bar\"", "\"foo <]]< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("\"foo <]]&gt;< bar\"", "\"foo <]]>< bar\"");
+ this.verifyConvertToXmlElementCDATAContent("foo <]", "foo <]");
+ this.verifyConvertToXmlElementCDATAContent("foo <]]", "foo <]]");
+ this.verifyConvertToXmlElementCDATAContent("foo <]]&gt;", "foo <]]>");
+ this.verifyConvertToXmlElementCDATAContent("]foo", "]foo");
+ this.verifyConvertToXmlElementCDATAContent("]]foo", "]]foo");
+ this.verifyConvertToXmlElementCDATAContent("]]&gt;foo", "]]>foo");
+ }
+
+ protected abstract void verifyConvertToXmlElementCDATAContent(String expected, String string);
+
+ public void testConvertToXmlElementCDATAContentTransformer_methods() throws Exception {
+ Object transformer = this.getXmlElementCDATAContentTransformer();
+ assertEquals("XmlElementCDATAContentTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
+ }
+
+ protected abstract Object getXmlElementCDATAContentTransformer();
+
+ // ********** constructor **********
+
+ public void testConstructor() {
+ boolean exCaught = false;
+ try {
+ Object at = ClassTools.newInstance(this.getToolsClass());
+ fail("bogus: " + at); //$NON-NLS-1$
+ } catch (RuntimeException ex) {
+ if (ex.getCause() instanceof InvocationTargetException) {
+ if (ex.getCause().getCause() instanceof UnsupportedOperationException) {
+ exCaught = true;
+ }
+ }
+ }
+ assertTrue(exCaught);
+ }
+
+ protected String getSimpleToolsClassName() {
+ return this.getToolsClass().getSimpleName();
+ }
+
+ protected abstract Class<?> getToolsClass();
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CharArrayToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CharArrayToolsTests.java
index 94dd16a2ec..07e1cff9b1 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CharArrayToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CharArrayToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,593 +9,474 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal;
-import java.util.Arrays;
-import junit.framework.TestCase;
+import java.nio.charset.Charset;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
-import org.eclipse.jpt.common.utility.internal.ByteArrayTools;
import org.eclipse.jpt.common.utility.internal.CharArrayTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+import org.eclipse.jpt.common.utility.predicate.Predicate;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
import org.junit.Assert;
@SuppressWarnings("nls")
public class CharArrayToolsTests
- extends TestCase
+ extends AbstractStringToolsTests
{
- // ********** padding/truncating/centering/repeating **********
-
- public void testCenter() {
- TestTools.assertEquals("fred", CharArrayTools.center("fred".toCharArray(), 4));
- TestTools.assertEquals(" fred ", CharArrayTools.center("fred".toCharArray(), 6));
- TestTools.assertEquals(" fred ", CharArrayTools.center("fred".toCharArray(), 7));
- TestTools.assertEquals("re", CharArrayTools.center("fred".toCharArray(), 2));
- TestTools.assertEquals("fre", CharArrayTools.center("fred".toCharArray(), 3));
- }
-
- public void testPad() {
- TestTools.assertEquals("fred", CharArrayTools.pad(new char[] { 'f', 'r', 'e', 'd' }, 4));
- TestTools.assertEquals("fred ", CharArrayTools.pad(new char[] { 'f', 'r', 'e', 'd' }, 6));
- boolean exThrown = false;
- try {
- TestTools.assertEquals("fr", CharArrayTools.pad(new char[] { 'f', 'r', 'e', 'd' }, 2));
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
+ public CharArrayToolsTests(String name) {
+ super(name);
}
- public void testFit() {
- TestTools.assertEquals("fred", CharArrayTools.fit(new char[] { 'f', 'r', 'e', 'd' }, 4));
- TestTools.assertEquals("fred ", CharArrayTools.fit(new char[] { 'f', 'r', 'e', 'd' }, 6));
- TestTools.assertEquals("fr", CharArrayTools.fit(new char[] { 'f', 'r', 'e', 'd' }, 2));
+ @Override
+ protected String CR() {
+ return String.valueOf(CharArrayTools.CR);
}
- public void testZeroPad() {
- TestTools.assertEquals("1234", CharArrayTools.zeroPad(new char[] { '1', '2', '3', '4' }, 4));
- TestTools.assertEquals("001234", CharArrayTools.zeroPad(new char[] { '1', '2', '3', '4' }, 6));
- boolean exThrown = false;
- try {
- TestTools.assertEquals("12", CharArrayTools.zeroPad(new char[] { '1', '2', '3', '4' }, 2));
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
+ @Override
+ protected void verifyReverse(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.reverse(string.toCharArray()));
}
- public void testZeroFit() {
- TestTools.assertEquals("1234", CharArrayTools.zeroFit(new char[] { '1', '2', '3', '4' }, 4));
- TestTools.assertEquals("001234", CharArrayTools.zeroFit(new char[] { '1', '2', '3', '4' }, 6));
- TestTools.assertEquals("34", CharArrayTools.zeroFit(new char[] { '1', '2', '3', '4' }, 2));
+ @Override
+ protected void verifyLast(char expected, String string) {
+ assertEquals(expected, CharArrayTools.last(string.toCharArray()));
}
- public void testRepeat() {
- this.verifyRepeat("", "1234", 0);
- this.verifyRepeat("12", "1234", 2);
- this.verifyRepeat("1234", "1234", 4);
- this.verifyRepeat("123412", "1234", 6);
- this.verifyRepeat("12341234", "1234", 8);
- this.verifyRepeat("123412341234123412341", "1234", 21);
+ @Override
+ protected void verifyConcatenate(String expected, String[] array) {
+ TestTools.assertEquals(expected, CharArrayTools.concatenate(this.convert(array)));
+ Iterable<char[]> iterable = IterableTools.transform(IterableTools.iterable(array), StringTools.CHAR_ARRAY_TRANSFORMER);
+ TestTools.assertEquals(expected, CharArrayTools.concatenate(iterable));
+ TestTools.assertEquals(expected, CharArrayTools.concatenate(iterable.iterator()));
}
- private void verifyRepeat(String expected, String string, int length) {
- TestTools.assertEquals(expected, CharArrayTools.repeat(string.toCharArray(), length));
+ private char[][] convert(String[] stringArray) {
+ char[][] array = new char[stringArray.length][];
+ for (int i = 0; i < array.length; i++) {
+ array[i] = stringArray[i].toCharArray();
+ }
+ return array;
}
- // ********** separating **********
-
- public void testSeparate() {
- this.verifySeparate("012345", '-', 22, "012345");
- this.verifySeparate("012345", '-', 6, "012345");
- this.verifySeparate("012345", '-', 5, "01234-5");
- this.verifySeparate("012345", '-', 4, "0123-45");
- this.verifySeparate("012345", '-', 3, "012-345");
- this.verifySeparate("012345", '-', 2, "01-23-45");
- this.verifySeparate("012345", '-', 1, "0-1-2-3-4-5");
+ @Override
+ protected void verifyConcatenate(String expected, String[] array, String delim) {
+ TestTools.assertEquals(expected, CharArrayTools.concatenate(this.convert(array), delim.toCharArray()));
+ Iterable<char[]> iterable = IterableTools.transform(IterableTools.iterable(array), StringTools.CHAR_ARRAY_TRANSFORMER);
+ TestTools.assertEquals(expected, CharArrayTools.concatenate(iterable, delim.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.concatenate(iterable.iterator(), delim.toCharArray()));
}
- private void verifySeparate(String string, char separator, int segmentLength, String expected) {
- TestTools.assertEquals(expected, CharArrayTools.separate(string.toCharArray(), separator, segmentLength));
+ @Override
+ protected void verifyCenter(String expected, String string, int len) {
+ TestTools.assertEquals(expected, CharArrayTools.center(string.toCharArray(), len));
}
- // ********** removing characters **********
-
- public void testRemoveFirstOccurrence() {
- this.verifyRemoveFirstOccurrence("Emplo&yee", '&', "Employee");
- this.verifyRemoveFirstOccurrence("Emplo&yee&", '&', "Employee&");
- this.verifyRemoveFirstOccurrence("Employee &Foo", '&', "Employee Foo");
- this.verifyRemoveFirstOccurrence("Employee&", '&', "Employee");
- this.verifyRemoveFirstOccurrence("&Employee", '&', "Employee");
+ @Override
+ protected void verifyPad(String expected, String string, int len) {
+ TestTools.assertEquals(expected, CharArrayTools.pad(string.toCharArray(), len));
}
- private void verifyRemoveFirstOccurrence(String string, char charToRemove, String expectedString) {
- TestTools.assertEquals(expectedString, CharArrayTools.removeFirstOccurrence(string.toCharArray(), charToRemove));
+ @Override
+ protected void verifyFit(String expected, String string, int len) {
+ TestTools.assertEquals(expected, CharArrayTools.fit(string.toCharArray(), len));
}
- public void testRemoveAllOccurrences() {
- this.verifyRemoveAllOccurrences("Employee Fred", ' ', "EmployeeFred");
- this.verifyRemoveAllOccurrences(" Employee ", ' ', "Employee");
- this.verifyRemoveAllOccurrences("Employee Foo", ' ', "EmployeeFoo");
- this.verifyRemoveAllOccurrences(" Emp loyee Foo", ' ', "EmployeeFoo");
+ @Override
+ protected void verifyZeroPad(String expected, String string, int len) {
+ TestTools.assertEquals(expected, CharArrayTools.zeroPad(string.toCharArray(), len));
}
- private void verifyRemoveAllOccurrences(String string, char charToRemove, String expectedString) {
- TestTools.assertEquals(expectedString, CharArrayTools.removeAllOccurrences(string.toCharArray(), charToRemove));
+ @Override
+ protected void verifyZeroFit(String expected, String string, int len) {
+ TestTools.assertEquals(expected, CharArrayTools.zeroFit(string.toCharArray(), len));
}
- public void testRemoveAllWhitespace() {
- this.verifyRemoveAllWhitespace("Employee Fred\t", "EmployeeFred");
- this.verifyRemoveAllWhitespace("\tEmployee\n", "Employee");
- this.verifyRemoveAllWhitespace("Employee \t Foo", "EmployeeFoo");
- this.verifyRemoveAllWhitespace(" Emp\tloyee \n Foo", "EmployeeFoo");
+ @Override
+ protected void verifyRepeat(String expected, String string, int length) {
+ TestTools.assertEquals(expected, CharArrayTools.repeat(string.toCharArray(), length));
}
- private void verifyRemoveAllWhitespace(String string, String expectedString) {
- TestTools.assertEquals(expectedString, CharArrayTools.removeAllWhitespace(string.toCharArray()));
+ @Override
+ protected void verifySeparate(String expected, String string, char separator, int segmentLength) {
+ TestTools.assertEquals(expected, CharArrayTools.separate(string.toCharArray(), separator, segmentLength));
}
- public void testCompressWhitespace() {
- this.verifyCompressWhitespace("Employee Fred\t", "Employee Fred ");
- this.verifyCompressWhitespace("\tEmployee \n", " Employee ");
- this.verifyCompressWhitespace("Employee \t Foo", "Employee Foo");
- this.verifyCompressWhitespace(" Emp\tloyee \n Foo ", " Emp loyee Foo ");
+ @Override
+ protected void verifyQuote(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.quote(string.toCharArray()));
}
- private void verifyCompressWhitespace(String string, String expectedString) {
- TestTools.assertEquals(expectedString, CharArrayTools.compressWhitespace(string.toCharArray()));
+ @Override
+ protected void verifyCharDelimiter(String expected, String string, char delimiter) {
+ Transformer<char[], char[]> transformer = this.buildCharDelimiter(delimiter);
+ TestTools.assertEquals(expected, transformer.transform(string.toCharArray()));
}
- // ********** common prefix **********
-
- // ********** capitalization **********
-
- public void testCapitalize() {
- this.verifyCapitalize("Oracle", new char[] { 'O', 'r', 'a', 'c', 'l', 'e' });
- this.verifyCapitalize("Oracle", new char[] { 'o', 'r', 'a', 'c', 'l', 'e' });
- this.verifyCapitalize(" ", new char[] { ' ', ' ', ' ' });
- this.verifyCapitalize("ORACLE", new char[] { 'O', 'R', 'A', 'C', 'L', 'E' });
- this.verifyCapitalize("", new char[0]);
- this.verifyCapitalize("A", new char[] { 'a' });
- this.verifyCapitalize("\u00C9cole", new char[] { '\u00E9', 'c', 'o', 'l', 'e' });
+ @Override
+ protected Transformer<char[], char[]> buildCharDelimiter(char delimiter) {
+ return new CharArrayTools.CharDelimiter(delimiter);
}
- private void verifyCapitalize(String expected, char[] string) {
- TestTools.assertEquals(expected, CharArrayTools.capitalize(string));
+ @Override
+ protected void verifyDelimit(String expected, String string, String delimiter) {
+ TestTools.assertEquals(expected, CharArrayTools.delimit(string.toCharArray(), delimiter.toCharArray()));
}
- public void testUnapitalize() {
- this.verifyUncapitalize("oracle", new char[] { 'O', 'r', 'a', 'c', 'l', 'e' });
- this.verifyUncapitalize("oracle", new char[] { 'o', 'r', 'a', 'c', 'l', 'e' });
- this.verifyUncapitalize(" ", new char[] { ' ', ' ', ' ' });
- this.verifyUncapitalize("ORACLE", new char[] { 'O', 'R', 'A', 'C', 'L', 'E' });
- this.verifyUncapitalize("", new char[0]);
- this.verifyUncapitalize("a", new char[] { 'A' });
- this.verifyUncapitalize("\u00E9cole", new char[] { '\u00C9', 'c', 'o', 'l', 'e' });
+ @Override
+ protected void verifyStringDelimiter(String expected, String string, String delimiter) {
+ Transformer<char[], char[]> transformer = this.buildStringDelimiter(delimiter);
+ TestTools.assertEquals(expected, transformer.transform(string.toCharArray()));
}
- private void verifyUncapitalize(String expected, char[] string) {
- TestTools.assertEquals(expected, CharArrayTools.uncapitalize(string));
+ @Override
+ protected Transformer<char[], char[]> buildStringDelimiter(String delimiter) {
+ return new CharArrayTools.CharArrayDelimiter(delimiter.toCharArray());
}
- // ********** queries **********
-
- public void testIsBlank() {
- assertTrue(CharArrayTools.isBlank((char[]) null));
- this.verifyIsBlank("");
- this.verifyIsBlank(" \t\t ");
- this.verifyIsBlank(" ");
- this.verifyIsBlank(" \t\t " + StringTools.CR);
+ @Override
+ protected void verifyRemoveFirstOccurrence(String expected, String string, char charToRemove) {
+ TestTools.assertEquals(expected, CharArrayTools.removeFirstOccurrence(string.toCharArray(), charToRemove));
}
- private void verifyIsBlank(String string) {
- assertTrue(CharArrayTools.isBlank(string.toCharArray()));
+ @Override
+ protected void verifyRemoveAllOccurrences(String expected, String string, char charToRemove) {
+ TestTools.assertEquals(expected, CharArrayTools.removeAllOccurrences(string.toCharArray(), charToRemove));
}
- public void testEqualsIgnoreCase() {
- assertTrue(CharArrayTools.equalsIgnoreCase((char[]) null, (char[]) null));
- assertFalse(CharArrayTools.equalsIgnoreCase((char[]) null, "asdf".toCharArray()));
- assertFalse(CharArrayTools.equalsIgnoreCase("asdf".toCharArray(), (char[]) null));
- assertTrue(CharArrayTools.equalsIgnoreCase("asdf".toCharArray(), "asdf".toCharArray()));
- assertTrue(CharArrayTools.equalsIgnoreCase("asdf".toCharArray(), "ASDF".toCharArray()));
+ @Override
+ protected void verifyRemoveAllSpaces(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.removeAllSpaces(string.toCharArray()));
}
- public void testStartsWithIgnoreCase() {
- assertTrue(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "as".toCharArray()));
- assertTrue(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "aS".toCharArray()));
- assertTrue(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "".toCharArray()));
- assertTrue(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "A".toCharArray()));
- assertTrue(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "ASDF".toCharArray()));
- assertTrue(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "asdf".toCharArray()));
-
- assertFalse(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "bsdf".toCharArray()));
- assertFalse(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "g".toCharArray()));
- assertFalse(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "asdg".toCharArray()));
- assertFalse(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "asdfg".toCharArray()));
- assertFalse(CharArrayTools.startsWithIgnoreCase("asdf".toCharArray(), "asdfgggggg".toCharArray()));
+ @Override
+ protected void verifyRemoveAllWhitespace(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.removeAllWhitespace(string.toCharArray()));
}
- public void testIsUppercase() {
- this.verifyIsUppercase("FOO");
- this.verifyIsUppercase("FOO2");
- this.verifyIsUppercase("F O O");
- this.denyIsUppercase("Foo");
- this.denyIsUppercase("");
+ @Override
+ protected void verifyCompressWhitespace(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.compressWhitespace(string.toCharArray()));
}
- private void verifyIsUppercase(String s) {
- assertTrue(CharArrayTools.isUppercase(s.toCharArray()));
+ @Override
+ protected void verifyCommonPrefixLength(int expected, String string1, String string2) {
+ assertEquals(expected, CharArrayTools.commonPrefixLength(string1.toCharArray(), string2.toCharArray()));
}
- private void denyIsUppercase(String s) {
- assertFalse(CharArrayTools.isUppercase(s.toCharArray()));
+ @Override
+ protected void verifyCommonPrefixLengthMax(int expected, String string1, String string2, int max) {
+ assertEquals(expected, CharArrayTools.commonPrefixLength(string1.toCharArray(), string2.toCharArray(), max));
}
- public void testIsLowercase() {
- this.verifyIsLowercase("foo");
- this.verifyIsLowercase("foo2");
- this.verifyIsLowercase("f o o");
- this.denyIsLowercase("Foo");
- this.denyIsLowercase("");
+ @Override
+ protected void verifyCapitalize(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.capitalize(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.CAPITALIZER.transform(string.toCharArray()));
}
- private void verifyIsLowercase(String s) {
- assertTrue(CharArrayTools.isLowercase(s.toCharArray()));
+ @Override
+ protected Object getCapitalizer() {
+ return CharArrayTools.CAPITALIZER;
}
- private void denyIsLowercase(String s) {
- assertFalse(CharArrayTools.isLowercase(s.toCharArray()));
+ @Override
+ protected void verifyUncapitalize(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.uncapitalize(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.UNCAPITALIZER.transform(string.toCharArray()));
}
- // ********** byte arrays **********
+ @Override
+ protected Object getUncapitalizer() {
+ return CharArrayTools.UNCAPITALIZER;
+ }
- public void testConvertHexStringToByteArray_empty() throws Exception {
- char[] s = CharArrayTools.EMPTY_CHAR_ARRAY;
- byte[] byteArray = CharArrayTools.convertHexStringToByteArray(s);
- assertEquals(0, byteArray.length);
- assertTrue(Arrays.equals(ByteArrayTools.EMPTY_BYTE_ARRAY, byteArray));
+ @Override
+ protected void verifyIsBlank(boolean expected, String string) {
+ assertEquals(expected, CharArrayTools.isBlank(this.convert(string)));
+ assertEquals(expected, CharArrayTools.IS_BLANK.evaluate(this.convert(string)));
}
- public void testConvertHexStringToByteArray_oddLength() throws Exception {
- String s = "CAFEE";
- boolean exCaught = false;
- try {
- byte[] byteArray = CharArrayTools.convertHexStringToByteArray(s.toCharArray());
- fail("bogus byte array: " + Arrays.toString(byteArray));
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
+ @Override
+ protected Object getIsBlankPredicate() {
+ return CharArrayTools.IS_BLANK;
}
- public void testConvertHexStringToByteArray_illegalCharacter1() throws Exception {
- this.verifyConvertHexStringToByteArray_illegalCharacter("CAFEX0CAFE");
+ @Override
+ protected void verifyIsNotBlank(boolean expected, String string) {
+ assertEquals(expected, CharArrayTools.isNotBlank(this.convert(string)));
+ assertEquals(expected, CharArrayTools.IS_NOT_BLANK.evaluate(this.convert(string)));
}
- public void testConvertHexStringToByteArray_illegalCharacter2() throws Exception {
- this.verifyConvertHexStringToByteArray_illegalCharacter("CAFE0XCAFE");
+ @Override
+ protected Object getIsNotBlankPredicate() {
+ return CharArrayTools.IS_NOT_BLANK;
}
- private void verifyConvertHexStringToByteArray_illegalCharacter(String s) throws Exception {
- boolean exCaught = false;
- try {
- byte[] byteArray = CharArrayTools.convertHexStringToByteArray(s.toCharArray());
- fail("bogus byte array: " + Arrays.toString(byteArray));
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
+ @Override
+ protected void verifyEqualsIgnoreCase(boolean expected, String string1, String string2) {
+ assertEquals(expected, CharArrayTools.equalsIgnoreCase(this.convert(string1), this.convert(string2)));
}
- public void testConvertHexStringToByteArray_ok() throws Exception {
- String s = "74657374"; // UTF-8 values
- TestTools.assertEquals("test", CharArrayTools.convertHexStringToByteArray(s.toCharArray()));
+ /**
+ * add <code>null</code> check
+ */
+ private char[] convert(String string) {
+ return (string == null) ? null : string.toCharArray();
}
- public void testConvertHexStringToByteArray_negative() throws Exception {
- String s = this.getHexCafe();
- TestTools.assertEquals("caf\u00E9", CharArrayTools.convertHexStringToByteArray(s.toCharArray()));
+ @Override
+ protected void verifyStartsWithIgnoreCase(boolean expected, String string, String prefix) {
+ assertEquals(expected, CharArrayTools.startsWithIgnoreCase(string.toCharArray(), prefix.toCharArray()));
+ Predicate<char[]> predicate = new CharArrayTools.StartsWithIgnoreCase(prefix.toCharArray());
+ assertEquals(expected, predicate.evaluate(string.toCharArray()));
}
- public void testConvertHexStringToByteArray_lowercase() throws Exception {
- String s = this.getHexCafe().toLowerCase();
- TestTools.assertEquals("caf\u00E9", CharArrayTools.convertHexStringToByteArray(s.toCharArray()));
+ @Override
+ protected void verifyIsUppercase(String string) {
+ assertTrue(CharArrayTools.isUppercase(string.toCharArray()));
}
- private String getHexCafe() {
- return StringToolsTests.getHexCafe();
+ @Override
+ protected void denyIsUppercase(String string) {
+ assertFalse(CharArrayTools.isUppercase(string.toCharArray()));
}
- // ********** convert camel-case to all-caps **********
+ @Override
+ protected void verifyIsLowercase(String string) {
+ assertTrue(CharArrayTools.isLowercase(string.toCharArray()));
+ }
- // ********** convert all-caps to camel case **********
+ @Override
+ protected void denyIsLowercase(String string) {
+ assertFalse(CharArrayTools.isLowercase(string.toCharArray()));
+ }
- // ********** delimiting **********
+ @Override
+ protected byte[] convertHexStringToByteArray(String string) {
+ return CharArrayTools.convertHexStringToByteArray(string.toCharArray());
+ }
- public void testIsQuoted() {
- this.denyIsQuoted("foo");
- this.verifyIsQuoted("\"foo\"");
+ @Override
+ protected void verifyConvertCamelCaseToAllCaps(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertCamelCaseToAllCaps(string.toCharArray()));
+ }
- this.denyIsQuoted("");
- this.verifyIsQuoted("\"\"");
+ @Override
+ protected void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int max) {
+ TestTools.assertEquals(expected, CharArrayTools.convertCamelCaseToAllCaps(string.toCharArray(), max));
+ }
- this.denyIsQuoted("\"");
- this.denyIsQuoted(" ");
- this.denyIsQuoted("''");
- this.denyIsQuoted("'foo'");
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertAllCapsToCamelCase(string.toCharArray()));
}
- private void verifyIsQuoted(String s) {
- assertTrue(CharArrayTools.isQuoted(s.toCharArray()));
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string, boolean capFirst) {
+ TestTools.assertEquals(expected, CharArrayTools.convertAllCapsToCamelCase(string.toCharArray(), capFirst));
}
- private void denyIsQuoted(String s) {
- assertFalse(CharArrayTools.isQuoted(s.toCharArray()));
+ @Override
+ protected void verifyIsQuoted(String string) {
+ assertTrue(CharArrayTools.isQuoted(string.toCharArray()));
}
- public void testIsParenthetical() {
- this.denyIsParenthetical("foo");
- this.verifyIsParenthetical("(foo)");
+ @Override
+ protected void denyIsQuoted(String string) {
+ assertFalse(CharArrayTools.isQuoted(string.toCharArray()));
+ }
- this.denyIsParenthetical("");
- this.verifyIsParenthetical("()");
+ @Override
+ protected void verifyIsParenthetical(String string) {
+ assertTrue(CharArrayTools.isParenthetical(string.toCharArray()));
+ }
- this.denyIsParenthetical("(");
- this.denyIsParenthetical(" ");
- this.denyIsParenthetical("''");
- this.denyIsParenthetical("'foo'");
+ @Override
+ protected void denyIsParenthetical(String string) {
+ assertFalse(CharArrayTools.isParenthetical(string.toCharArray()));
}
- private void verifyIsParenthetical(String s) {
- assertTrue(CharArrayTools.isParenthetical(s.toCharArray()));
+ @Override
+ protected void verifyIsBracketed(String string) {
+ assertTrue(CharArrayTools.isBracketed(string.toCharArray()));
}
- private void denyIsParenthetical(String s) {
- assertFalse(CharArrayTools.isParenthetical(s.toCharArray()));
+ @Override
+ protected void denyIsBracketed(String string) {
+ assertFalse(CharArrayTools.isBracketed(string.toCharArray()));
}
- public void testIsBracketed() {
- this.denyIsBracketed("foo");
- this.verifyIsBracketed("[foo]");
+ @Override
+ protected void verifyIsBraced(String string) {
+ assertTrue(CharArrayTools.isBraced(string.toCharArray()));
+ }
- this.denyIsBracketed("");
- this.verifyIsBracketed("[]");
+ @Override
+ protected void denyIsBraced(String string) {
+ assertFalse(CharArrayTools.isBraced(string.toCharArray()));
+ }
- this.denyIsBracketed("[");
- this.denyIsBracketed(" ");
- this.denyIsBracketed("''");
- this.denyIsBracketed("'foo'");
+ @Override
+ protected void verifyIsChevroned(String string) {
+ assertTrue(CharArrayTools.isChevroned(string.toCharArray()));
}
- private void verifyIsBracketed(String s) {
- assertTrue(CharArrayTools.isBracketed(s.toCharArray()));
+ @Override
+ protected void denyIsChevroned(String string) {
+ assertFalse(CharArrayTools.isChevroned(string.toCharArray()));
}
- private void denyIsBracketed(String s) {
- assertFalse(CharArrayTools.isBracketed(s.toCharArray()));
+ @Override
+ protected void verifyIsDelimited(String string, char c) {
+ assertTrue(CharArrayTools.isDelimited(string.toCharArray(), c));
}
- public void testIsBraced() {
- this.denyIsBraced("foo");
- this.verifyIsBraced("{foo}");
+ @Override
+ protected void denyIsDelimited(String string, char c) {
+ assertFalse(CharArrayTools.isDelimited(string.toCharArray(), c));
+ }
- this.denyIsBraced("");
- this.verifyIsBraced("{}");
+ @Override
+ protected void verifyIsDelimited2(String string, char start, char end) {
+ assertTrue(CharArrayTools.isDelimited(string.toCharArray(), start, end));
+ }
- this.denyIsBraced("{");
- this.denyIsBraced(" ");
- this.denyIsBraced("''");
- this.denyIsBraced("'foo'");
+ @Override
+ protected void denyIsDelimited2(String string, char start, char end) {
+ assertFalse(CharArrayTools.isDelimited(string.toCharArray(), start, end));
}
- private void verifyIsBraced(String s) {
- assertTrue(CharArrayTools.isBraced(s.toCharArray()));
+ @Override
+ protected void verifyUndelimit(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.undelimit(string.toCharArray()));
}
- private void denyIsBraced(String s) {
- assertFalse(CharArrayTools.isBraced(s.toCharArray()));
+ @Override
+ protected void verifyUndelimitInt(String expected, String string, int count) {
+ TestTools.assertEquals(expected, CharArrayTools.undelimit(string.toCharArray(), count));
}
- public void testIsChevroned() {
- this.denyIsChevroned("foo");
- this.verifyIsChevroned("<foo>");
+ @Override
+ protected void verifyConvertToJavaStringLiteral(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToJavaStringLiteral(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.JAVA_STRING_LITERAL_TRANSFORMER.transform(string.toCharArray()));
+ }
- this.denyIsChevroned("");
- this.verifyIsChevroned("<>");
+ @Override
+ protected Object getJavaStringLiteralTransformer() {
+ return CharArrayTools.JAVA_STRING_LITERAL_TRANSFORMER;
+ }
- this.denyIsChevroned("{");
- this.denyIsChevroned(" ");
- this.denyIsChevroned("''");
- this.denyIsChevroned("'foo'");
+ @Override
+ protected void verifyConvertToJavaStringLiteralContent(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToJavaStringLiteralContent(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER.transform(string.toCharArray()));
}
- private void verifyIsChevroned(String s) {
- assertTrue(CharArrayTools.isChevroned(s.toCharArray()));
+ @Override
+ protected Object getJavaStringLiteralContentTransformer() {
+ return CharArrayTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER;
}
- private void denyIsChevroned(String s) {
- assertFalse(CharArrayTools.isChevroned(s.toCharArray()));
+ @Override
+ protected void verifyConvertToXmlAttributeValue(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToXmlAttributeValue(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.XML_ATTRIBUTE_VALUE_TRANSFORMER.transform(string.toCharArray()));
}
- public void testIsDelimited() {
- this.denyIsDelimited("foo", '?');
- this.verifyIsDelimited("?foo?", '?');
+ @Override
+ protected Object getXmlAttributeValueTransformer() {
+ return CharArrayTools.XML_ATTRIBUTE_VALUE_TRANSFORMER;
+ }
- this.denyIsDelimited("", '?');
- this.verifyIsDelimited("\"\"", '"');
- this.verifyIsDelimited("?xx?", '?');
- this.denyIsDelimited("?xx]", '?');
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValue(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToDoubleQuotedXmlAttributeValue(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_TRANSFORMER.transform(string.toCharArray()));
+ }
- this.denyIsDelimited("\"", '"');
- this.denyIsDelimited(" ", ' ');
- this.denyIsDelimited("''", '"');
- this.denyIsDelimited("'foo'", '?');
+ @Override
+ protected Object getDoubleQuotedXmlAttributeValueTransformer() {
+ return CharArrayTools.DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_TRANSFORMER;
}
- private void verifyIsDelimited(String s, char c) {
- assertTrue(CharArrayTools.isDelimited(s.toCharArray(), c));
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValueContent(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToDoubleQuotedXmlAttributeValueContent(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER.transform(string.toCharArray()));
}
- private void denyIsDelimited(String s, char c) {
- assertFalse(CharArrayTools.isDelimited(s.toCharArray(), c));
+ @Override
+ protected Object getDoubleQuotedXmlAttributeValueContentTransformer() {
+ return CharArrayTools.DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
}
- public void testIsDelimited2() {
- this.denyIsDelimited2("foo", '[', ']');
- this.verifyIsDelimited2("{foo}", '{', '}');
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValue(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToSingleQuotedXmlAttributeValue(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_TRANSFORMER.transform(string.toCharArray()));
+ }
- this.denyIsDelimited2("", '[', ']');
- this.verifyIsDelimited2("[]", '[', ']');
- this.verifyIsDelimited2("[xx]", '[', ']');
- this.denyIsDelimited2("?xx]", '[', ']');
+ @Override
+ protected Object getSingleQuotedXmlAttributeValueTransformer() {
+ return CharArrayTools.SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_TRANSFORMER;
+ }
- this.denyIsDelimited2("\"", '[', ']');
- this.denyIsDelimited2(" ", '[', ']');
- this.denyIsDelimited2("''", '[', ']');
- this.denyIsDelimited2("'foo'", '[', ']');
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValueContent(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToSingleQuotedXmlAttributeValueContent(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER.transform(string.toCharArray()));
}
- private void verifyIsDelimited2(String s, char start, char end) {
- assertTrue(CharArrayTools.isDelimited(s.toCharArray(), start, end));
+ @Override
+ protected Object getSingleQuotedXmlAttributeValueContentTransformer() {
+ return CharArrayTools.SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
}
- private void denyIsDelimited2(String s, char start, char end) {
- assertFalse(CharArrayTools.isDelimited(s.toCharArray(), start, end));
+ @Override
+ protected void verifyConvertToXmlElementText(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToXmlElementText(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.XML_ELEMENT_TEXT_TRANSFORMER.transform(string.toCharArray()));
}
- // ********** undelimiting **********
+ @Override
+ protected Object getXmlElementTextTransformer() {
+ return CharArrayTools.XML_ELEMENT_TEXT_TRANSFORMER;
+ }
- public void testUndelimit() {
- this.verifyUndelimit("\"foo\"", "foo");
- this.verifyUndelimit("\"\"", "");
- this.verifyUndelimit("'foo'", "foo");
- this.verifyUndelimit("\"fo\"\"o\"", "fo\"o");
- this.verifyUndelimit("\"foo\"\"\"", "foo\"");
- this.verifyUndelimit("\"\"\"foo\"", "\"foo");
- this.verifyUndelimit("[foo]", "foo");
- this.verifyUndelimit("\"\"\"", "\"");
- this.verifyUndelimit("\"foo\"bar\"", "foo\"");
- this.verifyUndelimit("\"foo\"\"", "foo\"");
+ @Override
+ protected void verifyConvertToXmlElementCDATA(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToXmlElementCDATA(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.XML_ELEMENT_CDATA_TRANSFORMER.transform(string.toCharArray()));
}
- private void verifyUndelimit(String s, String expected) {
- TestTools.assertEquals(expected, CharArrayTools.undelimit(s.toCharArray()));
+ @Override
+ protected Object getXmlElementCDATATransformer() {
+ return CharArrayTools.XML_ELEMENT_CDATA_TRANSFORMER;
}
- public void testUndelimitInt() {
- this.verifyUndelimitInt("\"foo\"", 2, "o");
- this.verifyUndelimitInt("\"\"foo\"\"", 2, "foo");
- this.verifyUndelimitInt("'foo'", 2, "o");
+ @Override
+ protected void verifyConvertToXmlElementCDATAContent(String expected, String string) {
+ TestTools.assertEquals(expected, CharArrayTools.convertToXmlElementCDATAContent(string.toCharArray()));
+ TestTools.assertEquals(expected, CharArrayTools.XML_ELEMENT_CDATA_CONTENT_TRANSFORMER.transform(string.toCharArray()));
}
- private void verifyUndelimitInt(String s, int count, String expected) {
- TestTools.assertEquals(expected, CharArrayTools.undelimit(s.toCharArray(), count));
+ @Override
+ protected Object getXmlElementCDATAContentTransformer() {
+ return CharArrayTools.XML_ELEMENT_CDATA_CONTENT_TRANSFORMER;
}
- public void testUndelimitIntException() {
- this.denyUndelimitInt("\"\"", 2);
- this.denyUndelimitInt("'o'", 2);
+ @Override
+ protected Class<?> getToolsClass() {
+ return CharArrayTools.class;
}
- private void denyUndelimitInt(String s, int count) {
- boolean exCaught = false;
- try {
- char[] bogus = CharArrayTools.undelimit(s.toCharArray(), count);
- fail("invalid string: " + new String(bogus));
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- }
-
- // ********** converting to Java string literal **********
-
- public void testConvertToJavaStringLiteral() {
- this.verifyConvertToJavaStringLiteral("", "\"\"");
- this.verifyConvertToJavaStringLiteral("\"\"", "\"\\\"\\\"\"");
- this.verifyConvertToJavaStringLiteral("'foo'", "\"'foo'\"");
- this.verifyConvertToJavaStringLiteral("foo\bbar", "\"foo\\bbar\"");
- this.verifyConvertToJavaStringLiteral("foo\n\tbar", "\"foo\\n\\tbar\"");
- this.verifyConvertToJavaStringLiteral("foo\"bar", "\"foo\\\"bar\"");
- this.verifyConvertToJavaStringLiteral("foo\\bar", "\"foo\\\\bar\"");
- }
-
- private void verifyConvertToJavaStringLiteral(String s, String expected) {
- TestTools.assertEquals(expected, CharArrayTools.convertToJavaStringLiteral(s.toCharArray()));
- }
-
- // ********** converting to XML **********
-
- public void testConvertToXmlAttributeValue() {
- this.verifyConvertToXmlAttributeValue("", "\"\"");
- this.verifyConvertToXmlAttributeValue("\"", "'\"'");
- this.verifyConvertToXmlAttributeValue("\"\"", "'\"\"'");
- this.verifyConvertToXmlAttributeValue("'", "\"'\"");
- this.verifyConvertToXmlAttributeValue("''", "\"''\"");
- this.verifyConvertToXmlAttributeValue("\"'\"", "\"&quot;'&quot;\"");
- this.verifyConvertToXmlAttributeValue("\"''\"", "\"&quot;''&quot;\"");
- this.verifyConvertToXmlAttributeValue("'foo'", "\"'foo'\"");
- this.verifyConvertToXmlAttributeValue("\"foo\"", "'\"foo\"'");
- this.verifyConvertToXmlAttributeValue("\"foo\" 'bar'", "\"&quot;foo&quot; 'bar'\"");
- this.verifyConvertToXmlAttributeValue("foo & bar", "\"foo &amp; bar\"");
- this.verifyConvertToXmlAttributeValue("\"foo & bar\"", "'\"foo &amp; bar\"'");
- this.verifyConvertToXmlAttributeValue("foo <<< bar", "\"foo &lt;&lt;&lt; bar\"");
- this.verifyConvertToXmlAttributeValue("\"foo <<< bar\"", "'\"foo &lt;&lt;&lt; bar\"'");
- }
-
- private void verifyConvertToXmlAttributeValue(String s, String expected) {
- TestTools.assertEquals(expected, CharArrayTools.convertToXmlAttributeValue(s.toCharArray()));
- }
-
- public void testConvertToXmlElementText() {
- this.verifyConvertToXmlElementText("", "");
- this.verifyConvertToXmlElementText("\"", "\"");
- this.verifyConvertToXmlElementText("\"\"", "\"\"");
- this.verifyConvertToXmlElementText("'", "'");
- this.verifyConvertToXmlElementText("''", "''");
- this.verifyConvertToXmlElementText("\"'\"", "\"'\"");
- this.verifyConvertToXmlElementText("\"''\"", "\"''\"");
- this.verifyConvertToXmlElementText("'foo'", "'foo'");
- this.verifyConvertToXmlElementText("foo & bar", "foo &amp; bar");
- this.verifyConvertToXmlElementText("foo &", "foo &amp;");
- this.verifyConvertToXmlElementText("& bar", "&amp; bar");
- this.verifyConvertToXmlElementText("\"foo & bar\"", "\"foo &amp; bar\"");
- this.verifyConvertToXmlElementText("foo <<< bar", "foo &lt;&lt;&lt; bar");
- this.verifyConvertToXmlElementText("\"foo <<< bar\"", "\"foo &lt;&lt;&lt; bar\"");
- }
-
- private void verifyConvertToXmlElementText(String s, String expected) {
- TestTools.assertEquals(expected, CharArrayTools.convertToXmlElementText(s.toCharArray()));
- }
-
- public void testConvertToXmlElementCDATA() {
- String START = "<![CDATA[";
- String END = "]]>";
- this.verifyConvertToXmlElementCDATA("", START + END);
- this.verifyConvertToXmlElementCDATA("\"", START + "\"" + END);
- this.verifyConvertToXmlElementCDATA("\"\"", START + "\"\"" + END);
- this.verifyConvertToXmlElementCDATA("'", START + "'" + END);
- this.verifyConvertToXmlElementCDATA("''", START + "''" + END);
- this.verifyConvertToXmlElementCDATA("\"'\"", START + "\"'\"" + END);
- this.verifyConvertToXmlElementCDATA("\"''\"", START + "\"''\"" + END);
- this.verifyConvertToXmlElementCDATA("'foo'", START + "'foo'" + END);
- this.verifyConvertToXmlElementCDATA("foo & bar", START + "foo & bar" + END);
- this.verifyConvertToXmlElementCDATA("foo &", START + "foo &" + END);
- this.verifyConvertToXmlElementCDATA("& bar", START + "& bar" + END);
- this.verifyConvertToXmlElementCDATA("\"foo & bar\"", START + "\"foo & bar\"" + END);
- this.verifyConvertToXmlElementCDATA("foo <<< bar", START + "foo <<< bar" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <<< bar\"", START + "\"foo <<< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <&< bar\"", START + "\"foo <&< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <]< bar\"", START + "\"foo <]< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <]]< bar\"", START + "\"foo <]]< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <]]>< bar\"", START + "\"foo <]]&gt;< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("foo <]", START + "foo <]" + END);
- this.verifyConvertToXmlElementCDATA("foo <]]", START + "foo <]]" + END);
- this.verifyConvertToXmlElementCDATA("foo <]]>", START + "foo <]]&gt;" + END);
- this.verifyConvertToXmlElementCDATA("]foo", START + "]foo" + END);
- this.verifyConvertToXmlElementCDATA("]]foo", START + "]]foo" + END);
- this.verifyConvertToXmlElementCDATA("]]>foo", START + "]]&gt;foo" + END);
- }
-
- private void verifyConvertToXmlElementCDATA(String s, String expected) {
- TestTools.assertEquals(expected, CharArrayTools.convertToXmlElementCDATA(s.toCharArray()));
+ // ********** CharArrayTools-specific **********
+
+ public void testStringTransformer() throws Exception {
+ Transformer<char[], String> transformer = CharArrayTools.STRING_TRANSFORMER;
+ assertEquals("foo", transformer.transform("foo".toCharArray()));
+ assertEquals("StringTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
}
// ********** String methods **********
@@ -644,6 +525,8 @@ public class CharArrayToolsTests
this.verifyCompareToIgnoreCase("foo", "FOO");
this.verifyCompareToIgnoreCase("foo", "zoo");
this.verifyCompareToIgnoreCase("foo", "ZOO");
+ this.verifyCompareToIgnoreCase("foo", "fooo");
+ this.verifyCompareToIgnoreCase("fooo", "foo");
}
private void verifyCompareToIgnoreCase(String s1, String s2) {
@@ -693,7 +576,7 @@ public class CharArrayToolsTests
private void verifyContainsCharArray(String s1, String s2) {
StringBuilder sb = new StringBuilder(s2);
- assertEquals(s1.contains(sb), CharArrayTools.contains(s1.toCharArray(), s2));
+ assertEquals(s1.contains(sb), CharArrayTools.contains(s1.toCharArray(), s2.toCharArray()));
}
public void testContentEqualsCharSequence() {
@@ -746,6 +629,23 @@ public class CharArrayToolsTests
assertEquals(s1.endsWith(s2), CharArrayTools.endsWith(s1.toCharArray(), s2.toCharArray()));
}
+ public void testGetBytes() {
+ this.verifyGetBytes("foo");
+ }
+
+ private void verifyGetBytes(String string) {
+ Assert.assertArrayEquals(string.getBytes(), CharArrayTools.getBytes(string.toCharArray()));
+ }
+
+ public void testGetBytesCharSet() throws Exception {
+ this.verifyGetBytesCharSet("foo");
+ }
+
+ private void verifyGetBytesCharSet(String string) throws Exception {
+ String charset = Charset.defaultCharset().name();
+ Assert.assertArrayEquals(string.getBytes(charset), CharArrayTools.getBytes(string.toCharArray(), charset));
+ }
+
public void testGetChars() {
this.verifyGetChars("foo-bar-baz", 0, 11, 0);
this.verifyGetChars("foo-bar-baz", 11, 11, 11);
@@ -761,6 +661,38 @@ public class CharArrayToolsTests
Assert.assertArrayEquals(a1, a2);
}
+ public void testIndexOfChar() {
+ this.verifyIndexOfChar("foo-bar-baz", ' ');
+ this.verifyIndexOfChar("foo-bar-baz", 'f');
+ this.verifyIndexOfChar("foo-bar-baz", 'b');
+ this.verifyIndexOfChar("foo-bar-baz", 'z');
+
+ this.verifyIndexOfChar("", ' ');
+ this.verifyIndexOfChar("", 'f');
+ this.verifyIndexOfChar("", 'b');
+ this.verifyIndexOfChar("", 'z');
+ }
+
+ private void verifyIndexOfChar(String string, char c) {
+ assertEquals(string.indexOf(c), CharArrayTools.indexOf(string.toCharArray(), c));
+ }
+
+ public void testIndexOfCharIndex() {
+ this.verifyIndexOfCharIndex("foo-bar-baz", ' ');
+ this.verifyIndexOfCharIndex("foo-bar-baz", 'f');
+ this.verifyIndexOfCharIndex("foo-bar-baz", 'b');
+ this.verifyIndexOfCharIndex("foo-bar-baz", 'z');
+
+ this.verifyIndexOfCharIndex("", ' ');
+ this.verifyIndexOfCharIndex("", 'f');
+ this.verifyIndexOfCharIndex("", 'b');
+ this.verifyIndexOfCharIndex("", 'z');
+ }
+
+ private void verifyIndexOfCharIndex(String string, char c) {
+ assertEquals(string.indexOf(c, 3), CharArrayTools.indexOf(string.toCharArray(), c, 3));
+ }
+
public void testIndexOfCharSequence() {
this.verifyIndexOfCharSequence("foo-bar-baz", "");
this.verifyIndexOfCharSequence("foo-bar-baz", "foo-bar-baz");
@@ -775,6 +707,7 @@ public class CharArrayToolsTests
private void verifyIndexOfCharSequence(String s1, String s2) {
assertEquals(s1.indexOf(s2), CharArrayTools.indexOf(s1.toCharArray(), s2));
+ assertEquals(s1.indexOf(s2), CharArrayTools.indexOf(s1.toCharArray(), s2, -3));
}
public void testIndexOfCharArray() {
@@ -791,6 +724,7 @@ public class CharArrayToolsTests
private void verifyIndexOfCharArray(String s1, String s2) {
assertEquals(s1.indexOf(s2), CharArrayTools.indexOf(s1.toCharArray(), s2.toCharArray()));
+ assertEquals(s1.indexOf(s2), CharArrayTools.indexOf(s1.toCharArray(), s2.toCharArray(), -3));
}
public void testLastIndexOf() {
@@ -807,6 +741,33 @@ public class CharArrayToolsTests
private void verifyLastIndexOf(String s1, String s2) {
assertEquals(s1.lastIndexOf(s2), CharArrayTools.lastIndexOf(s1.toCharArray(), s2.toCharArray()));
+ assertEquals(-1, CharArrayTools.lastIndexOf(s1.toCharArray(), s2.toCharArray(), -3));
+ }
+
+ public void testLastIndexOfChar() {
+ this.verifyLastIndexOfChar("foo-bar-baz", ' ');
+ this.verifyLastIndexOfChar("foo-bar-baz", 'f');
+ this.verifyLastIndexOfChar("foo-bar-baz", 'v');
+ this.verifyLastIndexOfChar("foo-bar-baz", 'z');
+
+ this.verifyLastIndexOfChar("", ' ');
+ this.verifyLastIndexOfChar("", 'f');
+ this.verifyLastIndexOfChar("", 'b');
+ this.verifyLastIndexOfChar("", 'z');
+ }
+
+ private void verifyLastIndexOfChar(String string, char c) {
+ assertEquals(string.lastIndexOf(c), CharArrayTools.lastIndexOf(string.toCharArray(), c));
+ assertEquals(-1, CharArrayTools.lastIndexOf(string.toCharArray(), c, -3));
+ }
+
+ public void testOffsetByCodePoints() {
+ this.verifyOffsetByCodePoints("foo-bar-baz", 3, 3);
+ this.verifyOffsetByCodePoints("aaaaab", 3, 3);
+ }
+
+ private void verifyOffsetByCodePoints(String string, int index, int codePointOffset) {
+ assertEquals(string.offsetByCodePoints(index, codePointOffset), CharArrayTools.offsetByCodePoints(string.toCharArray(), index, codePointOffset));
}
public void testMatches() {
@@ -848,6 +809,7 @@ public class CharArrayToolsTests
public void testReplace() {
this.verifyReplace("foo-bar-baz", 'b', 'x');
this.verifyReplace("foo-bar-baz", 'X', 'T');
+ this.verifyReplace("foo-bar-baz", 'X', 'X');
}
private void verifyReplace(String string, char oldChar, char newChar) {
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBufferToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBufferToolsTests.java
index 2ebafee255..6b8dbe7526 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBufferToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBufferToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,487 +9,418 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal;
-import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.internal.StringBufferTools;
+import org.junit.Assert;
-@SuppressWarnings("nls")
public class StringBufferToolsTests
- extends TestCase
+ extends AbstractStringBuilderToolsTests
{
public StringBufferToolsTests(String name) {
super(name);
}
- // ********** padding/truncating/centering/repeating **********
-
- public void testCenter() {
- this.verifyCenter("fred", "fred", 4);
- this.verifyCenter(" fred ", "fred", 6);
- this.verifyCenter(" fred ", "fred", 7);
- this.verifyCenter("re", "fred", 2);
- this.verifyCenter("fre", "fred", 3);
+ @Override
+ protected void verifyConvertToCharArray(String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ sb.append(string);
+ Assert.assertArrayEquals(string.toCharArray(), StringBufferTools.convertToCharArray(sb));
}
- private void verifyCenter(String expected, String s, int len) {
+ @Override
+ protected void verifyReverse(String expected, String string) {
StringBuffer sb;
sb = new StringBuffer();
- StringBufferTools.center(sb, s, len);
+ StringBufferTools.reverse(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuffer();
- StringBufferTools.center(sb, s.toCharArray(), len);
+ StringBufferTools.reverse(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testPad() {
+ @Override
+ protected void verifyCenter(String expected, String s, int len) {
StringBuffer sb;
sb = new StringBuffer();
- StringBufferTools.pad(sb, "fred", 4);
- assertEquals("fred", sb.toString());
-
- sb = new StringBuffer();
- StringBufferTools.pad(sb, "fred", 6);
- assertEquals("fred ", sb.toString());
+ StringBufferTools.center(sb, s, len);
+ assertEquals(expected, sb.toString());
sb = new StringBuffer();
- boolean exThrown = false;
- try {
- StringBufferTools.pad(sb, "fred", 2);
- fail();
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
+ StringBufferTools.center(sb, s.toCharArray(), len);
+ assertEquals(expected, sb.toString());
}
- public void testFit() {
- this.verifyFit("fred", "fred", 4);
- this.verifyFit("fred ", "fred", 6);
- this.verifyFit("fr", "fred", 2);
- }
+ @Override
+ protected void verifyPad(String expected, String string, int length) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ StringBufferTools.pad(sb, string, length);
+ assertEquals(expected, sb.toString());
- private void verifyFit(String expected, String string, int length) {
- StringBuffer sb = new StringBuffer();
- StringBufferTools.fit(sb, string, length);
+ sb = new StringBuffer();
+ StringBufferTools.pad(sb, string.toCharArray(), length);
assertEquals(expected, sb.toString());
}
- public void testZeroPad() {
+ @Override
+ protected void verifyFit(String expected, String string, int length) {
StringBuffer sb;
sb = new StringBuffer();
- StringBufferTools.zeroPad(sb, "1234", 4);
- assertEquals("1234", sb.toString());
+ StringBufferTools.fit(sb, string, length);
+ assertEquals(expected, sb.toString());
sb = new StringBuffer();
- StringBufferTools.zeroPad(sb, "1234", 6);
- assertEquals("001234", sb.toString());
+ StringBufferTools.fit(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
+ }
+ @Override
+ protected void verifyZeroPad(String expected, String string, int length) {
+ StringBuffer sb;
sb = new StringBuffer();
- boolean exThrown = false;
- try {
- StringBufferTools.zeroPad(sb, "1234", 2);
- fail();
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
- }
+ StringBufferTools.zeroPad(sb, string, length);
+ assertEquals(expected, sb.toString());
- public void testZeroFit() {
- this.verifyZeroFit("1234", "1234", 4);
- this.verifyZeroFit("001234", "1234", 6);
- this.verifyZeroFit("34", "1234", 2);
+ sb = new StringBuffer();
+ StringBufferTools.zeroPad(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- private void verifyZeroFit(String expected, String string, int length) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyZeroFit(String expected, String string, int length) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.zeroFit(sb, string, length);
assertEquals(expected, sb.toString());
- }
- public void testRepeat() {
- this.verifyRepeat("", "1234", 0);
- this.verifyRepeat("12", "1234", 2);
- this.verifyRepeat("1234", "1234", 4);
- this.verifyRepeat("123412", "1234", 6);
- this.verifyRepeat("12341234", "1234", 8);
- this.verifyRepeat("123412341234123412341", "1234", 21);
+ sb = new StringBuffer();
+ StringBufferTools.zeroFit(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- private void verifyRepeat(String expected, String string, int length) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyRepeat(String expected, String string, int length) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.repeat(sb, string, length);
assertEquals(expected, sb.toString());
- }
-
- public void testRepeatCharArray() {
- this.verifyRepeatCharArray("", "1234", 0);
- this.verifyRepeatCharArray("12", "1234", 2);
- this.verifyRepeatCharArray("1234", "1234", 4);
- this.verifyRepeatCharArray("123412", "1234", 6);
- this.verifyRepeatCharArray("12341234", "1234", 8);
- this.verifyRepeatCharArray("123412341234123412341", "1234", 21);
- }
- private void verifyRepeatCharArray(String expected, String string, int length) {
- StringBuffer sb = new StringBuffer();
+ sb = new StringBuffer();
StringBufferTools.repeat(sb, string.toCharArray(), length);
assertEquals(expected, sb.toString());
}
- public void testSeparateOnStringCharInt() {
- this.verifySeparate("012345", '-', 22, "012345");
- this.verifySeparate("012345", '-', 6, "012345");
- this.verifySeparate("012345", '-', 5, "01234-5");
- this.verifySeparate("012345", '-', 4, "0123-45");
- this.verifySeparate("012345", '-', 3, "012-345");
- this.verifySeparate("012345", '-', 2, "01-23-45");
- this.verifySeparate("012345", '-', 1, "0-1-2-3-4-5");
- }
-
- private void verifySeparate(String string, char separator, int segmentLength, String expected) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifySeparate(String expected, String string, char separator, int segmentLength) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.separate(sb, string, separator, segmentLength);
assertEquals(expected, sb.toString());
- }
-
- public void testSeparateOnCharArrayCharInt() {
- this.verifySeparateCharArray("012345", '-', 22, "012345");
- this.verifySeparateCharArray("012345", '-', 6, "012345");
- this.verifySeparateCharArray("012345", '-', 5, "01234-5");
- this.verifySeparateCharArray("012345", '-', 4, "0123-45");
- this.verifySeparateCharArray("012345", '-', 3, "012-345");
- this.verifySeparateCharArray("012345", '-', 2, "01-23-45");
- this.verifySeparateCharArray("012345", '-', 1, "0-1-2-3-4-5");
- }
- private void verifySeparateCharArray(String string, char separator, int segmentLength, String expected) {
- StringBuffer sb = new StringBuffer();
+ sb = new StringBuffer();
StringBufferTools.separate(sb, string.toCharArray(), separator, segmentLength);
assertEquals(expected, sb.toString());
}
- public void testDelimit() {
- this.verifyDelimit("Employee", "123", "123Employee123");
- this.verifyDelimit("123", "123", "123123123");
- this.verifyDelimit("", "123", "123123");
- }
-
- private void verifyDelimit(String string, String delimiter, String expectedString) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyDelimit(String expected, String string, String delimiter) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.delimit(sb, string, delimiter);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testQuote() {
- this.verifyQuote("Employee", "\"Employee\"");
- this.verifyQuote("123", "\"123\"");
- this.verifyQuote("", "\"\"");
- this.verifyQuote("Emp\"loyee", "\"Emp\"\"loyee\"");
+ sb = new StringBuffer();
+ StringBufferTools.delimit(sb, string.toCharArray(), delimiter.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyQuote(String string, String expectedString) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyQuote(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.quote(sb, string);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testRemoveFirstOccurrence() {
- this.verifyRemoveFirstOccurrence("Emplo&yee", '&', "Employee");
- this.verifyRemoveFirstOccurrence("Emplo&yee&", '&', "Employee&");
- this.verifyRemoveFirstOccurrence("Employee &Foo", '&', "Employee Foo");
- this.verifyRemoveFirstOccurrence("Employee&", '&', "Employee");
- this.verifyRemoveFirstOccurrence("&Employee", '&', "Employee");
+ sb = new StringBuffer();
+ StringBufferTools.quote(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveFirstOccurrence(String string, char charToRemove, String expectedString) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyRemoveFirstOccurrence(String expected, String string, char charToRemove) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.removeFirstOccurrence(sb, string, charToRemove);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testRemoveAllOccurrences() {
- this.verifyRemoveAllOccurrences("Employee Fred", ' ', "EmployeeFred");
- this.verifyRemoveAllOccurrences(" Employee ", ' ', "Employee");
- this.verifyRemoveAllOccurrences("Employee Foo", ' ', "EmployeeFoo");
- this.verifyRemoveAllOccurrences(" Emp loyee Foo", ' ', "EmployeeFoo");
+ sb = new StringBuffer();
+ StringBufferTools.removeFirstOccurrence(sb, string.toCharArray(), charToRemove);
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveAllOccurrences(String string, char charToRemove, String expectedString) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyRemoveAllOccurrences(String expected, String string, char charToRemove) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.removeAllOccurrences(sb, string, charToRemove);
- assertEquals(expectedString, sb.toString());
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.removeAllOccurrences(sb, string.toCharArray(), charToRemove);
+ assertEquals(expected, sb.toString());
}
- public void testRemoveAllWhitespace() {
- this.verifyRemoveAllWhitespace("Employee Fred\t", "EmployeeFred");
- this.verifyRemoveAllWhitespace("\tEmployee\n", "Employee");
- this.verifyRemoveAllWhitespace("Employee \t Foo", "EmployeeFoo");
- this.verifyRemoveAllWhitespace(" Emp\tloyee \n Foo", "EmployeeFoo");
+ @Override
+ protected void verifyRemoveAllSpaces(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ StringBufferTools.removeAllSpaces(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.removeAllSpaces(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveAllWhitespace(String string, String expectedString) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyRemoveAllWhitespace(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.removeAllWhitespace(sb, string);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testCompressWhitespace() {
- this.verifyCompressWhitespace("Employee Fred\t", "Employee Fred ");
- this.verifyCompressWhitespace("\tEmployee \n", " Employee ");
- this.verifyCompressWhitespace("Employee \t Foo", "Employee Foo");
- this.verifyCompressWhitespace(" Emp\tloyee \n Foo ", " Emp loyee Foo ");
+ sb = new StringBuffer();
+ StringBufferTools.removeAllWhitespace(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCompressWhitespace(String string, String expectedString) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyCompressWhitespace(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.compressWhitespace(sb, string);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testCapitalizeOnStringStringBuffer() {
- this.verifyCapitalizeOnStringStringBuffer("Oracle", "Oracle");
- this.verifyCapitalizeOnStringStringBuffer("Oracle", "oracle");
- this.verifyCapitalizeOnStringStringBuffer(" ", " ");
- this.verifyCapitalizeOnStringStringBuffer("ORACLE", "ORACLE");
- this.verifyCapitalizeOnStringStringBuffer("", "");
- this.verifyCapitalizeOnStringStringBuffer("A", "a");
- this.verifyCapitalizeOnStringStringBuffer("\u00C9cole", "\u00E9cole"); // e'cole -> E'cole
+ sb = new StringBuffer();
+ StringBufferTools.compressWhitespace(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCapitalizeOnStringStringBuffer(String expected, String string) {
- StringBuffer sb = new StringBuffer();
+ @Override
+ protected void verifyCapitalize(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
StringBufferTools.capitalize(sb, string);
assertEquals(expected, sb.toString());
- }
- public void testCapitalizeOnCharArray() {
- this.verifyCapitalizeOnCharArray("Oracle", new char[] { 'O', 'r', 'a', 'c', 'l', 'e' });
- this.verifyCapitalizeOnCharArray("Oracle", new char[] { 'o', 'r', 'a', 'c', 'l', 'e' });
- this.verifyCapitalizeOnCharArray(" ", new char[] { ' ', ' ', ' ' });
- this.verifyCapitalizeOnCharArray("ORACLE", new char[] { 'O', 'R', 'A', 'C', 'L', 'E' });
- this.verifyCapitalizeOnCharArray("", new char[0]);
- this.verifyCapitalizeOnCharArray("A", new char[] { 'a' });
- this.verifyCapitalizeOnCharArray("\u00C9cole", new char[] { '\u00E9', 'c', 'o', 'l', 'e' });
+ sb = new StringBuffer();
+ StringBufferTools.capitalize(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCapitalizeOnCharArray(String expected, char[] string) {
- StringBuffer sb = new StringBuffer();
- StringBufferTools.capitalize(sb, string);
+ @Override
+ protected void verifyUncapitalize(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ StringBufferTools.uncapitalize(sb, string);
assertEquals(expected, sb.toString());
- }
- public void testUncapitalizeOnString() {
- this.verifyUncapitalizeOnString("oracle", "Oracle");
- this.verifyUncapitalizeOnString("oracle", "oracle");
- this.verifyUncapitalizeOnString(" ", " ");
- this.verifyUncapitalizeOnString("ORACLE", "ORACLE");
- this.verifyUncapitalizeOnString("", "");
- this.verifyUncapitalizeOnString("a", "A");
- this.verifyUncapitalizeOnString("\u00E9cole", "\u00C9cole"); // E'cole -> e'cole
+ sb = new StringBuffer();
+ StringBufferTools.uncapitalize(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUncapitalizeOnString(String expected, String string) {
- StringBuffer sb = new StringBuffer();
- StringBufferTools.uncapitalize(sb, string);
+ @Override
+ protected void verifyConvertToHexString(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ StringBufferTools.convertToHexString(sb, string.getBytes());
assertEquals(expected, sb.toString());
}
- public void testUncapitalizeOnCharArray() {
- this.verifyUncapitalizeOnCharArray("oracle", new char[] { 'O', 'r', 'a', 'c', 'l', 'e' });
- this.verifyUncapitalizeOnCharArray("oracle", new char[] { 'o', 'r', 'a', 'c', 'l', 'e' });
- this.verifyUncapitalizeOnCharArray(" ", new char[] { ' ', ' ', ' ' });
- this.verifyUncapitalizeOnCharArray("ORACLE", new char[] { 'O', 'R', 'A', 'C', 'L', 'E' });
- this.verifyUncapitalizeOnCharArray("", new char[0]);
- this.verifyUncapitalizeOnCharArray("a", new char[] { 'A' });
- this.verifyUncapitalizeOnCharArray("\u00E9cole", new char[] { '\u00C9', 'c', 'o', 'l', 'e' });
- }
+ @Override
+ protected void verifyConvertCamelCaseToAllCaps(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ StringBufferTools.convertCamelCaseToAllCaps(sb, string);
+ assertEquals(expected, sb.toString());
- private void verifyUncapitalizeOnCharArray(String expected, char[] string) {
- StringBuffer sb = new StringBuffer();
- StringBufferTools.uncapitalize(sb, string);
+ sb = new StringBuffer();
+ StringBufferTools.convertCamelCaseToAllCaps(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testConvertToHexString() {
- this.verifyConvertToHexString("74657374", "test"); // UTF-8 values
+ @Override
+ protected void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int maxLength) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ StringBufferTools.convertCamelCaseToAllCaps(sb, string, maxLength);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertCamelCaseToAllCaps(sb, string.toCharArray(), maxLength);
+ assertEquals(expected, sb.toString());
}
- public void testConvertToHexString_negative() {
- this.verifyConvertToHexString(this.getHexCafe(), "caf\u00E9"); // UTF-8 values
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ StringBufferTools.convertAllCapsToCamelCase(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertAllCapsToCamelCase(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private String getHexCafe() {
- return StringToolsTests.getHexCafe();
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string, boolean capFirst) {
+ StringBuffer sb;
+ sb = new StringBuffer();
+ StringBufferTools.convertAllCapsToCamelCase(sb, string, capFirst);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertAllCapsToCamelCase(sb, string.toCharArray(), capFirst);
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertToHexString(String expected, String string) {
+ @Override
+ protected void verifyUndelimit(String expected, String s) {
StringBuffer sb = new StringBuffer();
- StringBufferTools.convertToHexString(sb, string.getBytes());
+ StringBufferTools.undelimit(sb, s);
assertEquals(expected, sb.toString());
- }
- public void testConvertCamelCaseToAllCaps() {
- this.verifyConvertCamelCaseToAllCaps("TEST", "test");
- this.verifyConvertCamelCaseToAllCaps("TEST", "TEST");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "testTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "TestTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "testTESTTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "TestTESTTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST_T", "TestTESTTestT");
+ sb = new StringBuffer();
+ StringBufferTools.undelimit(sb, s.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertCamelCaseToAllCaps(String expected, String string) {
+ @Override
+ protected void verifyUndelimitCount(String expected, String s, int count) {
StringBuffer sb = new StringBuffer();
- StringBufferTools.convertCamelCaseToAllCaps(sb, string);
+ StringBufferTools.undelimit(sb, s, count);
assertEquals(expected, sb.toString());
- }
- public void testConvertCamelCaseToAllCapsMaxLength() {
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 44);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 4);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TES", "test", 3);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TEST", 5);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TE", "TEST", 2);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "testTest", 9);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TES", "testTest", 8);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_T", "testTest", 6);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_", "testTest", 5);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "testTest", 4);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "TestTest", 9);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "TestTest", 1100);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_", "testTESTTest", 10);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST", "TestTESTTest", 14);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST_T", "TestTESTTestT", 16);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST_", "TestTESTTestT", 15);
+ sb = new StringBuffer();
+ StringBufferTools.undelimit(sb, s.toCharArray(), count);
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int max) {
+ @Override
+ protected void verifyConvertToJavaStringLiteral(String expected, String s) {
StringBuffer sb = new StringBuffer();
- StringBufferTools.convertCamelCaseToAllCaps(sb, string, max);
- assertEquals(expected, sb.toString());
- }
-
- public void testConvertUnderscoresToCamelCase() {
- this.verifyConvertUnderscoresToCamelCase("test", "TEST", false);
- this.verifyConvertUnderscoresToCamelCase("test", "TEST_", false);
- this.verifyConvertUnderscoresToCamelCase("test", "TEST____", false);
- this.verifyConvertUnderscoresToCamelCase("Test", "TEST", true);
- this.verifyConvertUnderscoresToCamelCase("test", "TeST", false);
- this.verifyConvertUnderscoresToCamelCase("testTest", "TEST_TEST", false);
- this.verifyConvertUnderscoresToCamelCase("testTest", "TEST___TEST", false);
- this.verifyConvertUnderscoresToCamelCase("TestTest", "TEST_TEST", true);
- this.verifyConvertUnderscoresToCamelCase("testTestTest", "TEST_TEST_TEST", false);
- this.verifyConvertUnderscoresToCamelCase("TestTestTest", "TEST_TEST_TEST", true);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "TEST_TEST_TEST_T", false);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "_TEST_TEST_TEST_T", false);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "__TEST_TEST_TEST_T", false);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "TEST_TEST_TEST_T", true);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "_TEST_TEST_TEST_T", true);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "__TEST_TEST_TEST_T", true);
- }
-
- public void testConvertUnderscoresToCamelCaseLowercase() {
- this.verifyConvertUnderscoresToCamelCase("test", "test", false);
- this.verifyConvertUnderscoresToCamelCase("test", "test_", false);
- this.verifyConvertUnderscoresToCamelCase("test", "test____", false);
- this.verifyConvertUnderscoresToCamelCase("Test", "test", true);
- this.verifyConvertUnderscoresToCamelCase("test", "test", false);
- this.verifyConvertUnderscoresToCamelCase("testTest", "test_test", false);
- this.verifyConvertUnderscoresToCamelCase("testTest", "test___test", false);
- this.verifyConvertUnderscoresToCamelCase("TestTest", "test_test", true);
- this.verifyConvertUnderscoresToCamelCase("testTestTest", "test_test_test", false);
- this.verifyConvertUnderscoresToCamelCase("TestTestTest", "test_test_test", true);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "test_test_test_t", false);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "_test_test_test_t", false);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "__test_test_test_t", false);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "test_test_test_t", true);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "_test_test_test_t", true);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "__test_test_test_t", true);
- }
-
- private void verifyConvertUnderscoresToCamelCase(String expected, String string, boolean capitalizeFirstLetter) {
+ StringBufferTools.convertToJavaStringLiteral(sb, s);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertToJavaStringLiteral(sb, s.toCharArray());
+ assertEquals(expected, sb.toString());
+ }
+
+ @Override
+ protected void verifyConvertToJavaStringLiteralContent(String expected, String s) {
StringBuffer sb = new StringBuffer();
- StringBufferTools.convertAllCapsToCamelCase(sb, string, capitalizeFirstLetter);
+ StringBufferTools.convertToJavaStringLiteralContent(sb, s);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertToJavaStringLiteralContent(sb, s.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testUndelimit() {
- this.verifyUndelimit("\"foo\"", "foo");
- this.verifyUndelimit("\"\"", "");
- this.verifyUndelimit("'foo'", "foo");
- this.verifyUndelimit("\"fo\"\"o\"", "fo\"o");
- this.verifyUndelimit("\"foo\"\"\"", "foo\"");
- this.verifyUndelimit("\"\"\"foo\"", "\"foo");
- this.verifyUndelimit("[foo]", "foo");
- this.verifyUndelimit("\"\"\"", "\"");
- this.verifyUndelimit("\"foo\"bar\"", "foo\"");
- this.verifyUndelimit("\"foo\"\"", "foo\"");
+ @Override
+ protected void verifyConvertToXmlAttributeValue(String expected, String string) {
+ StringBuffer sb = new StringBuffer();
+ StringBufferTools.convertToXmlAttributeValue(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertToXmlAttributeValue(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUndelimit(String s, String expected) {
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValue(String expected, String string) {
StringBuffer sb = new StringBuffer();
- StringBufferTools.undelimit(sb, s);
+ StringBufferTools.convertToDoubleQuotedXmlAttributeValue(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuffer();
- StringBufferTools.undelimit(sb, s.toCharArray());
+ StringBufferTools.convertToDoubleQuotedXmlAttributeValue(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testUndelimitCount() {
- this.verifyUndelimitCount("\"foo\"", 2, "o");
- this.verifyUndelimitCount("\"\"\"\"", 2, "");
- this.verifyUndelimitCount("XXfooXX", 2, "foo");
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValueContent(String expected, String string) {
+ StringBuffer sb = new StringBuffer();
+ StringBufferTools.convertToDoubleQuotedXmlAttributeValueContent(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertToDoubleQuotedXmlAttributeValueContent(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUndelimitCount(String s, int count, String expected) {
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValue(String expected, String string) {
StringBuffer sb = new StringBuffer();
- StringBufferTools.undelimit(sb, s, count);
+ StringBufferTools.convertToSingleQuotedXmlAttributeValue(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuffer();
- StringBufferTools.undelimit(sb, s.toCharArray(), count);
+ StringBufferTools.convertToSingleQuotedXmlAttributeValue(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testConvertToJavaStringLiteral() {
- this.verifyConvertToJavaStringLiteral("", "\"\"");
- this.verifyConvertToJavaStringLiteral("\"\"", "\"\\\"\\\"\"");
- this.verifyConvertToJavaStringLiteral("'foo'", "\"'foo'\"");
- this.verifyConvertToJavaStringLiteral("foo\bbar", "\"foo\\bbar\"");
- this.verifyConvertToJavaStringLiteral("foo\n\tbar", "\"foo\\n\\tbar\"");
- this.verifyConvertToJavaStringLiteral("foo\"bar", "\"foo\\\"bar\"");
- this.verifyConvertToJavaStringLiteral("foo\\bar", "\"foo\\\\bar\"");
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValueContent(String expected, String string) {
+ StringBuffer sb = new StringBuffer();
+ StringBufferTools.convertToSingleQuotedXmlAttributeValueContent(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertToSingleQuotedXmlAttributeValueContent(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertToJavaStringLiteral(String s, String expected) {
+ @Override
+ protected void verifyConvertToXmlElementText(String expected, String string) {
StringBuffer sb = new StringBuffer();
- StringBufferTools.convertToJavaStringLiteral(sb, s);
+ StringBufferTools.convertToXmlElementText(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuffer();
- StringBufferTools.convertToJavaStringLiteral(sb, s.toCharArray());
+ StringBufferTools.convertToXmlElementText(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testConvertToJavaStringLiteralContent() {
- this.verifyConvertToJavaStringLiteralContent("", "");
- this.verifyConvertToJavaStringLiteralContent("\"\"", "\\\"\\\"");
- this.verifyConvertToJavaStringLiteralContent("'foo'", "'foo'");
- this.verifyConvertToJavaStringLiteralContent("foo\bbar", "foo\\bbar");
- this.verifyConvertToJavaStringLiteralContent("foo\n\tbar", "foo\\n\\tbar");
- this.verifyConvertToJavaStringLiteralContent("foo\"bar", "foo\\\"bar");
- this.verifyConvertToJavaStringLiteralContent("foo\\bar", "foo\\\\bar");
+ @Override
+ protected void verifyConvertToXmlElementCDATA(String expected, String string) {
+ StringBuffer sb = new StringBuffer();
+ StringBufferTools.convertToXmlElementCDATA(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuffer();
+ StringBufferTools.convertToXmlElementCDATA(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertToJavaStringLiteralContent(String s, String expected) {
+ @Override
+ protected void verifyConvertToXmlElementCDATAContent(String expected, String string) {
StringBuffer sb = new StringBuffer();
- StringBufferTools.convertToJavaStringLiteralContent(sb, s);
+ StringBufferTools.convertToXmlElementCDATAContent(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuffer();
- StringBufferTools.convertToJavaStringLiteralContent(sb, s.toCharArray());
+ StringBufferTools.convertToXmlElementCDATAContent(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
+
+ @Override
+ protected Class<?> getToolsClass() {
+ return StringBufferTools.class;
+ }
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBuilderToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBuilderToolsTests.java
index e5ce89fadf..0b33cb3c8a 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBuilderToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringBuilderToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,418 +9,498 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal;
-import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.internal.StringBuilderTools;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+import org.junit.Assert;
@SuppressWarnings("nls")
public class StringBuilderToolsTests
- extends TestCase
+ extends AbstractStringBuilderToolsTests
{
public StringBuilderToolsTests(String name) {
super(name);
}
- // ********** padding/truncating/centering/repeating **********
-
- public void testCenter() {
- this.verifyCenter("fred", "fred", 4);
- this.verifyCenter(" fred ", "fred", 6);
- this.verifyCenter(" fred ", "fred", 7);
- this.verifyCenter("re", "fred", 2);
- this.verifyCenter("fre", "fred", 3);
+ @Override
+ protected void verifyConvertToCharArray(String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ sb.append(string);
+ Assert.assertArrayEquals(string.toCharArray(), StringBuilderTools.convertToCharArray(sb));
}
- private void verifyCenter(String expected, String s, int len) {
+ @Override
+ protected void verifyReverse(String expected, String string) {
StringBuilder sb;
sb = new StringBuilder();
- StringBuilderTools.center(sb, s, len);
+ StringBuilderTools.reverse(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuilder();
- StringBuilderTools.center(sb, s.toCharArray(), len);
+ StringBuilderTools.reverse(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testPad() {
+ @Override
+ protected void verifyCenter(String expected, String s, int len) {
StringBuilder sb;
sb = new StringBuilder();
- StringBuilderTools.pad(sb, "fred", 4);
- assertEquals("fred", sb.toString());
-
- sb = new StringBuilder();
- StringBuilderTools.pad(sb, "fred", 6);
- assertEquals("fred ", sb.toString());
+ StringBuilderTools.center(sb, s, len);
+ assertEquals(expected, sb.toString());
sb = new StringBuilder();
- boolean exThrown = false;
- try {
- StringBuilderTools.pad(sb, "fred", 2);
- fail();
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
+ StringBuilderTools.center(sb, s.toCharArray(), len);
+ assertEquals(expected, sb.toString());
}
- public void testFit() {
- this.verifyFit("fred", "fred", 4);
- this.verifyFit("fred ", "fred", 6);
- this.verifyFit("fr", "fred", 2);
- }
+ @Override
+ protected void verifyPad(String expected, String string, int length) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ StringBuilderTools.pad(sb, string, length);
+ assertEquals(expected, sb.toString());
- private void verifyFit(String expected, String string, int length) {
- StringBuilder sb = new StringBuilder();
- StringBuilderTools.fit(sb, string, length);
+ sb = new StringBuilder();
+ StringBuilderTools.pad(sb, string.toCharArray(), length);
assertEquals(expected, sb.toString());
}
- public void testZeroPad() {
+ @Override
+ protected void verifyFit(String expected, String string, int length) {
StringBuilder sb;
sb = new StringBuilder();
- StringBuilderTools.zeroPad(sb, "1234", 4);
- assertEquals("1234", sb.toString());
+ StringBuilderTools.fit(sb, string, length);
+ assertEquals(expected, sb.toString());
sb = new StringBuilder();
- StringBuilderTools.zeroPad(sb, "1234", 6);
- assertEquals("001234", sb.toString());
+ StringBuilderTools.fit(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
+ }
+ @Override
+ protected void verifyZeroPad(String expected, String string, int length) {
+ StringBuilder sb;
sb = new StringBuilder();
- boolean exThrown = false;
- try {
- StringBuilderTools.zeroPad(sb, "1234", 2);
- fail();
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
- }
+ StringBuilderTools.zeroPad(sb, string, length);
+ assertEquals(expected, sb.toString());
- public void testZeroFit() {
- this.verifyZeroFit("1234", "1234", 4);
- this.verifyZeroFit("001234", "1234", 6);
- this.verifyZeroFit("34", "1234", 2);
+ sb = new StringBuilder();
+ StringBuilderTools.zeroPad(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- private void verifyZeroFit(String expected, String string, int length) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyZeroFit(String expected, String string, int length) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.zeroFit(sb, string, length);
assertEquals(expected, sb.toString());
- }
- public void testRepeat() {
- this.verifyRepeat("", "1234", 0);
- this.verifyRepeat("12", "1234", 2);
- this.verifyRepeat("1234", "1234", 4);
- this.verifyRepeat("123412", "1234", 6);
- this.verifyRepeat("12341234", "1234", 8);
- this.verifyRepeat("123412341234123412341", "1234", 21);
+ sb = new StringBuilder();
+ StringBuilderTools.zeroFit(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- private void verifyRepeat(String expected, String string, int length) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyRepeat(String expected, String string, int length) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.repeat(sb, string, length);
assertEquals(expected, sb.toString());
- }
-
- public void testRepeatCharArray() {
- this.verifyRepeatCharArray("", "1234", 0);
- this.verifyRepeatCharArray("12", "1234", 2);
- this.verifyRepeatCharArray("1234", "1234", 4);
- this.verifyRepeatCharArray("123412", "1234", 6);
- this.verifyRepeatCharArray("12341234", "1234", 8);
- this.verifyRepeatCharArray("123412341234123412341", "1234", 21);
- }
- private void verifyRepeatCharArray(String expected, String string, int length) {
- StringBuilder sb = new StringBuilder();
+ sb = new StringBuilder();
StringBuilderTools.repeat(sb, string.toCharArray(), length);
assertEquals(expected, sb.toString());
}
- public void testSeparateOnStringCharInt() {
- this.verifySeparate("012345", '-', 22, "012345");
- this.verifySeparate("012345", '-', 6, "012345");
- this.verifySeparate("012345", '-', 5, "01234-5");
- this.verifySeparate("012345", '-', 4, "0123-45");
- this.verifySeparate("012345", '-', 3, "012-345");
- this.verifySeparate("012345", '-', 2, "01-23-45");
- this.verifySeparate("012345", '-', 1, "0-1-2-3-4-5");
- }
-
- private void verifySeparate(String string, char separator, int segmentLength, String expected) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifySeparate(String expected, String string, char separator, int segmentLength) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.separate(sb, string, separator, segmentLength);
assertEquals(expected, sb.toString());
- }
- public void testSeparateOnCharArrayCharInt() {
- this.verifySeparateCharArray("012345", '-', 22, "012345");
- this.verifySeparateCharArray("012345", '-', 6, "012345");
- this.verifySeparateCharArray("012345", '-', 5, "01234-5");
- this.verifySeparateCharArray("012345", '-', 4, "0123-45");
- this.verifySeparateCharArray("012345", '-', 3, "012-345");
- this.verifySeparateCharArray("012345", '-', 2, "01-23-45");
- this.verifySeparateCharArray("012345", '-', 1, "0-1-2-3-4-5");
- }
-
- private void verifySeparateCharArray(String string, char separator, int segmentLength, String expected) {
- StringBuilder sb = new StringBuilder();
+ sb = new StringBuilder();
StringBuilderTools.separate(sb, string.toCharArray(), separator, segmentLength);
assertEquals(expected, sb.toString());
}
- public void testDelimit() {
- this.verifyDelimit("Employee", "123", "123Employee123");
- this.verifyDelimit("123", "123", "123123123");
- this.verifyDelimit("", "123", "123123");
- }
-
- private void verifyDelimit(String string, String delimiter, String expectedString) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyDelimit(String expected, String string, String delimiter) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.delimit(sb, string, delimiter);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testQuote() {
- this.verifyQuote("Employee", "\"Employee\"");
- this.verifyQuote("123", "\"123\"");
- this.verifyQuote("", "\"\"");
- this.verifyQuote("Emp\"loyee", "\"Emp\"\"loyee\"");
+ sb = new StringBuilder();
+ StringBuilderTools.delimit(sb, string.toCharArray(), delimiter.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyQuote(String string, String expectedString) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyQuote(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.quote(sb, string);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testRemoveFirstOccurrence() {
- this.verifyRemoveFirstOccurrence("Emplo&yee", '&', "Employee");
- this.verifyRemoveFirstOccurrence("Emplo&yee&", '&', "Employee&");
- this.verifyRemoveFirstOccurrence("Employee &Foo", '&', "Employee Foo");
- this.verifyRemoveFirstOccurrence("Employee&", '&', "Employee");
- this.verifyRemoveFirstOccurrence("&Employee", '&', "Employee");
+ sb = new StringBuilder();
+ StringBuilderTools.quote(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveFirstOccurrence(String string, char charToRemove, String expectedString) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyRemoveFirstOccurrence(String expected, String string, char charToRemove) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.removeFirstOccurrence(sb, string, charToRemove);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testRemoveAllOccurrences() {
- this.verifyRemoveAllOccurrences("Employee Fred", ' ', "EmployeeFred");
- this.verifyRemoveAllOccurrences(" Employee ", ' ', "Employee");
- this.verifyRemoveAllOccurrences("Employee Foo", ' ', "EmployeeFoo");
- this.verifyRemoveAllOccurrences(" Emp loyee Foo", ' ', "EmployeeFoo");
+ sb = new StringBuilder();
+ StringBuilderTools.removeFirstOccurrence(sb, string.toCharArray(), charToRemove);
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveAllOccurrences(String string, char charToRemove, String expectedString) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyRemoveAllOccurrences(String expected, String string, char charToRemove) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.removeAllOccurrences(sb, string, charToRemove);
- assertEquals(expectedString, sb.toString());
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.removeAllOccurrences(sb, string.toCharArray(), charToRemove);
+ assertEquals(expected, sb.toString());
}
- public void testRemoveAllWhitespace() {
- this.verifyRemoveAllWhitespace("Employee Fred\t", "EmployeeFred");
- this.verifyRemoveAllWhitespace("\tEmployee\n", "Employee");
- this.verifyRemoveAllWhitespace("Employee \t Foo", "EmployeeFoo");
- this.verifyRemoveAllWhitespace(" Emp\tloyee \n Foo", "EmployeeFoo");
+ @Override
+ protected void verifyRemoveAllSpaces(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ StringBuilderTools.removeAllSpaces(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.removeAllSpaces(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveAllWhitespace(String string, String expectedString) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyRemoveAllWhitespace(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.removeAllWhitespace(sb, string);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testCompressWhitespace() {
- this.verifyCompressWhitespace("Employee Fred\t", "Employee Fred ");
- this.verifyCompressWhitespace("\tEmployee \n", " Employee ");
- this.verifyCompressWhitespace("Employee \t Foo", "Employee Foo");
- this.verifyCompressWhitespace(" Emp\tloyee \n Foo ", " Emp loyee Foo ");
+ sb = new StringBuilder();
+ StringBuilderTools.removeAllWhitespace(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCompressWhitespace(String string, String expectedString) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyCompressWhitespace(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.compressWhitespace(sb, string);
- assertEquals(expectedString, sb.toString());
- }
+ assertEquals(expected, sb.toString());
- public void testCapitalizeOnString() {
- this.verifyCapitalizeOnString("Oracle", "Oracle");
- this.verifyCapitalizeOnString("Oracle", "oracle");
- this.verifyCapitalizeOnString(" ", " ");
- this.verifyCapitalizeOnString("ORACLE", "ORACLE");
- this.verifyCapitalizeOnString("", "");
- this.verifyCapitalizeOnString("A", "a");
- this.verifyCapitalizeOnString("\u00C9cole", "\u00E9cole"); // e'cole -> E'cole
+ sb = new StringBuilder();
+ StringBuilderTools.compressWhitespace(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCapitalizeOnString(String expected, String string) {
- StringBuilder sb = new StringBuilder();
+ @Override
+ protected void verifyCapitalize(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
StringBuilderTools.capitalize(sb, string);
assertEquals(expected, sb.toString());
- }
- public void testCapitalizeOnCharArray() {
- this.verifyCapitalizeOnCharArray("Oracle", new char[] { 'O', 'r', 'a', 'c', 'l', 'e' });
- this.verifyCapitalizeOnCharArray("Oracle", new char[] { 'o', 'r', 'a', 'c', 'l', 'e' });
- this.verifyCapitalizeOnCharArray(" ", new char[] { ' ', ' ', ' ' });
- this.verifyCapitalizeOnCharArray("ORACLE", new char[] { 'O', 'R', 'A', 'C', 'L', 'E' });
- this.verifyCapitalizeOnCharArray("", new char[0]);
- this.verifyCapitalizeOnCharArray("A", new char[] { 'a' });
- this.verifyCapitalizeOnCharArray("\u00C9cole", new char[] { '\u00E9', 'c', 'o', 'l', 'e' });
+ sb = new StringBuilder();
+ StringBuilderTools.capitalize(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCapitalizeOnCharArray(String expected, char[] string) {
- StringBuilder sb = new StringBuilder();
- StringBuilderTools.capitalize(sb, string);
+ @Override
+ protected void verifyUncapitalize(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ StringBuilderTools.uncapitalize(sb, string);
assertEquals(expected, sb.toString());
- }
- public void testUncapitalizeOnString() {
- this.verifyUncapitalizeOnString("oracle", "Oracle");
- this.verifyUncapitalizeOnString("oracle", "oracle");
- this.verifyUncapitalizeOnString(" ", " ");
- this.verifyUncapitalizeOnString("ORACLE", "ORACLE");
- this.verifyUncapitalizeOnString("", "");
- this.verifyUncapitalizeOnString("a", "A");
- this.verifyUncapitalizeOnString("\u00E9cole", "\u00C9cole"); // E'cole -> e'cole
+ sb = new StringBuilder();
+ StringBuilderTools.uncapitalize(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUncapitalizeOnString(String expected, String string) {
- StringBuilder sb = new StringBuilder();
- StringBuilderTools.uncapitalize(sb, string);
+ @Override
+ protected void verifyConvertToHexString(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ StringBuilderTools.convertToHexString(sb, string.getBytes());
assertEquals(expected, sb.toString());
}
- public void testUncapitalizeOnCharArray() {
- this.verifyUncapitalizeOnCharArray("oracle", new char[] { 'O', 'r', 'a', 'c', 'l', 'e' });
- this.verifyUncapitalizeOnCharArray("oracle", new char[] { 'o', 'r', 'a', 'c', 'l', 'e' });
- this.verifyUncapitalizeOnCharArray(" ", new char[] { ' ', ' ', ' ' });
- this.verifyUncapitalizeOnCharArray("ORACLE", new char[] { 'O', 'R', 'A', 'C', 'L', 'E' });
- this.verifyUncapitalizeOnCharArray("", new char[0]);
- this.verifyUncapitalizeOnCharArray("a", new char[] { 'A' });
- this.verifyUncapitalizeOnCharArray("\u00E9cole", new char[] { '\u00C9', 'c', 'o', 'l', 'e' });
+ @Override
+ protected void verifyConvertCamelCaseToAllCaps(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ StringBuilderTools.convertCamelCaseToAllCaps(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertCamelCaseToAllCaps(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUncapitalizeOnCharArray(String expected, char[] string) {
- StringBuilder sb = new StringBuilder();
- StringBuilderTools.uncapitalize(sb, string);
+ @Override
+ protected void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int maxLength) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ StringBuilderTools.convertCamelCaseToAllCaps(sb, string, maxLength);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertCamelCaseToAllCaps(sb, string.toCharArray(), maxLength);
assertEquals(expected, sb.toString());
}
- public void testConvertToHexString() {
- this.verifyConvertToHexString("74657374", "test"); // UTF-8 values
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ StringBuilderTools.convertAllCapsToCamelCase(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertAllCapsToCamelCase(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testConvertToHexString_negative() {
- this.verifyConvertToHexString(this.getHexCafe(), "caf\u00E9"); // UTF-8 values
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string, boolean capFirst) {
+ StringBuilder sb;
+ sb = new StringBuilder();
+ StringBuilderTools.convertAllCapsToCamelCase(sb, string, capFirst);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertAllCapsToCamelCase(sb, string.toCharArray(), capFirst);
+ assertEquals(expected, sb.toString());
}
- private String getHexCafe() {
- return StringToolsTests.getHexCafe();
+ @Override
+ protected void verifyUndelimit(String expected, String s) {
+ StringBuilder sb = new StringBuilder();
+ StringBuilderTools.undelimit(sb, s);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.undelimit(sb, s.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertToHexString(String expected, String string) {
+ @Override
+ protected void verifyUndelimitCount(String expected, String s, int count) {
StringBuilder sb = new StringBuilder();
- StringBuilderTools.convertToHexString(sb, string.getBytes());
+ StringBuilderTools.undelimit(sb, s, count);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.undelimit(sb, s.toCharArray(), count);
assertEquals(expected, sb.toString());
}
- public void testConvertCamelCaseToAllCaps() {
- this.verifyConvertCamelCaseToAllCaps("TEST", "test");
- this.verifyConvertCamelCaseToAllCaps("TEST", "TEST");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "testTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "TestTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "testTESTTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "TestTESTTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST_T", "TestTESTTestT");
+ @Override
+ protected void verifyConvertToJavaStringLiteral(String expected, String s) {
+ StringBuilder sb = new StringBuilder();
+ StringBuilderTools.convertToJavaStringLiteral(sb, s);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertToJavaStringLiteral(sb, s.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertCamelCaseToAllCaps(String expected, String string) {
+ @Override
+ protected void verifyConvertToJavaStringLiteralContent(String expected, String s) {
StringBuilder sb = new StringBuilder();
- StringBuilderTools.convertCamelCaseToAllCaps(sb, string);
+ StringBuilderTools.convertToJavaStringLiteralContent(sb, s);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertToJavaStringLiteralContent(sb, s.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testUndelimit() {
- this.verifyUndelimit("\"foo\"", "foo");
- this.verifyUndelimit("\"\"", "");
- this.verifyUndelimit("'foo'", "foo");
- this.verifyUndelimit("\"fo\"\"o\"", "fo\"o");
- this.verifyUndelimit("\"foo\"\"\"", "foo\"");
- this.verifyUndelimit("\"\"\"foo\"", "\"foo");
- this.verifyUndelimit("[foo]", "foo");
- this.verifyUndelimit("\"\"\"", "\"");
- this.verifyUndelimit("\"foo\"bar\"", "foo\"");
- this.verifyUndelimit("\"foo\"\"", "foo\"");
+ @Override
+ protected void verifyConvertToXmlAttributeValue(String expected, String string) {
+ StringBuilder sb = new StringBuilder();
+ StringBuilderTools.convertToXmlAttributeValue(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertToXmlAttributeValue(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUndelimit(String s, String expected) {
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValue(String expected, String string) {
StringBuilder sb = new StringBuilder();
- StringBuilderTools.undelimit(sb, s);
+ StringBuilderTools.convertToDoubleQuotedXmlAttributeValue(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuilder();
- StringBuilderTools.undelimit(sb, s.toCharArray());
+ StringBuilderTools.convertToDoubleQuotedXmlAttributeValue(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testUndelimitCount() {
- this.verifyUndelimitCount("\"foo\"", 2, "o");
- this.verifyUndelimitCount("\"\"\"\"", 2, "");
- this.verifyUndelimitCount("XXfooXX", 2, "foo");
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValueContent(String expected, String string) {
+ StringBuilder sb = new StringBuilder();
+ StringBuilderTools.convertToDoubleQuotedXmlAttributeValueContent(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertToDoubleQuotedXmlAttributeValueContent(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUndelimitCount(String s, int count, String expected) {
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValue(String expected, String string) {
StringBuilder sb = new StringBuilder();
- StringBuilderTools.undelimit(sb, s, count);
+ StringBuilderTools.convertToSingleQuotedXmlAttributeValue(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuilder();
- StringBuilderTools.undelimit(sb, s.toCharArray(), count);
+ StringBuilderTools.convertToSingleQuotedXmlAttributeValue(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testConvertToJavaStringLiteral() {
- this.verifyConvertToJavaStringLiteral("", "\"\"");
- this.verifyConvertToJavaStringLiteral("\"\"", "\"\\\"\\\"\"");
- this.verifyConvertToJavaStringLiteral("'foo'", "\"'foo'\"");
- this.verifyConvertToJavaStringLiteral("foo\bbar", "\"foo\\bbar\"");
- this.verifyConvertToJavaStringLiteral("foo\n\tbar", "\"foo\\n\\tbar\"");
- this.verifyConvertToJavaStringLiteral("foo\"bar", "\"foo\\\"bar\"");
- this.verifyConvertToJavaStringLiteral("foo\\bar", "\"foo\\\\bar\"");
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValueContent(String expected, String string) {
+ StringBuilder sb = new StringBuilder();
+ StringBuilderTools.convertToSingleQuotedXmlAttributeValueContent(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertToSingleQuotedXmlAttributeValueContent(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertToJavaStringLiteral(String s, String expected) {
+ @Override
+ protected void verifyConvertToXmlElementText(String expected, String string) {
StringBuilder sb = new StringBuilder();
- StringBuilderTools.convertToJavaStringLiteral(sb, s);
+ StringBuilderTools.convertToXmlElementText(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuilder();
- StringBuilderTools.convertToJavaStringLiteral(sb, s.toCharArray());
+ StringBuilderTools.convertToXmlElementText(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testConvertToJavaStringLiteralContent() {
- this.verifyConvertToJavaStringLiteralContent("", "");
- this.verifyConvertToJavaStringLiteralContent("\"\"", "\\\"\\\"");
- this.verifyConvertToJavaStringLiteralContent("'foo'", "'foo'");
- this.verifyConvertToJavaStringLiteralContent("foo\bbar", "foo\\bbar");
- this.verifyConvertToJavaStringLiteralContent("foo\n\tbar", "foo\\n\\tbar");
- this.verifyConvertToJavaStringLiteralContent("foo\"bar", "foo\\\"bar");
- this.verifyConvertToJavaStringLiteralContent("foo\\bar", "foo\\\\bar");
+ @Override
+ protected void verifyConvertToXmlElementCDATA(String expected, String string) {
+ StringBuilder sb = new StringBuilder();
+ StringBuilderTools.convertToXmlElementCDATA(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringBuilder();
+ StringBuilderTools.convertToXmlElementCDATA(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertToJavaStringLiteralContent(String s, String expected) {
+ @Override
+ protected void verifyConvertToXmlElementCDATAContent(String expected, String string) {
StringBuilder sb = new StringBuilder();
- StringBuilderTools.convertToJavaStringLiteralContent(sb, s);
+ StringBuilderTools.convertToXmlElementCDATAContent(sb, string);
assertEquals(expected, sb.toString());
sb = new StringBuilder();
- StringBuilderTools.convertToJavaStringLiteralContent(sb, s.toCharArray());
+ StringBuilderTools.convertToXmlElementCDATAContent(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
+
+ @Override
+ protected Class<?> getToolsClass() {
+ return StringBuilderTools.class;
+ }
+
+ // ********** StringBuilderTools-specific **********
+
+ public void testAppendObjectArray_null() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Object[] array = null;
+ StringBuilderTools.append(sb, array);
+ assertEquals("null", sb.toString());
+ }
+
+ public void testAppendObjectArray_empty() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Object[] array = new Object[0];
+ StringBuilderTools.append(sb, array);
+ assertEquals("[]", sb.toString());
+ }
+
+ public void testAppendObjectArray_one() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Object[] array = new Object[] {"foo"};
+ StringBuilderTools.append(sb, array);
+ assertEquals("[foo]", sb.toString());
+ }
+
+ public void testAppendObjectArray_multiple() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Object[] array = new Object[] {"foo", "bar", "baz"};
+ StringBuilderTools.append(sb, array);
+ assertEquals("[foo, bar, baz]", sb.toString());
+ }
+
+ public void testAppendIterable_empty() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Iterable<Object> iterable = IterableTools.iterable(new Object[0]);
+ StringBuilderTools.append(sb, iterable);
+ assertEquals("[]", sb.toString());
+ }
+
+ public void testAppendIterable_one() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Iterable<Object> iterable = IterableTools.iterable(new Object[] {"foo"});
+ StringBuilderTools.append(sb, iterable);
+ assertEquals("[foo]", sb.toString());
+ }
+
+ public void testAppendIterable_multiple() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Iterable<Object> iterable = IterableTools.iterable(new Object[] {"foo", "bar", "baz"});
+ StringBuilderTools.append(sb, iterable);
+ assertEquals("[foo, bar, baz]", sb.toString());
+ }
+
+ public void testAppendHashCodeToString() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Object object = new Object();
+ StringBuilderTools.appendHashCodeToString(sb, object);
+ String string = sb.toString();
+ String prefix = "Object[";
+ assertTrue(string.startsWith(prefix));
+ assertTrue(string.endsWith("]"));
+ for (int i = prefix.length(); i < string.length() - 1; i++) {
+ char c = string.charAt(i);
+ assertTrue(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F')) || (c == '-'));
+ }
+ }
+
+ public void testAppendIdentityToString() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ Object object = new Object();
+ StringBuilderTools.appendIdentityToString(sb, object); // "java.lang.Object@3cb5cdba"
+ String string = sb.toString();
+ String prefix = "java.lang.Object@";
+ assertTrue(string.startsWith(prefix));
+ for (int i = prefix.length(); i < string.length(); i++) {
+ char c = string.charAt(i);
+ assertTrue(((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')));
+ }
+ }
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringToolsTests.java
index b20486b736..b73218c99c 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StringToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,770 +9,454 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal;
-import java.util.Arrays;
-import junit.framework.TestCase;
-import org.eclipse.jpt.common.utility.internal.ByteArrayTools;
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
-import org.eclipse.jpt.common.utility.internal.SystemTools;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+import org.eclipse.jpt.common.utility.predicate.Predicate;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
@SuppressWarnings("nls")
public class StringToolsTests
- extends TestCase
+ extends AbstractStringToolsTests
{
public StringToolsTests(String name) {
super(name);
}
- // ********** padding/truncating/centering/repeating **********
-
- public void testCenter() {
- assertEquals("fred", StringTools.center("fred", 4));
- assertEquals(" fred ", StringTools.center("fred", 6));
- assertEquals(" fred ", StringTools.center("fred", 7));
- assertEquals("re", StringTools.center("fred", 2));
- assertEquals("fre", StringTools.center("fred", 3));
+ @Override
+ protected String CR() {
+ return StringTools.CR;
}
- public void testPad() {
- assertEquals("fred", StringTools.pad("fred", 4));
- assertEquals("fred ", StringTools.pad("fred", 6));
- boolean exThrown = false;
- try {
- assertEquals("fr", StringTools.pad("fred", 2));
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
+ @Override
+ protected void verifyReverse(String expected, String string) {
+ assertEquals(expected, StringTools.reverse(string));
}
- public void testFit() {
- assertEquals("fred", StringTools.fit("fred", 4));
- assertEquals("fred ", StringTools.fit("fred", 6));
- assertEquals("fr", StringTools.fit("fred", 2));
+ @Override
+ protected void verifyLast(char expected, String string) {
+ assertEquals(expected, StringTools.last(string));
}
- public void testZeroPad() {
- assertEquals("1234", StringTools.zeroPad("1234", 4));
- assertEquals("001234", StringTools.zeroPad("1234", 6));
- boolean exThrown = false;
- try {
- assertEquals("12", StringTools.zeroPad("1234", 2));
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
+ @Override
+ protected void verifyConcatenate(String expected, String[] array) {
+ assertEquals(expected, StringTools.concatenate(array));
+ Iterable<String> iterable = IterableTools.iterable(array);
+ assertEquals(expected, StringTools.concatenate(iterable));
+ assertEquals(expected, StringTools.concatenate(iterable.iterator()));
}
- public void testZeroFit() {
- assertEquals("1234", StringTools.zeroFit("1234", 4));
- assertEquals("001234", StringTools.zeroFit("1234", 6));
- assertEquals("34", StringTools.zeroFit("1234", 2));
+ @Override
+ protected void verifyConcatenate(String expected, String[] array, String delim) {
+ assertEquals(expected, StringTools.concatenate(array, delim));
+ Iterable<String> iterable = IterableTools.iterable(array);
+ assertEquals(expected, StringTools.concatenate(iterable, delim));
+ assertEquals(expected, StringTools.concatenate(iterable.iterator(), delim));
}
- public void testRepeat() {
- this.verifyRepeat("", "1234", 0);
- this.verifyRepeat("12", "1234", 2);
- this.verifyRepeat("1234", "1234", 4);
- this.verifyRepeat("123412", "1234", 6);
- this.verifyRepeat("12341234", "1234", 8);
- this.verifyRepeat("123412341234123412341", "1234", 21);
+ @Override
+ protected void verifyCenter(String expected, String string, int len) {
+ assertEquals(expected, StringTools.center(string, len));
}
- private void verifyRepeat(String expected, String string, int length) {
- assertEquals(expected, StringTools.repeat(string, length));
+ @Override
+ protected void verifyPad(String expected, String string, int len) {
+ assertEquals(expected, StringTools.pad(string, len));
}
- // ********** separating **********
-
- public void testSeparateCharInt() {
- this.verifySeparate("012345", '-', 22, "012345");
- this.verifySeparate("012345", '-', 6, "012345");
- this.verifySeparate("012345", '-', 5, "01234-5");
- this.verifySeparate("012345", '-', 4, "0123-45");
- this.verifySeparate("012345", '-', 3, "012-345");
- this.verifySeparate("012345", '-', 2, "01-23-45");
- this.verifySeparate("012345", '-', 1, "0-1-2-3-4-5");
+ @Override
+ protected void verifyFit(String expected, String string, int len) {
+ assertEquals(expected, StringTools.fit(string, len));
}
- private void verifySeparate(String string, char separator, int segmentLength, String expected) {
- assertEquals(expected, StringTools.separate(string, separator, segmentLength));
+ @Override
+ protected void verifyZeroPad(String expected, String string, int len) {
+ assertEquals(expected, StringTools.zeroPad(string, len));
}
- // ********** delimiting **********
-
- public void testDelimit() {
- this.verifyDelimit("Employee", "123", "123Employee123");
- this.verifyDelimit("123", "123", "123123123");
- this.verifyDelimit("", "123", "123123");
+ @Override
+ protected void verifyZeroFit(String expected, String string, int len) {
+ assertEquals(expected, StringTools.zeroFit(string, len));
}
- private void verifyDelimit(String string, String delimiter, String expectedString) {
- assertEquals(expectedString, StringTools.delimit(string, delimiter));
+ @Override
+ protected void verifyRepeat(String expected, String string, int length) {
+ assertEquals(expected, StringTools.repeat(string, length));
}
- public void testQuote() {
- this.verifyQuote("Employee", "\"Employee\"");
- this.verifyQuote("123", "\"123\"");
- this.verifyQuote("", "\"\"");
- this.verifyQuote("Emp\"loyee", "\"Emp\"\"loyee\"");
+ @Override
+ protected void verifySeparate(String expected, String string, char separator, int segmentLength) {
+ assertEquals(expected, StringTools.separate(string, separator, segmentLength));
}
- private void verifyQuote(String string, String expectedString) {
- assertEquals(expectedString, StringTools.quote(string));
+ @Override
+ protected void verifyQuote(String expected, String string) {
+ assertEquals(expected, StringTools.quote(string));
}
- // ********** removing characters **********
-
- public void testRemoveFirstOccurrence() {
- this.verifyRemoveFirstOccurrence("Emplo&yee", '&', "Employee");
- this.verifyRemoveFirstOccurrence("Emplo&yee&", '&', "Employee&");
- this.verifyRemoveFirstOccurrence("Employee &Foo", '&', "Employee Foo");
- this.verifyRemoveFirstOccurrence("Employee&", '&', "Employee");
- this.verifyRemoveFirstOccurrence("&Employee", '&', "Employee");
+ @Override
+ protected void verifyCharDelimiter(String expected, String string, char delimiter) {
+ Transformer<String, String> transformer = this.buildCharDelimiter(delimiter);
+ assertEquals(expected, transformer.transform(string));
}
- private void verifyRemoveFirstOccurrence(String string, char charToRemove, String expectedString) {
- assertEquals(expectedString, StringTools.removeFirstOccurrence(string, charToRemove));
+ @Override
+ protected Transformer<String, String> buildCharDelimiter(char delimiter) {
+ return new StringTools.CharDelimiter(delimiter);
}
- public void testRemoveAllOccurrences() {
- this.verifyRemoveAllOccurrences("Employee Fred", ' ', "EmployeeFred");
- this.verifyRemoveAllOccurrences(" Employee ", ' ', "Employee");
- this.verifyRemoveAllOccurrences("Employee Foo", ' ', "EmployeeFoo");
- this.verifyRemoveAllOccurrences(" Emp loyee Foo", ' ', "EmployeeFoo");
+ @Override
+ protected void verifyDelimit(String expected, String string, String delimiter) {
+ assertEquals(expected, StringTools.delimit(string, delimiter));
}
- private void verifyRemoveAllOccurrences(String string, char charToRemove, String expectedString) {
- assertEquals(expectedString, StringTools.removeAllOccurrences(string, charToRemove));
+ @Override
+ protected void verifyStringDelimiter(String expected, String string, String delimiter) {
+ Transformer<String, String> transformer = this.buildStringDelimiter(delimiter);
+ assertEquals(expected, transformer.transform(string));
}
- public void testRemoveAllWhitespace() {
- this.verifyRemoveAllWhitespace("Employee Fred\t", "EmployeeFred");
- this.verifyRemoveAllWhitespace("\tEmployee\n", "Employee");
- this.verifyRemoveAllWhitespace("Employee \t Foo", "EmployeeFoo");
- this.verifyRemoveAllWhitespace(" Emp\tloyee \n Foo", "EmployeeFoo");
+ @Override
+ protected Transformer<String, String> buildStringDelimiter(String string) {
+ return new StringTools.StringDelimiter(string);
}
- private void verifyRemoveAllWhitespace(String string, String expectedString) {
- assertEquals(expectedString, StringTools.removeAllWhitespace(string));
+ @Override
+ protected void verifyRemoveFirstOccurrence(String expected, String string, char charToRemove) {
+ assertEquals(expected, StringTools.removeFirstOccurrence(string, charToRemove));
}
- public void testCompressWhitespace() {
- this.verifyCompressWhitespace("Employee Fred\t", "Employee Fred ");
- this.verifyCompressWhitespace("\tEmployee \n", " Employee ");
- this.verifyCompressWhitespace("Employee \t Foo", "Employee Foo");
- this.verifyCompressWhitespace(" Emp\tloyee \n Foo ", " Emp loyee Foo ");
+ @Override
+ protected void verifyRemoveAllOccurrences(String expected, String string, char charToRemove) {
+ assertEquals(expected, StringTools.removeAllOccurrences(string, charToRemove));
}
- private void verifyCompressWhitespace(String string, String expectedString) {
- assertEquals(expectedString, StringTools.compressWhitespace(string));
+ @Override
+ protected void verifyRemoveAllSpaces(String expected, String string) {
+ assertEquals(expected, StringTools.removeAllSpaces(string));
}
- // ********** common prefix **********
-
- public void testCommonPrefixLength() {
- assertEquals(3, StringTools.commonPrefixLength("fooZZZ", "fooBBB"));
- assertEquals(3, StringTools.commonPrefixLength("foo", "fooBBB"));
- assertEquals(3, StringTools.commonPrefixLength("fooZZZ", "foo"));
- assertEquals(3, StringTools.commonPrefixLength("foo", "foo"));
+ @Override
+ protected void verifyRemoveAllWhitespace(String expected, String string) {
+ assertEquals(expected, StringTools.removeAllWhitespace(string));
}
- public void testCommonPrefixLengthMax() {
- assertEquals(2, StringTools.commonPrefixLength("fooZZZ", "fooBBB", 2));
- assertEquals(2, StringTools.commonPrefixLength("foo", "fooBBB", 2));
- assertEquals(2, StringTools.commonPrefixLength("fooZZZ", "foo", 2));
- assertEquals(2, StringTools.commonPrefixLength("foo", "foo", 2));
+ @Override
+ protected void verifyCompressWhitespace(String expected, String string) {
+ assertEquals(expected, StringTools.compressWhitespace(string));
}
- // ********** capitalization **********
+ @Override
+ protected void verifyCommonPrefixLength(int expected, String string1, String string2) {
+ assertEquals(expected, StringTools.commonPrefixLength(string1, string2));
+ }
- public void testCapitalize() {
- this.verifyCapitalize("Oracle", "Oracle");
- this.verifyCapitalize("Oracle", "oracle");
- this.verifyCapitalize(" ", " ");
- this.verifyCapitalize("ORACLE", "ORACLE");
- this.verifyCapitalize("", "");
- this.verifyCapitalize("A", "a");
- this.verifyCapitalize("\u00C9cole", "\u00E9cole"); // e'cole -> E'cole
+ @Override
+ protected void verifyCommonPrefixLengthMax(int expected, String string1, String string2, int max) {
+ assertEquals(expected, StringTools.commonPrefixLength(string1, string2, max));
}
- private void verifyCapitalize(String expected, String string) {
+ @Override
+ protected void verifyCapitalize(String expected, String string) {
assertEquals(expected, StringTools.capitalize(string));
+ assertEquals(expected, StringTools.CAPITALIZER.transform(string));
}
- public void testUncapitalize() {
- this.verifyUncapitalize("oracle", "Oracle");
- this.verifyUncapitalize("oracle", "oracle");
- this.verifyUncapitalize(" ", " ");
- this.verifyUncapitalize("ORACLE", "ORACLE");
- this.verifyUncapitalize("", "");
- this.verifyUncapitalize("a", "A");
- this.verifyUncapitalize("\u00E9cole", "\u00C9cole"); // E'cole -> e'cole
+ @Override
+ protected Object getCapitalizer() {
+ return StringTools.CAPITALIZER;
}
- private void verifyUncapitalize(String expected, String string) {
+ @Override
+ protected void verifyUncapitalize(String expected, String string) {
assertEquals(expected, StringTools.uncapitalize(string));
+ assertEquals(expected, StringTools.UNCAPITALIZER.transform(string));
}
- // ********** queries **********
-
- public void testIsBlank() {
- assertTrue(StringTools.isBlank((String) null));
- assertTrue(StringTools.isBlank(""));
- assertTrue(StringTools.isBlank(" "));
- assertTrue(StringTools.isBlank(" \t\t "));
- assertTrue(StringTools.isBlank(" \t\t " + StringTools.CR));
+ @Override
+ protected Object getUncapitalizer() {
+ return StringTools.UNCAPITALIZER;
}
- public void testEquals() {
- assertTrue(ObjectTools.equals((String) null, (String) null));
- assertFalse(ObjectTools.equals(null, "asdf"));
- assertFalse(ObjectTools.equals("asdf", null));
- assertTrue(ObjectTools.equals("asdf", "asdf"));
- assertFalse(ObjectTools.equals("asdf", "ASDF"));
+ @Override
+ protected void verifyIsBlank(boolean expected, String string) {
+ assertEquals(expected, StringTools.isBlank(string));
+ assertEquals(expected, StringTools.IS_BLANK.evaluate(string));
}
- public void testEqualsIgnoreCase() {
- assertTrue(StringTools.equalsIgnoreCase((String) null, (String) null));
- assertFalse(StringTools.equalsIgnoreCase(null, "asdf"));
- assertFalse(StringTools.equalsIgnoreCase("asdf", null));
- assertTrue(StringTools.equalsIgnoreCase("asdf", "asdf"));
- assertTrue(StringTools.equalsIgnoreCase("asdf", "ASDF"));
+ @Override
+ protected Object getIsBlankPredicate() {
+ return StringTools.IS_BLANK;
}
- public void testStartsWithIgnoreCase() {
- assertTrue(StringTools.startsWithIgnoreCase("asdf", "as"));
- assertTrue(StringTools.startsWithIgnoreCase("asdf", "aS"));
- assertTrue(StringTools.startsWithIgnoreCase("asdf", ""));
- assertTrue(StringTools.startsWithIgnoreCase("asdf", "A"));
-
- assertFalse(StringTools.startsWithIgnoreCase("asdf", "bsdf"));
- assertFalse(StringTools.startsWithIgnoreCase("asdf", "g"));
- assertFalse(StringTools.startsWithIgnoreCase("asdf", "asdg"));
- assertFalse(StringTools.startsWithIgnoreCase("asdf", "asdfg"));
- assertFalse(StringTools.startsWithIgnoreCase("asdf", "asdfgggggg"));
+ @Override
+ protected void verifyIsNotBlank(boolean expected, String string) {
+ assertEquals(expected, StringTools.isNotBlank(string));
+ assertEquals(expected, StringTools.IS_NOT_BLANK.evaluate(string));
}
- public void testIsUppercase() {
- this.verifyIsUppercase("FOO");
- this.verifyIsUppercase("FOO2");
- this.verifyIsUppercase("F O O");
- this.denyIsUppercase("Foo");
- this.denyIsUppercase("");
+ @Override
+ protected Object getIsNotBlankPredicate() {
+ return StringTools.IS_NOT_BLANK;
}
- private void verifyIsUppercase(String s) {
- assertTrue(StringTools.isUppercase(s));
+ @Override
+ protected void verifyEqualsIgnoreCase(boolean expected, String string1, String string2) {
+ assertEquals(expected, StringTools.equalsIgnoreCase(string1, string2));
}
- private void denyIsUppercase(String s) {
- assertFalse(StringTools.isUppercase(s));
+ @Override
+ protected void verifyStartsWithIgnoreCase(boolean expected, String string, String prefix) {
+ assertEquals(expected, StringTools.startsWithIgnoreCase(string, prefix));
+ Predicate<String> predicate = new StringTools.StartsWithIgnoreCase(prefix);
+ assertEquals(expected, predicate.evaluate(string));
}
- public void testIsLowercase() {
- this.verifyIsLowercase("foo");
- this.verifyIsLowercase("foo2");
- this.verifyIsLowercase("f o o");
- this.denyIsLowercase("Foo");
- this.denyIsLowercase("");
+ @Override
+ protected void verifyIsUppercase(String string) {
+ assertTrue(StringTools.isUppercase(string));
}
- private void verifyIsLowercase(String s) {
- assertTrue(StringTools.isLowercase(s));
+ @Override
+ protected void denyIsUppercase(String string) {
+ assertFalse(StringTools.isUppercase(string));
}
- private void denyIsLowercase(String s) {
- assertFalse(StringTools.isLowercase(s));
+ @Override
+ protected void verifyIsLowercase(String string) {
+ assertTrue(StringTools.isLowercase(string));
}
- // ********** byte arrays **********
-
- public void testConvertHexStringToByteArray_empty() throws Exception {
- String s = StringTools.EMPTY_STRING;
- byte[] byteArray = StringTools.convertHexStringToByteArray(s);
- assertEquals(0, byteArray.length);
- assertTrue(Arrays.equals(ByteArrayTools.EMPTY_BYTE_ARRAY, byteArray));
+ @Override
+ protected void denyIsLowercase(String string) {
+ assertFalse(StringTools.isLowercase(string));
}
- public void testConvertHexStringToByteArray_oddLength() throws Exception {
- String s = "CAFEE";
- boolean exCaught = false;
- try {
- byte[] byteArray = StringTools.convertHexStringToByteArray(s);
- fail("bogus byte array: " + Arrays.toString(byteArray));
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
+ @Override
+ protected byte[] convertHexStringToByteArray(String string) {
+ return StringTools.convertHexStringToByteArray(string);
}
- public void testConvertHexStringToByteArray_illegalCharacter1() throws Exception {
- this.verifyConvertHexStringToByteArray_illegalCharacter("CAFEX0CAFEX0");
+ @Override
+ protected void verifyConvertCamelCaseToAllCaps(String expected, String string) {
+ assertEquals(expected, StringTools.convertCamelCaseToAllCaps(string));
}
- public void testConvertHexStringToByteArray_illegalCharacter2() throws Exception {
- this.verifyConvertHexStringToByteArray_illegalCharacter("CAFE0XCAFE0x");
+ @Override
+ protected void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int max) {
+ assertEquals(expected, StringTools.convertCamelCaseToAllCaps(string, max));
}
- private void verifyConvertHexStringToByteArray_illegalCharacter(String s) throws Exception {
- boolean exCaught = false;
- try {
- byte[] byteArray = StringTools.convertHexStringToByteArray(s);
- fail("bogus byte array: " + Arrays.toString(byteArray));
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- }
-
- public void testConvertHexStringToByteArray_ok() throws Exception {
- String s = "74657374"; // UTF-8 values
- assertEquals("test", new String(StringTools.convertHexStringToByteArray(s)));
- }
-
- public void testConvertHexStringToByteArray_negative() throws Exception {
- String s = getHexCafe();
- assertEquals("caf\u00E9", new String(StringTools.convertHexStringToByteArray(s)));
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string) {
+ assertEquals(expected, StringTools.convertAllCapsToCamelCase(string));
}
- public void testConvertHexStringToByteArray_lowercase() throws Exception {
- String s = getHexCafe().toLowerCase();
- assertEquals("caf\u00E9", new String(StringTools.convertHexStringToByteArray(s)));
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string, boolean capFirst) {
+ assertEquals(expected, StringTools.convertAllCapsToCamelCase(string, capFirst));
}
- public static String getHexCafe() {
- if (SystemTools.fileEncodingIsWindows()) {
- return "636166E9";
- }
- if (SystemTools.fileEncodingIsUTF8()) {
- return "636166C3A9";
- }
- return null;
+ @Override
+ protected void verifyIsQuoted(String string) {
+ assertTrue(StringTools.isQuoted(string));
}
- // ********** convert camel-case to all-caps **********
-
- public void testConvertCamelCaseToAllCaps() {
- assertEquals("TEST", StringTools.convertCamelCaseToAllCaps("test"));
- assertEquals("TEST", StringTools.convertCamelCaseToAllCaps("TEST"));
- assertEquals("TEST_TEST", StringTools.convertCamelCaseToAllCaps("testTest"));
- assertEquals("TEST_TEST", StringTools.convertCamelCaseToAllCaps("TestTest"));
- assertEquals("TEST_TEST_TEST", StringTools.convertCamelCaseToAllCaps("testTESTTest"));
- assertEquals("TEST_TEST_TEST", StringTools.convertCamelCaseToAllCaps("TestTESTTest"));
- assertEquals("TEST_TEST_TEST_T", StringTools.convertCamelCaseToAllCaps("TestTESTTestT"));
+ @Override
+ protected void denyIsQuoted(String string) {
+ assertFalse(StringTools.isQuoted(string));
}
- public void testConvertCamelCaseToAllCapsMaxLength() {
- assertEquals("TEST", StringTools.convertCamelCaseToAllCaps("test", 44));
- assertEquals("TEST", StringTools.convertCamelCaseToAllCaps("test", 4));
- assertEquals("TES", StringTools.convertCamelCaseToAllCaps("test", 3));
- assertEquals("TEST", StringTools.convertCamelCaseToAllCaps("TEST", 5));
- assertEquals("TE", StringTools.convertCamelCaseToAllCaps("TEST", 2));
- assertEquals("TEST_TEST", StringTools.convertCamelCaseToAllCaps("testTest", 9));
- assertEquals("TEST_TES", StringTools.convertCamelCaseToAllCaps("testTest", 8));
- assertEquals("TEST_T", StringTools.convertCamelCaseToAllCaps("testTest", 6));
- assertEquals("TEST_", StringTools.convertCamelCaseToAllCaps("testTest", 5));
- assertEquals("TEST", StringTools.convertCamelCaseToAllCaps("testTest", 4));
- assertEquals("TEST_TEST", StringTools.convertCamelCaseToAllCaps("TestTest", 9));
- assertEquals("TEST_TEST", StringTools.convertCamelCaseToAllCaps("TestTest", 1100));
- assertEquals("TEST_TEST_", StringTools.convertCamelCaseToAllCaps("testTESTTest", 10));
- assertEquals("TEST_TEST_TEST", StringTools.convertCamelCaseToAllCaps("TestTESTTest", 14));
- assertEquals("TEST_TEST_TEST_T", StringTools.convertCamelCaseToAllCaps("TestTESTTestT", 16));
- assertEquals("TEST_TEST_TEST_", StringTools.convertCamelCaseToAllCaps("TestTESTTestT", 15));
+ @Override
+ protected void verifyIsParenthetical(String string) {
+ assertTrue(StringTools.isParenthetical(string));
}
- // ********** convert all-caps to camel case **********
-
- public void testConvertAllCapsToCamelCase() {
- assertEquals("test", StringTools.convertAllCapsToCamelCase("TEST", false));
- assertEquals("test", StringTools.convertAllCapsToCamelCase("TEST_", false));
- assertEquals("test", StringTools.convertAllCapsToCamelCase("TEST____", false));
- assertEquals("Test", StringTools.convertAllCapsToCamelCase("TEST", true));
- assertEquals("test", StringTools.convertAllCapsToCamelCase("TeST", false));
- assertEquals("testTest", StringTools.convertAllCapsToCamelCase("TEST_TEST", false));
- assertEquals("testTest", StringTools.convertAllCapsToCamelCase("TEST___TEST", false));
- assertEquals("TestTest", StringTools.convertAllCapsToCamelCase("TEST_TEST", true));
- assertEquals("testTestTest", StringTools.convertAllCapsToCamelCase("TEST_TEST_TEST", false));
- assertEquals("TestTestTest", StringTools.convertAllCapsToCamelCase("TEST_TEST_TEST", true));
- assertEquals("testTestTestT", StringTools.convertAllCapsToCamelCase("TEST_TEST_TEST_T", false));
- assertEquals("testTestTestT", StringTools.convertAllCapsToCamelCase("_TEST_TEST_TEST_T", false));
- assertEquals("testTestTestT", StringTools.convertAllCapsToCamelCase("__TEST_TEST_TEST_T", false));
- assertEquals("TestTestTestT", StringTools.convertAllCapsToCamelCase("TEST_TEST_TEST_T", true));
- assertEquals("TestTestTestT", StringTools.convertAllCapsToCamelCase("_TEST_TEST_TEST_T", true));
- assertEquals("TestTestTestT", StringTools.convertAllCapsToCamelCase("__TEST_TEST_TEST_T", true));
+ @Override
+ protected void denyIsParenthetical(String string) {
+ assertFalse(StringTools.isParenthetical(string));
}
- public void testConvertAllCapsToCamelCaseLowercase() {
- assertEquals("test", StringTools.convertAllCapsToCamelCase("test", false));
- assertEquals("test", StringTools.convertAllCapsToCamelCase("test_", false));
- assertEquals("test", StringTools.convertAllCapsToCamelCase("test____", false));
- assertEquals("Test", StringTools.convertAllCapsToCamelCase("test", true));
- assertEquals("test", StringTools.convertAllCapsToCamelCase("test", false));
- assertEquals("testTest", StringTools.convertAllCapsToCamelCase("test_test", false));
- assertEquals("testTest", StringTools.convertAllCapsToCamelCase("test___test", false));
- assertEquals("TestTest", StringTools.convertAllCapsToCamelCase("test_test", true));
- assertEquals("testTestTest", StringTools.convertAllCapsToCamelCase("test_test_test", false));
- assertEquals("TestTestTest", StringTools.convertAllCapsToCamelCase("test_test_test", true));
- assertEquals("testTestTestT", StringTools.convertAllCapsToCamelCase("test_test_test_t", false));
- assertEquals("testTestTestT", StringTools.convertAllCapsToCamelCase("_test_test_test_t", false));
- assertEquals("testTestTestT", StringTools.convertAllCapsToCamelCase("__test_test_test_t", false));
- assertEquals("TestTestTestT", StringTools.convertAllCapsToCamelCase("test_test_test_t", true));
- assertEquals("TestTestTestT", StringTools.convertAllCapsToCamelCase("_test_test_test_t", true));
- assertEquals("TestTestTestT", StringTools.convertAllCapsToCamelCase("__test_test_test_t", true));
+ @Override
+ protected void verifyIsBracketed(String string) {
+ assertTrue(StringTools.isBracketed(string));
}
- // ********** delimiting **********
-
- public void testIsQuoted() {
- this.denyIsQuoted("foo");
- this.verifyIsQuoted("\"foo\"");
-
- this.denyIsQuoted("");
- this.verifyIsQuoted("\"\"");
-
- this.denyIsQuoted("\"");
- this.denyIsQuoted(" ");
- this.denyIsQuoted("''");
- this.denyIsQuoted("'foo'");
+ @Override
+ protected void denyIsBracketed(String string) {
+ assertFalse(StringTools.isBracketed(string));
}
- private void verifyIsQuoted(String s) {
- assertTrue(StringTools.isQuoted(s));
+ @Override
+ protected void verifyIsBraced(String string) {
+ assertTrue(StringTools.isBraced(string));
}
- private void denyIsQuoted(String s) {
- assertFalse(StringTools.isQuoted(s));
+ @Override
+ protected void denyIsBraced(String string) {
+ assertFalse(StringTools.isBraced(string));
}
- public void testIsParenthetical() {
- this.denyIsParenthetical("foo");
- this.verifyIsParenthetical("(foo)");
-
- this.denyIsParenthetical("");
- this.verifyIsParenthetical("()");
-
- this.denyIsParenthetical("(");
- this.denyIsParenthetical(" ");
- this.denyIsParenthetical("''");
- this.denyIsParenthetical("'foo'");
+ @Override
+ protected void verifyIsChevroned(String string) {
+ assertTrue(StringTools.isChevroned(string));
}
- private void verifyIsParenthetical(String s) {
- assertTrue(StringTools.isParenthetical(s));
+ @Override
+ protected void denyIsChevroned(String string) {
+ assertFalse(StringTools.isChevroned(string));
}
- private void denyIsParenthetical(String s) {
- assertFalse(StringTools.isParenthetical(s));
+ @Override
+ protected void verifyIsDelimited(String string, char c) {
+ assertTrue(StringTools.isDelimited(string, c));
}
- public void testIsBracketed() {
- this.denyIsBracketed("foo");
- this.verifyIsBracketed("[foo]");
-
- this.denyIsBracketed("");
- this.verifyIsBracketed("[]");
-
- this.denyIsBracketed("[");
- this.denyIsBracketed(" ");
- this.denyIsBracketed("''");
- this.denyIsBracketed("'foo'");
+ @Override
+ protected void denyIsDelimited(String string, char c) {
+ assertFalse(StringTools.isDelimited(string, c));
}
- private void verifyIsBracketed(String s) {
- assertTrue(StringTools.isBracketed(s));
+ @Override
+ protected void verifyIsDelimited2(String string, char start, char end) {
+ assertTrue(StringTools.isDelimited(string, start, end));
}
- private void denyIsBracketed(String s) {
- assertFalse(StringTools.isBracketed(s));
+ @Override
+ protected void denyIsDelimited2(String string, char start, char end) {
+ assertFalse(StringTools.isDelimited(string, start, end));
}
- public void testIsBraced() {
- this.denyIsBraced("foo");
- this.verifyIsBraced("{foo}");
-
- this.denyIsBraced("");
- this.verifyIsBraced("{}");
-
- this.denyIsBraced("{");
- this.denyIsBraced(" ");
- this.denyIsBraced("''");
- this.denyIsBraced("'foo'");
+ @Override
+ protected void verifyUndelimit(String expected, String string) {
+ assertEquals(expected, StringTools.undelimit(string));
}
- private void verifyIsBraced(String s) {
- assertTrue(StringTools.isBraced(s));
+ @Override
+ protected void verifyUndelimitInt(String expected, String string, int count) {
+ assertEquals(expected, StringTools.undelimit(string, count));
}
- private void denyIsBraced(String s) {
- assertFalse(StringTools.isBraced(s));
+ @Override
+ protected void verifyConvertToJavaStringLiteral(String expected, String string) {
+ assertEquals(expected, StringTools.convertToJavaStringLiteral(string));
+ assertEquals(expected, StringTools.JAVA_STRING_LITERAL_TRANSFORMER.transform(string));
}
- public void testIsChevroned() {
- this.denyIsChevroned("foo");
- this.verifyIsChevroned("<foo>");
-
- this.denyIsChevroned("");
- this.verifyIsChevroned("<>");
-
- this.denyIsChevroned("{");
- this.denyIsChevroned(" ");
- this.denyIsChevroned("''");
- this.denyIsChevroned("'foo'");
+ @Override
+ protected Object getJavaStringLiteralTransformer() {
+ return StringTools.JAVA_STRING_LITERAL_TRANSFORMER;
}
- private void verifyIsChevroned(String s) {
- assertTrue(StringTools.isChevroned(s));
+ @Override
+ protected void verifyConvertToJavaStringLiteralContent(String expected, String string) {
+ assertEquals(expected, StringTools.convertToJavaStringLiteralContent(string));
+ assertEquals(expected, StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER.transform(string));
}
- private void denyIsChevroned(String s) {
- assertFalse(StringTools.isChevroned(s));
+ @Override
+ protected Object getJavaStringLiteralContentTransformer() {
+ return StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER;
}
- public void testIsDelimited() {
- this.denyIsDelimited("foo", '?');
- this.verifyIsDelimited("?foo?", '?');
-
- this.denyIsDelimited("", '?');
- this.verifyIsDelimited("\"\"", '"');
- this.verifyIsDelimited("?xx?", '?');
- this.denyIsDelimited("?xx]", '?');
-
- this.denyIsDelimited("\"", '"');
- this.denyIsDelimited(" ", ' ');
- this.denyIsDelimited("''", '"');
- this.denyIsDelimited("'foo'", '?');
+ @Override
+ protected void verifyConvertToXmlAttributeValue(String expected, String string) {
+ assertEquals(expected, StringTools.convertToXmlAttributeValue(string));
+ assertEquals(expected, StringTools.XML_ATTRIBUTE_VALUE_TRANSFORMER.transform(string));
}
- private void verifyIsDelimited(String s, char c) {
- assertTrue(StringTools.isDelimited(s, c));
+ @Override
+ protected Object getXmlAttributeValueTransformer() {
+ return StringTools.XML_ATTRIBUTE_VALUE_TRANSFORMER;
}
- private void denyIsDelimited(String s, char c) {
- assertFalse(StringTools.isDelimited(s, c));
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValue(String expected, String string) {
+ assertEquals(expected, StringTools.convertToDoubleQuotedXmlAttributeValue(string));
+ assertEquals(expected, StringTools.DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_TRANSFORMER.transform(string));
}
- public void testIsDelimited2() {
- this.denyIsDelimited2("foo", '[', ']');
- this.verifyIsDelimited2("{foo}", '{', '}');
-
- this.denyIsDelimited2("", '[', ']');
- this.verifyIsDelimited2("[]", '[', ']');
- this.verifyIsDelimited2("[xx]", '[', ']');
- this.denyIsDelimited2("?xx]", '[', ']');
-
- this.denyIsDelimited2("\"", '[', ']');
- this.denyIsDelimited2(" ", '[', ']');
- this.denyIsDelimited2("''", '[', ']');
- this.denyIsDelimited2("'foo'", '[', ']');
+ @Override
+ protected Object getDoubleQuotedXmlAttributeValueTransformer() {
+ return StringTools.DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_TRANSFORMER;
}
- private void verifyIsDelimited2(String s, char start, char end) {
- assertTrue(StringTools.isDelimited(s, start, end));
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValueContent(String expected, String string) {
+ assertEquals(expected, StringTools.convertToDoubleQuotedXmlAttributeValueContent(string));
+ assertEquals(expected, StringTools.DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER.transform(string));
}
- private void denyIsDelimited2(String s, char start, char end) {
- assertFalse(StringTools.isDelimited(s, start, end));
+ @Override
+ protected Object getDoubleQuotedXmlAttributeValueContentTransformer() {
+ return StringTools.DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
}
- // ********** undelimiting **********
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValue(String expected, String string) {
+ assertEquals(expected, StringTools.convertToSingleQuotedXmlAttributeValue(string));
+ assertEquals(expected, StringTools.SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_TRANSFORMER.transform(string));
+ }
- public void testUndelimit() {
- this.verifyUndelimit("\"foo\"", "foo");
- this.verifyUndelimit("\"\"", "");
- this.verifyUndelimit("'foo'", "foo");
- this.verifyUndelimit("\"fo\"\"o\"", "fo\"o");
- this.verifyUndelimit("\"foo\"\"\"", "foo\"");
- this.verifyUndelimit("\"\"\"foo\"", "\"foo");
- this.verifyUndelimit("[foo]", "foo");
- this.verifyUndelimit("\"\"\"", "\"");
- this.verifyUndelimit("\"foo\"bar\"", "foo\"");
- this.verifyUndelimit("\"foo\"\"", "foo\"");
+ @Override
+ protected Object getSingleQuotedXmlAttributeValueTransformer() {
+ return StringTools.SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_TRANSFORMER;
}
- private void verifyUndelimit(String s, String expected) {
- assertEquals(expected, StringTools.undelimit(s));
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValueContent(String expected, String string) {
+ assertEquals(expected, StringTools.convertToSingleQuotedXmlAttributeValueContent(string));
+ assertEquals(expected, StringTools.SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER.transform(string));
}
- public void testUndelimitInt() {
- this.verifyUndelimitInt("\"foo\"", 2, "o");
- this.verifyUndelimitInt("\"\"foo\"\"", 2, "foo");
- this.verifyUndelimitInt("'foo'", 2, "o");
+ @Override
+ protected Object getSingleQuotedXmlAttributeValueContentTransformer() {
+ return StringTools.SINGLE_QUOTED_XML_ATTRIBUTE_VALUE_CONTENT_TRANSFORMER;
}
- private void verifyUndelimitInt(String s, int count, String expected) {
- assertEquals(expected, StringTools.undelimit(s, count));
+ @Override
+ protected void verifyConvertToXmlElementText(String expected, String string) {
+ assertEquals(expected, StringTools.convertToXmlElementText(string));
+ assertEquals(expected, StringTools.XML_ELEMENT_TEXT_TRANSFORMER.transform(string));
}
- public void testUndelimitIntException() {
- this.denyUndelimitInt("\"\"", 2);
- this.denyUndelimitInt("'o'", 2);
+ @Override
+ protected Object getXmlElementTextTransformer() {
+ return StringTools.XML_ELEMENT_TEXT_TRANSFORMER;
}
- private void denyUndelimitInt(String s, int count) {
- boolean exCaught = false;
- try {
- String bogus = StringTools.undelimit(s, count);
- fail("invalid string: " + bogus);
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
+ @Override
+ protected void verifyConvertToXmlElementCDATA(String expected, String string) {
+ assertEquals(expected, StringTools.convertToXmlElementCDATA(string));
+ assertEquals(expected, StringTools.XML_ELEMENT_CDATA_TRANSFORMER.transform(string));
}
- // ********** converting to Java string literal **********
+ @Override
+ protected Object getXmlElementCDATATransformer() {
+ return StringTools.XML_ELEMENT_CDATA_TRANSFORMER;
+ }
- public void testConvertToJavaStringLiteral() {
- this.verifyConvertToJavaStringLiteral("", "\"\"");
- this.verifyConvertToJavaStringLiteral("\"\"", "\"\\\"\\\"\"");
- this.verifyConvertToJavaStringLiteral("'foo'", "\"'foo'\"");
- this.verifyConvertToJavaStringLiteral("foo\bbar", "\"foo\\bbar\"");
- this.verifyConvertToJavaStringLiteral("foo\n\tbar", "\"foo\\n\\tbar\"");
- this.verifyConvertToJavaStringLiteral("foo\"bar", "\"foo\\\"bar\"");
- this.verifyConvertToJavaStringLiteral("foo\\bar", "\"foo\\\\bar\"");
+ @Override
+ protected void verifyConvertToXmlElementCDATAContent(String expected, String string) {
+ assertEquals(expected, StringTools.convertToXmlElementCDATAContent(string));
+ assertEquals(expected, StringTools.XML_ELEMENT_CDATA_CONTENT_TRANSFORMER.transform(string));
}
- private void verifyConvertToJavaStringLiteral(String s, String expected) {
- assertEquals(expected, StringTools.convertToJavaStringLiteral(s));
+ @Override
+ protected Object getXmlElementCDATAContentTransformer() {
+ return StringTools.XML_ELEMENT_CDATA_CONTENT_TRANSFORMER;
}
- public void testConvertToJavaStringLiteralContent() {
- this.verifyConvertToJavaStringLiteralContent("", "");
- this.verifyConvertToJavaStringLiteralContent("\"\"", "\\\"\\\"");
- this.verifyConvertToJavaStringLiteralContent("'foo'", "'foo'");
- this.verifyConvertToJavaStringLiteralContent("foo\bbar", "foo\\bbar");
- this.verifyConvertToJavaStringLiteralContent("foo\n\tbar", "foo\\n\\tbar");
- this.verifyConvertToJavaStringLiteralContent("foo\"bar", "foo\\\"bar");
- this.verifyConvertToJavaStringLiteralContent("foo\\bar", "foo\\\\bar");
+ @Override
+ protected Class<?> getToolsClass() {
+ return StringTools.class;
}
- private void verifyConvertToJavaStringLiteralContent(String s, String expected) {
- assertEquals(expected, StringTools.convertToJavaStringLiteralContent(s));
- }
-
- // ********** converting to XML **********
-
- public void testConvertToXmlAttributeValue() {
- this.verifyConvertToXmlAttributeValue("", "\"\"");
- this.verifyConvertToXmlAttributeValue("\"", "'\"'");
- this.verifyConvertToXmlAttributeValue("\"\"", "'\"\"'");
- this.verifyConvertToXmlAttributeValue("'", "\"'\"");
- this.verifyConvertToXmlAttributeValue("''", "\"''\"");
- this.verifyConvertToXmlAttributeValue("\"'\"", "\"&quot;'&quot;\"");
- this.verifyConvertToXmlAttributeValue("\"''\"", "\"&quot;''&quot;\"");
- this.verifyConvertToXmlAttributeValue("'foo'", "\"'foo'\"");
- this.verifyConvertToXmlAttributeValue("\"foo\"", "'\"foo\"'");
- this.verifyConvertToXmlAttributeValue("\"foo\" 'bar'", "\"&quot;foo&quot; 'bar'\"");
- this.verifyConvertToXmlAttributeValue("foo & bar", "\"foo &amp; bar\"");
- this.verifyConvertToXmlAttributeValue("\"foo & bar\"", "'\"foo &amp; bar\"'");
- this.verifyConvertToXmlAttributeValue("foo <<< bar", "\"foo &lt;&lt;&lt; bar\"");
- this.verifyConvertToXmlAttributeValue("\"foo <<< bar\"", "'\"foo &lt;&lt;&lt; bar\"'");
- }
-
- private void verifyConvertToXmlAttributeValue(String s, String expected) {
- assertEquals(expected, StringTools.convertToXmlAttributeValue(s));
- }
-
- public void testConvertToXmlElementText() {
- this.verifyConvertToXmlElementText("", "");
- this.verifyConvertToXmlElementText("\"", "\"");
- this.verifyConvertToXmlElementText("\"\"", "\"\"");
- this.verifyConvertToXmlElementText("'", "'");
- this.verifyConvertToXmlElementText("''", "''");
- this.verifyConvertToXmlElementText("\"'\"", "\"'\"");
- this.verifyConvertToXmlElementText("\"''\"", "\"''\"");
- this.verifyConvertToXmlElementText("'foo'", "'foo'");
- this.verifyConvertToXmlElementText("foo & bar", "foo &amp; bar");
- this.verifyConvertToXmlElementText("foo &", "foo &amp;");
- this.verifyConvertToXmlElementText("& bar", "&amp; bar");
- this.verifyConvertToXmlElementText("\"foo & bar\"", "\"foo &amp; bar\"");
- this.verifyConvertToXmlElementText("foo <<< bar", "foo &lt;&lt;&lt; bar");
- this.verifyConvertToXmlElementText("\"foo <<< bar\"", "\"foo &lt;&lt;&lt; bar\"");
- }
-
- private void verifyConvertToXmlElementText(String s, String expected) {
- assertEquals(expected, StringTools.convertToXmlElementText(s));
- }
-
- public void testConvertToXmlElementCDATA() {
- String START = "<![CDATA[";
- String END = "]]>";
- this.verifyConvertToXmlElementCDATA("", START + END);
- this.verifyConvertToXmlElementCDATA("\"", START + "\"" + END);
- this.verifyConvertToXmlElementCDATA("\"\"", START + "\"\"" + END);
- this.verifyConvertToXmlElementCDATA("'", START + "'" + END);
- this.verifyConvertToXmlElementCDATA("''", START + "''" + END);
- this.verifyConvertToXmlElementCDATA("\"'\"", START + "\"'\"" + END);
- this.verifyConvertToXmlElementCDATA("\"''\"", START + "\"''\"" + END);
- this.verifyConvertToXmlElementCDATA("'foo'", START + "'foo'" + END);
- this.verifyConvertToXmlElementCDATA("foo & bar", START + "foo & bar" + END);
- this.verifyConvertToXmlElementCDATA("foo &", START + "foo &" + END);
- this.verifyConvertToXmlElementCDATA("& bar", START + "& bar" + END);
- this.verifyConvertToXmlElementCDATA("\"foo & bar\"", START + "\"foo & bar\"" + END);
- this.verifyConvertToXmlElementCDATA("foo <<< bar", START + "foo <<< bar" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <<< bar\"", START + "\"foo <<< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <&< bar\"", START + "\"foo <&< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <]< bar\"", START + "\"foo <]< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <]]< bar\"", START + "\"foo <]]< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("\"foo <]]>< bar\"", START + "\"foo <]]&gt;< bar\"" + END);
- this.verifyConvertToXmlElementCDATA("foo <]", START + "foo <]" + END);
- this.verifyConvertToXmlElementCDATA("foo <]]", START + "foo <]]" + END);
- this.verifyConvertToXmlElementCDATA("foo <]]>", START + "foo <]]&gt;" + END);
- this.verifyConvertToXmlElementCDATA("]foo", START + "]foo" + END);
- this.verifyConvertToXmlElementCDATA("]]foo", START + "]]foo" + END);
- this.verifyConvertToXmlElementCDATA("]]>foo", START + "]]&gt;foo" + END);
- }
-
- private void verifyConvertToXmlElementCDATA(String s, String expected) {
- assertEquals(expected, StringTools.convertToXmlElementCDATA(s));
- }
-
- public void testConcatenate() throws Exception {
- String[] array = new String[0];
- Iterable<String> iterable = IterableTools.iterable(array);
-
- String result = "";
-
- assertEquals(result, StringTools.concatenate(array));
- assertEquals(result, StringTools.concatenate(iterable));
- assertEquals(result, StringTools.concatenate(iterable.iterator()));
-
- String delim = "";
- result = "";
-
- assertEquals(result, StringTools.concatenate(array, delim));
- assertEquals(result, StringTools.concatenate(iterable, delim));
- assertEquals(result, StringTools.concatenate(iterable.iterator(), delim));
-
- delim = ";";
- result = "";
-
- assertEquals(result, StringTools.concatenate(array, delim));
- assertEquals(result, StringTools.concatenate(iterable, delim));
- assertEquals(result, StringTools.concatenate(iterable.iterator(), delim));
-
- array = new String[] {"foo", "bar", "baz"};
- iterable = IterableTools.iterable(array);
-
- result = "foobarbaz";
-
- assertEquals(result, StringTools.concatenate(array));
- assertEquals(result, StringTools.concatenate(iterable));
- assertEquals(result, StringTools.concatenate(iterable.iterator()));
-
- delim = "";
- result = "foobarbaz";
-
- assertEquals(result, StringTools.concatenate(array, delim));
- assertEquals(result, StringTools.concatenate(iterable, delim));
- assertEquals(result, StringTools.concatenate(iterable.iterator(), delim));
-
- delim = ";";
- result = "foo;bar;baz";
-
- assertEquals(result, StringTools.concatenate(array, delim));
- assertEquals(result, StringTools.concatenate(iterable, delim));
- assertEquals(result, StringTools.concatenate(iterable.iterator(), delim));
+ // ********** StringTools-specific **********
+
+ public void testCharArrayTransformer() throws Exception {
+ Transformer<String, char[]> transformer = StringTools.CHAR_ARRAY_TRANSFORMER;
+ TestTools.assertEquals("foo", transformer.transform("foo"));
+ assertEquals("CharArrayTransformer", transformer.toString());
+ assertSame(transformer, TestTools.serialize(transformer));
}
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/WriterToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/WriterToolsTests.java
index 43bcec421a..751808edd8 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/WriterToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/WriterToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,488 +11,415 @@ package org.eclipse.jpt.common.utility.tests.internal.io;
import java.io.StringWriter;
import java.io.Writer;
-import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.internal.io.WriterTools;
-import org.eclipse.jpt.common.utility.tests.internal.StringToolsTests;
+import org.eclipse.jpt.common.utility.tests.internal.AbstractStringBuilderToolsTests;
-@SuppressWarnings("nls")
public class WriterToolsTests
- extends TestCase
+ extends AbstractStringBuilderToolsTests
{
public WriterToolsTests(String name) {
super(name);
}
- // ********** padding/truncating/centering/repeating **********
-
- public void testCenter() throws Exception {
- this.verifyCenter("fred", "fred", 4);
- this.verifyCenter(" fred ", "fred", 6);
- this.verifyCenter(" fred ", "fred", 7);
- this.verifyCenter("re", "fred", 2);
- this.verifyCenter("fre", "fred", 3);
+ @Override
+ protected void verifyConvertToCharArray(String string) throws Exception {
+ // NOP
}
- private void verifyCenter(String expected, String s, int len) throws Exception {
- Writer writer;
- writer = new StringWriter();
- WriterTools.center(writer, s, len);
- assertEquals(expected, writer.toString());
+ @Override
+ protected void verifyReverse(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.reverse(sb, string);
+ assertEquals(expected, sb.toString());
- writer = new StringWriter();
- WriterTools.center(writer, s.toCharArray(), len);
- assertEquals(expected, writer.toString());
+ sb = new StringWriter();
+ WriterTools.reverse(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testPad() throws Exception {
- Writer writer;
- writer = new StringWriter();
- WriterTools.pad(writer, "fred", 4);
- assertEquals("fred", writer.toString());
-
- writer = new StringWriter();
- WriterTools.pad(writer, "fred", 6);
- assertEquals("fred ", writer.toString());
+ @Override
+ protected void verifyCenter(String expected, String s, int len) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.center(sb, s, len);
+ assertEquals(expected, sb.toString());
- writer = new StringWriter();
- boolean exThrown = false;
- try {
- WriterTools.pad(writer, "fred", 2);
- fail();
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
+ sb = new StringWriter();
+ WriterTools.center(sb, s.toCharArray(), len);
+ assertEquals(expected, sb.toString());
}
- public void testFit() throws Exception {
- this.verifyFit("fred", "fred", 4);
- this.verifyFit("fred ", "fred", 6);
- this.verifyFit("fr", "fred", 2);
- }
+ @Override
+ protected void verifyPad(String expected, String string, int length) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.pad(sb, string, length);
+ assertEquals(expected, sb.toString());
- private void verifyFit(String expected, String string, int length) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.fit(writer, string, length);
- assertEquals(expected, writer.toString());
+ sb = new StringWriter();
+ WriterTools.pad(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- public void testZeroPad() throws Exception {
- Writer writer;
- writer = new StringWriter();
- WriterTools.zeroPad(writer, "1234", 4);
- assertEquals("1234", writer.toString());
-
- writer = new StringWriter();
- WriterTools.zeroPad(writer, "1234", 6);
- assertEquals("001234", writer.toString());
+ @Override
+ protected void verifyFit(String expected, String string, int length) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.fit(sb, string, length);
+ assertEquals(expected, sb.toString());
- writer = new StringWriter();
- boolean exThrown = false;
- try {
- WriterTools.zeroPad(writer, "1234", 2);
- fail();
- } catch (IllegalArgumentException ex) {
- exThrown = true;
- }
- assertTrue(exThrown);
+ sb = new StringWriter();
+ WriterTools.fit(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- public void testZeroFit() throws Exception {
- this.verifyZeroFit("1234", "1234", 4);
- this.verifyZeroFit("001234", "1234", 6);
- this.verifyZeroFit("34", "1234", 2);
- }
+ @Override
+ protected void verifyZeroPad(String expected, String string, int length) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.zeroPad(sb, string, length);
+ assertEquals(expected, sb.toString());
- private void verifyZeroFit(String expected, String string, int length) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.zeroFit(writer, string, length);
- assertEquals(expected, writer.toString());
+ sb = new StringWriter();
+ WriterTools.zeroPad(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- public void testRepeat() throws Exception {
- this.verifyRepeat("", "1234", 0);
- this.verifyRepeat("12", "1234", 2);
- this.verifyRepeat("1234", "1234", 4);
- this.verifyRepeat("123412", "1234", 6);
- this.verifyRepeat("12341234", "1234", 8);
- this.verifyRepeat("123412341234123412341", "1234", 21);
- }
+ @Override
+ protected void verifyZeroFit(String expected, String string, int length) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.zeroFit(sb, string, length);
+ assertEquals(expected, sb.toString());
- private void verifyRepeat(String expected, String string, int length) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.repeat(writer, string, length);
- assertEquals(expected, writer.toString());
+ sb = new StringWriter();
+ WriterTools.zeroFit(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- public void testRepeatCharArray() throws Exception {
- this.verifyRepeatCharArray("", "1234", 0);
- this.verifyRepeatCharArray("12", "1234", 2);
- this.verifyRepeatCharArray("1234", "1234", 4);
- this.verifyRepeatCharArray("123412", "1234", 6);
- this.verifyRepeatCharArray("12341234", "1234", 8);
- this.verifyRepeatCharArray("123412341234123412341", "1234", 21);
- }
+ @Override
+ protected void verifyRepeat(String expected, String string, int length) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.repeat(sb, string, length);
+ assertEquals(expected, sb.toString());
- private void verifyRepeatCharArray(String expected, String string, int length) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.repeat(writer, string.toCharArray(), length);
- assertEquals(expected, writer.toString());
+ sb = new StringWriter();
+ WriterTools.repeat(sb, string.toCharArray(), length);
+ assertEquals(expected, sb.toString());
}
- public void testSeparateOnStringCharInt() throws Exception {
- this.verifySeparate("012345", '-', 22, "012345");
- this.verifySeparate("012345", '-', 6, "012345");
- this.verifySeparate("012345", '-', 5, "01234-5");
- this.verifySeparate("012345", '-', 4, "0123-45");
- this.verifySeparate("012345", '-', 3, "012-345");
- this.verifySeparate("012345", '-', 2, "01-23-45");
- this.verifySeparate("012345", '-', 1, "0-1-2-3-4-5");
- }
+ @Override
+ protected void verifySeparate(String expected, String string, char separator, int segmentLength) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.separate(sb, string, separator, segmentLength);
+ assertEquals(expected, sb.toString());
- private void verifySeparate(String string, char separator, int segmentLength, String expected) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.separate(writer, string, separator, segmentLength);
- assertEquals(expected, writer.toString());
+ sb = new StringWriter();
+ WriterTools.separate(sb, string.toCharArray(), separator, segmentLength);
+ assertEquals(expected, sb.toString());
}
- public void testSeparateOnCharArrayCharInt() throws Exception {
- this.verifySeparateCharArray("012345", '-', 22, "012345");
- this.verifySeparateCharArray("012345", '-', 6, "012345");
- this.verifySeparateCharArray("012345", '-', 5, "01234-5");
- this.verifySeparateCharArray("012345", '-', 4, "0123-45");
- this.verifySeparateCharArray("012345", '-', 3, "012-345");
- this.verifySeparateCharArray("012345", '-', 2, "01-23-45");
- this.verifySeparateCharArray("012345", '-', 1, "0-1-2-3-4-5");
+ @Override
+ protected void verifyDelimit(String expected, String string, String delimiter) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.delimit(sb, string, delimiter);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.delimit(sb, string.toCharArray(), delimiter.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifySeparateCharArray(String string, char separator, int segmentLength, String expected) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.separate(writer, string.toCharArray(), separator, segmentLength);
- assertEquals(expected, writer.toString());
+ @Override
+ protected void verifyQuote(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.quote(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.quote(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testDelimit() throws Exception {
- this.verifyDelimit("Employee", "123", "123Employee123");
- this.verifyDelimit("123", "123", "123123123");
- this.verifyDelimit("", "123", "123123");
+ @Override
+ protected void verifyRemoveFirstOccurrence(String expected, String string, char charToRemove) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.removeFirstOccurrence(sb, string, charToRemove);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.removeFirstOccurrence(sb, string.toCharArray(), charToRemove);
+ assertEquals(expected, sb.toString());
}
- private void verifyDelimit(String string, String delimiter, String expectedString) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.delimit(writer, string, delimiter);
- assertEquals(expectedString, writer.toString());
+ @Override
+ protected void verifyRemoveAllOccurrences(String expected, String string, char charToRemove) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.removeAllOccurrences(sb, string, charToRemove);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.removeAllOccurrences(sb, string.toCharArray(), charToRemove);
+ assertEquals(expected, sb.toString());
}
- public void testQuote() throws Exception {
- this.verifyQuote("Employee", "\"Employee\"");
- this.verifyQuote("123", "\"123\"");
- this.verifyQuote("", "\"\"");
- this.verifyQuote("Emp\"loyee", "\"Emp\"\"loyee\"");
+ @Override
+ protected void verifyRemoveAllSpaces(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.removeAllSpaces(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.removeAllSpaces(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyQuote(String string, String expectedString) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.quote(writer, string);
- assertEquals(expectedString, writer.toString());
+ @Override
+ protected void verifyRemoveAllWhitespace(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.removeAllWhitespace(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.removeAllWhitespace(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testRemoveFirstOccurrence() throws Exception {
- this.verifyRemoveFirstOccurrence("Emplo&yee", '&', "Employee");
- this.verifyRemoveFirstOccurrence("Emplo&yee&", '&', "Employee&");
- this.verifyRemoveFirstOccurrence("Employee &Foo", '&', "Employee Foo");
- this.verifyRemoveFirstOccurrence("Employee&", '&', "Employee");
- this.verifyRemoveFirstOccurrence("&Employee", '&', "Employee");
+ @Override
+ protected void verifyCompressWhitespace(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.compressWhitespace(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.compressWhitespace(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveFirstOccurrence(String string, char charToRemove, String expectedString) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.removeFirstOccurrence(writer, string, charToRemove);
- assertEquals(expectedString, writer.toString());
+ @Override
+ protected void verifyCapitalize(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.capitalize(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.capitalize(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testRemoveAllOccurrences() throws Exception {
- this.verifyRemoveAllOccurrences("Employee Fred", ' ', "EmployeeFred");
- this.verifyRemoveAllOccurrences(" Employee ", ' ', "Employee");
- this.verifyRemoveAllOccurrences("Employee Foo", ' ', "EmployeeFoo");
- this.verifyRemoveAllOccurrences(" Emp loyee Foo", ' ', "EmployeeFoo");
+ @Override
+ protected void verifyUncapitalize(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.uncapitalize(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.uncapitalize(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveAllOccurrences(String string, char charToRemove, String expectedString) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.removeAllOccurrences(writer, string, charToRemove);
- assertEquals(expectedString, writer.toString());
+ @Override
+ protected void verifyConvertToHexString(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.convertToHexString(sb, string.getBytes());
+ assertEquals(expected, sb.toString());
}
- public void testRemoveAllWhitespace() throws Exception {
- this.verifyRemoveAllWhitespace("Employee Fred\t", "EmployeeFred");
- this.verifyRemoveAllWhitespace("\tEmployee\n", "Employee");
- this.verifyRemoveAllWhitespace("Employee \t Foo", "EmployeeFoo");
- this.verifyRemoveAllWhitespace(" Emp\tloyee \n Foo", "EmployeeFoo");
+ @Override
+ protected void verifyConvertCamelCaseToAllCaps(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.convertCamelCaseToAllCaps(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertCamelCaseToAllCaps(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyRemoveAllWhitespace(String string, String expectedString) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.removeAllWhitespace(writer, string);
- assertEquals(expectedString, writer.toString());
+ @Override
+ protected void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int maxLength) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.convertCamelCaseToAllCaps(sb, string, maxLength);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertCamelCaseToAllCaps(sb, string.toCharArray(), maxLength);
+ assertEquals(expected, sb.toString());
}
- public void testCompressWhitespace() throws Exception {
- this.verifyCompressWhitespace("Employee Fred\t", "Employee Fred ");
- this.verifyCompressWhitespace("\tEmployee \n", " Employee ");
- this.verifyCompressWhitespace("Employee \t Foo", "Employee Foo");
- this.verifyCompressWhitespace(" Emp\tloyee \n Foo ", " Emp loyee Foo ");
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.convertAllCapsToCamelCase(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertAllCapsToCamelCase(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCompressWhitespace(String string, String expectedString) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.compressWhitespace(writer, string);
- assertEquals(expectedString, writer.toString());
+ @Override
+ protected void verifyConvertAllCapsToCamelCase(String expected, String string, boolean capFirst) throws Exception {
+ Writer sb;
+ sb = new StringWriter();
+ WriterTools.convertAllCapsToCamelCase(sb, string, capFirst);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertAllCapsToCamelCase(sb, string.toCharArray(), capFirst);
+ assertEquals(expected, sb.toString());
}
- public void testCapitalizeOnStringWriter() throws Exception {
- this.verifyCapitalizeOnStringWriter("Oracle", "Oracle");
- this.verifyCapitalizeOnStringWriter("Oracle", "oracle");
- this.verifyCapitalizeOnStringWriter(" ", " ");
- this.verifyCapitalizeOnStringWriter("ORACLE", "ORACLE");
- this.verifyCapitalizeOnStringWriter("", "");
- this.verifyCapitalizeOnStringWriter("A", "a");
- this.verifyCapitalizeOnStringWriter("\u00C9cole", "\u00E9cole"); // e'cole -> E'cole
+ @Override
+ protected void verifyUndelimit(String expected, String s) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.undelimit(sb, s);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.undelimit(sb, s.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCapitalizeOnStringWriter(String expected, String string) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.capitalize(writer, string);
- assertEquals(expected, writer.toString());
+ @Override
+ protected void verifyUndelimitCount(String expected, String s, int count) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.undelimit(sb, s, count);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.undelimit(sb, s.toCharArray(), count);
+ assertEquals(expected, sb.toString());
}
- public void testCapitalizeOnCharArray() throws Exception {
- this.verifyCapitalizeOnCharArray("Oracle", new char[] { 'O', 'r', 'a', 'c', 'l', 'e' });
- this.verifyCapitalizeOnCharArray("Oracle", new char[] { 'o', 'r', 'a', 'c', 'l', 'e' });
- this.verifyCapitalizeOnCharArray(" ", new char[] { ' ', ' ', ' ' });
- this.verifyCapitalizeOnCharArray("ORACLE", new char[] { 'O', 'R', 'A', 'C', 'L', 'E' });
- this.verifyCapitalizeOnCharArray("", new char[0]);
- this.verifyCapitalizeOnCharArray("A", new char[] { 'a' });
- this.verifyCapitalizeOnCharArray("\u00C9cole", new char[] { '\u00E9', 'c', 'o', 'l', 'e' });
+ @Override
+ protected void verifyConvertToJavaStringLiteral(String expected, String s) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToJavaStringLiteral(sb, s);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToJavaStringLiteral(sb, s.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyCapitalizeOnCharArray(String expected, char[] string) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.capitalize(writer, string);
- assertEquals(expected, writer.toString());
+ @Override
+ protected void verifyConvertToJavaStringLiteralContent(String expected, String s) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToJavaStringLiteralContent(sb, s);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToJavaStringLiteralContent(sb, s.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testUncapitalizeOnStringWriter() throws Exception {
- this.verifyUncapitalizeOnStringWriter("oracle", "Oracle");
- this.verifyUncapitalizeOnStringWriter("oracle", "oracle");
- this.verifyUncapitalizeOnStringWriter(" ", " ");
- this.verifyUncapitalizeOnStringWriter("ORACLE", "ORACLE");
- this.verifyUncapitalizeOnStringWriter("", "");
- this.verifyUncapitalizeOnStringWriter("a", "A");
- this.verifyUncapitalizeOnStringWriter("\u00E9cole", "\u00C9cole"); // E'cole -> e'cole
+ @Override
+ protected void verifyConvertToXmlAttributeValue(String expected, String string) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToXmlAttributeValue(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToXmlAttributeValue(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUncapitalizeOnStringWriter(String expected, String string) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.uncapitalize(writer, string);
- assertEquals(expected, writer.toString());
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValue(String expected, String string) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToDoubleQuotedXmlAttributeValue(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToDoubleQuotedXmlAttributeValue(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testUncapitalizeOnCharArray() throws Exception {
- this.verifyUncapitalizeOnCharArray("oracle", new char[] { 'O', 'r', 'a', 'c', 'l', 'e' });
- this.verifyUncapitalizeOnCharArray("oracle", new char[] { 'o', 'r', 'a', 'c', 'l', 'e' });
- this.verifyUncapitalizeOnCharArray(" ", new char[] { ' ', ' ', ' ' });
- this.verifyUncapitalizeOnCharArray("ORACLE", new char[] { 'O', 'R', 'A', 'C', 'L', 'E' });
- this.verifyUncapitalizeOnCharArray("", new char[0]);
- this.verifyUncapitalizeOnCharArray("a", new char[] { 'A' });
- this.verifyUncapitalizeOnCharArray("\u00E9cole", new char[] { '\u00C9', 'c', 'o', 'l', 'e' });
+ @Override
+ protected void verifyConvertToDoubleQuotedXmlAttributeValueContent(String expected, String string) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToDoubleQuotedXmlAttributeValueContent(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToDoubleQuotedXmlAttributeValueContent(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyUncapitalizeOnCharArray(String expected, char[] string) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.uncapitalize(writer, string);
- assertEquals(expected, writer.toString());
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValue(String expected, String string) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToSingleQuotedXmlAttributeValue(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToSingleQuotedXmlAttributeValue(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testConvertToHexString() throws Exception {
- this.verifyConvertToHexString("74657374", "test"); // UTF-8 values
+ @Override
+ protected void verifyConvertToSingleQuotedXmlAttributeValueContent(String expected, String string) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToSingleQuotedXmlAttributeValueContent(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToSingleQuotedXmlAttributeValueContent(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- public void testConvertToHexString_negative() throws Exception {
- this.verifyConvertToHexString(this.getHexCafe(), "caf\u00E9"); // UTF-8 values
+ @Override
+ protected void verifyConvertToXmlElementText(String expected, String string) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToXmlElementText(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToXmlElementText(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private String getHexCafe() {
- return StringToolsTests.getHexCafe();
+ @Override
+ protected void verifyConvertToXmlElementCDATA(String expected, String string) throws Exception {
+ Writer sb = new StringWriter();
+ WriterTools.convertToXmlElementCDATA(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToXmlElementCDATA(sb, string.toCharArray());
+ assertEquals(expected, sb.toString());
}
- private void verifyConvertToHexString(String expected, String string) throws Exception {
+ @Override
+ protected void verifyConvertToXmlElementCDATAContent(String expected, String string) throws Exception {
Writer sb = new StringWriter();
- WriterTools.convertToHexString(sb, string.getBytes());
+ WriterTools.convertToXmlElementCDATAContent(sb, string);
+ assertEquals(expected, sb.toString());
+
+ sb = new StringWriter();
+ WriterTools.convertToXmlElementCDATAContent(sb, string.toCharArray());
assertEquals(expected, sb.toString());
}
- public void testConvertCamelCaseToAllCaps() throws Exception {
- this.verifyConvertCamelCaseToAllCaps("TEST", "test");
- this.verifyConvertCamelCaseToAllCaps("TEST", "TEST");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "testTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST", "TestTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "testTESTTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST", "TestTESTTest");
- this.verifyConvertCamelCaseToAllCaps("TEST_TEST_TEST_T", "TestTESTTestT");
- }
-
- private void verifyConvertCamelCaseToAllCaps(String expected, String string) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.convertCamelCaseToAllCaps(writer, string);
- assertEquals(expected, writer.toString());
- }
-
- public void testConvertCamelCaseToAllCapsMaxLength() throws Exception {
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 44);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "test", 4);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TES", "test", 3);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "TEST", 5);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TE", "TEST", 2);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "testTest", 9);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TES", "testTest", 8);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_T", "testTest", 6);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_", "testTest", 5);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST", "testTest", 4);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "TestTest", 9);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST", "TestTest", 1100);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_", "testTESTTest", 10);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST", "TestTESTTest", 14);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST_T", "TestTESTTestT", 16);
- this.verifyConvertCamelCaseToAllCapsMaxLength("TEST_TEST_TEST_", "TestTESTTestT", 15);
- }
-
- private void verifyConvertCamelCaseToAllCapsMaxLength(String expected, String string, int max) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.convertCamelCaseToAllCaps(writer, string, max);
- assertEquals(expected, writer.toString());
- }
-
- public void testConvertUnderscoresToCamelCase() throws Exception {
- this.verifyConvertUnderscoresToCamelCase("test", "TEST", false);
- this.verifyConvertUnderscoresToCamelCase("test", "TEST_", false);
- this.verifyConvertUnderscoresToCamelCase("test", "TEST____", false);
- this.verifyConvertUnderscoresToCamelCase("Test", "TEST", true);
- this.verifyConvertUnderscoresToCamelCase("test", "TeST", false);
- this.verifyConvertUnderscoresToCamelCase("testTest", "TEST_TEST", false);
- this.verifyConvertUnderscoresToCamelCase("testTest", "TEST___TEST", false);
- this.verifyConvertUnderscoresToCamelCase("TestTest", "TEST_TEST", true);
- this.verifyConvertUnderscoresToCamelCase("testTestTest", "TEST_TEST_TEST", false);
- this.verifyConvertUnderscoresToCamelCase("TestTestTest", "TEST_TEST_TEST", true);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "TEST_TEST_TEST_T", false);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "_TEST_TEST_TEST_T", false);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "__TEST_TEST_TEST_T", false);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "TEST_TEST_TEST_T", true);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "_TEST_TEST_TEST_T", true);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "__TEST_TEST_TEST_T", true);
- }
-
- public void testConvertUnderscoresToCamelCaseLowercase() throws Exception {
- this.verifyConvertUnderscoresToCamelCase("test", "test", false);
- this.verifyConvertUnderscoresToCamelCase("test", "test_", false);
- this.verifyConvertUnderscoresToCamelCase("test", "test____", false);
- this.verifyConvertUnderscoresToCamelCase("Test", "test", true);
- this.verifyConvertUnderscoresToCamelCase("test", "test", false);
- this.verifyConvertUnderscoresToCamelCase("testTest", "test_test", false);
- this.verifyConvertUnderscoresToCamelCase("testTest", "test___test", false);
- this.verifyConvertUnderscoresToCamelCase("TestTest", "test_test", true);
- this.verifyConvertUnderscoresToCamelCase("testTestTest", "test_test_test", false);
- this.verifyConvertUnderscoresToCamelCase("TestTestTest", "test_test_test", true);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "test_test_test_t", false);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "_test_test_test_t", false);
- this.verifyConvertUnderscoresToCamelCase("testTestTestT", "__test_test_test_t", false);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "test_test_test_t", true);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "_test_test_test_t", true);
- this.verifyConvertUnderscoresToCamelCase("TestTestTestT", "__test_test_test_t", true);
- }
-
- private void verifyConvertUnderscoresToCamelCase(String expected, String string, boolean capitalizeFirstLetter) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.convertAllCapsToCamelCase(writer, string, capitalizeFirstLetter);
- assertEquals(expected, writer.toString());
- }
-
- public void testUndelimit() throws Exception {
- this.verifyUndelimit("\"foo\"", "foo");
- this.verifyUndelimit("\"\"", "");
- this.verifyUndelimit("'foo'", "foo");
- this.verifyUndelimit("\"fo\"\"o\"", "fo\"o");
- this.verifyUndelimit("\"foo\"\"\"", "foo\"");
- this.verifyUndelimit("\"\"\"foo\"", "\"foo");
- this.verifyUndelimit("[foo]", "foo");
- this.verifyUndelimit("\"\"\"", "\"");
- this.verifyUndelimit("\"foo\"bar\"", "foo\"");
- this.verifyUndelimit("\"foo\"\"", "foo\"");
- }
-
- private void verifyUndelimit(String s, String expected) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.undelimit(writer, s);
- assertEquals(expected, writer.toString());
-
- writer = new StringWriter();
- WriterTools.undelimit(writer, s.toCharArray());
- assertEquals(expected, writer.toString());
- }
-
- public void testUndelimitCount() throws Exception {
- this.verifyUndelimitCount("\"foo\"", 2, "o");
- this.verifyUndelimitCount("\"\"\"\"", 2, "");
- this.verifyUndelimitCount("XXfooXX", 2, "foo");
- }
-
- private void verifyUndelimitCount(String s, int count, String expected) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.undelimit(writer, s, count);
- assertEquals(expected, writer.toString());
-
- writer = new StringWriter();
- WriterTools.undelimit(writer, s.toCharArray(), count);
- assertEquals(expected, writer.toString());
- }
-
- public void testConvertToJavaStringLiteral() throws Exception {
- this.verifyConvertToJavaStringLiteral("", "\"\"");
- this.verifyConvertToJavaStringLiteral("\"\"", "\"\\\"\\\"\"");
- this.verifyConvertToJavaStringLiteral("'foo'", "\"'foo'\"");
- this.verifyConvertToJavaStringLiteral("foo\bbar", "\"foo\\bbar\"");
- this.verifyConvertToJavaStringLiteral("foo\n\tbar", "\"foo\\n\\tbar\"");
- this.verifyConvertToJavaStringLiteral("foo\"bar", "\"foo\\\"bar\"");
- this.verifyConvertToJavaStringLiteral("foo\\bar", "\"foo\\\\bar\"");
- }
-
- private void verifyConvertToJavaStringLiteral(String s, String expected) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.convertToJavaStringLiteral(writer, s);
- assertEquals(expected, writer.toString());
-
- writer = new StringWriter();
- WriterTools.convertToJavaStringLiteral(writer, s.toCharArray());
- assertEquals(expected, writer.toString());
- }
-
- public void testConvertToJavaStringLiteralContent() throws Exception {
- this.verifyConvertToJavaStringLiteralContent("", "");
- this.verifyConvertToJavaStringLiteralContent("\"\"", "\\\"\\\"");
- this.verifyConvertToJavaStringLiteralContent("'foo'", "'foo'");
- this.verifyConvertToJavaStringLiteralContent("foo\bbar", "foo\\bbar");
- this.verifyConvertToJavaStringLiteralContent("foo\n\tbar", "foo\\n\\tbar");
- this.verifyConvertToJavaStringLiteralContent("foo\"bar", "foo\\\"bar");
- this.verifyConvertToJavaStringLiteralContent("foo\\bar", "foo\\\\bar");
- }
-
- private void verifyConvertToJavaStringLiteralContent(String s, String expected) throws Exception {
- Writer writer = new StringWriter();
- WriterTools.convertToJavaStringLiteralContent(writer, s);
- assertEquals(expected, writer.toString());
-
- writer = new StringWriter();
- WriterTools.convertToJavaStringLiteralContent(writer, s.toCharArray());
- assertEquals(expected, writer.toString());
+ @Override
+ protected Class<?> getToolsClass() {
+ return WriterTools.class;
}
}

Back to the top