Partial and mostly automated migration of assertions from JUnit to AssertJ. (closes #70)
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/e55d0ac1 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/e55d0ac1 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/e55d0ac1 Branch: refs/heads/master Commit: e55d0ac1c17a7fd71dbb4f65034c7b739be6a35a Parents: 6665a02 Author: Pascal Schumacher <pascalschumac...@gmx.net> Authored: Sun Oct 15 12:11:39 2017 +0200 Committer: Pascal Schumacher <pascalschumac...@gmx.net> Committed: Fri Oct 27 16:25:04 2017 +0200 ---------------------------------------------------------------------- pom.xml | 6 + .../commons/text/AlphabetConverterTest.java | 56 +- .../org/apache/commons/text/CaseUtilsTest.java | 70 ++- .../commons/text/CharacterPredicatesTest.java | 115 ++-- .../commons/text/FormattableUtilsTest.java | 157 +++--- .../commons/text/RandomStringGeneratorTest.java | 32 +- .../text/StrBuilderAppendInsertTest.java | 486 ++++++++--------- .../org/apache/commons/text/StrMatcherTest.java | 188 ++++--- .../org/apache/commons/text/WordUtilsTest.java | 534 +++++++++---------- .../text/diff/ReplacementsFinderTest.java | 4 +- .../text/diff/StringsComparatorTest.java | 8 +- .../text/similarity/CosineDistanceTest.java | 13 +- .../text/similarity/CosineSimilarityTest.java | 7 +- .../commons/text/similarity/FuzzyScoreTest.java | 20 +- .../text/similarity/HammingDistanceTest.java | 18 +- .../LevenshteinDetailedDistanceTest.java | 428 +++++++-------- .../similarity/LevenshteinDistanceTest.java | 109 ++-- .../text/similarity/LevenshteinResultsTest.java | 13 +- .../LongestCommonSubsequenceDistanceTest.java | 29 +- .../LongestCommonSubsequenceTest.java | 89 ++-- .../similarity/SimilarityScoreFromTest.java | 4 +- .../text/translate/AggregateTranslatorTest.java | 14 +- .../text/translate/CodePointTranslatorTest.java | 4 +- .../text/translate/CsvTranslatorsTest.java | 22 +- .../text/translate/EntityArraysTest.java | 26 +- .../text/translate/JavaUnicodeEscaperTest.java | 13 +- .../text/translate/LookupTranslatorTest.java | 10 +- .../translate/NumericEntityEscaperTest.java | 10 +- .../translate/NumericEntityUnescaperTest.java | 22 +- .../text/translate/OctalUnescaperTest.java | 27 +- .../translate/SinglePassTranslatorTest.java | 8 +- .../text/translate/UnicodeEscaperTest.java | 11 +- .../text/translate/UnicodeUnescaperTest.java | 8 +- .../UnicodeUnpairedSurrogateRemoverTest.java | 16 +- 34 files changed, 1289 insertions(+), 1288 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/e55d0ac1/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index dcee00d..112b5c8 100644 --- a/pom.xml +++ b/pom.xml @@ -77,6 +77,12 @@ <version>1.3</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>2.8.0</version> + <scope>test</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/commons-text/blob/e55d0ac1/src/test/java/org/apache/commons/text/AlphabetConverterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/AlphabetConverterTest.java b/src/test/java/org/apache/commons/text/AlphabetConverterTest.java index 0178a4a..7a59c6e 100644 --- a/src/test/java/org/apache/commons/text/AlphabetConverterTest.java +++ b/src/test/java/org/apache/commons/text/AlphabetConverterTest.java @@ -26,10 +26,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -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.assertj.core.api.Assertions.assertThat; /** * Unit tests for {@link AlphabetConverter}. @@ -110,11 +107,11 @@ public class AlphabetConverterTest { public void javadocExampleTest() throws UnsupportedEncodingException { final AlphabetConverter ac = createJavadocExample(); - assertEquals("00", ac.encode("a")); - assertEquals("01", ac.encode("b")); - assertEquals("0d", ac.encode("c")); - assertEquals("d", ac.encode("d")); - assertEquals("00010dd", ac.encode("abcd")); + assertThat(ac.encode("a")).isEqualTo("00"); + assertThat(ac.encode("b")).isEqualTo("01"); + assertThat(ac.encode("c")).isEqualTo("0d"); + assertThat(ac.encode("d")).isEqualTo("d"); + assertThat(ac.encode("abcd")).isEqualTo("00010dd"); } @Test @@ -147,14 +144,14 @@ public class AlphabetConverterTest { final AlphabetConverter ac = AlphabetConverter.createConverter(unicode, lowerCaseEnglishCodepoints, doNotEncodeCodepoints); - assertEquals(2, ac.getEncodedCharLength()); + assertThat(ac.getEncodedCharLength()).isEqualTo(2); final String original = "\u8a43\u8a45 \u8dce ab \u8dc3 c \u8983"; final String encoded = ac.encode(original); final String decoded = ac.decode(encoded); - assertEquals("Encoded '" + original + "' into '" + encoded + "', but decoded into '" + decoded + "'", original, - decoded); + assertThat(decoded).as("Encoded '" + original + "' into '" + encoded + "', but decoded into '" + decoded + "'") + .isEqualTo(original); } @Test @@ -203,11 +200,11 @@ public class AlphabetConverterTest { final AlphabetConverter reconstructedAlphabetConverter = AlphabetConverter .createConverterFromMap(ac.getOriginalToEncoded()); - assertEquals(ac, reconstructedAlphabetConverter); - assertEquals(ac.hashCode(), reconstructedAlphabetConverter.hashCode()); - assertEquals(ac.toString(), reconstructedAlphabetConverter.toString()); - assertNull(ac.encode(null)); // test null conversions - assertEquals("", ac.encode("")); // test empty conversion + assertThat(reconstructedAlphabetConverter).isEqualTo(ac); + assertThat(reconstructedAlphabetConverter.hashCode()).isEqualTo(ac.hashCode()); + assertThat(reconstructedAlphabetConverter.toString()).isEqualTo(ac.toString()); + assertThat(ac.encode(null)).isNull(); // test null conversions + assertThat(ac.encode("")).isEqualTo(""); // test empty conversion // test all the trial strings for (final String s : strings) { @@ -216,7 +213,7 @@ public class AlphabetConverterTest { // test that only encoding chars are used final List<Character> originalEncodingChars = Arrays.asList(encodingChars); for (int i = 0; i < encoded.length(); i++) { - assertTrue(originalEncodingChars.contains(encoded.charAt(i))); + assertThat(originalEncodingChars.contains(encoded.charAt(i))).isTrue(); } final String decoded = ac.decode(encoded); @@ -224,10 +221,11 @@ public class AlphabetConverterTest { // test that only the original alphabet is used after decoding final List<Character> originalCharsList = Arrays.asList(originalChars); for (int i = 0; i < decoded.length(); i++) { - assertTrue(originalCharsList.contains(decoded.charAt(i))); + assertThat(originalCharsList.contains(decoded.charAt(i))).isTrue(); } - assertEquals("Encoded '" + s + "' into '" + encoded + "', but decoded into '" + decoded + "'", s, decoded); + assertThat(decoded).as("Encoded '" + s + "' into '" + encoded + "', but decoded into '" + decoded + "'") + .isEqualTo(s); } } @@ -248,7 +246,7 @@ public class AlphabetConverterTest { final AlphabetConverter alphabetConverter = AlphabetConverter.createConverterFromChars(characterArray, characterArray, characterArray); - assertEquals(1, alphabetConverter.getEncodedCharLength()); + assertThat(alphabetConverter.getEncodedCharLength()).isEqualTo(1); } @Test @@ -258,8 +256,8 @@ public class AlphabetConverterTest { hashMap.put(0, "CtDs"); final AlphabetConverter alphabetConverterTwo = AlphabetConverter.createConverterFromMap(hashMap); - assertFalse(alphabetConverter.equals(alphabetConverterTwo)); - assertEquals(1, alphabetConverter.getEncodedCharLength()); + assertThat(alphabetConverter.equals(alphabetConverterTwo)).isFalse(); + assertThat(alphabetConverter.getEncodedCharLength()).isEqualTo(1); } @Test @@ -273,8 +271,8 @@ public class AlphabetConverterTest { final Map<Integer, String> map = new HashMap<>(); final AlphabetConverter alphabetConverterTwo = AlphabetConverter.createConverterFromMap(map); - assertEquals(1, alphabetConverterTwo.getEncodedCharLength()); - assertFalse(alphabetConverter.equals(alphabetConverterTwo)); + assertThat(alphabetConverterTwo.getEncodedCharLength()).isEqualTo(1); + assertThat(alphabetConverter.equals(alphabetConverterTwo)).isFalse(); } @Test @@ -286,7 +284,7 @@ public class AlphabetConverterTest { final AlphabetConverter alphabetConverter = AlphabetConverter.createConverterFromChars(characterArray, characterArray, characterArray); - assertTrue(alphabetConverter.equals(alphabetConverter)); + assertThat(alphabetConverter.equals(alphabetConverter)).isTrue(); } @Test @@ -295,7 +293,7 @@ public class AlphabetConverterTest { final AlphabetConverter alphabetConverter = AlphabetConverter.createConverterFromChars(characterArray, null, null); - assertFalse(alphabetConverter.equals(null)); + assertThat(alphabetConverter.equals(null)).isFalse(); } @Test @@ -308,7 +306,7 @@ public class AlphabetConverterTest { final AlphabetConverter alphabetConverter = AlphabetConverter.createConverterFromChars(characterArray, characterArray, characterArray); - assertFalse(alphabetConverter.equals(charOne)); + assertThat(alphabetConverter.equals(charOne)).isFalse(); } @Test @@ -317,7 +315,7 @@ public class AlphabetConverterTest { final AlphabetConverter alphabetConverter = AlphabetConverter.createConverterFromMap(map); alphabetConverter.decode(null); - assertEquals(1, alphabetConverter.getEncodedCharLength()); + assertThat(alphabetConverter.getEncodedCharLength()).isEqualTo(1); } } http://git-wip-us.apache.org/repos/asf/commons-text/blob/e55d0ac1/src/test/java/org/apache/commons/text/CaseUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/CaseUtilsTest.java b/src/test/java/org/apache/commons/text/CaseUtilsTest.java index 3211b18..5b085ce 100644 --- a/src/test/java/org/apache/commons/text/CaseUtilsTest.java +++ b/src/test/java/org/apache/commons/text/CaseUtilsTest.java @@ -21,11 +21,7 @@ import org.junit.Test; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; -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.assertj.core.api.Assertions.assertThat; /** * Unit tests for {@link CaseUtils} class. @@ -35,49 +31,49 @@ public class CaseUtilsTest { //----------------------------------------------------------------------- @Test public void testConstructor() { - assertNotNull(new CaseUtils()); + assertThat(new CaseUtils()).isNotNull(); final Constructor<?>[] cons = CaseUtils.class.getDeclaredConstructors(); - assertEquals(1, cons.length); - assertTrue(Modifier.isPublic(cons[0].getModifiers())); - assertTrue(Modifier.isPublic(CaseUtils.class.getModifiers())); - assertFalse(Modifier.isFinal(CaseUtils.class.getModifiers())); + assertThat(cons.length).isEqualTo(1); + assertThat(Modifier.isPublic(cons[0].getModifiers())).isTrue(); + assertThat(Modifier.isPublic(CaseUtils.class.getModifiers())).isTrue(); + assertThat(Modifier.isFinal(CaseUtils.class.getModifiers())).isFalse(); } //------------------------------------------------------------------------ @Test public void testToCamelCase() throws Exception { - assertNull(CaseUtils.toCamelCase(null, false, null)); - assertEquals("", CaseUtils.toCamelCase("", true, null)); - assertEquals(" ", CaseUtils.toCamelCase(" ", false, null)); - assertEquals("aBC@def", CaseUtils.toCamelCase("a b c @def", false, null)); - assertEquals("ABC@def", CaseUtils.toCamelCase("a b c @def", true, new char[]{})); - assertEquals("ABC@def", CaseUtils.toCamelCase("a b c @def", true, new char[]{'-'})); - assertEquals("ABC@def", CaseUtils.toCamelCase("a b c @def", true, new char[]{'-'})); + assertThat(CaseUtils.toCamelCase(null, false, null)).isNull(); + assertThat(CaseUtils.toCamelCase("", true, null)).isEqualTo(""); + assertThat(CaseUtils.toCamelCase(" ", false, null)).isEqualTo(" "); + assertThat(CaseUtils.toCamelCase("a b c @def", false, null)).isEqualTo("aBC@def"); + assertThat(CaseUtils.toCamelCase("a b c @def", true, new char[]{})).isEqualTo("ABC@def"); + assertThat(CaseUtils.toCamelCase("a b c @def", true, new char[]{'-'})).isEqualTo("ABC@def"); + assertThat(CaseUtils.toCamelCase("a b c @def", true, new char[]{'-'})).isEqualTo("ABC@def"); final char[] chars = {'-', '+', ' ', '@'}; - assertEquals("-+@ ", CaseUtils.toCamelCase("-+@ ", true, chars)); - assertEquals("toCamelCase", CaseUtils.toCamelCase(" to-CAMEL-cASE", false, chars)); - assertEquals("ToCamelCase", CaseUtils.toCamelCase("@@@@ to+CAMEL@cASE ", true, chars)); - assertEquals("ToCaMeLCase", CaseUtils.toCamelCase("To+CA+ME L@cASE", true, chars)); + assertThat(CaseUtils.toCamelCase("-+@ ", true, chars)).isEqualTo("-+@ "); + assertThat(CaseUtils.toCamelCase(" to-CAMEL-cASE", false, chars)).isEqualTo("toCamelCase"); + assertThat(CaseUtils.toCamelCase("@@@@ to+CAMEL@cASE ", true, chars)).isEqualTo("ToCamelCase"); + assertThat(CaseUtils.toCamelCase("To+CA+ME L@cASE", true, chars)).isEqualTo("ToCaMeLCase"); - assertEquals("toCamelCase", CaseUtils.toCamelCase("To.Camel.Case", false, new char[]{'.'})); - assertEquals("toCamelCase", CaseUtils.toCamelCase("To.Camel-Case", false, new char[]{'-', '.'})); - assertEquals("toCamelCase", CaseUtils.toCamelCase(" to @ Camel case", false, new char[]{'-', '@'})); - assertEquals("ToCamelCase", CaseUtils.toCamelCase(" @to @ Camel case", true, new char[]{'-', '@'})); + assertThat(CaseUtils.toCamelCase("To.Camel.Case", false, new char[]{'.'})).isEqualTo("toCamelCase"); + assertThat(CaseUtils.toCamelCase("To.Camel-Case", false, new char[]{'-', '.'})).isEqualTo("toCamelCase"); + assertThat(CaseUtils.toCamelCase(" to @ Camel case", false, new char[]{'-', '@'})).isEqualTo("toCamelCase"); + assertThat(CaseUtils.toCamelCase(" @to @ Camel case", true, new char[]{'-', '@'})).isEqualTo("ToCamelCase"); - assertEquals("ToCamelCase", CaseUtils.toCamelCase("TO CAMEL CASE", true, null)); - assertEquals("toCamelCase", CaseUtils.toCamelCase("TO CAMEL CASE", false, null)); - assertEquals("toCamelCase", CaseUtils.toCamelCase("TO CAMEL CASE", false, null)); - assertEquals("tocamelcase", CaseUtils.toCamelCase("tocamelcase", false, null)); - assertEquals("Tocamelcase", CaseUtils.toCamelCase("tocamelcase", true, null)); - assertEquals("tocamelcase", CaseUtils.toCamelCase("Tocamelcase", false, null)); + assertThat(CaseUtils.toCamelCase("TO CAMEL CASE", true, null)).isEqualTo("ToCamelCase"); + assertThat(CaseUtils.toCamelCase("TO CAMEL CASE", false, null)).isEqualTo("toCamelCase"); + assertThat(CaseUtils.toCamelCase("TO CAMEL CASE", false, null)).isEqualTo("toCamelCase"); + assertThat(CaseUtils.toCamelCase("tocamelcase", false, null)).isEqualTo("tocamelcase"); + assertThat(CaseUtils.toCamelCase("tocamelcase", true, null)).isEqualTo("Tocamelcase"); + assertThat(CaseUtils.toCamelCase("Tocamelcase", false, null)).isEqualTo("tocamelcase"); - assertEquals("Tocamelcase", CaseUtils.toCamelCase("tocamelcase", true)); - assertEquals("tocamelcase", CaseUtils.toCamelCase("tocamelcase", false)); + assertThat(CaseUtils.toCamelCase("tocamelcase", true)).isEqualTo("Tocamelcase"); + assertThat(CaseUtils.toCamelCase("tocamelcase", false)).isEqualTo("tocamelcase"); - assertEquals("\uD800\uDF00\uD800\uDF02", CaseUtils.toCamelCase("\uD800\uDF00 \uD800\uDF02", true)); - assertEquals("\uD800\uDF00\uD800\uDF01\uD800\uDF02\uD800\uDF03", - CaseUtils.toCamelCase("\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF02\uD800\uDF03", true, - new char[]{'\uD800', '\uDF14'})); + assertThat(CaseUtils.toCamelCase("\uD800\uDF00 \uD800\uDF02", true)).isEqualTo("\uD800\uDF00\uD800\uDF02"); + assertThat(CaseUtils.toCamelCase("\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF02\uD800\uDF03", true, + new char[]{'\uD800', '\uDF14'})) + .isEqualTo("\uD800\uDF00\uD800\uDF01\uD800\uDF02\uD800\uDF03"); } } http://git-wip-us.apache.org/repos/asf/commons-text/blob/e55d0ac1/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java b/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java index 63f606b..070a84a 100644 --- a/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java +++ b/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java @@ -16,11 +16,10 @@ */ package org.apache.commons.text; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for {@link CharacterPredicates}. */ @@ -28,87 +27,87 @@ public class CharacterPredicatesTest { @Test public void testLetters() throws Exception { - assertTrue(CharacterPredicates.LETTERS.test('a')); - assertTrue(CharacterPredicates.LETTERS.test('Z')); + assertThat(CharacterPredicates.LETTERS.test('a')).isTrue(); + assertThat(CharacterPredicates.LETTERS.test('Z')).isTrue(); - assertFalse(CharacterPredicates.LETTERS.test('1')); - assertFalse(CharacterPredicates.LETTERS.test('?')); - assertFalse(CharacterPredicates.LETTERS.test('@')); + assertThat(CharacterPredicates.LETTERS.test('1')).isFalse(); + assertThat(CharacterPredicates.LETTERS.test('?')).isFalse(); + assertThat(CharacterPredicates.LETTERS.test('@')).isFalse(); } @Test public void testDigits() { - assertTrue(CharacterPredicates.DIGITS.test('0')); - assertTrue(CharacterPredicates.DIGITS.test('9')); + assertThat(CharacterPredicates.DIGITS.test('0')).isTrue(); + assertThat(CharacterPredicates.DIGITS.test('9')).isTrue(); - assertFalse(CharacterPredicates.DIGITS.test('-')); - assertFalse(CharacterPredicates.DIGITS.test('.')); - assertFalse(CharacterPredicates.DIGITS.test('L')); + assertThat(CharacterPredicates.DIGITS.test('-')).isFalse(); + assertThat(CharacterPredicates.DIGITS.test('.')).isFalse(); + assertThat(CharacterPredicates.DIGITS.test('L')).isFalse(); } @Test public void testArabicNumerals() { - assertTrue(CharacterPredicates.ARABIC_NUMERALS.test('0')); - assertTrue(CharacterPredicates.ARABIC_NUMERALS.test('1')); - assertTrue(CharacterPredicates.ARABIC_NUMERALS.test('9')); + assertThat(CharacterPredicates.ARABIC_NUMERALS.test('0')).isTrue(); + assertThat(CharacterPredicates.ARABIC_NUMERALS.test('1')).isTrue(); + assertThat(CharacterPredicates.ARABIC_NUMERALS.test('9')).isTrue(); - assertFalse(CharacterPredicates.ARABIC_NUMERALS.test('/')); - assertFalse(CharacterPredicates.ARABIC_NUMERALS.test(':')); - assertFalse(CharacterPredicates.ARABIC_NUMERALS.test('a')); + assertThat(CharacterPredicates.ARABIC_NUMERALS.test('/')).isFalse(); + assertThat(CharacterPredicates.ARABIC_NUMERALS.test(':')).isFalse(); + assertThat(CharacterPredicates.ARABIC_NUMERALS.test('a')).isFalse(); } @Test public void testAsciiLowercaseLetters() { - assertTrue(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('a')); - assertTrue(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('z')); - - assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('9')); - assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('A')); - assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('Z')); - assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('`')); - assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('{')); + assertThat(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('a')).isTrue(); + assertThat(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('z')).isTrue(); + + assertThat(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('9')).isFalse(); + assertThat(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('A')).isFalse(); + assertThat(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('Z')).isFalse(); + assertThat(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('`')).isFalse(); + assertThat(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('{')).isFalse(); } @Test public void testAsciiUppercaseLetters() { - assertTrue(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('A')); - assertTrue(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('Z')); - - assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('9')); - assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('@')); - assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('[')); - assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('a')); - assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('z')); + assertThat(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('A')).isTrue(); + assertThat(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('Z')).isTrue(); + + assertThat(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('9')).isFalse(); + assertThat(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('@')).isFalse(); + assertThat(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('[')).isFalse(); + assertThat(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('a')).isFalse(); + assertThat(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('z')).isFalse(); } @Test public void testAsciiLetters() { - assertTrue(CharacterPredicates.ASCII_LETTERS.test('a')); - assertTrue(CharacterPredicates.ASCII_LETTERS.test('z')); - assertTrue(CharacterPredicates.ASCII_LETTERS.test('A')); - assertTrue(CharacterPredicates.ASCII_LETTERS.test('Z')); - - assertFalse(CharacterPredicates.ASCII_LETTERS.test('9')); - assertFalse(CharacterPredicates.ASCII_LETTERS.test('`')); - assertFalse(CharacterPredicates.ASCII_LETTERS.test('{')); - assertFalse(CharacterPredicates.ASCII_LETTERS.test('@')); - assertFalse(CharacterPredicates.ASCII_LETTERS.test('[')); + assertThat(CharacterPredicates.ASCII_LETTERS.test('a')).isTrue(); + assertThat(CharacterPredicates.ASCII_LETTERS.test('z')).isTrue(); + assertThat(CharacterPredicates.ASCII_LETTERS.test('A')).isTrue(); + assertThat(CharacterPredicates.ASCII_LETTERS.test('Z')).isTrue(); + + assertThat(CharacterPredicates.ASCII_LETTERS.test('9')).isFalse(); + assertThat(CharacterPredicates.ASCII_LETTERS.test('`')).isFalse(); + assertThat(CharacterPredicates.ASCII_LETTERS.test('{')).isFalse(); + assertThat(CharacterPredicates.ASCII_LETTERS.test('@')).isFalse(); + assertThat(CharacterPredicates.ASCII_LETTERS.test('[')).isFalse(); } @Test public void testAsciiAlphaNumerals() { - assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('a')); - assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('z')); - assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('A')); - assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('Z')); - assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('0')); - assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('9')); - - assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('`')); - assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('{')); - assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('@')); - assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('[')); - assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('/')); - assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test(':')); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('a')).isTrue(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('z')).isTrue(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('A')).isTrue(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('Z')).isTrue(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('0')).isTrue(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('9')).isTrue(); + + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('`')).isFalse(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('{')).isFalse(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('@')).isFalse(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('[')).isFalse(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('/')).isFalse(); + assertThat(CharacterPredicates.ASCII_ALPHA_NUMERALS.test(':')).isFalse(); } } http://git-wip-us.apache.org/repos/asf/commons-text/blob/e55d0ac1/src/test/java/org/apache/commons/text/FormattableUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/FormattableUtilsTest.java b/src/test/java/org/apache/commons/text/FormattableUtilsTest.java index 6038f62..7741523 100644 --- a/src/test/java/org/apache/commons/text/FormattableUtilsTest.java +++ b/src/test/java/org/apache/commons/text/FormattableUtilsTest.java @@ -17,7 +17,7 @@ package org.apache.commons.text; import static java.util.FormattableFlags.LEFT_JUSTIFY; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Formattable; import java.util.Formatter; @@ -38,61 +38,73 @@ public class FormattableUtilsTest { public void testSimplestFormat() { final Formattable formattable = new SimplestFormattable("foo"); - assertEquals("foo", FormattableUtils.toString(formattable)); + assertThat(FormattableUtils.toString(formattable)).isEqualTo("foo"); } @Test public void testDefaultAppend() { - assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1).toString()); - assertEquals("fo", FormattableUtils.append("foo", new Formatter(), 0, -1, 2).toString()); - assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1).toString()); - assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1).toString()); - assertEquals(" fo", FormattableUtils.append("foo", new Formatter(), 0, 3, 2).toString()); - assertEquals(" fo", FormattableUtils.append("foo", new Formatter(), 0, 5, 2).toString()); - assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1).toString()); - assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1).toString()); - assertEquals("fo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2).toString()); - assertEquals("fo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2).toString()); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, -1).toString()).isEqualTo("foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, 2).toString()).isEqualTo("fo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 4, -1).toString()).isEqualTo(" foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 6, -1).toString()).isEqualTo(" foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 3, 2).toString()).isEqualTo(" fo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 5, 2).toString()).isEqualTo(" fo"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1).toString()).isEqualTo("foo "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1).toString()).isEqualTo("foo "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2).toString()).isEqualTo("fo "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2).toString()).isEqualTo("fo "); } @Test public void testAlternatePadCharacter() { final char pad = '_'; - assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, pad).toString()); - assertEquals("fo", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, pad).toString()); - assertEquals("_foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, pad).toString()); - assertEquals("___foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, pad).toString()); - assertEquals("_fo", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, pad).toString()); - assertEquals("___fo", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, pad).toString()); - assertEquals("foo_", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, pad).toString()); - assertEquals("foo___", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, pad).toString()); - assertEquals("fo_", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, pad).toString()); - assertEquals("fo___", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, pad).toString()); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, -1, pad).toString()).isEqualTo("foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, 2, pad).toString()).isEqualTo("fo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 4, -1, pad).toString()).isEqualTo("_foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 6, -1, pad).toString()).isEqualTo("___foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 3, 2, pad).toString()).isEqualTo("_fo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 5, 2, pad).toString()).isEqualTo("___fo"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, pad).toString()) + .isEqualTo("foo_"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, pad).toString()) + .isEqualTo("foo___"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, pad).toString()) + .isEqualTo("fo_"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, pad).toString()) + .isEqualTo("fo___"); } @Test public void testEllipsis() { - assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, "*").toString()); - assertEquals("f*", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, "*").toString()); - assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, "*").toString()); - assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, "*").toString()); - assertEquals(" f*", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, "*").toString()); - assertEquals(" f*", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, "*").toString()); - assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, "*").toString()); - assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, "*").toString()); - assertEquals("f* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, "*").toString()); - assertEquals("f* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, "*").toString()); - - assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, "+*").toString()); - assertEquals("+*", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, "+*").toString()); - assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, "+*").toString()); - assertEquals(" foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, "+*").toString()); - assertEquals(" +*", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, "+*").toString()); - assertEquals(" +*", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, "+*").toString()); - assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, "+*").toString()); - assertEquals("foo ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, "+*").toString()); - assertEquals("+* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, "+*").toString()); - assertEquals("+* ", FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, "+*").toString()); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, -1, "*").toString()).isEqualTo("foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, 2, "*").toString()).isEqualTo("f*"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 4, -1, "*").toString()).isEqualTo(" foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 6, -1, "*").toString()).isEqualTo(" foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 3, 2, "*").toString()).isEqualTo(" f*"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 5, 2, "*").toString()).isEqualTo(" f*"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, "*").toString()) + .isEqualTo("foo "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, "*").toString()) + .isEqualTo("foo "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, "*").toString()) + .isEqualTo("f* "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, "*").toString()) + .isEqualTo("f* "); + + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, -1, "+*").toString()).isEqualTo("foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, 2, "+*").toString()).isEqualTo("+*"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 4, -1, "+*").toString()).isEqualTo(" foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 6, -1, "+*").toString()).isEqualTo(" foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 3, 2, "+*").toString()).isEqualTo(" +*"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 5, 2, "+*").toString()).isEqualTo(" +*"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, "+*").toString()) + .isEqualTo("foo "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, "+*").toString()) + .isEqualTo("foo "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, "+*").toString()) + .isEqualTo("+* "); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, "+*").toString()) + .isEqualTo("+* "); } @Test(expected = IllegalArgumentException.class) @@ -102,35 +114,36 @@ public class FormattableUtilsTest { @Test public void testAlternatePadCharAndEllipsis() { - assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, '_', "*").toString()); - assertEquals("f*", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, '_', "*").toString()); - assertEquals("_foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, '_', "*").toString()); - assertEquals("___foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, '_', "*").toString()); - assertEquals("_f*", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, '_', "*").toString()); - assertEquals("___f*", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, '_', "*").toString()); - assertEquals("foo_", - FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, '_', "*").toString()); - assertEquals("foo___", - FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, '_', "*").toString()); - assertEquals("f*_", - FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, '_', "*").toString()); - assertEquals("f*___", - FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, '_', "*").toString()); - - assertEquals("foo", FormattableUtils.append("foo", new Formatter(), 0, -1, -1, '_', "+*").toString()); - assertEquals("+*", FormattableUtils.append("foo", new Formatter(), 0, -1, 2, '_', "+*").toString()); - assertEquals("_foo", FormattableUtils.append("foo", new Formatter(), 0, 4, -1, '_', "+*").toString()); - assertEquals("___foo", FormattableUtils.append("foo", new Formatter(), 0, 6, -1, '_', "+*").toString()); - assertEquals("_+*", FormattableUtils.append("foo", new Formatter(), 0, 3, 2, '_', "+*").toString()); - assertEquals("___+*", FormattableUtils.append("foo", new Formatter(), 0, 5, 2, '_', "+*").toString()); - assertEquals("foo_", - FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, '_', "+*").toString()); - assertEquals("foo___", - FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, '_', "+*").toString()); - assertEquals("+*_", - FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, '_', "+*").toString()); - assertEquals("+*___", - FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, '_', "+*").toString()); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, -1, '_', "*").toString()).isEqualTo("foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, 2, '_', "*").toString()).isEqualTo("f*"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 4, -1, '_', "*").toString()).isEqualTo("_foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 6, -1, '_', "*").toString()).isEqualTo("___foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 3, 2, '_', "*").toString()).isEqualTo("_f*"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 5, 2, '_', "*").toString()).isEqualTo("___f*"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, '_', "*").toString()) + .isEqualTo("foo_"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, '_', "*").toString()) + .isEqualTo("foo___"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, '_', "*").toString()) + .isEqualTo("f*_"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, '_', "*").toString()) + .isEqualTo("f*___"); + + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, -1, '_', "+*").toString()).isEqualTo("foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, -1, 2, '_', "+*").toString()).isEqualTo("+*"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 4, -1, '_', "+*").toString()).isEqualTo("_foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 6, -1, '_', "+*").toString()) + .isEqualTo("___foo"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 3, 2, '_', "+*").toString()).isEqualTo("_+*"); + assertThat(FormattableUtils.append("foo", new Formatter(), 0, 5, 2, '_', "+*").toString()).isEqualTo("___+*"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 4, -1, '_', "+*").toString()) + .isEqualTo("foo_"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 6, -1, '_', "+*").toString()) + .isEqualTo("foo___"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 3, 2, '_', "+*").toString()) + .isEqualTo("+*_"); + assertThat(FormattableUtils.append("foo", new Formatter(), LEFT_JUSTIFY, 5, 2, '_', "+*").toString()) + .isEqualTo("+*___"); } @Test(expected = NullPointerException.class) http://git-wip-us.apache.org/repos/asf/commons-text/blob/e55d0ac1/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java index 8b7a172..be1443e 100644 --- a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java +++ b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java @@ -19,11 +19,9 @@ package org.apache.commons.text; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.junit.Test; @@ -73,7 +71,7 @@ public class RandomStringGeneratorTest { final int length = 99; final RandomStringGenerator generator = new RandomStringGenerator.Builder().build(); final String str = generator.generate(length); - assertEquals(length, codePointLength(str)); + assertThat(codePointLength(str)).isEqualTo(length); } @Test @@ -107,7 +105,7 @@ public class RandomStringGeneratorTest { int i = 0; do { final int codePoint = str.codePointAt(i); - assertTrue(codePoint >= minimumCodePoint && codePoint <= maximumCodePoint); + assertThat(codePoint >= minimumCodePoint && codePoint <= maximumCodePoint).isTrue(); i += Character.charCount(codePoint); } while (i < str.length()); } @@ -131,7 +129,7 @@ public class RandomStringGeneratorTest { int i = 0; do { final int codePoint = str.codePointAt(i); - assertTrue(codePoint >= minimumCodePoint && codePoint <= maximumCodePoint); + assertThat(codePoint >= minimumCodePoint && codePoint <= maximumCodePoint).isTrue(); i += Character.charCount(codePoint); } while (i < str.length()); } @@ -147,16 +145,16 @@ public class RandomStringGeneratorTest { final char c = str.charAt(i); if (Character.isLowSurrogate(c)) { - assertTrue(Character.isHighSurrogate(lastChar)); + assertThat(Character.isHighSurrogate(lastChar)).isTrue(); } if (Character.isHighSurrogate(lastChar)) { - assertTrue(Character.isLowSurrogate(c)); + assertThat(Character.isLowSurrogate(c)).isTrue(); } if (Character.isHighSurrogate(c)) { // test this isn't the last character in the string - assertTrue(i + 1 < str.length()); + assertThat(i + 1 < str.length()).isTrue(); } lastChar = c; @@ -176,7 +174,7 @@ public class RandomStringGeneratorTest { final String str = new RandomStringGenerator.Builder().usingRandom(testRandom).build().generate(10); for (final char c : str.toCharArray()) { - assertEquals(testChar, c); + assertThat(c).isEqualTo(testChar); } } @@ -198,7 +196,7 @@ public class RandomStringGeneratorTest { } } - assertTrue(aFound && bFound); + assertThat(aFound && bFound).isTrue(); } @Test @@ -213,7 +211,7 @@ public class RandomStringGeneratorTest { int i = 0; do { final int codePoint = str.codePointAt(i); - assertFalse(Character.getType(codePoint) == Character.PRIVATE_USE); + assertThat(Character.getType(codePoint) == Character.PRIVATE_USE).isFalse(); i += Character.charCount(codePoint); } while (i < str.length()); } @@ -248,14 +246,14 @@ public class RandomStringGeneratorTest { final String str = builder.filteredBy(B_FILTER).build().generate(100); for (final char c : str.toCharArray()) { - assertTrue(c == 'b'); + assertThat(c == 'b').isTrue(); } } @Test public void testZeroLength() { final RandomStringGenerator generator = new RandomStringGenerator.Builder().build(); - assertEquals("", generator.generate(0)); + assertThat(generator.generate(0)).isEqualTo(""); } @Test @@ -267,7 +265,7 @@ public class RandomStringGeneratorTest { final String randomText = generator.generate(5); for (final char c : randomText.toCharArray()) { - assertTrue(str.indexOf(c) != -1); + assertThat(str.indexOf(c) != -1).isTrue(); } } @@ -277,7 +275,7 @@ public class RandomStringGeneratorTest { final RandomStringGenerator generator = new RandomStringGenerator.Builder().selectFrom('a', 'b', 'c').build(); final String randomText = generator.generate(5); for (final char c : randomText.toCharArray()) { - assertTrue(str.indexOf(c) != -1); + assertThat(str.indexOf(c) != -1).isTrue(); } }