http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/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 5a5c7b7..cb566c2 100644 --- a/src/test/java/org/apache/commons/text/StringEscapeUtilsTest.java +++ b/src/test/java/org/apache/commons/text/StringEscapeUtilsTest.java @@ -5,9 +5,9 @@ * 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. @@ -45,7 +45,7 @@ import static org.junit.Assert.fail; * */ public class StringEscapeUtilsTest { - private final static String FOO = "foo"; + private static final String FOO = "foo"; @Test public void testConstructor() { @@ -106,8 +106,8 @@ public class StringEscapeUtilsTest { final String actual = StringEscapeUtils.escapeJava(input); /** - * In 2.4 StringEscapeUtils.escapeJava(String) escapes '/' characters, which are not a valid character to escape - * in a Java string. + * In 2.4 StringEscapeUtils.escapeJava(String) escapes '/' characters, which are not a valid character + * to escape in a Java string. */ assertEquals(expected, actual); } @@ -165,21 +165,21 @@ public class StringEscapeUtilsTest { assertUnescapeJava(null, unescaped, original); } - private void assertUnescapeJava(final String message, final String unescaped, final String original) throws IOException { + private void assertUnescapeJava(final String message, final String unescaped, final String original) + throws IOException { final String expected = unescaped; final String actual = StringEscapeUtils.unescapeJava(original); - assertEquals("unescape(String) failed" + - (message == null ? "" : (": " + message)) + - ": expected '" + StringEscapeUtils.escapeJava(expected) + + assertEquals("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) + "'", + + "' actual '" + StringEscapeUtils.escapeJava(actual) + "'", expected, actual); final StringWriter writer = new StringWriter(); StringEscapeUtils.UNESCAPE_JAVA.translate(original, writer); assertEquals(unescaped, writer.toString()); - } @Test @@ -202,7 +202,8 @@ public class StringEscapeUtilsTest { assertEquals("He didn\\'t say, \\\"stop!\\\"", StringEscapeUtils.escapeEcmaScript("He didn't say, \"stop!\"")); assertEquals("document.getElementById(\\\"test\\\").value = \\'<script>alert(\\'aaa\\');<\\/script>\\';", - StringEscapeUtils.escapeEcmaScript("document.getElementById(\"test\").value = '<script>alert('aaa');</script>';")); + StringEscapeUtils.escapeEcmaScript( + "document.getElementById(\"test\").value = '<script>alert('aaa');</script>';")); } @@ -219,7 +220,8 @@ public class StringEscapeUtilsTest { {"final character only", "greater than >", "greater than >"}, {"first character only", "< less than", "< less than"}, {"apostrophe", "Huntington's chorea", "Huntington's chorea"}, - {"languages", "English,Français,\u65E5\u672C\u8A9E (nihongo)", "English,Fran\u00E7ais,\u65E5\u672C\u8A9E (nihongo)"}, + {"languages", "English,Français,\u65E5\u672C\u8A9E (nihongo)", + "English,Fran\u00E7ais,\u65E5\u672C\u8A9E (nihongo)"}, {"8-bit ascii shouldn't number-escape", "\u0080\u009F", "\u0080\u009F"}, }; @@ -258,7 +260,7 @@ public class StringEscapeUtilsTest { } // \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 + // on some locales assertEquals("funny chars pass through OK", "Fran\u00E7ais", StringEscapeUtils.unescapeHtml3("Fran\u00E7ais")); assertEquals("Hello&;World", StringEscapeUtils.unescapeHtml3("Hello&;World")); @@ -302,7 +304,7 @@ public class StringEscapeUtilsTest { } // \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 + // on some locales assertEquals("funny chars pass through OK", "Fran\u00E7ais", StringEscapeUtils.unescapeHtml4("Fran\u00E7ais")); assertEquals("Hello&;World", StringEscapeUtils.unescapeHtml4("Hello&;World")); @@ -313,17 +315,18 @@ public class StringEscapeUtilsTest { @Test public void testUnescapeHexCharsHtml() { - // Simple easy to grok test + // Simple easy to grok test assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ")); assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ")); // Test all Character values: for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) { final Character c1 = new Character(i); - final Character c2 = new Character((char)(i+1)); + final Character c2 = new Character((char) (i + 1)); final String expected = c1.toString() + c2.toString(); - final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";"; - final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";"; - assertEquals("hex number unescape index " + (int)i, expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2)); + final String escapedC1 = "&#x" + Integer.toHexString(c1.charValue()) + ";"; + final String escapedC2 = "&#x" + Integer.toHexString(c2.charValue()) + ";"; + assertEquals("hex number unescape index " + i, expected, + StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2)); } } @@ -354,7 +357,8 @@ public class StringEscapeUtilsTest { 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")); + "a\u007e„\u0085†Ÿ\u00a0b", + StringEscapeUtils.escapeXml10("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b")); } @Test @@ -365,9 +369,11 @@ public class StringEscapeUtilsTest { 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")); + "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")); + "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", @@ -382,10 +388,10 @@ public class StringEscapeUtilsTest { @Test public void testUnescapeXmlSupplementaryCharacters() { assertEquals("Supplementary character must be represented using a single escape", "\uD84C\uDFB4", - StringEscapeUtils.unescapeXml("𣎴") ); + StringEscapeUtils.unescapeXml("𣎴")); - assertEquals("Supplementary characters mixed with basic characters should be decoded correctly", "a b c \uD84C\uDFB4", - StringEscapeUtils.unescapeXml("a b c 𣎴") ); + assertEquals("Supplementary characters mixed with basic characters should be decoded correctly", + "a b c \uD84C\uDFB4", StringEscapeUtils.unescapeXml("a b c 𣎴")); } // Tests issue #38569 @@ -405,23 +411,23 @@ public class StringEscapeUtilsTest { @Test public void testEscapeCsvString() throws Exception { - assertEquals("foo.bar", StringEscapeUtils.escapeCsv("foo.bar")); - assertEquals("\"foo,bar\"", StringEscapeUtils.escapeCsv("foo,bar")); - assertEquals("\"foo\nbar\"", StringEscapeUtils.escapeCsv("foo\nbar")); - assertEquals("\"foo\rbar\"", StringEscapeUtils.escapeCsv("foo\rbar")); - assertEquals("\"foo\"\"bar\"", StringEscapeUtils.escapeCsv("foo\"bar")); + assertEquals("foo.bar", StringEscapeUtils.escapeCsv("foo.bar")); + assertEquals("\"foo,bar\"", StringEscapeUtils.escapeCsv("foo,bar")); + assertEquals("\"foo\nbar\"", StringEscapeUtils.escapeCsv("foo\nbar")); + assertEquals("\"foo\rbar\"", StringEscapeUtils.escapeCsv("foo\rbar")); + assertEquals("\"foo\"\"bar\"", StringEscapeUtils.escapeCsv("foo\"bar")); assertEquals("foo\uD84C\uDFB4bar", StringEscapeUtils.escapeCsv("foo\uD84C\uDFB4bar")); - assertEquals("", StringEscapeUtils.escapeCsv("")); + assertEquals("", StringEscapeUtils.escapeCsv("")); assertNull(StringEscapeUtils.escapeCsv(null)); } @Test public void testEscapeCsvWriter() throws Exception { - checkCsvEscapeWriter("foo.bar", "foo.bar"); - checkCsvEscapeWriter("\"foo,bar\"", "foo,bar"); - checkCsvEscapeWriter("\"foo\nbar\"", "foo\nbar"); - checkCsvEscapeWriter("\"foo\rbar\"", "foo\rbar"); - checkCsvEscapeWriter("\"foo\"\"bar\"", "foo\"bar"); + checkCsvEscapeWriter("foo.bar", "foo.bar"); + checkCsvEscapeWriter("\"foo,bar\"", "foo,bar"); + checkCsvEscapeWriter("\"foo\nbar\"", "foo\nbar"); + checkCsvEscapeWriter("\"foo\rbar\"", "foo\rbar"); + checkCsvEscapeWriter("\"foo\"\"bar\"", "foo\"bar"); checkCsvEscapeWriter("foo\uD84C\uDFB4bar", "foo\uD84C\uDFB4bar"); checkCsvEscapeWriter("", null); checkCsvEscapeWriter("", ""); @@ -439,30 +445,30 @@ public class StringEscapeUtilsTest { @Test public void testUnescapeCsvString() throws Exception { - assertEquals("foo.bar", StringEscapeUtils.unescapeCsv("foo.bar")); - assertEquals("foo,bar", StringEscapeUtils.unescapeCsv("\"foo,bar\"")); - assertEquals("foo\nbar", StringEscapeUtils.unescapeCsv("\"foo\nbar\"")); - assertEquals("foo\rbar", StringEscapeUtils.unescapeCsv("\"foo\rbar\"")); - assertEquals("foo\"bar", StringEscapeUtils.unescapeCsv("\"foo\"\"bar\"")); - assertEquals("foo\uD84C\uDFB4bar", StringEscapeUtils.unescapeCsv("foo\uD84C\uDFB4bar")); - assertEquals("", StringEscapeUtils.unescapeCsv("")); + assertEquals("foo.bar", StringEscapeUtils.unescapeCsv("foo.bar")); + assertEquals("foo,bar", StringEscapeUtils.unescapeCsv("\"foo,bar\"")); + assertEquals("foo\nbar", StringEscapeUtils.unescapeCsv("\"foo\nbar\"")); + assertEquals("foo\rbar", StringEscapeUtils.unescapeCsv("\"foo\rbar\"")); + assertEquals("foo\"bar", StringEscapeUtils.unescapeCsv("\"foo\"\"bar\"")); + assertEquals("foo\uD84C\uDFB4bar", StringEscapeUtils.unescapeCsv("foo\uD84C\uDFB4bar")); + assertEquals("", StringEscapeUtils.unescapeCsv("")); assertNull(StringEscapeUtils.unescapeCsv(null)); - assertEquals("\"foo.bar\"", StringEscapeUtils.unescapeCsv("\"foo.bar\"")); + assertEquals("\"foo.bar\"", StringEscapeUtils.unescapeCsv("\"foo.bar\"")); } @Test public void testUnescapeCsvWriter() throws Exception { - checkCsvUnescapeWriter("foo.bar", "foo.bar"); - checkCsvUnescapeWriter("foo,bar", "\"foo,bar\""); - checkCsvUnescapeWriter("foo\nbar", "\"foo\nbar\""); - checkCsvUnescapeWriter("foo\rbar", "\"foo\rbar\""); - checkCsvUnescapeWriter("foo\"bar", "\"foo\"\"bar\""); + checkCsvUnescapeWriter("foo.bar", "foo.bar"); + checkCsvUnescapeWriter("foo,bar", "\"foo,bar\""); + checkCsvUnescapeWriter("foo\nbar", "\"foo\nbar\""); + checkCsvUnescapeWriter("foo\rbar", "\"foo\rbar\""); + checkCsvUnescapeWriter("foo\"bar", "\"foo\"\"bar\""); checkCsvUnescapeWriter("foo\uD84C\uDFB4bar", "foo\uD84C\uDFB4bar"); checkCsvUnescapeWriter("", null); checkCsvUnescapeWriter("", ""); - checkCsvUnescapeWriter("\"foo.bar\"", "\"foo.bar\""); + checkCsvUnescapeWriter("\"foo.bar\"", "\"foo.bar\""); } private void checkCsvUnescapeWriter(final String expected, final String value) { @@ -484,19 +490,19 @@ public class StringEscapeUtilsTest { // COUNTING ROD UNIT DIGIT THREE // in Unicode // codepoint: U+1D362 - final byte[] data = new byte[] { (byte)0xF0, (byte)0x9D, (byte)0x8D, (byte)0xA2 }; + final byte[] data = {(byte) 0xF0, (byte) 0x9D, (byte) 0x8D, (byte) 0xA2}; 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); + final String escaped = StringEscapeUtils.escapeHtml4(original); + assertEquals("High Unicode should not have been escaped", original, escaped); - final String unescaped = StringEscapeUtils.unescapeHtml4( escaped ); - assertEquals( "High Unicode should have been unchanged", original, unescaped); + final String unescaped = StringEscapeUtils.unescapeHtml4(escaped); + assertEquals("High Unicode should have been unchanged", original, unescaped); // TODO: I think this should hold, needs further investigation - // String unescapedFromEntity = StringEscapeUtils.unescapeHtml4( "𝍢" ); - // assertEquals( "High Unicode should have been unescaped", original, unescapedFromEntity); + // String unescapedFromEntity = StringEscapeUtils.unescapeHtml4("𝍢"); + // assertEquals("High Unicode should have been unescaped", original, unescapedFromEntity); } /** @@ -507,12 +513,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", + assertEquals("Hiragana character Unicode behaviour should not be being escaped by escapeHtml4", original, escaped); - final String unescaped = StringEscapeUtils.unescapeHtml4( escaped ); + final String unescaped = StringEscapeUtils.unescapeHtml4(escaped); - assertEquals( "Hiragana character Unicode behaviour has changed - expected no unescaping", escaped, unescaped); + assertEquals("Hiragana character Unicode behaviour has changed - expected no unescaping", escaped, unescaped); } /** @@ -564,14 +570,15 @@ public class StringEscapeUtilsTest { assertEquals("He didn't say, \\\"stop!\\\"", StringEscapeUtils.escapeJson("He didn't say, \"stop!\"")); final String expected = "\\\"foo\\\" isn't \\\"bar\\\". specials: \\b\\r\\n\\f\\t\\\\\\/"; - final String input ="\"foo\" isn't \"bar\". specials: \b\r\n\f\t\\/"; + final String input = "\"foo\" isn't \"bar\". specials: \b\r\n\f\t\\/"; assertEquals(expected, StringEscapeUtils.escapeJson(input)); } @Test public void testBuilder() { - final String result = StringEscapeUtils.builder(StringEscapeUtils.ESCAPE_XML10).escape("<").append(">").toString(); + final String result = + StringEscapeUtils.builder(StringEscapeUtils.ESCAPE_XML10).escape("<").append(">").toString(); assertEquals("<>", result); } @@ -611,7 +618,8 @@ public class StringEscapeUtilsTest { @Test public void testUnescapeJson() { - final String jsonString = "{\"age\":100,\"name\":\"kyong.com\n\",\"messages\":[\"msg 1\",\"msg 2\",\"msg 3\"]}"; + final String jsonString = + "{\"age\":100,\"name\":\"kyong.com\n\",\"messages\":[\"msg 1\",\"msg 2\",\"msg 3\"]}"; assertEquals("", StringEscapeUtils.unescapeJson("")); assertEquals(" ", StringEscapeUtils.unescapeJson(" ")); @@ -621,16 +629,17 @@ public class StringEscapeUtilsTest { @Test public void testUnescapeJsonFoundBug_Issue_Text_100() { - final String jsonString = "{\"age\":100,\"name\":\"m\\\"kyong.com\",\"messages\":[\"msg 1\",\"msg 2\",\"msg 3\"]}"; + final String jsonString = + "{\"age\":100,\"name\":\"m\\\"kyong.com\",\"messages\":[\"msg 1\",\"msg 2\",\"msg 3\"]}"; assertEquals(jsonString, StringEscapeUtils.unescapeJson(jsonString)); } @Test public void testUnescapeJsonFoundBug_Issue_Text_100_Fix() { - final String jsonString = "{\"age\":100,\"name\":\"n\\\"m\\\"kyong.com\",\"messages\":[\"msg 1\",\"msg 2\",\"msg 3\"]}"; + final String jsonString = + "{\"age\":100,\"name\":\"n\\\"m\\\"kyong.com\",\"messages\":[\"msg 1\",\"msg 2\",\"msg 3\"]}"; assertEquals(jsonString, StringEscapeUtils.unescapeJson(jsonString)); } - -} \ No newline at end of file +}
http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/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 955d094..2b374c6 100644 --- a/src/test/java/org/apache/commons/text/WordUtilsTest.java +++ b/src/test/java/org/apache/commons/text/WordUtilsTest.java @@ -16,20 +16,24 @@ */ package org.apache.commons.text; -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; +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 java.lang.reflect.Constructor; import java.lang.reflect.Modifier; -import static org.junit.Assert.*; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; /** * Unit tests for {@link WordUtils} class. */ public class WordUtilsTest { - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- @Test public void testConstructor() { assertNotNull(new WordUtils()); @@ -40,7 +44,7 @@ public class WordUtilsTest { assertFalse(Modifier.isFinal(WordUtils.class.getModifiers())); } - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- @Test public void testWrap_StringInt() { assertNull(WordUtils.wrap(null, 20)); @@ -52,20 +56,20 @@ public class WordUtilsTest { // normal final String systemNewLine = System.lineSeparator(); String input = "Here is one line of text that is going to be wrapped after 20 columns."; - String expected = "Here is one line of" + systemNewLine + "text that is going" - + systemNewLine + "to be wrapped after" + systemNewLine + "20 columns."; + String expected = "Here is one line of" + systemNewLine + "text that is going" + systemNewLine + + "to be wrapped after" + systemNewLine + "20 columns."; assertEquals(expected, WordUtils.wrap(input, 20)); // long word at end input = "Click here to jump to the commons website - http://commons.apache.org"; - expected = "Click here to jump" + systemNewLine + "to the commons" + systemNewLine - + "website -" + systemNewLine + "http://commons.apache.org"; + expected = "Click here to jump" + systemNewLine + "to the commons" + systemNewLine + "website -" + systemNewLine + + "http://commons.apache.org"; assertEquals(expected, WordUtils.wrap(input, 20)); // long word in middle input = "Click here, http://commons.apache.org, to jump to the commons website"; - expected = "Click here," + systemNewLine + "http://commons.apache.org," + systemNewLine - + "to jump to the" + systemNewLine + "commons website"; + expected = "Click here," + systemNewLine + "http://commons.apache.org," + systemNewLine + "to jump to the" + + systemNewLine + "commons website"; assertEquals(expected, WordUtils.wrap(input, 20)); // leading spaces on a new line are stripped @@ -114,8 +118,8 @@ public class WordUtilsTest { // system newline char final String systemNewLine = System.lineSeparator(); input = "Here is one line of text that is going to be wrapped after 20 columns."; - expected = "Here is one line of" + systemNewLine + "text that is going" + systemNewLine - + "to be wrapped after" + systemNewLine + "20 columns."; + expected = "Here is one line of" + systemNewLine + "text that is going" + systemNewLine + "to be wrapped after" + + systemNewLine + "20 columns."; assertEquals(expected, WordUtils.wrap(input, 20, null, false)); assertEquals(expected, WordUtils.wrap(input, 20, null, true)); @@ -155,7 +159,7 @@ public class WordUtilsTest { @Test public void testWrap_StringIntStringBooleanString() { - //no changes test + // no changes test String input = "flammable/inflammable"; String expected = "flammable/inflammable"; assertEquals(expected, WordUtils.wrap(input, 30, "\n", false, "/")); @@ -178,19 +182,19 @@ public class WordUtilsTest { assertEquals(expected, WordUtils.wrap(input, 15, "\n", true, "/")); } - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- @Test public void testCapitalize_String() { assertNull(WordUtils.capitalize(null)); assertEquals("", WordUtils.capitalize("")); assertEquals(" ", WordUtils.capitalize(" ")); - assertEquals("I", WordUtils.capitalize("I") ); - assertEquals("I", WordUtils.capitalize("i") ); - assertEquals("I Am Here 123", WordUtils.capitalize("i am here 123") ); - assertEquals("I Am Here 123", WordUtils.capitalize("I Am Here 123") ); - assertEquals("I Am HERE 123", WordUtils.capitalize("i am HERE 123") ); - assertEquals("I AM HERE 123", WordUtils.capitalize("I AM HERE 123") ); + assertEquals("I", WordUtils.capitalize("I")); + assertEquals("I", WordUtils.capitalize("i")); + assertEquals("I Am Here 123", WordUtils.capitalize("i am here 123")); + assertEquals("I Am Here 123", WordUtils.capitalize("I Am Here 123")); + assertEquals("I Am HERE 123", WordUtils.capitalize("i am HERE 123")); + assertEquals("I AM HERE 123", WordUtils.capitalize("I AM HERE 123")); } @Test @@ -199,16 +203,16 @@ public class WordUtilsTest { assertEquals("", WordUtils.capitalize("", new char[0])); assertEquals(" ", WordUtils.capitalize(" ", new char[0])); - char[] chars = new char[] { '-', '+', ' ', '@' }; - assertEquals("I", WordUtils.capitalize("I", chars) ); - assertEquals("I", WordUtils.capitalize("i", chars) ); - assertEquals("I-Am Here+123", WordUtils.capitalize("i-am here+123", chars) ); - assertEquals("I Am+Here-123", WordUtils.capitalize("I Am+Here-123", chars) ); - assertEquals("I+Am-HERE 123", WordUtils.capitalize("i+am-HERE 123", chars) ); - assertEquals("I-AM HERE+123", WordUtils.capitalize("I-AM HERE+123", chars) ); + char[] chars = new char[] {'-', '+', ' ', '@'}; + assertEquals("I", WordUtils.capitalize("I", chars)); + assertEquals("I", WordUtils.capitalize("i", chars)); + assertEquals("I-Am Here+123", WordUtils.capitalize("i-am here+123", chars)); + assertEquals("I Am+Here-123", WordUtils.capitalize("I Am+Here-123", chars)); + assertEquals("I+Am-HERE 123", WordUtils.capitalize("i+am-HERE 123", chars)); + assertEquals("I-AM HERE+123", WordUtils.capitalize("I-AM HERE+123", chars)); chars = new char[] {'.'}; - assertEquals("I aM.Fine", WordUtils.capitalize("i aM.fine", chars) ); - assertEquals("I Am.fine", WordUtils.capitalize("i am.fine", null) ); + assertEquals("I aM.Fine", WordUtils.capitalize("i aM.fine", chars)); + assertEquals("I Am.fine", WordUtils.capitalize("i am.fine", null)); } @Test @@ -217,23 +221,23 @@ public class WordUtilsTest { assertEquals("", WordUtils.capitalizeFully("")); assertEquals(" ", WordUtils.capitalizeFully(" ")); - assertEquals("I", WordUtils.capitalizeFully("I") ); - assertEquals("I", WordUtils.capitalizeFully("i") ); - assertEquals("I Am Here 123", WordUtils.capitalizeFully("i am here 123") ); - assertEquals("I Am Here 123", WordUtils.capitalizeFully("I Am Here 123") ); - assertEquals("I Am Here 123", WordUtils.capitalizeFully("i am HERE 123") ); - assertEquals("I Am Here 123", WordUtils.capitalizeFully("I AM HERE 123") ); - assertEquals("Alphabet", WordUtils.capitalizeFully("alphabet") ); // single word + assertEquals("I", WordUtils.capitalizeFully("I")); + assertEquals("I", WordUtils.capitalizeFully("i")); + assertEquals("I Am Here 123", WordUtils.capitalizeFully("i am here 123")); + assertEquals("I Am Here 123", WordUtils.capitalizeFully("I Am Here 123")); + assertEquals("I Am Here 123", WordUtils.capitalizeFully("i am HERE 123")); + assertEquals("I Am Here 123", WordUtils.capitalizeFully("I AM HERE 123")); + assertEquals("Alphabet", WordUtils.capitalizeFully("alphabet")); // single word } @Test public void testCapitalizeFully_Text88() { - assertEquals("I am fine now",WordUtils.capitalizeFully("i am fine now", new char[]{})); + assertEquals("I am fine now", WordUtils.capitalizeFully("i am fine now", new char[] {})); } @Test public void testUnCapitalize_Text88() { - assertEquals("i am fine now",WordUtils.uncapitalize("I am fine now", new char[]{})); + assertEquals("i am fine now", WordUtils.uncapitalize("I am fine now", new char[] {})); } @Test @@ -242,18 +246,18 @@ public class WordUtilsTest { assertEquals("", WordUtils.capitalizeFully("", new char[0])); assertEquals(" ", WordUtils.capitalizeFully(" ", new char[0])); - char[] chars = new char[] { '-', '+', ' ', '@' }; - assertEquals("I", WordUtils.capitalizeFully("I", chars) ); - assertEquals("I", WordUtils.capitalizeFully("i", chars) ); - assertEquals("I-Am Here+123", WordUtils.capitalizeFully("i-am here+123", chars) ); - assertEquals("I Am+Here-123", WordUtils.capitalizeFully("I Am+Here-123", chars) ); - assertEquals("I+Am-Here 123", WordUtils.capitalizeFully("i+am-HERE 123", chars) ); - assertEquals("I-Am Here+123", WordUtils.capitalizeFully("I-AM HERE+123", chars) ); + char[] chars = new char[] {'-', '+', ' ', '@'}; + assertEquals("I", WordUtils.capitalizeFully("I", chars)); + assertEquals("I", WordUtils.capitalizeFully("i", chars)); + assertEquals("I-Am Here+123", WordUtils.capitalizeFully("i-am here+123", chars)); + assertEquals("I Am+Here-123", WordUtils.capitalizeFully("I Am+Here-123", chars)); + assertEquals("I+Am-Here 123", WordUtils.capitalizeFully("i+am-HERE 123", chars)); + assertEquals("I-Am Here+123", WordUtils.capitalizeFully("I-AM HERE+123", chars)); chars = new char[] {'.'}; - assertEquals("I am.Fine", WordUtils.capitalizeFully("i aM.fine", chars) ); - assertEquals("I Am.fine", WordUtils.capitalizeFully("i am.fine", null) ); - assertEquals("Alphabet", WordUtils.capitalizeFully("alphabet", null) ); // single word - assertEquals("Alphabet", WordUtils.capitalizeFully("alphabet", new char[] {'!'}) ); // no matching delim + assertEquals("I am.Fine", WordUtils.capitalizeFully("i aM.fine", chars)); + assertEquals("I Am.fine", WordUtils.capitalizeFully("i am.fine", null)); + assertEquals("Alphabet", WordUtils.capitalizeFully("alphabet", null)); // single word + assertEquals("Alphabet", WordUtils.capitalizeFully("alphabet", new char[] {'!'})); // no matching delim } @Test @@ -282,12 +286,12 @@ public class WordUtilsTest { assertEquals("", WordUtils.uncapitalize("")); assertEquals(" ", WordUtils.uncapitalize(" ")); - assertEquals("i", WordUtils.uncapitalize("I") ); - assertEquals("i", WordUtils.uncapitalize("i") ); - assertEquals("i am here 123", WordUtils.uncapitalize("i am here 123") ); - assertEquals("i am here 123", WordUtils.uncapitalize("I Am Here 123") ); - assertEquals("i am hERE 123", WordUtils.uncapitalize("i am HERE 123") ); - assertEquals("i aM hERE 123", WordUtils.uncapitalize("I AM HERE 123") ); + assertEquals("i", WordUtils.uncapitalize("I")); + assertEquals("i", WordUtils.uncapitalize("i")); + assertEquals("i am here 123", WordUtils.uncapitalize("i am here 123")); + assertEquals("i am here 123", WordUtils.uncapitalize("I Am Here 123")); + assertEquals("i am hERE 123", WordUtils.uncapitalize("i am HERE 123")); + assertEquals("i aM hERE 123", WordUtils.uncapitalize("I AM HERE 123")); } @Test @@ -296,19 +300,19 @@ public class WordUtilsTest { assertEquals("", WordUtils.uncapitalize("", new char[0])); assertEquals(" ", WordUtils.uncapitalize(" ", new char[0])); - char[] chars = new char[] { '-', '+', ' ', '@' }; - assertEquals("i", WordUtils.uncapitalize("I", chars) ); - assertEquals("i", WordUtils.uncapitalize("i", chars) ); - assertEquals("i am-here+123", WordUtils.uncapitalize("i am-here+123", chars) ); - assertEquals("i+am here-123", WordUtils.uncapitalize("I+Am Here-123", chars) ); - assertEquals("i-am+hERE 123", WordUtils.uncapitalize("i-am+HERE 123", chars) ); - assertEquals("i aM-hERE+123", WordUtils.uncapitalize("I AM-HERE+123", chars) ); + char[] chars = new char[] {'-', '+', ' ', '@'}; + assertEquals("i", WordUtils.uncapitalize("I", chars)); + assertEquals("i", WordUtils.uncapitalize("i", chars)); + assertEquals("i am-here+123", WordUtils.uncapitalize("i am-here+123", chars)); + assertEquals("i+am here-123", WordUtils.uncapitalize("I+Am Here-123", chars)); + assertEquals("i-am+hERE 123", WordUtils.uncapitalize("i-am+HERE 123", chars)); + assertEquals("i aM-hERE+123", WordUtils.uncapitalize("I AM-HERE+123", chars)); chars = new char[] {'.'}; - assertEquals("i AM.fINE", WordUtils.uncapitalize("I AM.FINE", chars) ); - assertEquals("i aM.FINE", WordUtils.uncapitalize("I AM.FINE", null) ); + assertEquals("i AM.fINE", WordUtils.uncapitalize("I AM.FINE", chars)); + assertEquals("i aM.FINE", WordUtils.uncapitalize("I AM.FINE", null)); } - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- @Test public void testInitials_String() { assertNull(WordUtils.initials(null)); @@ -411,19 +415,25 @@ public class WordUtilsTest { @Test public void testInitialsSurrogatePairs() { - //Tests with space as default delimiter - assertEquals("\uD800\uDF00\uD800\uDF02", WordUtils.initials("\uD800\uDF00\uD800\uDF01 \uD800\uDF02\uD800\uDF03")); - assertEquals("\uD800\uDF00\uD800\uDF02", WordUtils.initials("\uD800\uDF00\uD800\uDF01 \uD800\uDF02\uD800\uDF03", null)); + // Tests with space as default delimiter + assertEquals("\uD800\uDF00\uD800\uDF02", + WordUtils.initials("\uD800\uDF00\uD800\uDF01 \uD800\uDF02\uD800\uDF03")); + assertEquals("\uD800\uDF00\uD800\uDF02", + WordUtils.initials("\uD800\uDF00\uD800\uDF01 \uD800\uDF02\uD800\uDF03", null)); assertEquals("\uD800\uDF00\uD800\uDF02", WordUtils.initials("\uD800\uDF00 \uD800\uDF02 ", null)); - //Tests with UTF-16 as delimiters - assertEquals("\uD800\uDF00\uD800\uDF02", WordUtils.initials("\uD800\uDF00\uD800\uDF01.\uD800\uDF02\uD800\uDF03", new char[]{'.'})); - assertEquals("\uD800\uDF00\uD800\uDF02", WordUtils.initials("\uD800\uDF00\uD800\uDF01A\uD800\uDF02\uD800\uDF03", new char[]{'A'})); - - //Tests with UTF-32 as delimiters - assertEquals("\uD800\uDF00\uD800\uDF02", WordUtils.initials("\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF02\uD800\uDF03", new char[]{'\uD800', '\uDF14'})); - assertEquals("\uD800\uDF00\uD800\uDF02", WordUtils.initials("\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF18\uD800\uDF02\uD800\uDF03", new char[]{'\uD800', '\uDF14', '\uD800', '\uDF18'})); - + // Tests with UTF-16 as delimiters + assertEquals("\uD800\uDF00\uD800\uDF02", + WordUtils.initials("\uD800\uDF00\uD800\uDF01.\uD800\uDF02\uD800\uDF03", new char[] {'.'})); + assertEquals("\uD800\uDF00\uD800\uDF02", + WordUtils.initials("\uD800\uDF00\uD800\uDF01A\uD800\uDF02\uD800\uDF03", new char[] {'A'})); + + // Tests with UTF-32 as delimiters + assertEquals("\uD800\uDF00\uD800\uDF02", WordUtils.initials( + "\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF02\uD800\uDF03", new char[] {'\uD800', '\uDF14'})); + assertEquals("\uD800\uDF00\uD800\uDF02", + WordUtils.initials("\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF18\uD800\uDF02\uD800\uDF03", + new char[] {'\uD800', '\uDF14', '\uD800', '\uDF18'})); } // ----------------------------------------------------------------------- @@ -433,12 +443,12 @@ public class WordUtilsTest { assertEquals("", WordUtils.swapCase("")); assertEquals(" ", WordUtils.swapCase(" ")); - assertEquals("i", WordUtils.swapCase("I") ); - assertEquals("I", WordUtils.swapCase("i") ); - assertEquals("I AM HERE 123", WordUtils.swapCase("i am here 123") ); - assertEquals("i aM hERE 123", WordUtils.swapCase("I Am Here 123") ); - assertEquals("I AM here 123", WordUtils.swapCase("i am HERE 123") ); - assertEquals("i am here 123", WordUtils.swapCase("I AM HERE 123") ); + assertEquals("i", WordUtils.swapCase("I")); + assertEquals("I", WordUtils.swapCase("i")); + assertEquals("I AM HERE 123", WordUtils.swapCase("i am here 123")); + assertEquals("i aM hERE 123", WordUtils.swapCase("I Am Here 123")); + assertEquals("I AM here 123", WordUtils.swapCase("i am HERE 123")); + assertEquals("i am here 123", WordUtils.swapCase("I AM HERE 123")); final String test = "This String contains a TitleCase character: \u01C8"; final String expect = "tHIS sTRING CONTAINS A tITLEcASE CHARACTER: \u01C9"; @@ -448,32 +458,32 @@ public class WordUtilsTest { // ----------------------------------------------------------------------- @Test public void testAbbreviateForNullAndEmptyString() { - assertNull((WordUtils.abbreviate(null, 1,-1,""))); - assertEquals(StringUtils.EMPTY, WordUtils.abbreviate("", 1,-1,"")); - assertEquals("", WordUtils.abbreviate("0123456790", 0,0,"")); - assertEquals("", WordUtils.abbreviate(" 0123456790", 0,-1,"")); + assertNull((WordUtils.abbreviate(null, 1, -1, ""))); + assertEquals(StringUtils.EMPTY, WordUtils.abbreviate("", 1, -1, "")); + assertEquals("", WordUtils.abbreviate("0123456790", 0, 0, "")); + assertEquals("", WordUtils.abbreviate(" 0123456790", 0, -1, "")); } // ----------------------------------------------------------------------- @Test public void testAbbreviateForUpperLimit() { - assertEquals("01234", WordUtils.abbreviate("0123456789", 0,5,"")); - assertEquals("012", WordUtils.abbreviate("012 3456789", 2, 5,"")); - assertEquals("0123456789", WordUtils.abbreviate("0123456789", 0,-1,"")); + assertEquals("01234", WordUtils.abbreviate("0123456789", 0, 5, "")); + assertEquals("012", WordUtils.abbreviate("012 3456789", 2, 5, "")); + assertEquals("0123456789", WordUtils.abbreviate("0123456789", 0, -1, "")); } // ----------------------------------------------------------------------- @Test public void testAbbreviateForUpperLimitAndAppendedString() { - assertEquals("01234-", WordUtils.abbreviate("0123456789", 0,5,"-")); + assertEquals("01234-", WordUtils.abbreviate("0123456789", 0, 5, "-")); assertEquals("012", WordUtils.abbreviate("012 3456789", 2, 5, null)); - assertEquals("0123456789", WordUtils.abbreviate("0123456789", 0,-1,"")); + assertEquals("0123456789", WordUtils.abbreviate("0123456789", 0, -1, "")); } // ----------------------------------------------------------------------- @Test public void testAbbreviateForLowerValue() { - assertEquals("012", WordUtils.abbreviate("012 3456789", 0,5, null)); + assertEquals("012", WordUtils.abbreviate("012 3456789", 0, 5, null)); assertEquals("01234", WordUtils.abbreviate("01234 56789", 5, 10, null)); assertEquals("01 23 45 67", WordUtils.abbreviate("01 23 45 67 89", 9, -1, null)); assertEquals("01 23 45 6", WordUtils.abbreviate("01 23 45 67 89", 9, 10, null)); @@ -483,7 +493,7 @@ public class WordUtilsTest { // ----------------------------------------------------------------------- @Test public void testAbbreviateForLowerValueAndAppendedString() { - assertEquals("012", WordUtils.abbreviate("012 3456789", 0,5, null)); + assertEquals("012", WordUtils.abbreviate("012 3456789", 0, 5, null)); assertEquals("01234-", WordUtils.abbreviate("01234 56789", 5, 10, "-")); assertEquals("01 23 45 67abc", WordUtils.abbreviate("01 23 45 67 89", 9, -1, "abc")); assertEquals("01 23 45 6", WordUtils.abbreviate("01 23 45 67 89", 9, 10, "")); @@ -496,14 +506,14 @@ public class WordUtilsTest { @Test(expected = IllegalArgumentException.class) public void testAbbreviateUpperLessThanLowerValues() { - assertEquals("01234", WordUtils.abbreviate("0123456789", 5, 2,"")); + assertEquals("01234", WordUtils.abbreviate("0123456789", 5, 2, "")); } @Test public void testLANG673() throws Exception { - assertEquals("01",WordUtils.abbreviate("01 23 45 67 89", 0, 40, "")); - assertEquals("01 23 45 67",WordUtils.abbreviate("01 23 45 67 89", 10, 40, "")); - assertEquals("01 23 45 67 89",WordUtils.abbreviate("01 23 45 67 89", 40, 40, "")); + assertEquals("01", WordUtils.abbreviate("01 23 45 67 89", 0, 40, "")); + assertEquals("01 23 45 67", WordUtils.abbreviate("01 23 45 67 89", 10, 40, "")); + assertEquals("01 23 45 67 89", WordUtils.abbreviate("01 23 45 67 89", 40, 40, "")); } @Test @@ -511,7 +521,7 @@ public class WordUtilsTest { // Prior to fix, this was throwing StringIndexOutOfBoundsException WordUtils.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " - + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",70); + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 70); } @Test @@ -519,4 +529,4 @@ public class WordUtilsTest { assertFalse(WordUtils.containsAllWords("M", null)); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/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 eea6f9f..8b99d03 100644 --- a/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java +++ b/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java @@ -38,10 +38,12 @@ public class ReplacementsFinderTest { private final int skipped; private final Character[] from; private final Character[] to; + @Before public void setUp() { handler = new SimpleHandler(); } + @Parameters public static Collection<Object[]> data() { return Arrays.asList(new Object[][] { @@ -60,6 +62,7 @@ public class ReplacementsFinderTest { } }); } + public ReplacementsFinderTest(final String left, final String right, final int skipped, final Character[] from, final Character[] to) { this.left = left; @@ -68,6 +71,7 @@ public class ReplacementsFinderTest { this.from = from; this.to = to; } + @Test public void testReplacementsHandler() { final StringsComparator sc = new StringsComparator(left, right); @@ -79,12 +83,13 @@ public class ReplacementsFinderTest { assertArrayEquals("To characters do not match", to, handler.getTo().toArray(new Character[0])); } + // Helper RecplacementsHandler implementation for testing private class SimpleHandler implements ReplacementsHandler<Character> { private int skipped; private final List<Character> from; private final List<Character> to; - public SimpleHandler() { + SimpleHandler() { skipped = 0; from = new ArrayList<>(); to = new ArrayList<>(); http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/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 bd91a21..70636a5 100644 --- a/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java +++ b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java @@ -32,6 +32,7 @@ public class StringsComparatorTest { private List<String> after; private int[] length; private int[] lcs; + @Test public void testLength() { for (int i = 0; i < before.size(); ++i) { @@ -39,6 +40,7 @@ public class StringsComparatorTest { assertEquals(length[i], comparator.getScript().getModifications()); } } + @Test public void testLongestCommonSubsequence() { for (int i = 0; i < before.size(); ++i) { @@ -46,6 +48,7 @@ public class StringsComparatorTest { assertEquals(lcs[i], comparator.getScript().getLCSLength()); } } + @Test public void testExecution() { for (int i = 0; i < before.size(); ++i) { @@ -54,9 +57,10 @@ public class StringsComparatorTest { assertEquals(after.get(i), ev.getString()); } } + private class ExecutionVisitor<T> implements CommandVisitor<T> { private final StringBuilder v; - public ExecutionVisitor() { + ExecutionVisitor() { v = new StringBuilder(); } @Override http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java index e1f03db..68ea13c 100644 --- a/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java @@ -5,9 +5,9 @@ * 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. http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java b/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java index 4409621..5197248 100644 --- a/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java +++ b/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java @@ -24,7 +24,7 @@ import java.util.Map; import static org.junit.Assert.assertEquals; -public class CosineSimilarityTest{ +public class CosineSimilarityTest { @Test public void testCosineSimilarityWithNonEmptyMap() { @@ -58,4 +58,4 @@ public class CosineSimilarityTest{ assertEquals(0.0, cosineSimilarity.cosineSimilarity(hashMap, hashMap), 0.01); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java b/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java index 9c1fbc5..1c88789 100644 --- a/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java +++ b/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java @@ -5,9 +5,9 @@ * 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. @@ -71,4 +71,4 @@ public class FuzzyScoreTest { assertSame(locale, localeTwo); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/HammingDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/HammingDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/HammingDistanceTest.java index 93c00a7..704ebae 100644 --- a/src/test/java/org/apache/commons/text/similarity/HammingDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/HammingDistanceTest.java @@ -5,9 +5,9 @@ * 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. @@ -45,12 +45,12 @@ public class HammingDistanceTest { assertEquals(Integer.valueOf(2), distance.apply("ATCG", "ACCC")); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testHammingDistance_nullLeftValue() { distance.apply(null, ""); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testHammingDistance_nullRightValue() { distance.apply("", null); } http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/JaccardDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/JaccardDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/JaccardDistanceTest.java index 47be780..e71aa78 100644 --- a/src/test/java/org/apache/commons/text/similarity/JaccardDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/JaccardDistanceTest.java @@ -27,7 +27,7 @@ import org.junit.Test; public class JaccardDistanceTest { private static JaccardDistance classBeingTested; - + @BeforeClass public static void setUp() { classBeingTested = new JaccardDistance(); @@ -43,7 +43,8 @@ public class JaccardDistanceTest { assertEquals(0.78d, classBeingTested.apply("elephant", "hippo"), 0.0d); assertEquals(0.36d, classBeingTested.apply("ABC Corporation", "ABC Corp"), 0.0d); assertEquals(0.24d, classBeingTested.apply("D N H Enterprises Inc", "D & H Enterprises, Inc."), 0.0d); - assertEquals(0.11d, classBeingTested.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.0d); + assertEquals(0.11d, + classBeingTested.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.0d); assertEquals(0.10d, classBeingTested.apply("PENNSYLVANIA", "PENNCISYLVNIA"), 0.0d); assertEquals(0.87d, classBeingTested.apply("left", "right"), 0.0d); assertEquals(0.87d, classBeingTested.apply("leettteft", "ritttght"), 0.0d); http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/JaccardSimilarityTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/JaccardSimilarityTest.java b/src/test/java/org/apache/commons/text/similarity/JaccardSimilarityTest.java index dddfe13..105e9f4 100644 --- a/src/test/java/org/apache/commons/text/similarity/JaccardSimilarityTest.java +++ b/src/test/java/org/apache/commons/text/similarity/JaccardSimilarityTest.java @@ -5,9 +5,9 @@ * 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. @@ -27,7 +27,7 @@ import org.junit.Test; public class JaccardSimilarityTest { private static JaccardSimilarity classBeingTested; - + @BeforeClass public static void setUp() { classBeingTested = new JaccardSimilarity(); @@ -43,7 +43,8 @@ public class JaccardSimilarityTest { assertEquals(0.22d, classBeingTested.apply("elephant", "hippo"), 0.0d); assertEquals(0.64d, classBeingTested.apply("ABC Corporation", "ABC Corp"), 0.0d); assertEquals(0.76d, classBeingTested.apply("D N H Enterprises Inc", "D & H Enterprises, Inc."), 0.0d); - assertEquals(0.89d, classBeingTested.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.0d); + assertEquals(0.89d, + classBeingTested.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.0d); assertEquals(0.9d, classBeingTested.apply("PENNSYLVANIA", "PENNCISYLVNIA"), 0.0d); assertEquals(0.13d, classBeingTested.apply("left", "right"), 0.0d); assertEquals(0.13d, classBeingTested.apply("leettteft", "ritttght"), 0.0d); http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceTest.java index 7d3613a..9a19c36 100644 --- a/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceTest.java @@ -5,9 +5,9 @@ * 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. @@ -27,12 +27,12 @@ import org.junit.Test; public class JaroWinklerDistanceTest { private static JaroWinklerDistance distance; - + @BeforeClass public static void setUp() { distance = new JaroWinklerDistance(); } - + @Test public void testGetJaroWinklerDistance_StringString() { assertEquals(0.92499d, distance.apply("frog", "fog"), 0.00001d); @@ -40,7 +40,8 @@ public class JaroWinklerDistanceTest { assertEquals(0.44166d, distance.apply("elephant", "hippo"), 0.00001d); assertEquals(0.92740d, distance.apply("ABC Corporation", "ABC Corp"), 0.00001d); assertEquals(0.94580d, distance.apply("D N H Enterprises Inc", "D & H Enterprises, Inc."), 0.00001d); - assertEquals(0.921458d, distance.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.00001d); + assertEquals(0.921458d, + distance.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.00001d); assertEquals(0.882329d, distance.apply("PENNSYLVANIA", "PENNCISYLVNIA"), 0.00001d); assertEquals(0.996598d, distance.apply("/opt/software1", "/opt/software2"), 0.00001d); } @@ -59,5 +60,5 @@ public class JaroWinklerDistanceTest { public void testGetJaroWinklerDistance_NullString() throws Exception { distance.apply(null, "clear"); } - + } http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java index 43f752d..2462e84 100644 --- a/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java @@ -5,9 +5,9 @@ * 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. @@ -87,14 +87,14 @@ public class LevenshteinDetailedDistanceTest { assertEquals(0, (int) result.getDeleteCount()); assertEquals(1, (int) result.getSubstituteCount()); } - + @Test public void testEquals() { final LevenshteinDetailedDistance classBeingTested = new LevenshteinDetailedDistance(); LevenshteinResults actualResult = classBeingTested.apply("hello", "hallo"); LevenshteinResults expectedResult = new LevenshteinResults(1, 0, 0, 1); assertEquals(actualResult, expectedResult); - + actualResult = classBeingTested.apply("zzzzzzzz", "hippo"); expectedResult = new LevenshteinResults(8, 0, 3, 5); assertEquals(actualResult, expectedResult); @@ -111,7 +111,7 @@ public class LevenshteinDetailedDistanceTest { LevenshteinResults actualResult = classBeingTested.apply("aaapppp", ""); LevenshteinResults expectedResult = new LevenshteinResults(7, 0, 7, 0); assertEquals(actualResult.hashCode(), expectedResult.hashCode()); - + actualResult = classBeingTested.apply("frog", "fog"); expectedResult = new LevenshteinResults(1, 0, 1, 0); assertEquals(actualResult.hashCode(), expectedResult.hashCode()); @@ -127,7 +127,7 @@ public class LevenshteinDetailedDistanceTest { LevenshteinResults actualResult = classBeingTested.apply("fly", "ant"); LevenshteinResults expectedResult = new LevenshteinResults(3, 0, 0, 3); assertEquals(actualResult.toString(), expectedResult.toString()); - + actualResult = classBeingTested.apply("hippo", "elephant"); expectedResult = new LevenshteinResults(7, 3, 0, 4); assertEquals(actualResult.toString(), expectedResult.toString()); @@ -403,16 +403,22 @@ public class LevenshteinDetailedDistanceTest { @Test public void testGetDefaultInstanceOne() { - final LevenshteinDetailedDistance levenshteinDetailedDistance = LevenshteinDetailedDistance.getDefaultInstance(); - final LevenshteinResults levenshteinResults = levenshteinDetailedDistance.apply("Distance: -2147483643, Insert: 0, Delete: 0, Substitute: 0", "Distance: 0, Insert: 2147483536, Delete: 0, Substitute: 0"); + final LevenshteinDetailedDistance levenshteinDetailedDistance = + LevenshteinDetailedDistance.getDefaultInstance(); + final LevenshteinResults levenshteinResults = + levenshteinDetailedDistance.apply("Distance: -2147483643, Insert: 0, Delete: 0, Substitute: 0", + "Distance: 0, Insert: 2147483536, Delete: 0, Substitute: 0"); assertEquals(21, (int) levenshteinResults.getDistance()); } @Test public void testGetDefaultInstanceTwo() { - final LevenshteinDetailedDistance levenshteinDetailedDistance = LevenshteinDetailedDistance.getDefaultInstance(); - final LevenshteinResults levenshteinResults = levenshteinDetailedDistance.apply("Distance: 2147483647, Insert: 0, Delete: 0, Substitute: 0", "Distance: 0, Insert: 2147483647, Delete: 0, Substitute: 0"); + final LevenshteinDetailedDistance levenshteinDetailedDistance = + LevenshteinDetailedDistance.getDefaultInstance(); + final LevenshteinResults levenshteinResults = + levenshteinDetailedDistance.apply("Distance: 2147483647, Insert: 0, Delete: 0, Substitute: 0", + "Distance: 0, Insert: 2147483647, Delete: 0, Substitute: 0"); assertEquals(20, (int) levenshteinResults.getDistance()); } @@ -420,7 +426,8 @@ public class LevenshteinDetailedDistanceTest { @Test public void testCreatesLevenshteinDetailedDistanceTakingInteger6() { final LevenshteinDetailedDistance levenshteinDetailedDistance = new LevenshteinDetailedDistance(0); - final LevenshteinResults levenshteinResults = levenshteinDetailedDistance.apply("", "Distance: 38, Insert: 0, Delete: 0, Substitute: 0"); + final LevenshteinResults levenshteinResults = + levenshteinDetailedDistance.apply("", "Distance: 38, Insert: 0, Delete: 0, Substitute: 0"); assertEquals(0, (int) levenshteinResults.getSubstituteCount()); assertEquals(0, (int) levenshteinResults.getDeleteCount()); @@ -429,7 +436,7 @@ public class LevenshteinDetailedDistanceTest { assertEquals(-1, (int) levenshteinResults.getDistance()); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testApplyThrowsIllegalArgumentExceptionAndCreatesLevenshteinDetailedDistanceTakingInteger() { final LevenshteinDetailedDistance levenshteinDetailedDistance = new LevenshteinDetailedDistance(0); final CharSequence charSequence = new StrBuilder(); @@ -437,7 +444,7 @@ public class LevenshteinDetailedDistanceTest { levenshteinDetailedDistance.apply(charSequence, null); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testApplyWithNull() { new LevenshteinDetailedDistance(0).apply(null, null); } @@ -449,4 +456,4 @@ public class LevenshteinDetailedDistanceTest { assertEquals(0, (int) levenshteinDetailedDistance.getThreshold()); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java index 6f2588f..51cce22 100644 --- a/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java @@ -5,9 +5,9 @@ * 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. @@ -147,4 +147,4 @@ public class LevenshteinDistanceTest { assertNull(new LevenshteinDistance().getThreshold()); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java b/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java index f4a1537..1216bf1 100644 --- a/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java @@ -27,8 +27,10 @@ public class LevenshteinResultsTest { public void testEqualsReturningFalse() { final Integer integerOne = new Integer(1662); final Integer integerTwo = new Integer(1164); - final LevenshteinResults levenshteinResults = new LevenshteinResults(integerOne, integerOne, integerOne, integerOne); - final LevenshteinResults levenshteinResultsTwo = new LevenshteinResults(integerOne, integerOne, integerTwo, integerTwo); + final LevenshteinResults levenshteinResults = + new LevenshteinResults(integerOne, integerOne, integerOne, integerOne); + final LevenshteinResults levenshteinResultsTwo = + new LevenshteinResults(integerOne, integerOne, integerTwo, integerTwo); assertFalse(levenshteinResults.equals(levenshteinResultsTwo)); } @@ -67,4 +69,4 @@ public class LevenshteinResultsTest { assertTrue(levenshteinResults.equals(levenshteinResults)); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceDistanceTest.java index 4c9ff6f..e7fe904 100644 --- a/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceDistanceTest.java @@ -27,7 +27,7 @@ import static org.junit.Assert.assertEquals; public class LongestCommonSubsequenceDistanceTest { private static LongestCommonSubsequenceDistance subject; - + @BeforeClass public static void setup() { subject = new LongestCommonSubsequenceDistance(); @@ -43,7 +43,8 @@ public class LongestCommonSubsequenceDistanceTest { assertEquals(Integer.valueOf(11), subject.apply("elephant", "hippo")); assertEquals(Integer.valueOf(7), subject.apply("ABC Corporation", "ABC Corp")); assertEquals(Integer.valueOf(4), subject.apply("D N H Enterprises Inc", "D & H Enterprises, Inc.")); - assertEquals(Integer.valueOf(9), subject.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")); + assertEquals(Integer.valueOf(9), + subject.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")); assertEquals(Integer.valueOf(3), subject.apply("PENNSYLVANIA", "PENNCISYLVNIA")); assertEquals(Integer.valueOf(7), subject.apply("left", "right")); assertEquals(Integer.valueOf(9), subject.apply("leettteft", "ritttght")); http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java b/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java index c8ad6a4..57efa01 100644 --- a/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java @@ -43,7 +43,8 @@ public class LongestCommonSubsequenceTest { assertEquals(Integer.valueOf(1), subject.apply("elephant", "hippo")); assertEquals(Integer.valueOf(8), subject.apply("ABC Corporation", "ABC Corp")); assertEquals(Integer.valueOf(20), subject.apply("D N H Enterprises Inc", "D & H Enterprises, Inc.")); - assertEquals(Integer.valueOf(24), subject.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")); + assertEquals(Integer.valueOf(24), + subject.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")); assertEquals(Integer.valueOf(11), subject.apply("PENNSYLVANIA", "PENNCISYLVNIA")); assertEquals(Integer.valueOf(1), subject.apply("left", "right")); assertEquals(Integer.valueOf(4), subject.apply("leettteft", "ritttght")); @@ -74,8 +75,10 @@ public class LongestCommonSubsequenceTest { assertEquals("", subject.longestCommonSubsequence("fly", "ant")); assertEquals("h", subject.longestCommonSubsequence("elephant", "hippo")); assertEquals("ABC Corp", subject.longestCommonSubsequence("ABC Corporation", "ABC Corp")); - assertEquals("D H Enterprises Inc", subject.longestCommonSubsequence("D N H Enterprises Inc", "D & H Enterprises, Inc.")); - assertEquals("My Gym Childrens Fitness", subject.longestCommonSubsequence("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")); + assertEquals("D H Enterprises Inc", + subject.longestCommonSubsequence("D N H Enterprises Inc", "D & H Enterprises, Inc.")); + assertEquals("My Gym Childrens Fitness", + subject.longestCommonSubsequence("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")); assertEquals("PENNSYLVNIA", subject.longestCommonSubsequence("PENNSYLVANIA", "PENNCISYLVNIA")); assertEquals("t", subject.longestCommonSubsequence("left", "right")); assertEquals("tttt", subject.longestCommonSubsequence("leettteft", "ritttght")); @@ -107,8 +110,10 @@ public class LongestCommonSubsequenceTest { assertEquals("", subject.logestCommonSubsequence("fly", "ant")); assertEquals("h", subject.logestCommonSubsequence("elephant", "hippo")); assertEquals("ABC Corp", subject.logestCommonSubsequence("ABC Corporation", "ABC Corp")); - assertEquals("D H Enterprises Inc", subject.logestCommonSubsequence("D N H Enterprises Inc", "D & H Enterprises, Inc.")); - assertEquals("My Gym Childrens Fitness", subject.logestCommonSubsequence("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")); + assertEquals("D H Enterprises Inc", + subject.logestCommonSubsequence("D N H Enterprises Inc", "D & H Enterprises, Inc.")); + assertEquals("My Gym Childrens Fitness", + subject.logestCommonSubsequence("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")); assertEquals("PENNSYLVNIA", subject.logestCommonSubsequence("PENNSYLVANIA", "PENNCISYLVNIA")); assertEquals("t", subject.logestCommonSubsequence("left", "right")); assertEquals("tttt", subject.logestCommonSubsequence("leettteft", "ritttght")); http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java b/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java index 0201ca0..8e0582e 100644 --- a/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java +++ b/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java @@ -5,9 +5,9 @@ * 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. @@ -52,19 +52,19 @@ public class ParameterizedEditDistanceFromTest<R> { @Parameters public static Iterable<Object[]> parameters() { - return Arrays.asList( new Object[][] { + return Arrays.asList(new Object[][] { - { new HammingDistance(), "Sam I am.", "Ham I am.", 1 }, - { new HammingDistance(), "Japtheth, Ham, Shem", "Japtheth, HAM, Shem", 2 }, - { new HammingDistance(), "Hamming", "Hamming", 0 }, + {new HammingDistance(), "Sam I am.", "Ham I am.", 1}, + {new HammingDistance(), "Japtheth, Ham, Shem", "Japtheth, HAM, Shem", 2}, + {new HammingDistance(), "Hamming", "Hamming", 0}, - { new LevenshteinDistance(), "Apache", "a patchy", 4 }, - { new LevenshteinDistance(), "go", "no go", 3 }, - { new LevenshteinDistance(), "go", "go", 0 }, + {new LevenshteinDistance(), "Apache", "a patchy", 4}, + {new LevenshteinDistance(), "go", "no go", 3}, + {new LevenshteinDistance(), "go", "go", 0}, - { new LevenshteinDistance(4), "Apache", "a patchy", 4 }, - { new LevenshteinDistance(4), "go", "no go", 3 }, - { new LevenshteinDistance(0), "go", "go", 0 }, + {new LevenshteinDistance(4), "Apache", "a patchy", 4}, + {new LevenshteinDistance(4), "go", "no go", 3}, + {new LevenshteinDistance(0), "go", "go", 0}, { new EditDistance<Boolean>() { @@ -78,7 +78,7 @@ public class ParameterizedEditDistanceFromTest<R> { false } - } ); + }); } @Test http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java index 0ef18d0..0310171 100644 --- a/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java @@ -5,9 +5,9 @@ * 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. @@ -50,70 +50,69 @@ public class ParameterizedLevenshteinDistanceTest { @Parameters public static Iterable<Object[]> parameters() { - return Arrays.asList( new Object[][] { + return Arrays.asList(new Object[][] { /* empty strings */ - { 0, "", "", 0 }, - { 8, "aaapppp", "", 7 }, - { 7, "aaapppp", "", 7 }, - { 6, "aaapppp", "", -1 }, + {0, "", "", 0}, + {8, "aaapppp", "", 7}, + {7, "aaapppp", "", 7}, + {6, "aaapppp", "", -1}, /* unequal strings, zero threshold */ - { 0, "b", "a", -1 }, - { 0, "a", "b", -1 }, + {0, "b", "a", -1}, + {0, "a", "b", -1}, /* equal strings */ - { 0, "aa", "aa", 0 }, - { 2, "aa", "aa", 0 }, + {0, "aa", "aa", 0}, + {2, "aa", "aa", 0}, /* same length */ - { 2, "aaa", "bbb", -1 }, - { 3, "aaa", "bbb", 3 }, + {2, "aaa", "bbb", -1}, + {3, "aaa", "bbb", 3}, /* big stripe */ - { 10, "aaaaaa", "b", 6 }, + {10, "aaaaaa", "b", 6}, /* distance less than threshold */ - { 8, "aaapppp", "b", 7 }, - { 4, "a", "bbb", 3 }, + {8, "aaapppp", "b", 7}, + {4, "a", "bbb", 3}, /* distance equal to threshold */ - { 7, "aaapppp", "b", 7 }, - { 3, "a", "bbb", 3 }, + {7, "aaapppp", "b", 7}, + {3, "a", "bbb", 3}, /* distance greater than threshold */ - { 2, "a", "bbb", -1 }, - { 2, "bbb", "a", -1 }, - { 6, "aaapppp", "b", -1 }, + {2, "a", "bbb", -1}, + {2, "bbb", "a", -1}, + {6, "aaapppp", "b", -1}, /* stripe runs off array, strings not similar */ - { 1, "a", "bbb", -1 }, - { 1, "bbb", "a", -1 }, + {1, "a", "bbb", -1}, + {1, "bbb", "a", -1}, /* stripe runs off array, strings are similar */ - { 1, "12345", "1234567", -1 }, - { 1, "1234567", "12345", -1 }, - - /* old getLevenshteinDistance test cases */ - { 1, "frog", "fog", 1 }, - { 3, "fly", "ant", 3 }, - { 7, "elephant", "hippo", 7 }, - { 6, "elephant", "hippo", -1 }, - { 7, "hippo", "elephant", 7 }, - { 6, "hippo", "elephant", -1 }, - { 8, "hippo", "zzzzzzzz", 8 }, - { 8, "zzzzzzzz", "hippo", 8 }, - { 1, "hello", "hallo", 1 }, - - { Integer.MAX_VALUE, "frog", "fog", 1 }, - { Integer.MAX_VALUE, "fly", "ant", 3 }, - { Integer.MAX_VALUE, "elephant", "hippo", 7 }, - { Integer.MAX_VALUE, "hippo", "elephant", 7 }, - { Integer.MAX_VALUE, "hippo", "zzzzzzzz", 8 }, - { Integer.MAX_VALUE, "zzzzzzzz", "hippo", 8 }, - { Integer.MAX_VALUE, "hello", "hallo", 1 } - - } ); + {1, "12345", "1234567", -1}, + {1, "1234567", "12345", -1}, + + /* old getLevenshteinDistance test cases */ + {1, "frog", "fog", 1}, + {3, "fly", "ant", 3}, + {7, "elephant", "hippo", 7}, + {6, "elephant", "hippo", -1}, + {7, "hippo", "elephant", 7}, + {6, "hippo", "elephant", -1}, + {8, "hippo", "zzzzzzzz", 8}, + {8, "zzzzzzzz", "hippo", 8}, + {1, "hello", "hallo", 1}, + + {Integer.MAX_VALUE, "frog", "fog", 1}, + {Integer.MAX_VALUE, "fly", "ant", 3}, + {Integer.MAX_VALUE, "elephant", "hippo", 7}, + {Integer.MAX_VALUE, "hippo", "elephant", 7}, + {Integer.MAX_VALUE, "hippo", "zzzzzzzz", 8}, + {Integer.MAX_VALUE, "zzzzzzzz", "hippo", 8}, + {Integer.MAX_VALUE, "hello", "hallo", 1} + }); } @Test http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java b/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java index 13dcea0..030cae6 100644 --- a/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java +++ b/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java @@ -52,11 +52,11 @@ public class ParameterizedSimilarityScoreFromTest<R> { @Parameters public static Iterable<Object[]> parameters() { - return Arrays.asList( new Object[][] { + return Arrays.asList(new Object[][] { - { new LevenshteinDistance(), "elephant", "hippo", 7 }, - { new LevenshteinDistance(), "hippo", "elephant", 7 }, - { new LevenshteinDistance(), "hippo", "zzzzzzzz", 8 }, + {new LevenshteinDistance(), "elephant", "hippo", 7}, + {new LevenshteinDistance(), "hippo", "elephant", 7}, + {new LevenshteinDistance(), "hippo", "zzzzzzzz", 8}, { new SimilarityScore<Boolean>() { @@ -70,7 +70,7 @@ public class ParameterizedSimilarityScoreFromTest<R> { false } - } ); + }); } @Test http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java b/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java index 75f81b7..8ff381e 100644 --- a/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java +++ b/src/test/java/org/apache/commons/text/similarity/SimilarityScoreFromTest.java @@ -31,9 +31,10 @@ public class SimilarityScoreFromTest { @Test public void testApply() { final LongestCommonSubsequence longestCommonSubsequence = new LongestCommonSubsequence(); - final SimilarityScoreFrom<Integer> similarityScoreFrom = new SimilarityScoreFrom<>(longestCommonSubsequence, "asdf"); + final SimilarityScoreFrom<Integer> similarityScoreFrom = + new SimilarityScoreFrom<>(longestCommonSubsequence, "asdf"); assertEquals(1, (int) similarityScoreFrom.apply("s")); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java b/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java index 2b6e7a8..96a54eb 100644 --- a/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java +++ b/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java @@ -5,9 +5,9 @@ * 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. @@ -46,8 +46,8 @@ public class StringMetricFromTest { new EditDistanceFrom<>(metric, target); String mostSimilar = null; Integer shortestDistance = null; - - for (final String test : new String[] { "Appaloosa", "a patchy", "apple" }) { + + for (final String test : new String[] {"Appaloosa", "a patchy", "apple" }) { final Integer distance = metricFrom.apply(test); if (shortestDistance == null || distance < shortestDistance) { shortestDistance = distance; http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java b/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java index f1a4639..c2649b0 100644 --- a/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java +++ b/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java @@ -36,7 +36,7 @@ public class AggregateTranslatorTest { final AggregateTranslator subject = new AggregateTranslator((CharSequenceTranslator[]) null); assertEquals(testString, subject.translate(testString)); } - + @Test public void testNullVarargConstructor() throws Exception { final String testString = "foo"; @@ -45,7 +45,7 @@ public class AggregateTranslatorTest { } @Test - public void testNonNull() throws IOException{ + public void testNonNull() throws IOException { final Map<CharSequence, CharSequence> oneTwoMap = new HashMap<>(); oneTwoMap.put("one", "two"); final Map<CharSequence, CharSequence> threeFourMap = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/translate/CodePointTranslatorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/translate/CodePointTranslatorTest.java b/src/test/java/org/apache/commons/text/translate/CodePointTranslatorTest.java index 3d90bb5..a60bf0a 100644 --- a/src/test/java/org/apache/commons/text/translate/CodePointTranslatorTest.java +++ b/src/test/java/org/apache/commons/text/translate/CodePointTranslatorTest.java @@ -37,4 +37,4 @@ public class CodePointTranslatorTest { assertEquals(1, numericEntityEscaper.translate(string, 0, pipedWriter)); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/6665a020/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java b/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java index 56ecee3..761c864 100644 --- a/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java +++ b/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java @@ -5,9 +5,9 @@ * 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. @@ -39,7 +39,8 @@ public class EntityArraysTest { @Test public void testForDuplicatedDeclaredMapKeys() throws Exception { final String packageDirectory = EntityArraysTest.class.getPackage().getName().replace(".", "/"); - try (BufferedReader br = new BufferedReader(new FileReader("src/main/java/" + packageDirectory + "/EntityArrays.java"))) { + try (BufferedReader br = new BufferedReader(new FileReader("src/main/java/" + packageDirectory + + "/EntityArrays.java"))) { String line; int mapDeclarationCounter = 0; while ((line = br.readLine()) != null) { @@ -52,7 +53,8 @@ public class EntityArraysTest { final String mapVariableName = line.split("=")[0].trim(); @SuppressWarnings("unchecked") // This is test code final - Map<String,String> mapValue = (Map<String, String>)EntityArrays.class.getDeclaredField(mapVariableName).get(EntityArrays.class); + Map<String, String> mapValue = (Map<String, String>) + EntityArrays.class.getDeclaredField(mapVariableName).get(EntityArrays.class); // Validate that we are not inserting into the same key twice in the map declaration. If this, // indeed was the case the keySet().size() would be smaller than the number of put() statements assertEquals(mapDeclarationCounter, mapValue.keySet().size()); @@ -126,5 +128,5 @@ public class EntityArraysTest { } } } - + }