diff --git a/src/test/org/apache/commons/lang/text/translate/EntityArraysTest.java b/src/test/org/apache/commons/lang/text/translate/EntityArraysTest.java new file mode 100644 index 000000000..171af7084 --- /dev/null +++ b/src/test/org/apache/commons/lang/text/translate/EntityArraysTest.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang.text.translate; + +import junit.framework.TestCase; + +import java.io.StringWriter; +import java.io.IOException; + +/** + * Unit tests for {@link org.apache.commons.lang.text.translate.EntityArrays}. + */ +public class EntityArraysTest extends TestCase { + + public void testConstructorExists() { + new EntityArrays(); + } +} diff --git a/src/test/org/apache/commons/lang/text/translate/EscapeUtilsTest.java b/src/test/org/apache/commons/lang/text/translate/EscapeUtilsTest.java new file mode 100644 index 000000000..9c1dd6e9c --- /dev/null +++ b/src/test/org/apache/commons/lang/text/translate/EscapeUtilsTest.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang.text.translate; + +import junit.framework.TestCase; + +import java.io.StringWriter; +import java.io.IOException; + +/** + * Unit tests for {@link org.apache.commons.lang.text.translate.EscapeUtils}. + */ +public class EscapeUtilsTest extends TestCase { + + public void testConstructorExists() { + new EscapeUtils(); + } +} diff --git a/src/test/org/apache/commons/lang/text/translate/NumericEntityEscaperTest.java b/src/test/org/apache/commons/lang/text/translate/NumericEntityEscaperTest.java new file mode 100644 index 000000000..052a34db8 --- /dev/null +++ b/src/test/org/apache/commons/lang/text/translate/NumericEntityEscaperTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang.text.translate; + +import junit.framework.TestCase; + +import java.io.StringWriter; +import java.io.IOException; + +/** + * Unit tests for {@link org.apache.commons.lang.text.translate.NumericEntityEscaper}. + */ +public class NumericEntityEscaperTest extends TestCase { + + public void testBelow() throws IOException { + NumericEntityEscaper nee = NumericEntityEscaper.below('F'); + + String input = "ADFGZ"; + String result = nee.translate(input); + assertEquals("Failed to escape numeric entities via the below method", "ADFGZ", result); + } + + public void testBetween() throws IOException { + NumericEntityEscaper nee = NumericEntityEscaper.between('F', 'L'); + + String input = "ADFGZ"; + String result = nee.translate(input); + assertEquals("Failed to escape numeric entities via the between method", "ADFGZ", result); + } + + public void testAbove() throws IOException { + NumericEntityEscaper nee = NumericEntityEscaper.above('F'); + + String input = "ADFGZ"; + String result = nee.translate(input); + assertEquals("Failed to escape numeric entities via the above method", "ADFGZ", result); + } +} diff --git a/src/test/org/apache/commons/lang/text/translate/UnescapeUtilsTest.java b/src/test/org/apache/commons/lang/text/translate/UnescapeUtilsTest.java new file mode 100644 index 000000000..11f9c20e2 --- /dev/null +++ b/src/test/org/apache/commons/lang/text/translate/UnescapeUtilsTest.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang.text.translate; + +import junit.framework.TestCase; + +import java.io.StringWriter; +import java.io.IOException; + +/** + * Unit tests for {@link org.apache.commons.lang.text.translate.UnescapeUtils}. + */ +public class UnescapeUtilsTest extends TestCase { + + public void testConstructorExists() { + new UnescapeUtils(); + } +} diff --git a/src/test/org/apache/commons/lang/text/translate/UnicodeEscaperTest.java b/src/test/org/apache/commons/lang/text/translate/UnicodeEscaperTest.java new file mode 100644 index 000000000..67ab5b744 --- /dev/null +++ b/src/test/org/apache/commons/lang/text/translate/UnicodeEscaperTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang.text.translate; + +import junit.framework.TestCase; + +import java.io.StringWriter; +import java.io.IOException; + +/** + * Unit tests for {@link org.apache.commons.lang.text.translate.UnicodeEscaper}. + */ +public class UnicodeEscaperTest extends TestCase { + + public void testBelow() throws IOException { + UnicodeEscaper nee = UnicodeEscaper.below('F'); + + String input = "ADFGZ"; + String result = nee.translate(input); + assertEquals("Failed to escape unicode characters via the below method", "\\u0041\\u0044FGZ", result); + } + + public void testBetween() throws IOException { + UnicodeEscaper nee = UnicodeEscaper.between('F', 'L'); + + String input = "ADFGZ"; + String result = nee.translate(input); + assertEquals("Failed to escape unicode characters via the between method", "AD\\u0046\\u0047Z", result); + } + + public void testAbove() throws IOException { + UnicodeEscaper nee = UnicodeEscaper.above('F'); + + String input = "ADFGZ"; + String result = nee.translate(input); + assertEquals("Failed to escape unicode characters via the above method", "ADF\\u0047\\u005A", result); + } +} diff --git a/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java b/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java new file mode 100644 index 000000000..3a6f85a50 --- /dev/null +++ b/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang.text.translate; + +import junit.framework.TestCase; + +import java.io.StringWriter; +import java.io.IOException; + +/** + * Unit tests for {@link org.apache.commons.lang.text.translate.UnicodeEscaper}. + */ +public class UnicodeUnescaperTest extends TestCase { + + public void testUuuuu() throws IOException { + UnicodeUnescaper uu = new UnicodeUnescaper(); + + String input = "\\uuuuuuuu0047"; + String result = uu.translate(input); + assertEquals("Failed to unescape unicode characters with many 'u' characters", "G", result); + } + + public void testLessThanFour() throws IOException { + UnicodeUnescaper uu = new UnicodeUnescaper(); + + String input = "\\0047\\u006"; + try { + uu.translate(input); + fail("A lack of digits in a unicode escape sequence failed to throw an exception"); + } catch(IllegalArgumentException iae) { + // expected + } + } +}