Improving code coverage with more tests

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@796062 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-07-20 23:28:45 +00:00
parent 75b967beaa
commit cc6281fc3e
6 changed files with 254 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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
}
}
}