You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/11/03 15:57:35 UTC
(commons-text) 02/02: Sort test members
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git
commit 3446379e8cb2e175fbfb4403e315899f21352ea1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 3 11:57:28 2023 -0400
Sort test members
---
.../apache/commons/text/AlphabetConverterTest.java | 148 ++++++++++-----------
1 file changed, 74 insertions(+), 74 deletions(-)
diff --git a/src/test/java/org/apache/commons/text/AlphabetConverterTest.java b/src/test/java/org/apache/commons/text/AlphabetConverterTest.java
index b0dac3a7..b17fad88 100644
--- a/src/test/java/org/apache/commons/text/AlphabetConverterTest.java
+++ b/src/test/java/org/apache/commons/text/AlphabetConverterTest.java
@@ -60,13 +60,6 @@ public class AlphabetConverterTest {
private static final Integer[] DO_NOT_ENCODE_CODEPOINTS = {32, 97, 98, 99}; // space, a, b, c
- @Test
- public void testBinaryTest() throws UnsupportedEncodingException {
- test(BINARY, NUMBERS, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "0", "1", "10", "11");
- test(NUMBERS, BINARY, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "12345", "0");
- test(LOWER_CASE_ENGLISH, BINARY, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "abc", "a");
- }
-
private AlphabetConverter createJavadocExample() {
final Character[] original = {'a', 'b', 'c', 'd'};
final Character[] encoding = {'0', '1', 'd'};
@@ -75,73 +68,6 @@ public class AlphabetConverterTest {
return AlphabetConverter.createConverterFromChars(original, encoding, doNotEncode);
}
- @Test
- public void testDoNotEncodeTest() throws UnsupportedEncodingException {
- test(ENGLISH_AND_NUMBERS, LOWER_CASE_ENGLISH_AND_NUMBERS, LOWER_CASE_ENGLISH, "1", "456", "abc", "ABC", "this will not be converted but THIS WILL");
- test(ENGLISH_AND_NUMBERS, LOWER_CASE_ENGLISH_AND_NUMBERS, NUMBERS, "1", "456", "abc", "ABC", "this will be converted but 12345 and this will be");
- }
-
- @Test
- public void testEncodeFailureTest() {
- assertThatThrownBy(() -> test(BINARY, NUMBERS, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "3")).isInstanceOf(UnsupportedEncodingException.class)
- .hasMessage("Couldn't find encoding for '3' in 3");
- }
-
- @Test
- public void testHebrewTest() throws UnsupportedEncodingException {
- test(HEBREW, BINARY, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "\u05d0", "\u05e2",
- "\u05d0\u05dc\u05e3_\u05d0\u05d5\u05d4\u05d1\u05dc_\u05d1\u05d9\u05ea_\u05d6\u05d4_\u05d1\u05d9\u05ea_"
- + "\u05d2\u05d9\u05de\u05dc_\u05d6\u05d4_\u05db\u05de\u05dc_\u05d2\u05d3\u05d5\u05dc");
- test(HEBREW, NUMBERS, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "\u05d0", "\u05e2",
- "\u05d0\u05dc\u05e3_\u05d0\u05d5\u05d4\u05d1\u05dc_\u05d1\u05d9\u05ea_\u05d6\u05d4_\u05d1\u05d9\u05ea_"
- + "\u05d2\u05d9\u05de\u05dc_\u05d6\u05d4_\u05db\u05de\u05dc_\u05d2\u05d3\u05d5\u05dc");
- test(NUMBERS, HEBREW, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "123456789", "1", "5");
- test(LOWER_CASE_ENGLISH, HEBREW, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "this is a test");
- }
-
- /*
- * Test example in javadocs for consistency
- */
- @Test
- public void testJavadocExampleTest() throws UnsupportedEncodingException {
- final AlphabetConverter ac = createJavadocExample();
-
- 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
- public void testMissingDoNotEncodeLettersFromEncodingTest() {
- assertThatThrownBy(() -> AlphabetConverter.createConverterFromChars(ENGLISH_AND_NUMBERS, LOWER_CASE_ENGLISH, NUMBERS))
- .isInstanceOf(IllegalArgumentException.class).hasMessage("Can not use 'do not encode' list because encoding alphabet does not contain '0'");
- }
-
- @Test
- public void testMissingDoNotEncodeLettersFromOriginalTest() {
- assertThatThrownBy(() -> AlphabetConverter.createConverterFromChars(LOWER_CASE_ENGLISH, ENGLISH_AND_NUMBERS, NUMBERS))
- .isInstanceOf(IllegalArgumentException.class).hasMessage("Can not use 'do not encode' list because original alphabet does not contain '0'");
- }
-
- @Test
- public void testNoEncodingLettersTest() {
- assertThatThrownBy(() -> AlphabetConverter.createConverterFromChars(ENGLISH_AND_NUMBERS, NUMBERS, NUMBERS)).isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Must have at least two encoding characters (excluding those in the 'do not encode' list), but has 0");
- }
-
- @Test
- public void testOnlyOneEncodingLettersTest() {
- assertThatThrownBy(() -> {
- final Character[] numbersPlusUnderscore = Arrays.copyOf(NUMBERS, NUMBERS.length + 1);
- numbersPlusUnderscore[numbersPlusUnderscore.length - 1] = '_';
-
- AlphabetConverter.createConverterFromChars(ENGLISH_AND_NUMBERS, numbersPlusUnderscore, NUMBERS);
- }).isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Must have at least two encoding characters (excluding those in the 'do not encode' list), but has 1");
- }
-
private void test(final Character[] originalChars, final Character[] encodingChars, final Character[] doNotEncodeChars, final String... strings)
throws UnsupportedEncodingException {
@@ -177,6 +103,13 @@ public class AlphabetConverterTest {
}
}
+ @Test
+ public void testBinaryTest() throws UnsupportedEncodingException {
+ test(BINARY, NUMBERS, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "0", "1", "10", "11");
+ test(NUMBERS, BINARY, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "12345", "0");
+ test(LOWER_CASE_ENGLISH, BINARY, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "abc", "a");
+ }
+
@Test
public void testCreateConverterFromCharsAndEquals() {
final Character[] characterArray = new Character[2];
@@ -230,6 +163,18 @@ public class AlphabetConverterTest {
assertThat(alphabetConverter.getEncodedCharLength()).isEqualTo(1);
}
+ @Test
+ public void testDoNotEncodeTest() throws UnsupportedEncodingException {
+ test(ENGLISH_AND_NUMBERS, LOWER_CASE_ENGLISH_AND_NUMBERS, LOWER_CASE_ENGLISH, "1", "456", "abc", "ABC", "this will not be converted but THIS WILL");
+ test(ENGLISH_AND_NUMBERS, LOWER_CASE_ENGLISH_AND_NUMBERS, NUMBERS, "1", "456", "abc", "ABC", "this will be converted but 12345 and this will be");
+ }
+
+ @Test
+ public void testEncodeFailureTest() {
+ assertThatThrownBy(() -> test(BINARY, NUMBERS, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "3")).isInstanceOf(UnsupportedEncodingException.class)
+ .hasMessage("Couldn't find encoding for '3' in 3");
+ }
+
@Test
public void testEquals() {
final Character[] characterArray = new Character[2];
@@ -263,6 +208,61 @@ public class AlphabetConverterTest {
assertThat(alphabetConverter.equals(alphabetConverter)).isTrue();
}
+ @Test
+ public void testHebrewTest() throws UnsupportedEncodingException {
+ test(HEBREW, BINARY, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "\u05d0", "\u05e2",
+ "\u05d0\u05dc\u05e3_\u05d0\u05d5\u05d4\u05d1\u05dc_\u05d1\u05d9\u05ea_\u05d6\u05d4_\u05d1\u05d9\u05ea_"
+ + "\u05d2\u05d9\u05de\u05dc_\u05d6\u05d4_\u05db\u05de\u05dc_\u05d2\u05d3\u05d5\u05dc");
+ test(HEBREW, NUMBERS, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "\u05d0", "\u05e2",
+ "\u05d0\u05dc\u05e3_\u05d0\u05d5\u05d4\u05d1\u05dc_\u05d1\u05d9\u05ea_\u05d6\u05d4_\u05d1\u05d9\u05ea_"
+ + "\u05d2\u05d9\u05de\u05dc_\u05d6\u05d4_\u05db\u05de\u05dc_\u05d2\u05d3\u05d5\u05dc");
+ test(NUMBERS, HEBREW, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "123456789", "1", "5");
+ test(LOWER_CASE_ENGLISH, HEBREW, ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, "this is a test");
+ }
+
+ /*
+ * Test example in javadocs for consistency
+ */
+ @Test
+ public void testJavadocExampleTest() throws UnsupportedEncodingException {
+ final AlphabetConverter ac = createJavadocExample();
+
+ 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
+ public void testMissingDoNotEncodeLettersFromEncodingTest() {
+ assertThatThrownBy(() -> AlphabetConverter.createConverterFromChars(ENGLISH_AND_NUMBERS, LOWER_CASE_ENGLISH, NUMBERS))
+ .isInstanceOf(IllegalArgumentException.class).hasMessage("Can not use 'do not encode' list because encoding alphabet does not contain '0'");
+ }
+
+ @Test
+ public void testMissingDoNotEncodeLettersFromOriginalTest() {
+ assertThatThrownBy(() -> AlphabetConverter.createConverterFromChars(LOWER_CASE_ENGLISH, ENGLISH_AND_NUMBERS, NUMBERS))
+ .isInstanceOf(IllegalArgumentException.class).hasMessage("Can not use 'do not encode' list because original alphabet does not contain '0'");
+ }
+
+ @Test
+ public void testNoEncodingLettersTest() {
+ assertThatThrownBy(() -> AlphabetConverter.createConverterFromChars(ENGLISH_AND_NUMBERS, NUMBERS, NUMBERS)).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Must have at least two encoding characters (excluding those in the 'do not encode' list), but has 0");
+ }
+
+ @Test
+ public void testOnlyOneEncodingLettersTest() {
+ assertThatThrownBy(() -> {
+ final Character[] numbersPlusUnderscore = Arrays.copyOf(NUMBERS, NUMBERS.length + 1);
+ numbersPlusUnderscore[numbersPlusUnderscore.length - 1] = '_';
+
+ AlphabetConverter.createConverterFromChars(ENGLISH_AND_NUMBERS, numbersPlusUnderscore, NUMBERS);
+ }).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Must have at least two encoding characters (excluding those in the 'do not encode' list), but has 1");
+ }
+
@Test
public void testUnexpectedEndWhileDecodingTest() {
final String toDecode = "00d01d0";