Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa/tests
diff options
context:
space:
mode:
authorbvosburgh2007-05-04 14:58:12 +0000
committerbvosburgh2007-05-04 14:58:12 +0000
commitecac8fd1160e2b17ae67986d350f13e6ea94f621 (patch)
tree8f12f79a9d26b8a38e66e3de6cb30af14aa2a0ae /jpa/tests
parenta4e8a2c43e075adc823250df753a9957465339cb (diff)
downloadwebtools.dali-ecac8fd1160e2b17ae67986d350f13e6ea94f621.tar.gz
webtools.dali-ecac8fd1160e2b17ae67986d350f13e6ea94f621.tar.xz
webtools.dali-ecac8fd1160e2b17ae67986d350f13e6ea94f621.zip
more code-completion work
Diffstat (limited to 'jpa/tests')
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java139
1 files changed, 137 insertions, 2 deletions
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
index 8e911e8e5a..454cb81651 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/StringToolsTests.java
@@ -226,6 +226,76 @@ public class StringToolsTests extends TestCase {
assertEquals(expected, sb.toString());
}
+ // ********** wrapping **********
+
+ public void testWrap() {
+ this.verifyWrap("Employee", "123", "123Employee123");
+ this.verifyWrap("123", "123", "123123123");
+ this.verifyWrap("", "123", "123123");
+ }
+
+ private void verifyWrap(String string, String wrap, String expectedString) {
+ assertEquals(expectedString, StringTools.wrap(string, wrap));
+ }
+
+ public void testWrapOnWriter() {
+ this.verifyWrapOnWriter("Employee", "123", "123Employee123");
+ this.verifyWrapOnWriter("123", "123", "123123123");
+ this.verifyWrapOnWriter("", "123", "123123");
+ }
+
+ private void verifyWrapOnWriter(String string, String wrap, String expectedString) {
+ Writer writer = new StringWriter();
+ StringTools.wrapOn(string, wrap, writer);
+ assertEquals(expectedString, writer.toString());
+ }
+
+ public void testWrapOnStringBuffer() {
+ this.verifyWrapOnStringBuffer("Employee", "123", "123Employee123");
+ this.verifyWrapOnStringBuffer("123", "123", "123123123");
+ this.verifyWrapOnStringBuffer("", "123", "123123");
+ }
+
+ private void verifyWrapOnStringBuffer(String string, String wrap, String expectedString) {
+ StringBuffer sb = new StringBuffer();
+ StringTools.wrapOn(string, wrap, sb);
+ assertEquals(expectedString, sb.toString());
+ }
+
+ public void testQuote() {
+ this.verifyQuote("Employee", "\"Employee\"");
+ this.verifyQuote("123", "\"123\"");
+ this.verifyQuote("", "\"\"");
+ }
+
+ private void verifyQuote(String string, String expectedString) {
+ assertEquals(expectedString, StringTools.quote(string));
+ }
+
+ public void testQuoteOnWriter() {
+ this.verifyQuoteOnWriter("Employee", "\"Employee\"");
+ this.verifyQuoteOnWriter("123", "\"123\"");
+ this.verifyQuoteOnWriter("", "\"\"");
+ }
+
+ private void verifyQuoteOnWriter(String string, String expectedString) {
+ Writer writer = new StringWriter();
+ StringTools.quoteOn(string, writer);
+ assertEquals(expectedString, writer.toString());
+ }
+
+ public void testQuoteOnStringBuffer() {
+ this.verifyQuoteOnStringBuffer("Employee", "\"Employee\"");
+ this.verifyQuoteOnStringBuffer("123", "\"123\"");
+ this.verifyQuoteOnStringBuffer("", "\"\"");
+ }
+
+ private void verifyQuoteOnStringBuffer(String string, String expectedString) {
+ StringBuffer sb = new StringBuffer();
+ StringTools.quoteOn(string, sb);
+ assertEquals(expectedString, sb.toString());
+ }
+
// ********** removing characters **********
public void testRemoveFirstOccurrence() {
@@ -337,6 +407,13 @@ public class StringToolsTests extends TestCase {
assertEquals(3, StringTools.commonPrefixLength("foo", "foo"));
}
+ 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));
+ }
+
// ********** capitalization **********
public void testCapitalizeCharArray() {
@@ -525,7 +602,7 @@ public class StringToolsTests extends TestCase {
// ********** queries **********
- public void testStringIsEmpty() {
+ public void testStringIsEmptyString() {
assertTrue(StringTools.stringIsEmpty((String) null));
assertTrue(StringTools.stringIsEmpty(""));
assertTrue(StringTools.stringIsEmpty(" "));
@@ -533,7 +610,19 @@ public class StringToolsTests extends TestCase {
assertTrue(StringTools.stringIsEmpty(" \t\t " + StringTools.CR));
}
- public void testStringsAreEqualIgnoreCase() {
+ public void testStringIsEmptyCharArray() {
+ assertTrue(StringTools.stringIsEmpty((char[]) null));
+ this.verifyStringIsEmptyCharArray("");
+ this.verifyStringIsEmptyCharArray(" \t\t ");
+ this.verifyStringIsEmptyCharArray(" ");
+ this.verifyStringIsEmptyCharArray(" \t\t " + StringTools.CR);
+ }
+
+ private void verifyStringIsEmptyCharArray(String string) {
+ assertTrue(StringTools.stringIsEmpty(string.toCharArray()));
+ }
+
+ public void testStringsAreEqualIgnoreCaseStringString() {
assertTrue(StringTools.stringsAreEqualIgnoreCase((String) null, (String) null));
assertFalse(StringTools.stringsAreEqualIgnoreCase(null, "asdf"));
assertFalse(StringTools.stringsAreEqualIgnoreCase("asdf", null));
@@ -541,6 +630,52 @@ public class StringToolsTests extends TestCase {
assertTrue(StringTools.stringsAreEqualIgnoreCase("asdf", "ASDF"));
}
+ public void testStringsAreEqualIgnoreCaseCharArrayCharArray() {
+ assertTrue(StringTools.stringsAreEqualIgnoreCase((char[]) null, (char[]) null));
+ assertFalse(StringTools.stringsAreEqualIgnoreCase((char[]) null, "asdf".toCharArray()));
+ assertFalse(StringTools.stringsAreEqualIgnoreCase("asdf".toCharArray(), (char[]) null));
+ assertTrue(StringTools.stringsAreEqualIgnoreCase("asdf".toCharArray(), "asdf".toCharArray()));
+ assertTrue(StringTools.stringsAreEqualIgnoreCase("asdf".toCharArray(), "ASDF".toCharArray()));
+ }
+
+ public void testStringStartsWithIgnoreCaseStringString() {
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf", "as"));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf", "aS"));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf", ""));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf", "A"));
+
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "bsdf"));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "g"));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "asdg"));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "asdfg"));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf", "asdfgggggg"));
+ }
+
+ public void testStringStartsWithIgnoreCaseCharArrayCharArray() {
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "as".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "aS".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "A".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "ASDF".toCharArray()));
+ assertTrue(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "asdf".toCharArray()));
+
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "bsdf".toCharArray()));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "g".toCharArray()));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "asdg".toCharArray()));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "asdfg".toCharArray()));
+ assertFalse(StringTools.stringStartsWithIgnoreCase("asdf".toCharArray(), "asdfgggggg".toCharArray()));
+ }
+
+ public void testCharactersAreEqualIgnoreCase() {
+ assertTrue(StringTools.charactersAreEqualIgnoreCase('a', 'a'));
+ assertTrue(StringTools.charactersAreEqualIgnoreCase('a', 'A'));
+ assertTrue(StringTools.charactersAreEqualIgnoreCase('A', 'a'));
+ assertTrue(StringTools.charactersAreEqualIgnoreCase('A', 'A'));
+
+ assertFalse(StringTools.charactersAreEqualIgnoreCase('a', 'b'));
+ assertFalse(StringTools.charactersAreEqualIgnoreCase('A', 'b'));
+ }
+
// ********** conversions **********
public void testConvertCamelCaseToAllCaps() {

Back to the top