From 7e6e243cf513bec3486001a2ad2789d1bf2a8eee Mon Sep 17 00:00:00 2001
From: Fabio Pistolesi <fabio.pistolesi@forgerock.com>
Date: Tue, 13 Oct 2015 15:53:29 +0000
Subject: [PATCH] Refactor StaticUtils in server code by calling SDK's basic methods. Remove unused methods (getBytes(char[]) and byteToBinary()) and inline some of the less used (byteToASCII() and one of the toLowerCase()).
---
opendj-server-legacy/src/test/java/org/opends/server/util/TestStaticUtils.java | 80 +++++++++++++++++----------------------
1 files changed, 35 insertions(+), 45 deletions(-)
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/util/TestStaticUtils.java b/opendj-server-legacy/src/test/java/org/opends/server/util/TestStaticUtils.java
index 01e36b8..2adef70 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/util/TestStaticUtils.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/util/TestStaticUtils.java
@@ -169,20 +169,6 @@
}
/**
- * Tests the {@link StaticUtils#getBytes(char[])} method.
- *
- * @param inputString
- * The input string.
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test(dataProvider = "getBytesTestData")
- public void testCharsToBytes(String inputString) throws Exception {
- Assert.assertEquals(StaticUtils.getBytes(inputString.toCharArray()),
- inputString.getBytes("UTF-8"));
- }
-
- /**
* Create test strings for the {@link StaticUtils#byteToHex(byte)}.
*
* @return Returns an array of test strings.
@@ -235,23 +221,6 @@
}
/**
- * Tests the {@link StaticUtils#byteToASCII(byte)} method.
- *
- * @param b
- * The input byte.
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test(dataProvider = "byteToHexTestData")
- public void testByteToASCII(byte b) throws Exception {
- if (b < 32 || b > 126) {
- Assert.assertEquals(StaticUtils.byteToASCII(b), ' ');
- } else {
- Assert.assertEquals(StaticUtils.byteToASCII(b), (char) b);
- }
- }
-
- /**
* Create test strings for the {@link StaticUtils#bytesToHex(byte[])}.
*
* @return Returns an array of test data.
@@ -302,19 +271,6 @@
}
/**
- * Tests the {@link StaticUtils#byteToBinary(byte)} method.
- *
- * @param b
- * The input byte.
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test(dataProvider = "byteToHexTestData")
- public void testByteToBinary(byte b) throws Exception {
- Assert.assertEquals(StaticUtils.byteToBinary(b), BIT_STRINGS[b & 0xff]);
- }
-
- /**
* Create test data for {@link StaticUtils#compare(byte[], byte[])}.
*
* @return Returns an array of test data.
@@ -1101,11 +1057,45 @@
}
/**
+ * Create test strings for the {@link StaticUtils#toLowerCase(ByteSequence, StringBuilder, boolean)} method
+ * with trimming enabled.
+ *
+ * @return Returns an array of test data.
+ */
+ @DataProvider(name = "stringCaseConversionTestDataWithTrim")
+ public Object[][] createStringCaseConversionTestDataWithTrim()
+ {
+ return new Object[][] {
+ {" aBc", "abc"},
+ {"abC", "abc"},
+ {" A bC ", "a bc"},
+ {"fgh ", "fgh"},
+ {" ", ""},
+ {" D ", "d"}
+ };
+ }
+
+ /**
+ * Tests to lower case strings with space trimming.
+ * @param input the test string
+ * @param lower test string in lower case
+ * @throws Exception if tests fails
+ */
+ @Test(dataProvider = "stringCaseConversionTestDataWithTrim")
+ public void testToLowerCaseWithTrim(String input, String lower) throws Exception
+ {
+ StringBuilder sb = new StringBuilder();
+ ByteString bytes = input != null ? ByteString.valueOf(input) : null;
+ StaticUtils.toLowerCase(bytes, sb, true);
+ Assert.assertEquals(sb.toString(), lower);
+ }
+
+ /**
* Create test strings for the
* {@link StaticUtils#toRFC3641StringValue(StringBuilder, String)}
* method.
*
- * @return Returns an array of test data.
+ * @return an array of test data.
*/
@DataProvider(name = "toRFC3641StringValueTestData")
public Object[][] createToRFC3641StringValueTestData() {
--
Gitblit v1.10.0