Update text tests to JUnit Jupiter

Upgrade the tests in the text package to use JUnit Jupiter as
part of the effort to remove the dependency on the Vintage Engine.

While most of these changes are drop-in replacements with no functional
benefit, there are some non-obvious changes worth mentioning.

Unlike org.junit.Test, org.junit.jupiter.api.Test does not have an
"expected" argument. Instead, an explicit call to
org.junit.jupiter.api.Assertions.assertThrows is used.

It's also worth noting this is a minimal patch for migrating the
package's tests to Jupiter. There are several tests that can be made
more elegant with Jupiter's new features, but that work is left for
subsequent patches.
This commit is contained in:
Allon Mureinik 2018-10-02 06:41:37 +03:00
parent cbc8e0b295
commit 182e335432
18 changed files with 194 additions and 193 deletions

View File

@ -17,9 +17,9 @@
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.text.FieldPosition; import java.text.FieldPosition;
import java.text.Format; import java.text.Format;
@ -71,8 +71,8 @@ public Object parseObject(final String source, final ParsePosition pos) {
composite.parseObject("", null); composite.parseObject("", null);
composite.format(new Object(), new StringBuffer(), null); composite.format(new Object(), new StringBuffer(), null);
assertEquals( "Parser get method incorrectly implemented", parser, composite.getParser() ); assertEquals(parser, composite.getParser(), "Parser get method incorrectly implemented");
assertEquals( "Formatter get method incorrectly implemented", formatter, composite.getFormatter() ); assertEquals(formatter, composite.getFormatter(), "Formatter get method incorrectly implemented");
} }
@Test @Test

View File

@ -16,12 +16,12 @@
*/ */
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.FieldPosition; import java.text.FieldPosition;
@ -47,7 +47,7 @@ public class ExtendedMessageFormatTest {
private final Map<String, FormatFactory> registry = new HashMap<>(); private final Map<String, FormatFactory> registry = new HashMap<>();
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
registry.put("lower", new LowerCaseFormatFactory()); registry.put("lower", new LowerCaseFormatFactory());
registry.put("upper", new UpperCaseFormatFactory()); registry.put("upper", new UpperCaseFormatFactory());
@ -60,12 +60,12 @@ public void setUp() throws Exception {
public void testExtendedFormats() { public void testExtendedFormats() {
final String pattern = "Lower: {0,lower} Upper: {1,upper}"; final String pattern = "Lower: {0,lower} Upper: {1,upper}";
final ExtendedMessageFormat emf = new ExtendedMessageFormat(pattern, registry); final ExtendedMessageFormat emf = new ExtendedMessageFormat(pattern, registry);
assertEquals("TOPATTERN", pattern, emf.toPattern()); assertEquals(pattern, emf.toPattern(), "TOPATTERN");
assertEquals("Lower: foo Upper: BAR", emf.format(new Object[] {"foo", "bar"})); assertEquals(emf.format(new Object[] {"foo", "bar"}), "Lower: foo Upper: BAR");
assertEquals("Lower: foo Upper: BAR", emf.format(new Object[] {"Foo", "Bar"})); assertEquals(emf.format(new Object[] {"Foo", "Bar"}), "Lower: foo Upper: BAR");
assertEquals("Lower: foo Upper: BAR", emf.format(new Object[] {"FOO", "BAR"})); assertEquals(emf.format(new Object[] {"FOO", "BAR"}), "Lower: foo Upper: BAR");
assertEquals("Lower: foo Upper: BAR", emf.format(new Object[] {"FOO", "bar"})); assertEquals(emf.format(new Object[] {"FOO", "bar"}), "Lower: foo Upper: BAR");
assertEquals("Lower: foo Upper: BAR", emf.format(new Object[] {"foo", "BAR"})); assertEquals(emf.format(new Object[] {"foo", "BAR"}), "Lower: foo Upper: BAR");
} }
/** /**
@ -143,8 +143,8 @@ public void testExtendedAndBuiltInFormats() {
expected.append(df.format(args[1])); expected.append(df.format(args[1]));
expected.append(" Salary: "); expected.append(" Salary: ");
expected.append(nf.format(args[2])); expected.append(nf.format(args[2]));
assertEquals("pattern comparison for locale " + locale, expectedPattern, emf.toPattern()); assertEquals(expectedPattern, emf.toPattern(), "pattern comparison for locale " + locale);
assertEquals(String.valueOf(locale), expected.toString(), emf.format(args)); assertEquals(expected.toString(), emf.format(args), String.valueOf(locale));
} }
} }
@ -268,8 +268,8 @@ public void testOverriddenBuiltinFormat() {
final MessageFormat dateDefault = createMessageFormat("{0,date}", locale); final MessageFormat dateDefault = createMessageFormat("{0,date}", locale);
final String pattern = "{0,date,short}"; final String pattern = "{0,date,short}";
final ExtendedMessageFormat dateShort = new ExtendedMessageFormat(pattern, locale, dateRegistry); final ExtendedMessageFormat dateShort = new ExtendedMessageFormat(pattern, locale, dateRegistry);
assertEquals("overridden date,short format", dateDefault.format(args), dateShort.format(args)); assertEquals(dateDefault.format(args), dateShort.format(args), "overridden date,short format");
assertEquals("overridden date,short pattern", pattern, dateShort.toPattern()); assertEquals(pattern, dateShort.toPattern(), "overridden date,short pattern");
} }
} }
@ -301,33 +301,33 @@ public void testEqualsHashcode() {
ExtendedMessageFormat other = null; ExtendedMessageFormat other = null;
// Same object // Same object
assertTrue("same, equals()", emf.equals(emf)); assertTrue(emf.equals(emf), "same, equals()");
assertTrue("same, hashcode()", emf.hashCode() == emf.hashCode()); assertTrue(emf.hashCode() == emf.hashCode(), "same, hashcode()");
// Equal Object // Equal Object
other = new ExtendedMessageFormat(pattern, Locale.US, fmtRegistry); other = new ExtendedMessageFormat(pattern, Locale.US, fmtRegistry);
assertTrue("equal, equals()", emf.equals(other)); assertTrue(emf.equals(other), "equal, equals()");
assertTrue("equal, hashcode()", emf.hashCode() == other.hashCode()); assertTrue(emf.hashCode() == other.hashCode(), "equal, hashcode()");
// Different Class // Different Class
other = new OtherExtendedMessageFormat(pattern, Locale.US, fmtRegistry); other = new OtherExtendedMessageFormat(pattern, Locale.US, fmtRegistry);
assertFalse("class, equals()", emf.equals(other)); assertFalse(emf.equals(other), "class, equals()");
assertTrue("class, hashcode()", emf.hashCode() == other.hashCode()); // same hashcode assertTrue(emf.hashCode() == other.hashCode(), "class, hashcode()"); // same hashcode
// Different pattern // Different pattern
other = new ExtendedMessageFormat("X" + pattern, Locale.US, fmtRegistry); other = new ExtendedMessageFormat("X" + pattern, Locale.US, fmtRegistry);
assertFalse("pattern, equals()", emf.equals(other)); assertFalse(emf.equals(other), "pattern, equals()");
assertFalse("pattern, hashcode()", emf.hashCode() == other.hashCode()); assertFalse(emf.hashCode() == other.hashCode(), "pattern, hashcode()");
// Different registry // Different registry
other = new ExtendedMessageFormat(pattern, Locale.US, otherRegitry); other = new ExtendedMessageFormat(pattern, Locale.US, otherRegitry);
assertFalse("registry, equals()", emf.equals(other)); assertFalse(emf.equals(other), "registry, equals()");
assertFalse("registry, hashcode()", emf.hashCode() == other.hashCode()); assertFalse(emf.hashCode() == other.hashCode(), "registry, hashcode()");
// Different Locale // Different Locale
other = new ExtendedMessageFormat(pattern, Locale.FRANCE, fmtRegistry); other = new ExtendedMessageFormat(pattern, Locale.FRANCE, fmtRegistry);
assertFalse("locale, equals()", emf.equals(other)); assertFalse(emf.equals(other), "locale, equals()");
assertTrue("locale, hashcode()", emf.hashCode() == other.hashCode()); // same hashcode assertTrue(emf.hashCode() == other.hashCode(), "locale, hashcode()"); // same hashcode
} }
/** /**
@ -376,8 +376,8 @@ private void checkBuiltInFormat(final String pattern, final Map<String, ?> regis
} else { } else {
emf = new ExtendedMessageFormat(pattern, locale); emf = new ExtendedMessageFormat(pattern, locale);
} }
assertEquals("format " + buffer.toString(), mf.format(args), emf.format(args)); assertEquals(mf.format(args), emf.format(args), "format " + buffer.toString());
assertEquals("toPattern " + buffer.toString(), mf.toPattern(), emf.toPattern()); assertEquals(mf.toPattern(), emf.toPattern(), "toPattern " + buffer.toString());
} }
/** /**

View File

@ -17,11 +17,12 @@
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import static java.util.FormattableFlags.LEFT_JUSTIFY; import static java.util.FormattableFlags.LEFT_JUSTIFY;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Formatter; import java.util.Formatter;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests {@link FormattableUtils}. * Unit tests {@link FormattableUtils}.
@ -83,9 +84,9 @@ public void testEllipsis() {
assertEquals("+* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, "+*").toString()); assertEquals("+* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, "+*").toString());
} }
@Test(expected=IllegalArgumentException.class) @Test
public void testIllegalEllipsis() { public void testIllegalEllipsis() {
FormattableUtils.append("foo", new Formatter(), 0, -1, 1, "xx"); assertThrows(IllegalArgumentException.class, () -> FormattableUtils.append("foo", new Formatter(), 0, -1, 1, "xx"));
} }
@Test @Test

View File

@ -17,10 +17,10 @@
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.Arrays; import java.util.Arrays;

View File

@ -17,16 +17,16 @@
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
@ -479,13 +479,13 @@ public void testToCharArray() {
assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, sb.toCharArray()); assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, sb.toCharArray());
char[] a = sb.toCharArray(); char[] a = sb.toCharArray();
assertNotNull("toCharArray() result is null", a); assertNotNull(a, "toCharArray() result is null");
assertEquals("toCharArray() result is too large", 0, a.length); assertEquals(0, a.length, "toCharArray() result is too large");
sb.append("junit"); sb.append("junit");
a = sb.toCharArray(); a = sb.toCharArray();
assertEquals("toCharArray() result incorrect length", 5, a.length); assertEquals(5, a.length, "toCharArray() result incorrect length");
assertTrue("toCharArray() result does not match", Arrays.equals("junit".toCharArray(), a)); assertTrue(Arrays.equals("junit".toCharArray(), a), "toCharArray() result does not match");
} }
@Test @Test
@ -495,19 +495,19 @@ public void testToCharArrayIntInt() {
sb.append("junit"); sb.append("junit");
char[] a = sb.toCharArray(0, 20); // too large test char[] a = sb.toCharArray(0, 20); // too large test
assertEquals("toCharArray(int,int) result incorrect length", 5, a.length); assertEquals(5, a.length, "toCharArray(int,int) result incorrect length");
assertTrue("toCharArray(int,int) result does not match", Arrays.equals("junit".toCharArray(), a)); assertTrue(Arrays.equals("junit".toCharArray(), a), "toCharArray(int,int) result does not match");
a = sb.toCharArray(0, 4); a = sb.toCharArray(0, 4);
assertEquals("toCharArray(int,int) result incorrect length", 4, a.length); assertEquals(4, a.length, "toCharArray(int,int) result incorrect length");
assertTrue("toCharArray(int,int) result does not match", Arrays.equals("juni".toCharArray(), a)); assertTrue(Arrays.equals("juni".toCharArray(), a), "toCharArray(int,int) result does not match");
a = sb.toCharArray(0, 4); a = sb.toCharArray(0, 4);
assertEquals("toCharArray(int,int) result incorrect length", 4, a.length); assertEquals(4, a.length, "toCharArray(int,int) result incorrect length");
assertTrue("toCharArray(int,int) result does not match", Arrays.equals("juni".toCharArray(), a)); assertTrue(Arrays.equals("juni".toCharArray(), a), "toCharArray(int,int) result does not match");
a = sb.toCharArray(0, 1); a = sb.toCharArray(0, 1);
assertNotNull("toCharArray(int,int) result is null", a); assertNotNull(a, "toCharArray(int,int) result is null");
try { try {
sb.toCharArray(-1, 5); sb.toCharArray(-1, 5);
@ -1927,8 +1927,8 @@ public void testIndexOfLang294() {
public void testLang295() { public void testLang295() {
final StrBuilder sb = new StrBuilder("onetwothree"); final StrBuilder sb = new StrBuilder("onetwothree");
sb.deleteFirst("three"); sb.deleteFirst("three");
assertFalse( "The contains(char) method is looking beyond the end of the string", sb.contains('h')); assertFalse(sb.contains('h'), "The contains(char) method is looking beyond the end of the string");
assertEquals( "The indexOf(char) method is looking beyond the end of the string", -1, sb.indexOf('h')); assertEquals(-1, sb.indexOf('h'), "The indexOf(char) method is looking beyond the end of the string");
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -1936,14 +1936,14 @@ public void testLang295() {
public void testLang412Right() { public void testLang412Right() {
final StrBuilder sb = new StrBuilder(); final StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadRight(null, 10, '*'); sb.appendFixedWidthPadRight(null, 10, '*');
assertEquals( "Failed to invoke appendFixedWidthPadRight correctly", "**********", sb.toString()); assertEquals("**********", sb.toString(), "Failed to invoke appendFixedWidthPadRight correctly");
} }
@Test @Test
public void testLang412Left() { public void testLang412Left() {
final StrBuilder sb = new StrBuilder(); final StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadLeft(null, 10, '*'); sb.appendFixedWidthPadLeft(null, 10, '*');
assertEquals( "Failed to invoke appendFixedWidthPadLeft correctly", "**********", sb.toString()); assertEquals("**********", sb.toString(), "Failed to invoke appendFixedWidthPadLeft correctly");
} }
@Test @Test

View File

@ -17,15 +17,15 @@
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Test class for StrLookup. * Test class for StrLookup.
@ -70,7 +70,7 @@ public void testSystemPropertiesLookupReplacedProperties() {
newProps.setProperty(osName, newOsName); newProps.setProperty(osName, newOsName);
System.setProperties(newProps); System.setProperties(newProps);
try { try {
assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName)); assertEquals(newOsName, sysLookup.lookup(osName), "Changed properties not detected");
} finally { } finally {
System.setProperties(oldProperties); System.setProperties(oldProperties);
} }
@ -89,7 +89,7 @@ public void testSystemPropertiesLookupUpdatedProperty() {
final StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup(); final StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup();
System.setProperty(osName, newOsName); System.setProperty(osName, newOsName);
try { try {
assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName)); assertEquals(newOsName, sysLookup.lookup(osName), "Changed properties not detected");
} finally { } finally {
System.setProperty(osName, oldOs); System.setProperty(osName, oldOs);
} }

View File

@ -17,11 +17,11 @@
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.StrMatcher}. * Unit tests for {@link org.apache.commons.lang3.text.StrMatcher}.

View File

@ -17,21 +17,21 @@
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.mutable.MutableObject;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Test class for StrSubstitutor. * Test class for StrSubstitutor.
@ -41,14 +41,14 @@ public class StrSubstitutorTest {
private Map<String, String> values; private Map<String, String> values;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
values = new HashMap<>(); values = new HashMap<>();
values.put("animal", "quick brown fox"); values.put("animal", "quick brown fox");
values.put("target", "lazy dog"); values.put("target", "lazy dog");
} }
@After @AfterEach
public void tearDown() throws Exception { public void tearDown() throws Exception {
values = null; values = null;
} }
@ -308,18 +308,18 @@ public void testReplaceInVariable() {
final StrSubstitutor sub = new StrSubstitutor(values); final StrSubstitutor sub = new StrSubstitutor(values);
sub.setEnableSubstitutionInVariables(true); sub.setEnableSubstitutionInVariables(true);
assertEquals( assertEquals(
"Wrong result (1)",
"The mouse jumps over the lazy dog.", "The mouse jumps over the lazy dog.",
sub.replace("The ${animal.${species}} jumps over the ${target}.")); sub.replace("The ${animal.${species}} jumps over the ${target}."),
"Wrong result (1)");
values.put("species", "1"); values.put("species", "1");
assertEquals( assertEquals(
"Wrong result (2)",
"The fox jumps over the lazy dog.", "The fox jumps over the lazy dog.",
sub.replace("The ${animal.${species}} jumps over the ${target}.")); sub.replace("The ${animal.${species}} jumps over the ${target}."),
"Wrong result (2)");
assertEquals( assertEquals(
"Wrong result (3)",
"The fox jumps over the lazy dog.", "The fox jumps over the lazy dog.",
sub.replace("The ${unknown.animal.${unknown.species:-1}:-fox} jumps over the ${unknown.target:-lazy dog}.")); sub.replace("The ${unknown.animal.${unknown.species:-1}:-fox} jumps over the ${unknown.target:-lazy dog}."),
"Wrong result (3)");
} }
/** /**
@ -332,13 +332,13 @@ public void testReplaceInVariableDisabled() {
values.put("species", "2"); values.put("species", "2");
final StrSubstitutor sub = new StrSubstitutor(values); final StrSubstitutor sub = new StrSubstitutor(values);
assertEquals( assertEquals(
"Wrong result (1)",
"The ${animal.${species}} jumps over the lazy dog.", "The ${animal.${species}} jumps over the lazy dog.",
sub.replace("The ${animal.${species}} jumps over the ${target}.")); sub.replace("The ${animal.${species}} jumps over the ${target}."),
"Wrong result (1)");
assertEquals( assertEquals(
"Wrong result (2)",
"The ${animal.${species:-1}} jumps over the lazy dog.", "The ${animal.${species:-1}} jumps over the lazy dog.",
sub.replace("The ${animal.${species:-1}} jumps over the ${target}.")); sub.replace("The ${animal.${species:-1}} jumps over the ${target}."),
"Wrong result (2)");
} }
/** /**
@ -354,13 +354,13 @@ public void testReplaceInVariableRecursive() {
final StrSubstitutor sub = new StrSubstitutor(values); final StrSubstitutor sub = new StrSubstitutor(values);
sub.setEnableSubstitutionInVariables(true); sub.setEnableSubstitutionInVariables(true);
assertEquals( assertEquals(
"Wrong result (1)",
"The white mouse jumps over the lazy dog.", "The white mouse jumps over the lazy dog.",
sub.replace("The ${animal.${species.${color}}} jumps over the ${target}.")); sub.replace("The ${animal.${species.${color}}} jumps over the ${target}."),
"Wrong result (1)");
assertEquals( assertEquals(
"Wrong result (2)",
"The brown fox jumps over the lazy dog.", "The brown fox jumps over the lazy dog.",
sub.replace("The ${animal.${species.${unknownColor:-brown}}} jumps over the ${target}.")); sub.replace("The ${animal.${species.${unknownColor:-brown}}} jumps over the ${target}."),
"Wrong result (2)");
} }
@Test @Test

View File

@ -17,13 +17,13 @@
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -61,10 +61,10 @@ public void test1() {
final String expected[] = new String[]{"a", "b", "c", "d;\"e", "f", "", "", "",}; final String expected[] = new String[]{"a", "b", "c", "d;\"e", "f", "", "", "",};
assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); assertEquals(expected.length, tokens.length, ArrayUtils.toString(tokens));
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", assertEquals(expected[i], tokens[i],
expected[i], tokens[i]); "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'");
} }
} }
@ -82,10 +82,10 @@ public void test2() {
final String expected[] = new String[]{"a", "b", "c ", "d;\"e", "f", " ", " ", "",}; final String expected[] = new String[]{"a", "b", "c ", "d;\"e", "f", " ", " ", "",};
assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); assertEquals(expected.length, tokens.length, ArrayUtils.toString(tokens));
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", assertEquals(expected[i], tokens[i],
expected[i], tokens[i]); "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'");
} }
} }
@ -103,10 +103,10 @@ public void test3() {
final String expected[] = new String[]{"a", "b", " c", "d;\"e", "f", " ", " ", "",}; final String expected[] = new String[]{"a", "b", " c", "d;\"e", "f", " ", " ", "",};
assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); assertEquals(expected.length, tokens.length, ArrayUtils.toString(tokens));
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", assertEquals(expected[i], tokens[i],
expected[i], tokens[i]); "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'");
} }
} }
@ -124,10 +124,10 @@ public void test4() {
final String expected[] = new String[]{"a", "b", "c", "d;\"e", "f",}; final String expected[] = new String[]{"a", "b", "c", "d;\"e", "f",};
assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); assertEquals(expected.length, tokens.length, ArrayUtils.toString(tokens));
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", assertEquals(expected[i], tokens[i],
expected[i], tokens[i]); "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'");
} }
} }
@ -146,10 +146,10 @@ public void test5() {
final String expected[] = new String[]{"a", "b", "c", "d;\"e", "f", null, null, null,}; final String expected[] = new String[]{"a", "b", "c", "d;\"e", "f", null, null, null,};
assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); assertEquals(expected.length, tokens.length, ArrayUtils.toString(tokens));
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", assertEquals(expected[i], tokens[i],
expected[i], tokens[i]); "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'");
} }
} }
@ -180,13 +180,13 @@ public void test6() {
prevCount++; prevCount++;
} }
assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); assertEquals(expected.length, tokens.length, ArrayUtils.toString(tokens));
assertTrue("could not cycle through entire token list" + " using the 'hasNext' and 'next' methods", assertTrue(nextCount == expected.length,
nextCount == expected.length); "could not cycle through entire token list" + " using the 'hasNext' and 'next' methods");
assertTrue("could not cycle through entire token list" + " using the 'hasPrevious' and 'previous' methods", assertTrue(prevCount == expected.length,
prevCount == expected.length); "could not cycle through entire token list" + " using the 'hasPrevious' and 'previous' methods");
} }
@ -203,10 +203,10 @@ public void test7() {
final String expected[] = new String[]{"a", "", "", "b", "c", "d e", "f", "",}; final String expected[] = new String[]{"a", "", "", "b", "c", "d e", "f", "",};
assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); assertEquals(expected.length, tokens.length, ArrayUtils.toString(tokens));
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", assertEquals(expected[i], tokens[i],
expected[i], tokens[i]); "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'");
} }
} }
@ -224,10 +224,10 @@ public void test8() {
final String expected[] = new String[]{"a", "b", "c", "d e", "f",}; final String expected[] = new String[]{"a", "b", "c", "d e", "f",};
assertEquals(ArrayUtils.toString(tokens), expected.length, tokens.length); assertEquals(expected.length, tokens.length, ArrayUtils.toString(tokens));
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", assertEquals(expected[i], tokens[i],
expected[i], tokens[i]); "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'");
} }
} }

View File

@ -16,16 +16,16 @@
*/ */
package org.apache.commons.lang3.text; package org.apache.commons.lang3.text;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for WordUtils class. * Unit tests for WordUtils class.

View File

@ -17,12 +17,12 @@
package org.apache.commons.lang3.text.translate; package org.apache.commons.lang3.text.translate;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.translate.EntityArrays}. * Unit tests for {@link org.apache.commons.lang3.text.translate.EntityArrays}.
@ -42,8 +42,8 @@ public void testHTML40_EXTENDED_ESCAPE(){
final Set<String> col1 = new HashSet<>(); final Set<String> col1 = new HashSet<>();
final String [][] sa = EntityArrays.HTML40_EXTENDED_ESCAPE(); final String [][] sa = EntityArrays.HTML40_EXTENDED_ESCAPE();
for(int i =0; i <sa.length; i++){ for(int i =0; i <sa.length; i++){
assertTrue("Already added entry 0: "+i+" "+sa[i][0],col0.add(sa[i][0])); assertTrue(col0.add(sa[i][0]), "Already added entry 0: "+i+" "+sa[i][0]);
assertTrue("Already added entry 1: "+i+" "+sa[i][1],col1.add(sa[i][1])); assertTrue(col1.add(sa[i][1]), "Already added entry 1: "+i+" "+sa[i][1]);
} }
} }
@ -66,7 +66,7 @@ public void testISO8859_1_ESCAPE(){
System.out.println("Already added entry 1: "+i+" "+sa[i][0]+" "+sa[i][1]); System.out.println("Already added entry 1: "+i+" "+sa[i][0]+" "+sa[i][1]);
} }
} }
assertTrue("One or more errors detected",success); assertTrue(success, "One or more errors detected");
} }

View File

@ -17,12 +17,12 @@
package org.apache.commons.lang3.text.translate; package org.apache.commons.lang3.text.translate;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.translate.LookupTranslator}. * Unit tests for {@link org.apache.commons.lang3.text.translate.LookupTranslator}.
@ -35,8 +35,8 @@ public void testBasicLookup() throws IOException {
final LookupTranslator lt = new LookupTranslator(new CharSequence[][] { { "one", "two" } }); final LookupTranslator lt = new LookupTranslator(new CharSequence[][] { { "one", "two" } });
final StringWriter out = new StringWriter(); final StringWriter out = new StringWriter();
final int result = lt.translate("one", 0, out); final int result = lt.translate("one", 0, out);
assertEquals("Incorrect codepoint consumption", 3, result); assertEquals(3, result, "Incorrect codepoint consumption");
assertEquals("Incorrect value", "two", out.toString()); assertEquals("two", out.toString(), "Incorrect value");
} }
// Tests: https://issues.apache.org/jira/browse/LANG-882 // Tests: https://issues.apache.org/jira/browse/LANG-882
@ -45,8 +45,8 @@ public void testLang882() throws IOException {
final LookupTranslator lt = new LookupTranslator(new CharSequence[][] { { new StringBuffer("one"), new StringBuffer("two") } }); final LookupTranslator lt = new LookupTranslator(new CharSequence[][] { { new StringBuffer("one"), new StringBuffer("two") } });
final StringWriter out = new StringWriter(); final StringWriter out = new StringWriter();
final int result = lt.translate(new StringBuffer("one"), 0, out); final int result = lt.translate(new StringBuffer("one"), 0, out);
assertEquals("Incorrect codepoint consumption", 3, result); assertEquals(3, result, "Incorrect codepoint consumption");
assertEquals("Incorrect value", "two", out.toString()); assertEquals("two", out.toString(), "Incorrect value");
} }
} }

View File

@ -17,9 +17,9 @@
package org.apache.commons.lang3.text.translate; package org.apache.commons.lang3.text.translate;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityEscaper}. * Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityEscaper}.
@ -33,7 +33,7 @@ public void testBelow() {
final String input = "ADFGZ"; final String input = "ADFGZ";
final String result = nee.translate(input); final String result = nee.translate(input);
assertEquals("Failed to escape numeric entities via the below method", "&#65;&#68;FGZ", result); assertEquals("&#65;&#68;FGZ", result, "Failed to escape numeric entities via the below method");
} }
@Test @Test
@ -42,7 +42,7 @@ public void testBetween() {
final String input = "ADFGZ"; final String input = "ADFGZ";
final String result = nee.translate(input); final String result = nee.translate(input);
assertEquals("Failed to escape numeric entities via the between method", "AD&#70;&#71;Z", result); assertEquals("AD&#70;&#71;Z", result, "Failed to escape numeric entities via the between method");
} }
@Test @Test
@ -51,7 +51,7 @@ public void testAbove() {
final String input = "ADFGZ"; final String input = "ADFGZ";
final String result = nee.translate(input); final String result = nee.translate(input);
assertEquals("Failed to escape numeric entities via the above method", "ADF&#71;&#90;", result); assertEquals("ADF&#71;&#90;", result, "Failed to escape numeric entities via the above method");
} }
// See LANG-617 // See LANG-617
@ -62,7 +62,7 @@ public void testSupplementary() {
final String expected = "&#68642;"; final String expected = "&#68642;";
final String result = nee.translate(input); final String result = nee.translate(input);
assertEquals("Failed to escape numeric entities supplementary characters", expected, result); assertEquals(expected, result, "Failed to escape numeric entities supplementary characters");
} }

View File

@ -17,10 +17,10 @@
package org.apache.commons.lang3.text.translate; package org.apache.commons.lang3.text.translate;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityUnescaper}. * Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityUnescaper}.
@ -35,17 +35,17 @@ public void testSupplementaryUnescaping() {
final String expected = "\uD803\uDC22"; final String expected = "\uD803\uDC22";
final String result = neu.translate(input); final String result = neu.translate(input);
assertEquals("Failed to unescape numeric entities supplementary characters", expected, result); assertEquals(expected, result, "Failed to unescape numeric entities supplementary characters");
} }
@Test @Test
public void testOutOfBounds() { public void testOutOfBounds() {
final NumericEntityUnescaper neu = new NumericEntityUnescaper(); final NumericEntityUnescaper neu = new NumericEntityUnescaper();
assertEquals("Failed to ignore when last character is &", "Test &", neu.translate("Test &")); assertEquals("Test &", neu.translate("Test &"), "Failed to ignore when last character is &");
assertEquals("Failed to ignore when last character is &", "Test &#", neu.translate("Test &#")); assertEquals("Test &#", neu.translate("Test &#"), "Failed to ignore when last character is &");
assertEquals("Failed to ignore when last character is &", "Test &#x", neu.translate("Test &#x")); assertEquals("Test &#x", neu.translate("Test &#x"), "Failed to ignore when last character is &");
assertEquals("Failed to ignore when last character is &", "Test &#X", neu.translate("Test &#X")); assertEquals("Test &#X", neu.translate("Test &#X"), "Failed to ignore when last character is &");
} }
@Test @Test
@ -56,7 +56,7 @@ public void testUnfinishedEntity() {
String expected = "Test \u0030 not test"; String expected = "Test \u0030 not test";
String result = neu.translate(input); String result = neu.translate(input);
assertEquals("Failed to support unfinished entities (i.e. missing semi-colon)", expected, result); assertEquals(expected, result, "Failed to support unfinished entities (i.e. missing semi-colon)");
// ignore it // ignore it
neu = new NumericEntityUnescaper(); neu = new NumericEntityUnescaper();
@ -64,7 +64,7 @@ public void testUnfinishedEntity() {
expected = input; expected = input;
result = neu.translate(input); result = neu.translate(input);
assertEquals("Failed to ignore unfinished entities (i.e. missing semi-colon)", expected, result); assertEquals(expected, result, "Failed to ignore unfinished entities (i.e. missing semi-colon)");
// fail it // fail it
neu = new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.errorIfNoSemiColon); neu = new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.errorIfNoSemiColon);

View File

@ -17,8 +17,8 @@
package org.apache.commons.lang3.text.translate; package org.apache.commons.lang3.text.translate;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.translate.OctalUnescaper}. * Unit tests for {@link org.apache.commons.lang3.text.translate.OctalUnescaper}.
@ -32,51 +32,51 @@ public void testBetween() {
String input = "\\45"; String input = "\\45";
String result = oue.translate(input); String result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\45", result); assertEquals("\45", result, "Failed to unescape octal characters via the between method");
input = "\\377"; input = "\\377";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\377", result); assertEquals("\377", result, "Failed to unescape octal characters via the between method");
input = "\\377 and"; input = "\\377 and";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\377 and", result); assertEquals("\377 and", result, "Failed to unescape octal characters via the between method");
input = "\\378 and"; input = "\\378 and";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\37" + "8 and", result); assertEquals("\37" + "8 and", result, "Failed to unescape octal characters via the between method");
input = "\\378"; input = "\\378";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\37" + "8", result); assertEquals("\37" + "8", result, "Failed to unescape octal characters via the between method");
input = "\\1"; input = "\\1";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\1", result); assertEquals("\1", result, "Failed to unescape octal characters via the between method");
input = "\\036"; input = "\\036";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\036", result); assertEquals("\036", result, "Failed to unescape octal characters via the between method");
input = "\\0365"; input = "\\0365";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\036" + "5", result); assertEquals("\036" + "5", result, "Failed to unescape octal characters via the between method");
input = "\\003"; input = "\\003";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\003", result); assertEquals("\003", result, "Failed to unescape octal characters via the between method");
input = "\\0003"; input = "\\0003";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\000" + "3", result); assertEquals("\000" + "3", result, "Failed to unescape octal characters via the between method");
input = "\\279"; input = "\\279";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to unescape octal characters via the between method", "\279", result); assertEquals("\279", result, "Failed to unescape octal characters via the between method");
input = "\\999"; input = "\\999";
result = oue.translate(input); result = oue.translate(input);
assertEquals("Failed to ignore an out of range octal character via the between method", "\\999", result); assertEquals("\\999", result, "Failed to ignore an out of range octal character via the between method");
} }
} }

View File

@ -17,9 +17,9 @@
package org.apache.commons.lang3.text.translate; package org.apache.commons.lang3.text.translate;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}. * Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
@ -33,7 +33,7 @@ public void testBelow() {
final String input = "ADFGZ"; final String input = "ADFGZ";
final String result = ue.translate(input); final String result = ue.translate(input);
assertEquals("Failed to escape Unicode characters via the below method", "\\u0041\\u0044FGZ", result); assertEquals("\\u0041\\u0044FGZ", result, "Failed to escape Unicode characters via the below method");
} }
@Test @Test
@ -42,7 +42,7 @@ public void testBetween() {
final String input = "ADFGZ"; final String input = "ADFGZ";
final String result = ue.translate(input); final String result = ue.translate(input);
assertEquals("Failed to escape Unicode characters via the between method", "AD\\u0046\\u0047Z", result); assertEquals("AD\\u0046\\u0047Z", result, "Failed to escape Unicode characters via the between method");
} }
@Test @Test
@ -51,6 +51,6 @@ public void testAbove() {
final String input = "ADFGZ"; final String input = "ADFGZ";
final String result = ue.translate(input); final String result = ue.translate(input);
assertEquals("Failed to escape Unicode characters via the above method", "ADF\\u0047\\u005A", result); assertEquals("ADF\\u0047\\u005A", result, "Failed to escape Unicode characters via the above method");
} }
} }

View File

@ -17,10 +17,10 @@
package org.apache.commons.lang3.text.translate; package org.apache.commons.lang3.text.translate;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}. * Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
@ -34,7 +34,7 @@ public void testUPlus() {
final UnicodeUnescaper uu = new UnicodeUnescaper(); final UnicodeUnescaper uu = new UnicodeUnescaper();
final String input = "\\u+0047"; final String input = "\\u+0047";
assertEquals("Failed to unescape Unicode characters with 'u+' notation", "G", uu.translate(input)); assertEquals("G", uu.translate(input), "Failed to unescape Unicode characters with 'u+' notation");
} }
@Test @Test
@ -43,7 +43,7 @@ public void testUuuuu() {
final String input = "\\uuuuuuuu0047"; final String input = "\\uuuuuuuu0047";
final String result = uu.translate(input); final String result = uu.translate(input);
assertEquals("Failed to unescape Unicode characters with many 'u' characters", "G", result); assertEquals("G", result, "Failed to unescape Unicode characters with many 'u' characters");
} }
@Test @Test

View File

@ -16,13 +16,13 @@
*/ */
package org.apache.commons.lang3.text.translate; package org.apache.commons.lang3.text.translate;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.CharArrayWriter; import java.io.CharArrayWriter;
import java.io.IOException; import java.io.IOException;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeUnpairedSurrogateRemover}. * Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeUnpairedSurrogateRemover}.