http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/StringEscapeUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/StringEscapeUtilsTest.java b/src/test/java/org/apache/commons/text/StringEscapeUtilsTest.java index 84eba94..5b127ab 100644 --- a/src/test/java/org/apache/commons/text/StringEscapeUtilsTest.java +++ b/src/test/java/org/apache/commons/text/StringEscapeUtilsTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.text; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.StringWriter; @@ -29,12 +29,12 @@ import java.nio.file.Paths; import static org.apache.commons.text.StringEscapeUtils.escapeXSI; import static org.apache.commons.text.StringEscapeUtils.unescapeXSI; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Unit tests for {@link StringEscapeUtils}. @@ -62,35 +62,35 @@ public class StringEscapeUtilsTest { assertNull(StringEscapeUtils.escapeJava(null)); try { StringEscapeUtils.ESCAPE_JAVA.translate(null, null); - fail(); + fail("Exception expected!"); } catch (final IOException ex) { - fail(); + fail("Exception expected!"); } catch (final IllegalArgumentException ex) { } try { StringEscapeUtils.ESCAPE_JAVA.translate("", null); - fail(); + fail("Exception expected!"); } catch (final IOException ex) { - fail(); + fail("Exception expected!"); } catch (final IllegalArgumentException ex) { } - assertEscapeJava("empty string", "", ""); + assertEscapeJava("", "", "empty string"); assertEscapeJava(FOO, FOO); - assertEscapeJava("tab", "\\t", "\t"); - assertEscapeJava("backslash", "\\\\", "\\"); - assertEscapeJava("single quote should not be escaped", "'", "'"); + assertEscapeJava("\\t", "\t", "tab"); + assertEscapeJava("\\\\", "\\", "backslash"); + assertEscapeJava("'", "'", "single quote should not be escaped"); assertEscapeJava("\\\\\\b\\t\\r", "\\\b\t\r"); assertEscapeJava("\\u1234", "\u1234"); assertEscapeJava("\\u0234", "\u0234"); assertEscapeJava("\\u00EF", "\u00ef"); assertEscapeJava("\\u0001", "\u0001"); - assertEscapeJava("Should use capitalized Unicode hex", "\\uABCD", "\uabcd"); + assertEscapeJava("\\uABCD", "\uabcd", "Should use capitalized Unicode hex"); assertEscapeJava("He didn't say, \\\"stop!\\\"", "He didn't say, \"stop!\""); - assertEscapeJava("non-breaking space", "This space is non-breaking:" + "\\u00A0", - "This space is non-breaking:\u00a0"); + assertEscapeJava("This space is non-breaking:" + "\\u00A0", "This space is non-breaking:\u00a0", + "non-breaking space"); assertEscapeJava("\\uABCD\\u1234\\u012C", "\uABCD\u1234\u012C"); } @@ -113,13 +113,13 @@ public class StringEscapeUtilsTest { } private void assertEscapeJava(final String escaped, final String original) throws IOException { - assertEscapeJava(null, escaped, original); + assertEscapeJava(escaped, original, null); } - private void assertEscapeJava(String message, final String expected, final String original) throws IOException { + private void assertEscapeJava(final String expected, final String original, String message) throws IOException { final String converted = StringEscapeUtils.escapeJava(original); message = "escapeJava(String) failed" + (message == null ? "" : (": " + message)); - assertEquals(message, expected, converted); + assertEquals(expected, converted, message); final StringWriter writer = new StringWriter(); StringEscapeUtils.ESCAPE_JAVA.translate(original, writer); @@ -131,21 +131,21 @@ public class StringEscapeUtilsTest { assertNull(StringEscapeUtils.unescapeJava(null)); try { StringEscapeUtils.UNESCAPE_JAVA.translate(null, null); - fail(); + fail("Exception expected!"); } catch (final IOException ex) { - fail(); + fail("Exception expected!"); } catch (final IllegalArgumentException ex) { } try { StringEscapeUtils.UNESCAPE_JAVA.translate("", null); - fail(); + fail("Exception expected!"); } catch (final IOException ex) { - fail(); + fail("Exception expected!"); } catch (final IllegalArgumentException ex) { } try { StringEscapeUtils.unescapeJava("\\u02-3"); - fail(); + fail("Exception expected!"); } catch (final RuntimeException ex) { } @@ -156,26 +156,25 @@ public class StringEscapeUtilsTest { assertUnescapeJava("'\foo\teste\r", "\\'\\foo\\teste\\r"); assertUnescapeJava("", "\\"); //foo - assertUnescapeJava("lowercase Unicode", "\uABCDx", "\\uabcdx"); - assertUnescapeJava("uppercase Unicode", "\uABCDx", "\\uABCDx"); - assertUnescapeJava("Unicode as final character", "\uABCD", "\\uabcd"); + assertUnescapeJava("\uABCDx", "\\uabcdx", "lowercase Unicode"); + assertUnescapeJava("\uABCDx", "\\uABCDx", "uppercase Unicode"); + assertUnescapeJava("\uABCD", "\\uabcd", "Unicode as final character"); } private void assertUnescapeJava(final String unescaped, final String original) throws IOException { - assertUnescapeJava(null, unescaped, original); + assertUnescapeJava(unescaped, original, null); } - private void assertUnescapeJava(final String message, final String unescaped, final String original) + private void assertUnescapeJava(final String unescaped, final String original, final String message) throws IOException { final String expected = unescaped; final String actual = StringEscapeUtils.unescapeJava(original); - assertEquals("unescape(String) failed" + assertEquals(expected, actual, "unescape(String) failed" + (message == null ? "" : (": " + message)) + ": expected '" + StringEscapeUtils.escapeJava(expected) // we escape this so we can see it in the error message - + "' actual '" + StringEscapeUtils.escapeJava(actual) + "'", - expected, actual); + + "' actual '" + StringEscapeUtils.escapeJava(actual) + "'"); final StringWriter writer = new StringWriter(); StringEscapeUtils.UNESCAPE_JAVA.translate(original, writer); @@ -187,16 +186,16 @@ public class StringEscapeUtilsTest { assertNull(StringEscapeUtils.escapeEcmaScript(null)); try { StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(null, null); - fail(); + fail("Exception expected!"); } catch (final IOException ex) { - fail(); + fail("Exception expected!"); } catch (final IllegalArgumentException ex) { } try { StringEscapeUtils.ESCAPE_ECMASCRIPT.translate("", null); - fail(); + fail("Exception expected!"); } catch (final IOException ex) { - fail(); + fail("Exception expected!"); } catch (final IllegalArgumentException ex) { } @@ -231,14 +230,14 @@ public class StringEscapeUtilsTest { final String message = element[0]; final String expected = element[1]; final String original = element[2]; - assertEquals(message, expected, StringEscapeUtils.escapeHtml4(original)); + assertEquals(expected, StringEscapeUtils.escapeHtml4(original), message); final StringWriter sw = new StringWriter(); try { StringEscapeUtils.ESCAPE_HTML3.translate(original, sw); } catch (final IOException e) { } final String actual = original == null ? null : sw.toString(); - assertEquals(message, expected, actual); + assertEquals(expected, actual, message); } } @@ -248,7 +247,7 @@ public class StringEscapeUtilsTest { final String message = element[0]; final String expected = element[2]; final String original = element[1]; - assertEquals(message, expected, StringEscapeUtils.unescapeHtml3(original)); + assertEquals(expected, StringEscapeUtils.unescapeHtml3(original), message); final StringWriter sw = new StringWriter(); try { @@ -256,12 +255,12 @@ public class StringEscapeUtilsTest { } catch (final IOException e) { } final String actual = original == null ? null : sw.toString(); - assertEquals(message, expected, actual); + assertEquals(expected, actual, message); } // \u00E7 is a cedilla (c with wiggle under) // note that the test string must be 7-bit-clean (Unicode escaped) or else it will compile incorrectly // on some locales - assertEquals("funny chars pass through OK", "Fran\u00E7ais", StringEscapeUtils.unescapeHtml3("Fran\u00E7ais")); + assertEquals("Fran\u00E7ais", StringEscapeUtils.unescapeHtml3("Fran\u00E7ais"), "funny chars pass through OK"); assertEquals("Hello&;World", StringEscapeUtils.unescapeHtml3("Hello&;World")); assertEquals("Hello&#;World", StringEscapeUtils.unescapeHtml3("Hello&#;World")); @@ -275,14 +274,14 @@ public class StringEscapeUtilsTest { final String message = element[0]; final String expected = element[1]; final String original = element[2]; - assertEquals(message, expected, StringEscapeUtils.escapeHtml4(original)); + assertEquals(expected, StringEscapeUtils.escapeHtml4(original), message); final StringWriter sw = new StringWriter(); try { StringEscapeUtils.ESCAPE_HTML4.translate(original, sw); } catch (final IOException e) { } final String actual = original == null ? null : sw.toString(); - assertEquals(message, expected, actual); + assertEquals(expected, actual, message); } } @@ -292,7 +291,7 @@ public class StringEscapeUtilsTest { final String message = element[0]; final String expected = element[2]; final String original = element[1]; - assertEquals(message, expected, StringEscapeUtils.unescapeHtml4(original)); + assertEquals(expected, StringEscapeUtils.unescapeHtml4(original), message); final StringWriter sw = new StringWriter(); try { @@ -300,12 +299,12 @@ public class StringEscapeUtilsTest { } catch (final IOException e) { } final String actual = original == null ? null : sw.toString(); - assertEquals(message, expected, actual); + assertEquals(expected, actual, message); } // \u00E7 is a cedilla (c with wiggle under) // note that the test string must be 7-bit-clean (Unicode escaped) or else it will compile incorrectly // on some locales - assertEquals("funny chars pass through OK", "Fran\u00E7ais", StringEscapeUtils.unescapeHtml4("Fran\u00E7ais")); + assertEquals("Fran\u00E7ais", StringEscapeUtils.unescapeHtml4("Fran\u00E7ais"), "funny chars pass through OK"); assertEquals("Hello&;World", StringEscapeUtils.unescapeHtml4("Hello&;World")); assertEquals("Hello&#;World", StringEscapeUtils.unescapeHtml4("Hello&#;World")); @@ -316,8 +315,8 @@ public class StringEscapeUtilsTest { @Test public void testUnescapeHexCharsHtml() { // Simple easy to grok test - assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ")); - assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ")); + assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape"); + assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape"); // Test all Character values: for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) { final Character c1 = i; @@ -325,8 +324,8 @@ public class StringEscapeUtilsTest { final String expected = c1.toString() + c2.toString(); final String escapedC1 = "&#x" + Integer.toHexString(c1) + ";"; final String escapedC2 = "&#x" + Integer.toHexString(c2) + ";"; - assertEquals("hex number unescape index " + i, expected, - StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2)); + assertEquals(expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2), + "hex number unescape index " + i); } } @@ -348,36 +347,36 @@ public class StringEscapeUtilsTest { @Test public void testEscapeXml10() { assertEquals("a<b>c"d'e&f", StringEscapeUtils.escapeXml10("a<b>c\"d'e&f")); - assertEquals("XML 1.0 should not escape \t \n \r", - "a\tb\rc\nd", StringEscapeUtils.escapeXml10("a\tb\rc\nd")); - assertEquals("XML 1.0 should omit most #x0-x8 | #xb | #xc | #xe-#x19", - "ab", StringEscapeUtils.escapeXml10("a\u0000\u0001\u0008\u000b\u000c\u000e\u001fb")); - assertEquals("XML 1.0 should omit #xd800-#xdfff", - "a\ud7ff \ue000b", StringEscapeUtils.escapeXml10("a\ud7ff\ud800 \udfff \ue000b")); - assertEquals("XML 1.0 should omit #xfffe | #xffff", - "a\ufffdb", StringEscapeUtils.escapeXml10("a\ufffd\ufffe\uffffb")); - assertEquals("XML 1.0 should escape #x7f-#x84 | #x86 - #x9f, for XML 1.1 compatibility", - "a\u007e„\u0085†Ÿ\u00a0b", - StringEscapeUtils.escapeXml10("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b")); + assertEquals("a\tb\rc\nd", StringEscapeUtils.escapeXml10("a\tb\rc\nd"), + "XML 1.0 should not escape \t \n \r"); + assertEquals("ab", StringEscapeUtils.escapeXml10("a\u0000\u0001\u0008\u000b\u000c\u000e\u001fb"), + "XML 1.0 should omit most #x0-x8 | #xb | #xc | #xe-#x19"); + assertEquals("a\ud7ff \ue000b", StringEscapeUtils.escapeXml10("a\ud7ff\ud800 \udfff \ue000b"), + "XML 1.0 should omit #xd800-#xdfff"); + assertEquals("a\ufffdb", StringEscapeUtils.escapeXml10("a\ufffd\ufffe\uffffb"), + "XML 1.0 should omit #xfffe | #xffff"); + assertEquals("a\u007e„\u0085†Ÿ\u00a0b", + StringEscapeUtils.escapeXml10("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"), + "XML 1.0 should escape #x7f-#x84 | #x86 - #x9f, for XML 1.1 compatibility"); } @Test public void testEscapeXml11() { assertEquals("a<b>c"d'e&f", StringEscapeUtils.escapeXml11("a<b>c\"d'e&f")); - assertEquals("XML 1.1 should not escape \t \n \r", - "a\tb\rc\nd", StringEscapeUtils.escapeXml11("a\tb\rc\nd")); - assertEquals("XML 1.1 should omit #x0", - "ab", StringEscapeUtils.escapeXml11("a\u0000b")); - assertEquals("XML 1.1 should escape #x1-x8 | #xb | #xc | #xe-#x19", - "ab", - StringEscapeUtils.escapeXml11("a\u0001\u0008\u000b\u000c\u000e\u001fb")); - assertEquals("XML 1.1 should escape #x7F-#x84 | #x86-#x9F", - "a\u007e„\u0085†Ÿ\u00a0b", - StringEscapeUtils.escapeXml11("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b")); - assertEquals("XML 1.1 should omit #xd800-#xdfff", - "a\ud7ff \ue000b", StringEscapeUtils.escapeXml11("a\ud7ff\ud800 \udfff \ue000b")); - assertEquals("XML 1.1 should omit #xfffe | #xffff", - "a\ufffdb", StringEscapeUtils.escapeXml11("a\ufffd\ufffe\uffffb")); + assertEquals("a\tb\rc\nd", StringEscapeUtils.escapeXml11("a\tb\rc\nd"), + "XML 1.1 should not escape \t \n \r"); + assertEquals("ab", StringEscapeUtils.escapeXml11("a\u0000b"), + "XML 1.1 should omit #x0"); + assertEquals("ab", + StringEscapeUtils.escapeXml11("a\u0001\u0008\u000b\u000c\u000e\u001fb"), + "XML 1.1 should escape #x1-x8 | #xb | #xc | #xe-#x19"); + assertEquals("a\u007e„\u0085†Ÿ\u00a0b", + StringEscapeUtils.escapeXml11("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"), + "XML 1.1 should escape #x7F-#x84 | #x86-#x9F"); + assertEquals("a\ud7ff \ue000b", StringEscapeUtils.escapeXml11("a\ud7ff\ud800 \udfff \ue000b"), + "XML 1.1 should omit #xd800-#xdfff"); + assertEquals("a\ufffdb", StringEscapeUtils.escapeXml11("a\ufffd\ufffe\uffffb"), + "XML 1.1 should omit #xfffe | #xffff"); } /** @@ -387,11 +386,11 @@ public class StringEscapeUtilsTest { */ @Test public void testUnescapeXmlSupplementaryCharacters() { - assertEquals("Supplementary character must be represented using a single escape", "\uD84C\uDFB4", - StringEscapeUtils.unescapeXml("𣎴")); + assertEquals("\uD84C\uDFB4", StringEscapeUtils.unescapeXml("𣎴"), + "Supplementary character must be represented using a single escape"); - assertEquals("Supplementary characters mixed with basic characters should be decoded correctly", - "a b c \uD84C\uDFB4", StringEscapeUtils.unescapeXml("a b c 𣎴")); + assertEquals("a b c \uD84C\uDFB4", StringEscapeUtils.unescapeXml("a b c 𣎴"), + "Supplementary characters mixed with basic characters should be decoded correctly"); } // Tests issue #38569 @@ -495,10 +494,10 @@ public class StringEscapeUtilsTest { final String original = new String(data, Charset.forName("UTF8")); final String escaped = StringEscapeUtils.escapeHtml4(original); - assertEquals("High Unicode should not have been escaped", original, escaped); + assertEquals(original, escaped, "High Unicode should not have been escaped"); final String unescaped = StringEscapeUtils.unescapeHtml4(escaped); - assertEquals("High Unicode should have been unchanged", original, unescaped); + assertEquals(original, unescaped, "High Unicode should have been unchanged"); // TODO: I think this should hold, needs further investigation // String unescapedFromEntity = StringEscapeUtils.unescapeHtml4("𝍢"); @@ -513,12 +512,12 @@ public class StringEscapeUtilsTest { // Some random Japanese Unicode characters final String original = "\u304B\u304C\u3068"; final String escaped = StringEscapeUtils.escapeHtml4(original); - assertEquals("Hiragana character Unicode behaviour should not be being escaped by escapeHtml4", - original, escaped); + assertEquals(original, escaped, + "Hiragana character Unicode behaviour should not be being escaped by escapeHtml4"); final String unescaped = StringEscapeUtils.unescapeHtml4(escaped); - assertEquals("Hiragana character Unicode behaviour has changed - expected no unescaping", escaped, unescaped); + assertEquals(escaped, unescaped, "Hiragana character Unicode behaviour has changed - expected no unescaping"); } /** @@ -533,9 +532,9 @@ public class StringEscapeUtilsTest { final String input = new String(inputBytes, StandardCharsets.UTF_8); final String escaped = StringEscapeUtils.escapeEcmaScript(input); // just the end: - assertTrue(escaped, escaped.endsWith("}]")); + assertTrue(escaped.endsWith("}]"), escaped); // a little more: - assertTrue(escaped, escaped.endsWith("\"valueCode\\\":\\\"\\\"}]")); + assertTrue(escaped.endsWith("\"valueCode\\\":\\\"\\\"}]"), escaped); } /** @@ -554,16 +553,16 @@ public class StringEscapeUtilsTest { assertNull(StringEscapeUtils.escapeJson(null)); try { StringEscapeUtils.ESCAPE_JSON.translate(null, null); - fail(); + fail("Exception expected!"); } catch (final IOException ex) { - fail(); + fail("Exception expected!"); } catch (final IllegalArgumentException ex) { } try { StringEscapeUtils.ESCAPE_JSON.translate("", null); - fail(); + fail("Exception expected!"); } catch (final IOException ex) { - fail(); + fail("Exception expected!"); } catch (final IllegalArgumentException ex) { } @@ -601,7 +600,7 @@ public class StringEscapeUtilsTest { @Test public void testUnescapeEcmaScript() { - assertNull("Should be null.", StringEscapeUtils.unescapeEcmaScript(null)); + assertNull(StringEscapeUtils.unescapeEcmaScript(null)); assertEquals("8lvc1u+6B#-I", StringEscapeUtils.unescapeEcmaScript("8lvc1u+6B#-I")); assertEquals("<script src=\"build/main.bundle.js\"></script>", StringEscapeUtils.unescapeEcmaScript("<script src=\"build/main.bundle.js\"></script>")); @@ -611,7 +610,7 @@ public class StringEscapeUtilsTest { @Test public void testEscapeHtmlThree() { - assertNull("Should be null.", StringEscapeUtils.escapeHtml3(null)); + assertNull(StringEscapeUtils.escapeHtml3(null)); assertEquals("a", StringEscapeUtils.escapeHtml3("a")); assertEquals("<b>a", StringEscapeUtils.escapeHtml3("<b>a")); }
http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/StringSubstitutorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java index e389342..92ee70b 100644 --- a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java +++ b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java @@ -17,11 +17,12 @@ package org.apache.commons.text; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashMap; import java.util.Map; @@ -32,9 +33,9 @@ import org.apache.commons.text.lookup.StringLookup; import org.apache.commons.text.lookup.StringLookupFactory; import org.apache.commons.text.matcher.StringMatcher; import org.apache.commons.text.matcher.StringMatcherFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test class for {@link StringSubstitutor}. @@ -147,14 +148,14 @@ public class StringSubstitutorTest { } } - @Before + @BeforeEach public void setUp() throws Exception { values = new HashMap<>(); values.put("animal", "quick brown fox"); values.put("target", "lazy dog"); } - @After + @AfterEach public void tearDown() throws Exception { values = null; } @@ -311,12 +312,12 @@ public class StringSubstitutorTest { values.put("species", "2"); final StringSubstitutor sub = new StringSubstitutor(values); sub.setEnableSubstitutionInVariables(true); - assertEquals("Wrong result (1)", "The mouse jumps over the lazy dog.", + assertEquals("The mouse jumps over the lazy dog.", sub.replace("The ${animal.${species}} jumps over the ${target}.")); values.put("species", "1"); - assertEquals("Wrong result (2)", "The fox jumps over the lazy dog.", + assertEquals("The fox jumps over the lazy dog.", sub.replace("The ${animal.${species}} jumps over the ${target}.")); - assertEquals("Wrong result (3)", "The fox jumps over the lazy dog.", sub.replace( + assertEquals("The fox jumps over the lazy dog.", sub.replace( "The ${unknown.animal.${unknown.species:-1}:-fox} " + "jumps over the ${unknow.target:-lazy dog}.")); } @@ -329,9 +330,9 @@ public class StringSubstitutorTest { values.put("animal.2", "mouse"); values.put("species", "2"); final StringSubstitutor sub = new StringSubstitutor(values); - assertEquals("Wrong result (1)", "The ${animal.${species}} jumps over the lazy dog.", + assertEquals("The ${animal.${species}} jumps over the lazy dog.", sub.replace("The ${animal.${species}} jumps over the ${target}.")); - assertEquals("Wrong result (2)", "The ${animal.${species:-1}} jumps over the lazy dog.", + assertEquals("The ${animal.${species:-1}} jumps over the lazy dog.", sub.replace("The ${animal.${species:-1}} jumps over the ${target}.")); } @@ -347,9 +348,9 @@ public class StringSubstitutorTest { values.put("species.brown", "2"); final StringSubstitutor sub = new StringSubstitutor(values); sub.setEnableSubstitutionInVariables(true); - assertEquals("Wrong result (1)", "The white mouse jumps over the lazy dog.", + assertEquals("The white mouse jumps over the lazy dog.", sub.replace("The ${animal.${species.${color}}} jumps over the ${target}.")); - assertEquals("Wrong result (2)", "The brown fox jumps over the lazy dog.", + assertEquals("The brown fox jumps over the lazy dog.", sub.replace("The ${animal.${species.${unknownColor:-brown}}} jumps over the ${target}.")); } @@ -456,9 +457,9 @@ public class StringSubstitutorTest { assertEquals('$', strSubstitutor.getEscapeChar()); } - @Test(expected = NullPointerException.class) + @Test public void testReplaceTakingThreeArgumentsThrowsNullPointerException() { - StringSubstitutor.replace(null, (Properties) null); + assertThatNullPointerException().isThrownBy(() -> StringSubstitutor.replace(null, (Properties) null)); } /** http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java b/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java index bfac9c8..0eb1b3d 100644 --- a/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java +++ b/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java @@ -1,73 +1,73 @@ -/* - * 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.text; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.text.lookup.StringLookupFactory; -import org.junit.Assert; -import org.junit.Test; - -public class StringSubstitutorWithInterpolatorStringLookupTest { - - @Test - public void testLocalHostLookup_Address() throws UnknownHostException { - final StringSubstitutor strSubst = new StringSubstitutor( - StringLookupFactory.INSTANCE.interpolatorStringLookup()); - Assert.assertEquals(InetAddress.getLocalHost().getHostAddress(), strSubst.replace("${localhost:address}")); - } - - @Test - public void testLocalHostLookup_CanonicalName() throws UnknownHostException { - final StringSubstitutor strSubst = new StringSubstitutor( - StringLookupFactory.INSTANCE.interpolatorStringLookup()); - Assert.assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), - strSubst.replace("${localhost:canonical-name}")); - } - - @Test - public void testLocalHostLookup_Name() throws UnknownHostException { - final StringSubstitutor strSubst = new StringSubstitutor( - StringLookupFactory.INSTANCE.interpolatorStringLookup()); - Assert.assertEquals(InetAddress.getLocalHost().getHostName(), strSubst.replace("${localhost:name}")); - } - - @Test - public void testMapAndSystemProperty() { - final String key = "key"; - final String value = "value"; - final Map<String, String> map = new HashMap<>(); - map.put(key, value); - final StringSubstitutor strSubst = new StringSubstitutor( - StringLookupFactory.INSTANCE.interpolatorStringLookup(map)); - final String spKey = "user.name"; - Assert.assertEquals(System.getProperty(spKey), strSubst.replace("${sys:" + spKey + "}")); - Assert.assertEquals(value, strSubst.replace("${" + key + "}")); - } - - @Test - public void testSystemProperty() { - final StringSubstitutor strSubst = new StringSubstitutor( - StringLookupFactory.INSTANCE.interpolatorStringLookup()); - final String spKey = "user.name"; - Assert.assertEquals(System.getProperty(spKey), strSubst.replace("${sys:" + spKey + "}")); - } -} +/* + * 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.text; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.text.lookup.StringLookupFactory; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class StringSubstitutorWithInterpolatorStringLookupTest { + + @Test + public void testLocalHostLookup_Address() throws UnknownHostException { + final StringSubstitutor strSubst = new StringSubstitutor( + StringLookupFactory.INSTANCE.interpolatorStringLookup()); + Assertions.assertEquals(InetAddress.getLocalHost().getHostAddress(), strSubst.replace("${localhost:address}")); + } + + @Test + public void testLocalHostLookup_CanonicalName() throws UnknownHostException { + final StringSubstitutor strSubst = new StringSubstitutor( + StringLookupFactory.INSTANCE.interpolatorStringLookup()); + Assertions.assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), + strSubst.replace("${localhost:canonical-name}")); + } + + @Test + public void testLocalHostLookup_Name() throws UnknownHostException { + final StringSubstitutor strSubst = new StringSubstitutor( + StringLookupFactory.INSTANCE.interpolatorStringLookup()); + Assertions.assertEquals(InetAddress.getLocalHost().getHostName(), strSubst.replace("${localhost:name}")); + } + + @Test + public void testMapAndSystemProperty() { + final String key = "key"; + final String value = "value"; + final Map<String, String> map = new HashMap<>(); + map.put(key, value); + final StringSubstitutor strSubst = new StringSubstitutor( + StringLookupFactory.INSTANCE.interpolatorStringLookup(map)); + final String spKey = "user.name"; + Assertions.assertEquals(System.getProperty(spKey), strSubst.replace("${sys:" + spKey + "}")); + Assertions.assertEquals(value, strSubst.replace("${" + key + "}")); + } + + @Test + public void testSystemProperty() { + final StringSubstitutor strSubst = new StringSubstitutor( + StringLookupFactory.INSTANCE.interpolatorStringLookup()); + final String spKey = "user.name"; + Assertions.assertEquals(System.getProperty(spKey), strSubst.replace("${sys:" + spKey + "}")); + } +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/StringTokenizerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/StringTokenizerTest.java b/src/test/java/org/apache/commons/text/StringTokenizerTest.java index 397954a..d0ffd84 100644 --- a/src/test/java/org/apache/commons/text/StringTokenizerTest.java +++ b/src/test/java/org/apache/commons/text/StringTokenizerTest.java @@ -17,11 +17,11 @@ package org.apache.commons.text; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Arrays; import java.util.Collections; @@ -30,7 +30,7 @@ import java.util.NoSuchElementException; import org.apache.commons.text.matcher.StringMatcher; import org.apache.commons.text.matcher.StringMatcherFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit test for {@link StringTokenizer}. @@ -60,10 +60,10 @@ public class StringTokenizerTest { final String[] expected = {"a", "b", "c", "d;\"e", "f", "", "", "" }; - assertEquals(Arrays.toString(tokens), expected.length, tokens.length); + assertEquals(expected.length, tokens.length, Arrays.toString(tokens)); for (int i = 0; i < expected.length; i++) { - assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", - expected[i], tokens[i]); + assertEquals(expected[i], tokens[i], + "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'"); } } @@ -81,10 +81,10 @@ public class StringTokenizerTest { final String[] expected = {"a", "b", "c ", "d;\"e", "f", " ", " ", "" }; - assertEquals(Arrays.toString(tokens), expected.length, tokens.length); + assertEquals(expected.length, tokens.length, Arrays.toString(tokens)); for (int i = 0; i < expected.length; i++) { - assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", - expected[i], tokens[i]); + assertEquals(expected[i], tokens[i], + "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'"); } } @@ -102,10 +102,10 @@ public class StringTokenizerTest { final String[] expected = {"a", "b", " c", "d;\"e", "f", " ", " ", "" }; - assertEquals(Arrays.toString(tokens), expected.length, tokens.length); + assertEquals(expected.length, tokens.length, Arrays.toString(tokens)); for (int i = 0; i < expected.length; i++) { - assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", - expected[i], tokens[i]); + assertEquals(expected[i], tokens[i], + "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'"); } } @@ -123,10 +123,10 @@ public class StringTokenizerTest { final String[] expected = {"a", "b", "c", "d;\"e", "f" }; - assertEquals(Arrays.toString(tokens), expected.length, tokens.length); + assertEquals(expected.length, tokens.length, Arrays.toString(tokens)); for (int i = 0; i < expected.length; i++) { - assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", - expected[i], tokens[i]); + assertEquals(expected[i], tokens[i], + "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'"); } } @@ -145,10 +145,10 @@ public class StringTokenizerTest { final String[] expected = {"a", "b", "c", "d;\"e", "f", null, null, null }; - assertEquals(Arrays.toString(tokens), expected.length, tokens.length); + assertEquals(expected.length, tokens.length, Arrays.toString(tokens)); for (int i = 0; i < expected.length; i++) { - assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", - expected[i], tokens[i]); + assertEquals(expected[i], tokens[i], + "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'"); } } @@ -179,14 +179,11 @@ public class StringTokenizerTest { prevCount++; } - assertEquals(Arrays.toString(tokens), expected.length, tokens.length); - - assertTrue("could not cycle through entire token list" + " using the 'hasNext' and 'next' methods", - nextCount == expected.length); - - assertTrue("could not cycle through entire token list" + " using the 'hasPrevious' and 'previous' methods", - prevCount == expected.length); - + assertEquals(expected.length, tokens.length, Arrays.toString(tokens)); + assertTrue(nextCount == expected.length, + "could not cycle through entire token list using the 'hasNext' and 'next' methods"); + assertTrue(prevCount == expected.length, + "could not cycle through entire token list using the 'hasPrevious' and 'previous' methods"); } @Test @@ -202,10 +199,10 @@ public class StringTokenizerTest { final String[] expected = {"a", "", "", "b", "c", "d e", "f", "" }; - assertEquals(Arrays.toString(tokens), expected.length, tokens.length); + assertEquals(expected.length, tokens.length, Arrays.toString(tokens)); for (int i = 0; i < expected.length; i++) { - assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", - expected[i], tokens[i]); + assertEquals(expected[i], tokens[i], + "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'"); } } @@ -223,10 +220,10 @@ public class StringTokenizerTest { final String[] expected = {"a", "b", "c", "d e", "f" }; - assertEquals(Arrays.toString(tokens), expected.length, tokens.length); + assertEquals(expected.length, tokens.length, Arrays.toString(tokens)); for (int i = 0; i < expected.length; i++) { - assertEquals("token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'", - expected[i], tokens[i]); + assertEquals(expected[i], tokens[i], + "token[" + i + "] was '" + tokens[i] + "' but was expected to be '" + expected[i] + "'"); } } @@ -578,7 +575,7 @@ public class StringTokenizerTest { assertEquals(0, tokenizer.size()); try { tokenizer.next(); - fail(); + fail("Exception expected!"); } catch (final NoSuchElementException ex) { } } @@ -844,7 +841,7 @@ public class StringTokenizerTest { assertFalse(tkn.hasPrevious()); try { tkn.previous(); - fail(); + fail("Exception expected!"); } catch (final NoSuchElementException ex) { } assertTrue(tkn.hasNext()); @@ -852,17 +849,17 @@ public class StringTokenizerTest { assertEquals("a", tkn.next()); try { tkn.remove(); - fail(); + fail("Exception expected!"); } catch (final UnsupportedOperationException ex) { } try { tkn.set("x"); - fail(); + fail("Exception expected!"); } catch (final UnsupportedOperationException ex) { } try { tkn.add("y"); - fail(); + fail("Exception expected!"); } catch (final UnsupportedOperationException ex) { } assertTrue(tkn.hasPrevious()); @@ -878,7 +875,7 @@ public class StringTokenizerTest { try { tkn.next(); - fail(); + fail("Exception expected!"); } catch (final NoSuchElementException ex) { } assertTrue(tkn.hasPrevious()); http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/TextStringBuilderAppendInsertTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/TextStringBuilderAppendInsertTest.java b/src/test/java/org/apache/commons/text/TextStringBuilderAppendInsertTest.java index 8287d99..ce8d044 100644 --- a/src/test/java/org/apache/commons/text/TextStringBuilderAppendInsertTest.java +++ b/src/test/java/org/apache/commons/text/TextStringBuilderAppendInsertTest.java @@ -26,7 +26,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link TextStringBuilder}. http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/TextStringBuilderTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/TextStringBuilderTest.java b/src/test/java/org/apache/commons/text/TextStringBuilderTest.java index 8a58f8d..7f713dc 100644 --- a/src/test/java/org/apache/commons/text/TextStringBuilderTest.java +++ b/src/test/java/org/apache/commons/text/TextStringBuilderTest.java @@ -17,14 +17,15 @@ package org.apache.commons.text; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.io.Reader; @@ -38,7 +39,7 @@ import java.util.Arrays; import org.apache.commons.text.matcher.StringMatcher; import org.apache.commons.text.matcher.StringMatcherFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link TextStringBuilder}. @@ -481,13 +482,13 @@ public class TextStringBuilderTest { assertEquals(0, sb.toCharArray().length); char[] a = sb.toCharArray(); - assertNotNull("toCharArray() result is null", a); - assertEquals("toCharArray() result is too large", 0, a.length); + assertNotNull(a, "toCharArray() result is null"); + assertEquals(0, a.length, "toCharArray() result is too large"); sb.append("junit"); a = sb.toCharArray(); - assertEquals("toCharArray() result incorrect length", 5, a.length); - assertTrue("toCharArray() result does not match", Arrays.equals("junit".toCharArray(), a)); + assertEquals(5, a.length, "toCharArray() result incorrect length"); + assertTrue(Arrays.equals("junit".toCharArray(), a), "toCharArray() result does not match"); } @Test @@ -497,19 +498,19 @@ public class TextStringBuilderTest { sb.append("junit"); char[] a = sb.toCharArray(0, 20); // too large test - assertEquals("toCharArray(int,int) result incorrect length", 5, a.length); - assertTrue("toCharArray(int,int) result does not match", Arrays.equals("junit".toCharArray(), a)); + assertEquals(5, a.length, "toCharArray(int,int) result incorrect length"); + assertTrue(Arrays.equals("junit".toCharArray(), a), "toCharArray(int,int) result does not match"); a = sb.toCharArray(0, 4); - assertEquals("toCharArray(int,int) result incorrect length", 4, a.length); - assertTrue("toCharArray(int,int) result does not match", Arrays.equals("juni".toCharArray(), a)); + assertEquals(4, a.length, "toCharArray(int,int) result incorrect length"); + assertTrue(Arrays.equals("juni".toCharArray(), a), "toCharArray(int,int) result does not match"); a = sb.toCharArray(0, 4); - assertEquals("toCharArray(int,int) result incorrect length", 4, a.length); - assertTrue("toCharArray(int,int) result does not match", Arrays.equals("juni".toCharArray(), a)); + assertEquals(4, a.length, "toCharArray(int,int) result incorrect length"); + assertTrue(Arrays.equals("juni".toCharArray(), a), "toCharArray(int,int) result does not match"); a = sb.toCharArray(0, 1); - assertNotNull("toCharArray(int,int) result is null", a); + assertNotNull(a, "toCharArray(int,int) result is null"); try { sb.toCharArray(-1, 5); @@ -1044,7 +1045,7 @@ public class TextStringBuilderTest { sb = new TextStringBuilder("aaxaaaayaa"); try { sb.replace(StringMatcherFactory.INSTANCE.stringMatcher("aa"), "-", 11, sb.length(), -1); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException ex) { } assertEquals("aaxaaaayaa", sb.toString()); @@ -1052,7 +1053,7 @@ public class TextStringBuilderTest { sb = new TextStringBuilder("aaxaaaayaa"); try { sb.replace(StringMatcherFactory.INSTANCE.stringMatcher("aa"), "-", -1, sb.length(), -1); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException ex) { } assertEquals("aaxaaaayaa", sb.toString()); @@ -1107,7 +1108,7 @@ public class TextStringBuilderTest { sb = new TextStringBuilder("aaxaaaayaa"); try { sb.replace(StringMatcherFactory.INSTANCE.stringMatcher("aa"), "-", 2, 1, -1); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException ex) { } assertEquals("aaxaaaayaa", sb.toString()); @@ -1215,28 +1216,28 @@ public class TextStringBuilderTest { // Start index is negative try { sb.subSequence(-1, 5); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException e) { } // End index is negative try { sb.subSequence(2, -1); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException e) { } // End index greater than length() try { sb.subSequence(2, sb.length() + 1); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException e) { } // Start index greater then end index try { sb.subSequence(3, 2); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException e) { } @@ -1256,13 +1257,13 @@ public class TextStringBuilderTest { assertEquals("hello goodbye".substring(0), sb.substring(0)); try { sb.substring(-1); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException e) { } try { sb.substring(15); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException e) { } @@ -1281,13 +1282,13 @@ public class TextStringBuilderTest { try { sb.substring(-1, 5); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException e) { } try { sb.substring(15, 20); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException e) { } } @@ -1764,27 +1765,27 @@ public class TextStringBuilderTest { array = new char[3]; try { reader.read(array, -1, 0); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException ex) { } try { reader.read(array, 0, -1); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException ex) { } try { reader.read(array, 100, 1); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException ex) { } try { reader.read(array, 0, 100); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException ex) { } try { reader.read(array, Integer.MAX_VALUE, Integer.MAX_VALUE); - fail(); + fail("Exception expected!"); } catch (final IndexOutOfBoundsException ex) { } @@ -1956,8 +1957,8 @@ public class TextStringBuilderTest { public void testLang295() { final TextStringBuilder sb = new TextStringBuilder("onetwothree"); sb.deleteFirst("three"); - assertFalse("The contains(char) method is looking beyond the end of the string", sb.contains('h')); - assertEquals("The indexOf(char) method is looking beyond the end of the string", -1, sb.indexOf('h')); + assertFalse(sb.contains('h'), "The contains(char) method is looking beyond the end of the string"); + assertEquals(-1, sb.indexOf('h'), "The indexOf(char) method is looking beyond the end of the string"); } // ----------------------------------------------------------------------- @@ -1965,14 +1966,14 @@ public class TextStringBuilderTest { public void testLang412Right() { final TextStringBuilder sb = new TextStringBuilder(); sb.appendFixedWidthPadRight(null, 10, '*'); - assertEquals("Failed to invoke appendFixedWidthPadRight correctly", "**********", sb.toString()); + assertEquals("**********", sb.toString(), "Failed to invoke appendFixedWidthPadRight correctly"); } @Test public void testLang412Left() { final TextStringBuilder sb = new TextStringBuilder(); sb.appendFixedWidthPadLeft(null, 10, '*'); - assertEquals("Failed to invoke appendFixedWidthPadLeft correctly", "**********", sb.toString()); + assertEquals("**********", sb.toString(), "Failed to invoke appendFixedWidthPadLeft correctly"); } @Test @@ -2121,27 +2122,33 @@ public class TextStringBuilderTest { assertEquals("c" + System.lineSeparator(), sb1.appendln(ch).toString()); } - @Test(expected = StringIndexOutOfBoundsException.class) + @Test public void testAppendTakingTwoIntsWithZeroThrowsStringIndexOutOfBoundsException() { - final Charset charset = Charset.defaultCharset(); - final ByteBuffer byteBuffer = charset.encode("end < start"); - final CharBuffer charBuffer = charset.decode(byteBuffer); + assertThatExceptionOfType(StringIndexOutOfBoundsException.class).isThrownBy(() -> { + final Charset charset = Charset.defaultCharset(); + final ByteBuffer byteBuffer = charset.encode("end < start"); + final CharBuffer charBuffer = charset.decode(byteBuffer); - new TextStringBuilder(630).append(charBuffer, 0, 630); + new TextStringBuilder(630).append(charBuffer, 0, 630); + }); } - @Test(expected = StringIndexOutOfBoundsException.class) + @Test public void testAppendTakingTwoIntsWithIndexOutOfBoundsThrowsStringIndexOutOfBoundsExceptionTwo() { - final Charset charset = Charset.defaultCharset(); - final ByteBuffer byteBuffer = charset.encode("asdf"); - final CharBuffer charBuffer = charset.decode(byteBuffer); + assertThatExceptionOfType(StringIndexOutOfBoundsException.class).isThrownBy(() -> { + final Charset charset = Charset.defaultCharset(); + final ByteBuffer byteBuffer = charset.encode("asdf"); + final CharBuffer charBuffer = charset.decode(byteBuffer); - new TextStringBuilder().append(charBuffer, 933, 654); + new TextStringBuilder().append(charBuffer, 933, 654); + }); } - @Test(expected = StringIndexOutOfBoundsException.class) + @Test public void testDeleteCharAtWithNegative() { - new TextStringBuilder().deleteCharAt((-1258)); + assertThatExceptionOfType(StringIndexOutOfBoundsException.class).isThrownBy(() -> { + new TextStringBuilder().deleteCharAt((-1258)); + }); } } http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/WordUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/WordUtilsTest.java b/src/test/java/org/apache/commons/text/WordUtilsTest.java index 7ba224c..18d6eb9 100644 --- a/src/test/java/org/apache/commons/text/WordUtilsTest.java +++ b/src/test/java/org/apache/commons/text/WordUtilsTest.java @@ -17,12 +17,13 @@ package org.apache.commons.text; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; import org.apache.commons.lang3.StringUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link WordUtils} class. @@ -497,14 +498,18 @@ public class WordUtilsTest { assertThat(WordUtils.abbreviate("01 23 45 67 89", 9, 10, "")).isEqualTo("01 23 45 6"); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAbbreviateForLowerThanMinusOneValues() { - assertThat(WordUtils.abbreviate("01 23 45 67 89", 9, -10, null)).isEqualTo("01 23 45 67"); + assertThatIllegalArgumentException().isThrownBy(() -> { + assertThat(WordUtils.abbreviate("01 23 45 67 89", 9, -10, null)).isEqualTo("01 23 45 67"); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAbbreviateUpperLessThanLowerValues() { - assertThat(WordUtils.abbreviate("0123456789", 5, 2, "")).isEqualTo("01234"); + assertThatIllegalArgumentException().isThrownBy(() -> { + assertThat(WordUtils.abbreviate("0123456789", 5, 2, "")).isEqualTo("01234"); + }); } @Test http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java b/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java index fddf406..27f6160 100644 --- a/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java +++ b/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java @@ -15,73 +15,57 @@ * limitations under the License. */ package org.apache.commons.text.diff; -import static org.junit.Assert.assertArrayEquals; + import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; /** * Tests for the ReplacementsFinder. */ -@RunWith(Parameterized.class) public class ReplacementsFinderTest { + private SimpleHandler handler = null; - private final String left; - private final String right; - private final int skipped; - private final Character[] from; - private final Character[] to; - @Before + @BeforeEach public void setUp() { handler = new SimpleHandler(); } - @Parameters - public static Collection<Object[]> data() { - return Arrays.asList(new Object[][] { - { + public static Stream<Arguments> parameters() { + return Stream.of( + Arguments.of( "branco", "blanco", 1, new Character[] {'r'}, - new Character[] {'l'}}, - { + new Character[] {'l'}), + Arguments.of( "test the blocks before you use it", "try the blocks before you put it", 25, new Character[] {'e', 's', 't', 's', 'e'}, new Character[] {'r', 'y', 'p', 't'} - } - }); - } - - public ReplacementsFinderTest(final String left, final String right, final int skipped, - final Character[] from, final Character[] to) { - this.left = left; - this.right = right; - this.skipped = skipped; - this.from = from; - this.to = to; + )); } - @Test - public void testReplacementsHandler() { + @ParameterizedTest + @MethodSource("parameters") + public void testReplacementsHandler(String left, String right, int skipped, Character[] from, Character[] to) { final StringsComparator sc = new StringsComparator(left, right); final ReplacementsFinder<Character> replacementFinder = new ReplacementsFinder<>(handler); sc.getScript().visit(replacementFinder); assertThat(handler.getSkipped()).as("Skipped characters do not match").isEqualTo(skipped); - assertArrayEquals("From characters do not match", from, - handler.getFrom().toArray(new Character[0])); - assertArrayEquals("To characters do not match", to, - handler.getTo().toArray(new Character[0])); + assertArrayEquals(handler.getFrom().toArray(new Character[0]), from, "From characters do not match"); + assertArrayEquals(to, handler.getTo().toArray(new Character[0]), "To characters do not match"); } // Helper RecplacementsHandler implementation for testing http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java index f731d16..9e9d266 100644 --- a/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java +++ b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java @@ -18,9 +18,9 @@ package org.apache.commons.text.diff; import java.util.Arrays; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -78,7 +78,7 @@ public class StringsComparatorTest { return v.toString(); } } - @Before + @BeforeEach public void setUp() { before = Arrays.asList( "bottle", @@ -123,7 +123,7 @@ public class StringsComparatorTest { 2 }; } - @After + @AfterEach public void tearDown() { before = null; after = null; http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java index 229a1e8..020baf3 100644 --- a/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java +++ b/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java @@ -1,50 +1,50 @@ -/* - * 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.text.lookup; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.junit.Test; - -public class DateStringLookupTest { - - @Test - public void testDefault() throws ParseException { - final String formatted = DateStringLookup.INSTANCE.lookup(null); - DateFormat.getInstance().parse(formatted); // throws ParseException - - } - - @Test - public void testFormat() { - final String fomat = "yyyy-MM-dd"; - final String value = DateStringLookup.INSTANCE.lookup(fomat); - assertNotNull("No Date", value); - final SimpleDateFormat format = new SimpleDateFormat(fomat); - final String today = format.format(new Date()); - assertEquals(value, today); - - } - -} +/* + * 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.text.lookup; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.junit.jupiter.api.Test; + +public class DateStringLookupTest { + + @Test + public void testDefault() throws ParseException { + final String formatted = DateStringLookup.INSTANCE.lookup(null); + DateFormat.getInstance().parse(formatted); // throws ParseException + + } + + @Test + public void testFormat() { + final String fomat = "yyyy-MM-dd"; + final String value = DateStringLookup.INSTANCE.lookup(fomat); + assertNotNull("No Date", value); + final SimpleDateFormat format = new SimpleDateFormat(fomat); + final String today = format.format(new Date()); + assertEquals(value, today); + + } + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/lookup/EnvironmentVariableStringLookupTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/lookup/EnvironmentVariableStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/EnvironmentVariableStringLookupTest.java index 643e3d7..1348e00 100644 --- a/src/test/java/org/apache/commons/text/lookup/EnvironmentVariableStringLookupTest.java +++ b/src/test/java/org/apache/commons/text/lookup/EnvironmentVariableStringLookupTest.java @@ -1,37 +1,37 @@ -/* - * 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.text.lookup; - -import org.apache.commons.lang3.SystemUtils; -import org.junit.Assert; -import org.junit.Test; - -public class EnvironmentVariableStringLookupTest { - - @Test - public void testOne() { - if (SystemUtils.IS_OS_WINDOWS) { - final String key = "PATH"; - Assert.assertEquals(System.getenv(key), EnvironmentVariableStringLookup.INSTANCE.lookup(key)); - } else if (SystemUtils.IS_OS_LINUX) { - final String key = "USER"; - Assert.assertEquals(System.getenv(key), EnvironmentVariableStringLookup.INSTANCE.lookup(key)); - } - } - -} +/* + * 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.text.lookup; + +import org.apache.commons.lang3.SystemUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class EnvironmentVariableStringLookupTest { + + @Test + public void testOne() { + if (SystemUtils.IS_OS_WINDOWS) { + final String key = "PATH"; + Assertions.assertEquals(System.getenv(key), EnvironmentVariableStringLookup.INSTANCE.lookup(key)); + } else if (SystemUtils.IS_OS_LINUX) { + final String key = "USER"; + Assertions.assertEquals(System.getenv(key), EnvironmentVariableStringLookup.INSTANCE.lookup(key)); + } + } + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/lookup/InterpolatorStringLookupTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/lookup/InterpolatorStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/InterpolatorStringLookupTest.java index 0a86d9c..595d20c 100644 --- a/src/test/java/org/apache/commons/text/lookup/InterpolatorStringLookupTest.java +++ b/src/test/java/org/apache/commons/text/lookup/InterpolatorStringLookupTest.java @@ -1,101 +1,95 @@ -/* - * 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.text.lookup; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.ExternalResource; -import org.junit.rules.RuleChain; - -/** - * - */ -public class InterpolatorStringLookupTest { - - @ClassRule - public static RuleChain rules = RuleChain.outerRule(new ExternalResource() { - @Override - protected void after() { - System.clearProperty(TESTKEY); - System.clearProperty(TESTKEY2); - } - - @Override - protected void before() throws Throwable { - System.setProperty(TESTKEY, TESTVAL); - System.setProperty(TESTKEY2, TESTVAL); - } - }); - private static final String TESTKEY = "TestKey"; - private static final String TESTKEY2 = "TestKey2"; - - private static final String TESTVAL = "TestValue"; - - private void assertLookupNotEmpty(final StringLookup lookup, final String key) { - final String value = lookup.lookup(key); - assertNotNull(value); - assertFalse(value.isEmpty()); - System.out.println(key + " = " + value); - } - - @Test - public void testLookup() { - final Map<String, String> map = new HashMap<>(); - map.put(TESTKEY, TESTVAL); - final StringLookup lookup = new InterpolatorStringLookup(MapStringLookup.on(map)); - String value = lookup.lookup(TESTKEY); - assertEquals(TESTVAL, value); - value = lookup.lookup("ctx:" + TESTKEY); - assertEquals(TESTVAL, value); - value = lookup.lookup("sys:" + TESTKEY); - assertEquals(TESTVAL, value); - value = lookup.lookup("BadKey"); - assertNull(value); - value = lookup.lookup("ctx:" + TESTKEY); - assertEquals(TESTVAL, value); - } - - @Test - public void testLookupWithDefaultInterpolator() { - final StringLookup lookup = new InterpolatorStringLookup(); - String value = lookup.lookup("sys:" + TESTKEY); - assertEquals(TESTVAL, value); - value = lookup.lookup("env:PATH"); - assertNotNull(value); - value = lookup.lookup("date:yyyy-MM-dd"); - assertNotNull("No Date", value); - final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - final String today = format.format(new Date()); - assertEquals(value, today); - assertLookupNotEmpty(lookup, "java:version"); - assertLookupNotEmpty(lookup, "java:runtime"); - assertLookupNotEmpty(lookup, "java:vm"); - assertLookupNotEmpty(lookup, "java:os"); - assertLookupNotEmpty(lookup, "java:locale"); - assertLookupNotEmpty(lookup, "java:hardware"); - } -} +/* + * 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.text.lookup; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class InterpolatorStringLookupTest { + + @BeforeAll + public static void beforeAll() throws Throwable { + System.setProperty(TESTKEY, TESTVAL); + System.setProperty(TESTKEY2, TESTVAL); + } + + @AfterAll + public static void afterAll() throws Throwable { + System.clearProperty(TESTKEY); + System.clearProperty(TESTKEY2); + } + + private static final String TESTKEY = "TestKey"; + private static final String TESTKEY2 = "TestKey2"; + + private static final String TESTVAL = "TestValue"; + + private void assertLookupNotEmpty(final StringLookup lookup, final String key) { + final String value = lookup.lookup(key); + assertNotNull(value); + assertFalse(value.isEmpty()); + System.out.println(key + " = " + value); + } + + @Test + public void testLookup() { + final Map<String, String> map = new HashMap<>(); + map.put(TESTKEY, TESTVAL); + final StringLookup lookup = new InterpolatorStringLookup(MapStringLookup.on(map)); + String value = lookup.lookup(TESTKEY); + assertEquals(TESTVAL, value); + value = lookup.lookup("ctx:" + TESTKEY); + assertEquals(TESTVAL, value); + value = lookup.lookup("sys:" + TESTKEY); + assertEquals(TESTVAL, value); + value = lookup.lookup("BadKey"); + assertNull(value); + value = lookup.lookup("ctx:" + TESTKEY); + assertEquals(TESTVAL, value); + } + + @Test + public void testLookupWithDefaultInterpolator() { + final StringLookup lookup = new InterpolatorStringLookup(); + String value = lookup.lookup("sys:" + TESTKEY); + assertEquals(TESTVAL, value); + value = lookup.lookup("env:PATH"); + assertNotNull(value); + value = lookup.lookup("date:yyyy-MM-dd"); + assertNotNull("No Date", value); + final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + final String today = format.format(new Date()); + assertEquals(value, today); + assertLookupNotEmpty(lookup, "java:version"); + assertLookupNotEmpty(lookup, "java:runtime"); + assertLookupNotEmpty(lookup, "java:vm"); + assertLookupNotEmpty(lookup, "java:os"); + assertLookupNotEmpty(lookup, "java:locale"); + assertLookupNotEmpty(lookup, "java:hardware"); + } +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/lookup/JavaPlatformStringLookupTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/lookup/JavaPlatformStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/JavaPlatformStringLookupTest.java index 9a8941b..c7dd110 100644 --- a/src/test/java/org/apache/commons/text/lookup/JavaPlatformStringLookupTest.java +++ b/src/test/java/org/apache/commons/text/lookup/JavaPlatformStringLookupTest.java @@ -1,31 +1,32 @@ -/* - * 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.text.lookup; - -import org.junit.Assert; -import org.junit.Test; - -public class JavaPlatformStringLookupTest { - - @Test - public void testVm() { - final String key = "vm"; - Assert.assertTrue(JavaPlatformStringLookup.INSTANCE.lookup(key).contains(System.getProperty("java.vm.name"))); - } - -} +/* + * 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.text.lookup; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +public class JavaPlatformStringLookupTest { + + @Test + public void testVm() { + final String key = "vm"; + assertTrue(JavaPlatformStringLookup.INSTANCE.lookup(key).contains(System.getProperty("java.vm.name"))); + } + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/49db4cb3/src/test/java/org/apache/commons/text/lookup/LocalHostStringLookupTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/lookup/LocalHostStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/LocalHostStringLookupTest.java index c00a7dc..1ca1487 100644 --- a/src/test/java/org/apache/commons/text/lookup/LocalHostStringLookupTest.java +++ b/src/test/java/org/apache/commons/text/lookup/LocalHostStringLookupTest.java @@ -1,46 +1,46 @@ -/* - * 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.text.lookup; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.junit.Assert; -import org.junit.Test; - -public class LocalHostStringLookupTest { - - @Test - public void testAddress() throws UnknownHostException { - Assert.assertEquals(InetAddress.getLocalHost().getHostAddress(), - LocalHostStringLookup.INSTANCE.lookup("address")); - } - - @Test - public void testCanonicalName() throws UnknownHostException { - Assert.assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), - LocalHostStringLookup.INSTANCE.lookup("canonical-name")); - } - - @Test - public void testName() throws UnknownHostException { - Assert.assertEquals(InetAddress.getLocalHost().getHostName(), - LocalHostStringLookup.INSTANCE.lookup("name")); - } - -} +/* + * 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.text.lookup; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class LocalHostStringLookupTest { + + @Test + public void testAddress() throws UnknownHostException { + Assertions.assertEquals(InetAddress.getLocalHost().getHostAddress(), + LocalHostStringLookup.INSTANCE.lookup("address")); + } + + @Test + public void testCanonicalName() throws UnknownHostException { + Assertions.assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), + LocalHostStringLookup.INSTANCE.lookup("canonical-name")); + } + + @Test + public void testName() throws UnknownHostException { + Assertions.assertEquals(InetAddress.getLocalHost().getHostName(), + LocalHostStringLookup.INSTANCE.lookup("name")); + } + +}