diff options
Diffstat (limited to 'common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/WriterToolsTests.java')
-rw-r--r-- | common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/WriterToolsTests.java | 719 |
1 files changed, 323 insertions, 396 deletions
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; } } |