diff --git a/src/main/java/com/cedarsoftware/util/FastByteArrayOutputStream.java b/src/main/java/com/cedarsoftware/util/FastByteArrayOutputStream.java
index 0c925836d..365e81e9f 100644
--- a/src/main/java/com/cedarsoftware/util/FastByteArrayOutputStream.java
+++ b/src/main/java/com/cedarsoftware/util/FastByteArrayOutputStream.java
@@ -56,14 +56,12 @@ private void grow(int minCapacity) {
buf = Arrays.copyOf(buf, newCapacity);
}
- @Override
public void write(int b) {
ensureCapacity(count + 1);
buf[count] = (byte) b;
count += 1;
}
- @Override
public void write(byte[] b, int off, int len) {
if ((b == null) || (off < 0) || (len < 0) ||
(off > b.length) || (off + len > b.length) || (off + len < 0)) {
@@ -86,6 +84,11 @@ public byte[] toByteArray() {
return Arrays.copyOf(buf, count);
}
+ // Backwards compatibility
+ public byte[] getBuffer() {
+ return Arrays.copyOf(buf, count);
+ }
+
public int size() {
return count;
}
@@ -98,7 +101,6 @@ public void writeTo(OutputStream out) throws IOException {
out.write(buf, 0, count);
}
- @Override
public void close() throws IOException {
// No resources to close
}
diff --git a/src/main/java/com/cedarsoftware/util/StringUtilities.java b/src/main/java/com/cedarsoftware/util/StringUtilities.java
index f70ef6b4d..51f7eba56 100644
--- a/src/main/java/com/cedarsoftware/util/StringUtilities.java
+++ b/src/main/java/com/cedarsoftware/util/StringUtilities.java
@@ -24,22 +24,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-public final class StringUtilities
-{
- private static final char[] _hex = {
+public final class StringUtilities {
+ private static char[] _hex = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
- public static final String FOLDER_SEPARATOR = "/";
+ public static String FOLDER_SEPARATOR = "/";
- public static final String EMPTY = "";
+ public static String EMPTY = "";
/**
*
Constructor is declared private since all methods are static.
*/
- private StringUtilities()
- {
- super();
+ private StringUtilities() {
}
/**
@@ -49,12 +46,12 @@ private StringUtilities()
* {@code null}s are handled without exceptions. Two {@code null}
* references are considered to be equal. The comparison is case-sensitive.
*
- * @param cs1 the first CharSequence, may be {@code null}
- * @param cs2 the second CharSequence, may be {@code null}
+ * @param cs1 the first CharSequence, may be {@code null}
+ * @param cs2 the second CharSequence, may be {@code null}
* @return {@code true} if the CharSequences are equal (case-sensitive), or both {@code null}
* @see #equalsIgnoreCase(CharSequence, CharSequence)
*/
- public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
+ public static boolean equals(CharSequence cs1, CharSequence cs2) {
if (cs1 == cs2) {
return true;
}
@@ -68,7 +65,7 @@ public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
return cs1.equals(cs2);
}
// Step-wise comparison
- final int length = cs1.length();
+ int length = cs1.length();
for (int i = 0; i < length; i++) {
if (cs1.charAt(i) != cs2.charAt(i)) {
return false;
@@ -77,6 +74,13 @@ public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
return true;
}
+ /**
+ * @see StringUtilities#equals(CharSequence, CharSequence)
+ */
+ public static boolean equals(String s1, String s2) {
+ return equals((CharSequence) s1, (CharSequence) s2);
+ }
+
/**
* Compares two CharSequences, returning {@code true} if they represent
* equal sequences of characters, ignoring case.
@@ -84,12 +88,12 @@ public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
* {@code null}s are handled without exceptions. Two {@code null}
* references are considered equal. The comparison is case insensitive.
*
- * @param cs1 the first CharSequence, may be {@code null}
- * @param cs2 the second CharSequence, may be {@code null}
+ * @param cs1 the first CharSequence, may be {@code null}
+ * @param cs2 the second CharSequence, may be {@code null}
* @return {@code true} if the CharSequences are equal (case-insensitive), or both {@code null}
* @see #equals(CharSequence, CharSequence)
*/
- public static boolean equalsIgnoreCase(final CharSequence cs1, final CharSequence cs2) {
+ public static boolean equalsIgnoreCase(CharSequence cs1, CharSequence cs2) {
if (cs1 == cs2) {
return true;
}
@@ -102,19 +106,26 @@ public static boolean equalsIgnoreCase(final CharSequence cs1, final CharSequenc
return regionMatches(cs1, true, 0, cs2, 0, cs1.length());
}
+ /**
+ * @see StringUtilities@equalsIgnoreCase(CharSequence, CharSequence)
+ */
+ public static boolean equalsIgnoreCase(String s1, String s2) {
+ return equalsIgnoreCase((CharSequence) s1, (CharSequence) s2);
+ }
+
/**
* Green implementation of regionMatches.
*
- * @param cs the {@link CharSequence} to be processed
- * @param ignoreCase whether or not to be case-insensitive
- * @param thisStart the index to start on the {@code cs} CharSequence
- * @param substring the {@link CharSequence} to be looked for
- * @param start the index to start on the {@code substring} CharSequence
- * @param length character length of the region
+ * @param cs the {@link CharSequence} to be processed
+ * @param ignoreCase whether to be case-insensitive
+ * @param thisStart the index to start on the {@code cs} CharSequence
+ * @param substring the {@link CharSequence} to be looked for
+ * @param start the index to start on the {@code substring} CharSequence
+ * @param length character length of the region
* @return whether the region matched
*/
- static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart,
- final CharSequence substring, final int start, final int length) {
+ static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart,
+ CharSequence substring, int start, int length) {
Convention.throwIfNull(cs, "cs to be processed cannot be null");
Convention.throwIfNull(substring, "substring cannot be null");
@@ -126,8 +137,8 @@ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, fi
int tmpLen = length;
// Extract these first so we detect NPEs the same as the java.lang.String version
- final int srcLen = cs.length() - thisStart;
- final int otherLen = substring.length() - start;
+ int srcLen = cs.length() - thisStart;
+ int otherLen = substring.length() - start;
// Check for invalid parameters
if (thisStart < 0 || start < 0 || length < 0) {
@@ -140,8 +151,8 @@ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, fi
}
while (tmpLen-- > 0) {
- final char c1 = cs.charAt(index1++);
- final char c2 = substring.charAt(index2++);
+ char c1 = cs.charAt(index1++);
+ char c2 = substring.charAt(index2++);
if (c1 == c2) {
continue;
@@ -152,8 +163,8 @@ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, fi
}
// The real same check as in String.regionMatches():
- final char u1 = Character.toUpperCase(c1);
- final char u2 = Character.toUpperCase(c2);
+ char u1 = Character.toUpperCase(c1);
+ char u2 = Character.toUpperCase(c2);
if (u1 != u2 && Character.toLowerCase(u1) != Character.toLowerCase(u2)) {
return false;
}
@@ -162,19 +173,15 @@ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, fi
return true;
}
- public static boolean equalsWithTrim(final String s1, final String s2)
- {
- if (s1 == null || s2 == null)
- {
+ public static boolean equalsWithTrim(String s1, String s2) {
+ if (s1 == null || s2 == null) {
return s1 == s2;
}
return s1.trim().equals(s2.trim());
}
- public static boolean equalsIgnoreCaseWithTrim(final String s1, final String s2)
- {
- if (s1 == null || s2 == null)
- {
+ public static boolean equalsIgnoreCaseWithTrim(String s1, String s2) {
+ if (s1 == null || s2 == null) {
return s1 == s2;
}
return s1.trim().equalsIgnoreCase(s2.trim());
@@ -183,33 +190,28 @@ public static boolean equalsIgnoreCaseWithTrim(final String s1, final String s2)
/**
* Checks if a CharSequence is empty (""), null, or only whitespace.
*
- * @param cs the CharSequence to check, may be null
+ * @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is empty or null
*/
- public static boolean isEmpty(CharSequence cs)
- {
+ public static boolean isEmpty(CharSequence cs) {
return isWhitespace(cs);
}
/**
- * Checks if a CharSequence is not empty (""), not null and not whitespace only.
- *
- * @param cs the CharSequence to check, may be null
- * @return {@code true} if the CharSequence is
- * not empty and not null and not whitespace only
+ * @see StringUtilities#isEmpty(CharSequence)
*/
- public static boolean isNotWhitespace(final CharSequence cs) {
- return !isWhitespace(cs);
+ public static boolean isEmpty(String s) {
+ return isWhitespace(s);
}
/**
* Checks if a CharSequence is empty (""), null or whitespace only.
*
- * @param cs the CharSequence to check, may be null
+ * @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is null, empty or whitespace only
*/
- public static boolean isWhitespace(final CharSequence cs) {
- final int strLen = length(cs);
+ public static boolean isWhitespace(CharSequence cs) {
+ int strLen = length(cs);
if (strLen == 0) {
return true;
}
@@ -222,24 +224,14 @@ public static boolean isWhitespace(final CharSequence cs) {
}
/**
- * Checks if a CharSequence is not null, not empty (""), and not only whitespace.
- *
- * @param cs the CharSequence to check, may be null
- * @return {@code true} if the CharSequence is not empty and not null
- */
- public static boolean isNotEmpty(final CharSequence cs) {
- return !isWhitespace(cs);
- }
-
- /**
- * Checks if a CharSequence is not empty (""), not null and not whitespace only.
+ * Checks if a String is not empty (""), not null and not whitespace only.
*
- * @param cs the CharSequence to check, may be null
+ * @param s the CharSequence to check, may be null
* @return {@code true} if the CharSequence is
- * not empty and not null and not whitespace only
+ * not empty and not null and not whitespace only
*/
- public static boolean hasContent(final CharSequence cs) {
- return !isWhitespace(cs);
+ public static boolean hasContent(String s) {
+ return !isWhitespace(s);
}
/**
@@ -248,15 +240,22 @@ public static boolean hasContent(final CharSequence cs) {
* @param cs a CharSequence or {@code null}
* @return CharSequence length or {@code 0} if the CharSequence is {@code null}.
*/
- public static int length(final CharSequence cs) {
+ public static int length(CharSequence cs) {
return cs == null ? 0 : cs.length();
}
+ /**
+ * @see StringUtilities#length(CharSequence)
+ */
+ public static int length(String s) {
+ return s == null ? 0 : s.length();
+ }
+
/**
* @param s a String or {@code null}
* @return the trimmed length of the String or 0 if the string is null.
*/
- public static int trimLength(final String s) {
+ public static int trimLength(String s) {
return trimToEmpty(s).length();
}
@@ -271,19 +270,16 @@ public static int lastIndexOf(String path, char ch) {
// Turn hex String into byte[]
// If string is not even length, return null.
- public static byte[] decode(String s)
- {
- final int len = s.length();
- if (len % 2 != 0)
- {
+ public static byte[] decode(String s) {
+ int len = s.length();
+ if (len % 2 != 0) {
return null;
}
byte[] bytes = new byte[len / 2];
int pos = 0;
- for (int i = 0; i < len; i += 2)
- {
+ for (int i = 0; i < len; i += 2) {
byte hi = (byte) Character.digit(s.charAt(i), 16);
byte lo = (byte) Character.digit(s.charAt(i + 1), 16);
bytes[pos++] = (byte) (hi * 16 + lo);
@@ -298,11 +294,9 @@ public static byte[] decode(String s)
*
* @param bytes array representation
*/
- public static String encode(byte[] bytes)
- {
+ public static String encode(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length << 1);
- for (byte aByte : bytes)
- {
+ for (byte aByte : bytes) {
sb.append(convertDigit(aByte >> 4));
sb.append(convertDigit(aByte & 0x0f));
}
@@ -315,66 +309,56 @@ public static String encode(byte[] bytes)
* @param value to be converted
* @return '0'..'F' in char format.
*/
- private static char convertDigit(int value)
- {
+ private static char convertDigit(int value) {
return _hex[value & 0x0f];
}
- public static int count(String s, char c)
- {
- return count (s, EMPTY + c);
+ public static int count(String s, char c) {
+ return count(s, EMPTY + c);
}
/**
* Count the number of times that 'token' occurs within 'content'.
+ *
* @return int count (0 if it never occurs, null is the source string, or null is the token).
*/
- public static int count(CharSequence content, CharSequence token)
- {
- if (content == null || token == null)
- {
+ public static int count(CharSequence content, CharSequence token) {
+ if (content == null || token == null) {
return 0;
}
String source = content.toString();
- if (source.isEmpty())
- {
+ if (source.isEmpty()) {
return 0;
}
String sub = token.toString();
- if (sub.isEmpty())
- {
+ if (sub.isEmpty()) {
return 0;
}
int answer = 0;
int idx = 0;
- while (true)
- {
+ while (true) {
idx = source.indexOf(sub, idx);
- if (idx < answer)
- {
+ if (idx < answer) {
return answer;
}
- answer = ++answer;
- idx = ++idx;
+ ++answer;
+ ++idx;
}
}
/**
* Convert strings containing DOS-style '*' or '?' to a regex String.
*/
- public static String wildcardToRegexString(String wildcard)
- {
- final int len = wildcard.length();
+ public static String wildcardToRegexString(String wildcard) {
+ int len = wildcard.length();
StringBuilder s = new StringBuilder(len);
s.append('^');
- for (int i = 0; i < len; i++)
- {
+ for (int i = 0; i < len; i++) {
char c = wildcard.charAt(i);
- switch (c)
- {
+ switch (c) {
case '*':
s.append(".*");
break;
@@ -418,15 +402,11 @@ public static String wildcardToRegexString(String wildcard)
* @param t String two
* @return the 'edit distance' (Levenshtein distance) between the two strings.
*/
- public static int levenshteinDistance(CharSequence s, CharSequence t)
- {
- // degenerate cases s
- if (s == null || EMPTY.equals(s))
- {
- return t == null || EMPTY.equals(t) ? 0 : t.length();
- }
- else if (t == null || EMPTY.equals(t))
- {
+ public static int levenshteinDistance(CharSequence s, CharSequence t) {
+ // degenerate cases
+ if (s == null || EMPTY.contentEquals(s)) {
+ return t == null || EMPTY.contentEquals(t) ? 0 : t.length();
+ } else if (t == null || EMPTY.contentEquals(t)) {
return s.length();
}
@@ -437,15 +417,13 @@ else if (t == null || EMPTY.equals(t))
// initialize v0 (the previous row of distances)
// this row is A[0][i]: edit distance for an empty s
// the distance is just the number of characters to delete from t
- for (int i = 0; i < v0.length; i++)
- {
+ for (int i = 0; i < v0.length; i++) {
v0[i] = i;
}
int sLen = s.length();
int tLen = t.length();
- for (int i = 0; i < sLen; i++)
- {
+ for (int i = 0; i < sLen; i++) {
// calculate v1 (current row distances) from the previous row v0
// first element of v1 is A[i+1][0]
@@ -453,8 +431,7 @@ else if (t == null || EMPTY.equals(t))
v1[0] = i + 1;
// use formula to fill in the rest of the row
- for (int j = 0; j < tLen; j++)
- {
+ for (int j = 0; j < tLen; j++) {
int cost = (s.charAt(i) == t.charAt(j)) ? 0 : 1;
v1[j + 1] = (int) MathUtilities.minimum(v1[j] + 1, v0[j + 1] + 1, v0[j] + cost);
}
@@ -480,14 +457,10 @@ else if (t == null || EMPTY.equals(t))
* to make the source string identical to the target
* string
*/
- public static int damerauLevenshteinDistance(CharSequence source, CharSequence target)
- {
- if (source == null || EMPTY.equals(source))
- {
- return target == null || EMPTY.equals(target) ? 0 : target.length();
- }
- else if (target == null || EMPTY.equals(target))
- {
+ public static int damerauLevenshteinDistance(CharSequence source, CharSequence target) {
+ if (source == null || EMPTY.contentEquals(source)) {
+ return target == null || EMPTY.contentEquals(target) ? 0 : target.length();
+ } else if (target == null || EMPTY.contentEquals(target)) {
return source.length();
}
@@ -498,25 +471,21 @@ else if (target == null || EMPTY.equals(target))
// We need indexers from 0 to the length of the source string.
// This sequential set of numbers will be the row "headers"
// in the matrix.
- for (int srcIndex = 0; srcIndex <= srcLen; srcIndex++)
- {
+ for (int srcIndex = 0; srcIndex <= srcLen; srcIndex++) {
distanceMatrix[srcIndex][0] = srcIndex;
}
// We need indexers from 0 to the length of the target string.
// This sequential set of numbers will be the
// column "headers" in the matrix.
- for (int targetIndex = 0; targetIndex <= targetLen; targetIndex++)
- {
+ for (int targetIndex = 0; targetIndex <= targetLen; targetIndex++) {
// Set the value of the first cell in the column
// equivalent to the current value of the iterator
distanceMatrix[0][targetIndex] = targetIndex;
}
- for (int srcIndex = 1; srcIndex <= srcLen; srcIndex++)
- {
- for (int targetIndex = 1; targetIndex <= targetLen; targetIndex++)
- {
+ for (int srcIndex = 1; srcIndex <= srcLen; srcIndex++) {
+ for (int targetIndex = 1; targetIndex <= targetLen; targetIndex++) {
// If the current characters in both strings are equal
int cost = source.charAt(srcIndex - 1) == target.charAt(targetIndex - 1) ? 0 : 1;
@@ -535,15 +504,13 @@ else if (target == null || EMPTY.equals(target))
// We don't want to do the next series of calculations on
// the first pass because we would get an index out of bounds
// exception.
- if (srcIndex == 1 || targetIndex == 1)
- {
+ if (srcIndex == 1 || targetIndex == 1) {
continue;
}
// transposition check (if the current and previous
// character are switched around (e.g.: t[se]t and t[es]t)...
- if (source.charAt(srcIndex - 1) == target.charAt(targetIndex - 2) && source.charAt(srcIndex - 2) == target.charAt(targetIndex - 1))
- {
+ if (source.charAt(srcIndex - 1) == target.charAt(targetIndex - 2) && source.charAt(srcIndex - 2) == target.charAt(targetIndex - 1)) {
// What's the minimum cost between the current distance
// and a transposition.
distanceMatrix[srcIndex][targetIndex] = (int) MathUtilities.minimum(
@@ -564,22 +531,19 @@ else if (target == null || EMPTY.equals(target))
* @param maxLen maximum number of characters
* @return String of alphabetical characters, with the first character uppercase (Proper case strings).
*/
- public static String getRandomString(Random random, int minLen, int maxLen)
- {
+ public static String getRandomString(Random random, int minLen, int maxLen) {
StringBuilder s = new StringBuilder();
- final int len = minLen + random.nextInt(maxLen - minLen + 1);
+ int len = minLen + random.nextInt(maxLen - minLen + 1);
- for (int i=0; i < len; i++)
- {
+ for (int i = 0; i < len; i++) {
s.append(getRandomChar(random, i == 0));
}
return s.toString();
}
- public static String getRandomChar(Random random, boolean upper)
- {
+ public static String getRandomChar(Random random, boolean upper) {
int r = random.nextInt(26);
- return upper ? EMPTY + (char)((int)'A' + r) : EMPTY + (char)((int)'a' + r);
+ return upper ? EMPTY + (char) ((int) 'A' + r) : EMPTY + (char) ((int) 'a' + r);
}
/**
@@ -591,14 +555,11 @@ public static String getRandomChar(Random random, boolean upper)
* @param s string to encode into bytes
* @param encoding encoding to use
*/
- public static byte[] getBytes(String s, String encoding)
- {
- try
- {
+ public static byte[] getBytes(String s, String encoding) {
+ try {
return s == null ? null : s.getBytes(encoding);
}
- catch (UnsupportedEncodingException e)
- {
+ catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(String.format("Encoding (%s) is not supported by your JVM", encoding), e);
}
}
@@ -611,18 +572,16 @@ public static byte[] getBytes(String s, String encoding)
*
* @param bytes bytes to encode into a string
*/
- public static String createUtf8String(byte[] bytes)
- {
+ public static String createUtf8String(byte[] bytes) {
return createString(bytes, "UTF-8");
}
/**
* Convert a String into a byte[] encoded by UTF-8.
*
- * @param s string to encode into bytes
+ * @param s string to encode into bytes
*/
- public static byte[] getUTF8Bytes(String s)
- {
+ public static byte[] getUTF8Bytes(String s) {
return getBytes(s, "UTF-8");
}
@@ -635,14 +594,11 @@ public static byte[] getUTF8Bytes(String s)
* @param bytes bytes to encode into a string
* @param encoding encoding to use
*/
- public static String createString(byte[] bytes, String encoding)
- {
- try
- {
+ public static String createString(byte[] bytes, String encoding) {
+ try {
return bytes == null ? null : new String(bytes, encoding);
}
- catch (UnsupportedEncodingException e)
- {
+ catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(String.format("Encoding (%s) is not supported by your JVM", encoding), e);
}
}
@@ -650,30 +606,27 @@ public static String createString(byte[] bytes, String encoding)
/**
* Convert a byte[] into a UTF-8 encoded String.
*
- * @param bytes bytes to encode into a string
+ * @param bytes bytes to encode into a string
*/
- public static String createUTF8String(byte[] bytes)
- {
+ public static String createUTF8String(byte[] bytes) {
return createString(bytes, "UTF-8");
}
/**
* Get the hashCode of a String, insensitive to case, without any new Strings
* being created on the heap.
+ *
* @param s String input
* @return int hashCode of input String insensitive to case
*/
- public static int hashCodeIgnoreCase(String s)
- {
- if (s == null)
- {
+ public static int hashCodeIgnoreCase(String s) {
+ if (s == null) {
return 0;
}
- final int len = s.length();
+ int len = s.length();
int hash = 0;
- for (int i = 0; i < len; i++)
- {
- hash = 31 * hash + Character.toLowerCase((int)s.charAt(i));
+ for (int i = 0; i < len; i++) {
+ hash = 31 * hash + Character.toLowerCase((int) s.charAt(i));
}
return hash;
}
@@ -686,15 +639,16 @@ public static int hashCodeIgnoreCase(String s)
* The String is trimmed using {@link String#trim()}.
* Trim removes start and end characters <= 32.
*
- * @param str the String to be trimmed, may be null
+ * @param str the String to be trimmed, may be null
* @return the trimmed string, {@code null} if null String input
*/
- public static String trim(final String str) {
+ public static String trim(String str) {
return str == null ? null : str.trim();
}
/**
* Trims a string, its null safe and null will return empty string here..
+ *
* @param value string input
* @return String trimmed string, if value was null this will be empty
*/
@@ -704,17 +658,19 @@ public static String trimToEmpty(String value) {
/**
* Trims a string, If the string trims to empty then we return null.
+ *
* @param value string input
* @return String, trimmed from value. If the value was empty we return null.
*/
public static String trimToNull(String value) {
- final String ts = trim(value);
+ String ts = trim(value);
return isEmpty(ts) ? null : ts;
}
/**
* Trims a string, If the string trims to empty then we return the default.
- * @param value string input
+ *
+ * @param value string input
* @param defaultValue value to return on empty or null
* @return trimmed string, or defaultValue when null or empty
*/
diff --git a/src/test/java/com/cedarsoftware/util/TestStringUtilities.java b/src/test/java/com/cedarsoftware/util/TestStringUtilities.java
index 7bd2c0a03..37a5e493a 100644
--- a/src/test/java/com/cedarsoftware/util/TestStringUtilities.java
+++ b/src/test/java/com/cedarsoftware/util/TestStringUtilities.java
@@ -1,22 +1,18 @@
package com.cedarsoftware.util;
+import javax.swing.text.Segment;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
-import java.nio.ByteBuffer;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Stream;
-import com.cedarsoftware.util.convert.CommonValues;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.NullAndEmptySource;
-import org.mockito.internal.util.StringUtil;
-
-import javax.swing.text.Segment;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -80,28 +76,7 @@ void testIsEmpty_whenNullOrEmpty_returnsTrue(String s)
{
assertTrue(StringUtilities.isEmpty(s));
}
-
- @ParameterizedTest
- @MethodSource("stringsWithAllWhitespace")
- void testIsNotEmpty_whenStringHasOnlyWhitespace_returnsFalse(String s)
- {
- assertFalse(StringUtilities.isNotEmpty(s));
- }
-
- @ParameterizedTest
- @MethodSource("stringsWithContentOtherThanWhitespace")
- void testIsNotEmpty_whenStringHasContent_returnsTrue(String s)
- {
- assertTrue(StringUtilities.isNotEmpty(s));
- }
-
- @ParameterizedTest
- @NullAndEmptySource
- void testIsNotEmpty_whenNullOrEmpty_returnsFalse(String s)
- {
- assertFalse(StringUtilities.isNotEmpty(s));
- }
-
+
@ParameterizedTest
@MethodSource("stringsWithAllWhitespace")
void testIsWhiteSpace_whenStringHasWhitespace_returnsTrue(String s)
@@ -144,27 +119,7 @@ void testHasContent_whenNullOrEmpty_returnsFalse(String s)
{
assertFalse(StringUtilities.hasContent(s));
}
-
- @ParameterizedTest
- @MethodSource("stringsWithAllWhitespace")
- void testIsNotWhitespace_whenStringHasWhitespace_returnsFalse(String s)
- {
- assertFalse(StringUtilities.isNotWhitespace(s));
- }
-
- @ParameterizedTest
- @MethodSource("stringsWithContentOtherThanWhitespace")
- void testIsNotWhitespace_whenStringHasContent_returnsTrue(String s)
- {
- assertTrue(StringUtilities.isNotWhitespace(s));
- }
-
- @ParameterizedTest
- @NullAndEmptySource
- void testIsNotWhitespace_whenNullOrEmpty_returnsFalse(String s)
- {
- assertFalse(StringUtilities.isNotWhitespace(s));
- }
+
@Test
public void testIsEmpty()
{
diff --git a/src/test/java/com/cedarsoftware/util/convert/ConverterEverythingTest.java b/src/test/java/com/cedarsoftware/util/convert/ConverterEverythingTest.java
index 8e873933b..4f21e8398 100644
--- a/src/test/java/com/cedarsoftware/util/convert/ConverterEverythingTest.java
+++ b/src/test/java/com/cedarsoftware/util/convert/ConverterEverythingTest.java
@@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
+import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -40,14 +41,14 @@
import java.util.stream.Stream;
import com.cedarsoftware.util.ClassUtilities;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static com.cedarsoftware.util.MapUtilities.mapOf;
-import static com.cedarsoftware.util.convert.Converter.getShortName;
import static com.cedarsoftware.util.convert.Converter.pair;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -82,6 +83,7 @@ public ZoneId getZoneId() {
}
};
private static final Map, Class>>, Object[][]> TEST_DB = new ConcurrentHashMap<>(500, .8f);
+ private static final Map, Class>>, Boolean> STAT_DB = new ConcurrentHashMap<>(500, .8f);
static {
// Useful values for input
@@ -124,25 +126,25 @@ private static void loadAtomicLongTests() {
{null, null}
});
TEST_DB.put(pair(Instant.class, AtomicLong.class), new Object[][]{
- { Instant.parse("0000-01-01T00:00:00Z"), new AtomicLong(-62167219200000L), true},
- { Instant.parse("0000-01-01T00:00:00.001Z"), new AtomicLong(-62167219199999L), true},
- { Instant.parse("1969-12-31T23:59:59Z"), new AtomicLong(-1000L), true},
- { Instant.parse("1969-12-31T23:59:59.999Z"), new AtomicLong(-1L), true},
- { Instant.parse("1970-01-01T00:00:00Z"), new AtomicLong(0L), true},
- { Instant.parse("1970-01-01T00:00:00.001Z"), new AtomicLong(1L), true},
- { Instant.parse("1970-01-01T00:00:00.999Z"), new AtomicLong(999L), true},
+ {Instant.parse("0000-01-01T00:00:00Z"), new AtomicLong(-62167219200000L), true},
+ {Instant.parse("0000-01-01T00:00:00.001Z"), new AtomicLong(-62167219199999L), true},
+ {Instant.parse("1969-12-31T23:59:59Z"), new AtomicLong(-1000L), true},
+ {Instant.parse("1969-12-31T23:59:59.999Z"), new AtomicLong(-1L), true},
+ {Instant.parse("1970-01-01T00:00:00Z"), new AtomicLong(0L), true},
+ {Instant.parse("1970-01-01T00:00:00.001Z"), new AtomicLong(1L), true},
+ {Instant.parse("1970-01-01T00:00:00.999Z"), new AtomicLong(999L), true},
});
TEST_DB.put(pair(Duration.class, AtomicLong.class), new Object[][]{
- { Duration.ofMillis(Long.MIN_VALUE / 2), new AtomicLong(Long.MIN_VALUE / 2), true },
- { Duration.ofMillis(Integer.MIN_VALUE), new AtomicLong(Integer.MIN_VALUE), true },
- { Duration.ofMillis(-1), new AtomicLong(-1), true },
- { Duration.ofMillis(0), new AtomicLong(0), true },
- { Duration.ofMillis(1), new AtomicLong(1), true },
- { Duration.ofMillis(Integer.MAX_VALUE), new AtomicLong(Integer.MAX_VALUE), true },
- { Duration.ofMillis(Long.MAX_VALUE / 2), new AtomicLong(Long.MAX_VALUE / 2), true },
+ {Duration.ofMillis(Long.MIN_VALUE / 2), new AtomicLong(Long.MIN_VALUE / 2), true},
+ {Duration.ofMillis(Integer.MIN_VALUE), new AtomicLong(Integer.MIN_VALUE), true},
+ {Duration.ofMillis(-1), new AtomicLong(-1), true},
+ {Duration.ofMillis(0), new AtomicLong(0), true},
+ {Duration.ofMillis(1), new AtomicLong(1), true},
+ {Duration.ofMillis(Integer.MAX_VALUE), new AtomicLong(Integer.MAX_VALUE), true},
+ {Duration.ofMillis(Long.MAX_VALUE / 2), new AtomicLong(Long.MAX_VALUE / 2), true},
});
}
-
+
/**
* String
*/
@@ -459,33 +461,33 @@ private static void loadZoneOffsetTests() {
*/
private static void loadZoneDateTimeTests() {
TEST_DB.put(pair(Void.class, ZonedDateTime.class), new Object[][]{
- { null, null },
+ {null, null},
});
TEST_DB.put(pair(ZonedDateTime.class, ZonedDateTime.class), new Object[][]{
- { ZonedDateTime.parse("1970-01-01T00:00:00.000000000Z").withZoneSameInstant(TOKYO_Z), ZonedDateTime.parse("1970-01-01T00:00:00.000000000Z").withZoneSameInstant(TOKYO_Z) },
+ {ZonedDateTime.parse("1970-01-01T00:00:00.000000000Z").withZoneSameInstant(TOKYO_Z), ZonedDateTime.parse("1970-01-01T00:00:00.000000000Z").withZoneSameInstant(TOKYO_Z)},
});
TEST_DB.put(pair(Double.class, ZonedDateTime.class), new Object[][]{
- { -62167219200.0, ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
- { -0.000000001, ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z)}, // IEEE-754 limit prevents reverse test
- { 0d, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
- { 0.000000001, ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
- { 86400d, ZonedDateTime.parse("1970-01-02T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
- { 86400.000000001, ZonedDateTime.parse("1970-01-02T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
+ {-62167219200.0, ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
+ {-0.000000001, ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z)}, // IEEE-754 limit prevents reverse test
+ {0d, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
+ {0.000000001, ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
+ {86400d, ZonedDateTime.parse("1970-01-02T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
+ {86400.000000001, ZonedDateTime.parse("1970-01-02T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
});
TEST_DB.put(pair(BigInteger.class, ZonedDateTime.class), new Object[][]{
- { new BigInteger("-62167219200000000000"), ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true },
- { new BigInteger("-62167219199999999999"), ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true },
- { new BigInteger("-1"), ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z), true },
- { BigInteger.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true },
- { new BigInteger("1"), ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true },
+ {new BigInteger("-62167219200000000000"), ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
+ {new BigInteger("-62167219199999999999"), ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
+ {new BigInteger("-1"), ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z), true},
+ {BigInteger.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
+ {new BigInteger("1"), ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
});
TEST_DB.put(pair(BigDecimal.class, ZonedDateTime.class), new Object[][]{
- { new BigDecimal("-62167219200"), ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true },
- { new BigDecimal("-0.000000001"), ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z), true},
- { BigDecimal.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
- { new BigDecimal("0.000000001"), ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
- { BigDecimal.valueOf(86400), ZonedDateTime.parse("1970-01-02T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
- { new BigDecimal("86400.000000001"), ZonedDateTime.parse("1970-01-02T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
+ {new BigDecimal("-62167219200"), ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
+ {new BigDecimal("-0.000000001"), ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z), true},
+ {BigDecimal.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
+ {new BigDecimal("0.000000001"), ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
+ {BigDecimal.valueOf(86400), ZonedDateTime.parse("1970-01-02T00:00:00Z").withZoneSameInstant(TOKYO_Z), true},
+ {new BigDecimal("86400.000000001"), ZonedDateTime.parse("1970-01-02T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z), true},
});
}
@@ -493,34 +495,23 @@ private static void loadZoneDateTimeTests() {
* LocalDateTime
*/
private static void loadLocalDateTimeTests() {
- TEST_DB.put(pair(Void.class, LocalDateTime.class), new Object[][] {
- { null, null }
- });
- TEST_DB.put(pair(LocalDateTime.class, LocalDateTime.class), new Object[][] {
- { LocalDateTime.of(1970, 1, 1, 0,0), LocalDateTime.of(1970, 1, 1, 0,0), true }
- });
- TEST_DB.put(pair(Double.class, LocalDateTime.class), new Object[][] {
- { -0.000000001, LocalDateTime.parse("1969-12-31T23:59:59.999999999").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime() }, // IEEE-754 prevents perfect symmetry
- { 0d, LocalDateTime.parse("1970-01-01T00:00:00").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- { 0.000000001, LocalDateTime.parse("1970-01-01T00:00:00.000000001").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- });
- TEST_DB.put(pair(BigInteger.class, LocalDateTime.class), new Object[][]{
- { new BigInteger("-62167252739000000000"), ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), true },
- { new BigInteger("-62167252738999999999"), ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), true },
- { new BigInteger("-118800000000000"), ZonedDateTime.parse("1969-12-31T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), true },
- { new BigInteger("-118799999999999"), ZonedDateTime.parse("1969-12-31T00:00:00.000000001Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), true },
- { new BigInteger("-32400000000001"), ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), true },
- { new BigInteger("-32400000000000"), ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), true },
- { new BigInteger("-1"), ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- { BigInteger.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- { new BigInteger("1"), ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- });
- TEST_DB.put(pair(BigDecimal.class, LocalDateTime.class), new Object[][] {
- { new BigDecimal("-62167219200"), LocalDateTime.parse("0000-01-01T00:00:00").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- { new BigDecimal("-62167219199.999999999"), LocalDateTime.parse("0000-01-01T00:00:00.000000001").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- { new BigDecimal("-0.000000001"), LocalDateTime.parse("1969-12-31T23:59:59.999999999").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- { BigDecimal.ZERO, LocalDateTime.parse("1970-01-01T00:00:00").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
- { new BigDecimal("0.000000001"), LocalDateTime.parse("1970-01-01T00:00:00.000000001").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true },
+ TEST_DB.put(pair(Void.class, LocalDateTime.class), new Object[][]{
+ {null, null}
+ });
+ TEST_DB.put(pair(LocalDateTime.class, LocalDateTime.class), new Object[][]{
+ {LocalDateTime.of(1970, 1, 1, 0, 0), LocalDateTime.of(1970, 1, 1, 0, 0), true}
+ });
+ TEST_DB.put(pair(Double.class, LocalDateTime.class), new Object[][]{
+ {-0.000000001, LocalDateTime.parse("1969-12-31T23:59:59.999999999").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime()}, // IEEE-754 prevents perfect symmetry
+ {0d, LocalDateTime.parse("1970-01-01T00:00:00").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true},
+ {0.000000001, LocalDateTime.parse("1970-01-01T00:00:00.000000001").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true},
+ });
+ TEST_DB.put(pair(BigDecimal.class, LocalDateTime.class), new Object[][]{
+ {new BigDecimal("-62167219200"), LocalDateTime.parse("0000-01-01T00:00:00").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true},
+ {new BigDecimal("-62167219199.999999999"), LocalDateTime.parse("0000-01-01T00:00:00.000000001").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true},
+ {new BigDecimal("-0.000000001"), LocalDateTime.parse("1969-12-31T23:59:59.999999999").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true},
+ {BigDecimal.ZERO, LocalDateTime.parse("1970-01-01T00:00:00").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true},
+ {new BigDecimal("0.000000001"), LocalDateTime.parse("1970-01-01T00:00:00.000000001").atZone(ZoneId.of("UTC")).withZoneSameInstant(TOKYO_Z).toLocalDateTime(), true},
});
}
@@ -528,38 +519,33 @@ private static void loadLocalDateTimeTests() {
* LocalDate
*/
private static void loadLocalDateTests() {
- TEST_DB.put(pair(Void.class, LocalDate.class), new Object[][] {
- { null, null }
- });
- TEST_DB.put(pair(LocalDate.class, LocalDate.class), new Object[][] {
- { LocalDate.parse("1970-01-01"), LocalDate.parse("1970-01-01"), true }
- });
- TEST_DB.put(pair(Double.class, LocalDate.class), new Object[][] { // options timezone is factored in (86,400 seconds per day)
- { -118800d, LocalDate.parse("1969-12-31"), true },
- { -32400d, LocalDate.parse("1970-01-01"), true },
- { 0d, LocalDate.parse("1970-01-01") }, // Showing that there is a wide range of numbers that will convert to this date
- { 53999.999, LocalDate.parse("1970-01-01") }, // Showing that there is a wide range of numbers that will convert to this date
- { 54000d, LocalDate.parse("1970-01-02"), true },
- });
- TEST_DB.put(pair(BigInteger.class, LocalDate.class), new Object[][] { // options timezone is factored in (86,400 seconds per day)
- { new BigInteger("-62167252739000000000"), LocalDate.parse("0000-01-01"), true },
- { new BigInteger("-62167252739000000000"), ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), true },
- { new BigInteger("-118800000000000"), LocalDate.parse("1969-12-31"), true },
- // These 4 are all in the same date range
- { new BigInteger("-32400000000000"), LocalDate.parse("1970-01-01"), true },
- { BigInteger.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate() },
- { new BigInteger("53999999000000"), LocalDate.parse("1970-01-01") },
- { new BigInteger("54000000000000"), LocalDate.parse("1970-01-02"), true },
- });
- TEST_DB.put(pair(BigDecimal.class, LocalDate.class), new Object[][] { // options timezone is factored in (86,400 seconds per day)
- { new BigDecimal("-62167219200"), LocalDate.parse("0000-01-01") },
- { new BigDecimal("-62167219200"), ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate() },
- { new BigDecimal("-118800"), LocalDate.parse("1969-12-31"), true },
+ TEST_DB.put(pair(Void.class, LocalDate.class), new Object[][]{
+ {null, null}
+ });
+ TEST_DB.put(pair(LocalDate.class, LocalDate.class), new Object[][]{
+ {LocalDate.parse("1970-01-01"), LocalDate.parse("1970-01-01"), true}
+ });
+ TEST_DB.put(pair(Double.class, LocalDate.class), new Object[][]{ // options timezone is factored in (86,400 seconds per day)
+ {-118800d, LocalDate.parse("1969-12-31"), true},
+ {-32400d, LocalDate.parse("1970-01-01"), true},
+ {0d, LocalDate.parse("1970-01-01")}, // Showing that there is a wide range of numbers that will convert to this date
+ {53999.999, LocalDate.parse("1970-01-01")}, // Showing that there is a wide range of numbers that will convert to this date
+ {54000d, LocalDate.parse("1970-01-02"), true},
+ });
+ TEST_DB.put(pair(BigInteger.class, LocalDate.class), new Object[][]{ // options timezone is factored in (86,400 seconds per day)
+ // These are all in the same date range
+ {BigInteger.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate() },
+ {new BigInteger("53999999000000"), LocalDate.parse("1970-01-01")},
+ });
+ TEST_DB.put(pair(BigDecimal.class, LocalDate.class), new Object[][]{ // options timezone is factored in (86,400 seconds per day)
+ {new BigDecimal("-62167219200"), LocalDate.parse("0000-01-01")},
+ {new BigDecimal("-62167219200"), ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate()},
+ {new BigDecimal("-118800"), LocalDate.parse("1969-12-31"), true},
// These 4 are all in the same date range
- { new BigDecimal("-32400"), LocalDate.parse("1970-01-01"), true },
- { BigDecimal.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate() },
- { new BigDecimal("53999.999"), LocalDate.parse("1970-01-01") },
- { new BigDecimal("54000"), LocalDate.parse("1970-01-02"), true },
+ {new BigDecimal("-32400"), LocalDate.parse("1970-01-01"), true},
+ {BigDecimal.ZERO, ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate()},
+ {new BigDecimal("53999.999"), LocalDate.parse("1970-01-01")},
+ {new BigDecimal("54000"), LocalDate.parse("1970-01-02"), true},
});
}
@@ -568,66 +554,66 @@ private static void loadLocalDateTests() {
*/
private static void loadTimestampTests(long now) {
TEST_DB.put(pair(Void.class, Timestamp.class), new Object[][]{
- { null, null },
+ {null, null},
});
// No identity test - Timestamp is mutable
TEST_DB.put(pair(Double.class, Timestamp.class), new Object[][]{
- { -0.000000001, Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z"))}, // IEEE-754 limit prevents reverse test
- { 0d, Timestamp.from(Instant.parse("1970-01-01T00:00:00Z")), true},
- { 0.000000001, Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), true},
- { (double) now, new Timestamp((long)(now * 1000d)), true},
+ {-0.000000001, Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z"))}, // IEEE-754 limit prevents reverse test
+ {0d, Timestamp.from(Instant.parse("1970-01-01T00:00:00Z")), true},
+ {0.000000001, Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), true},
+ {(double) now, new Timestamp((long) (now * 1000d)), true},
});
TEST_DB.put(pair(BigInteger.class, Timestamp.class), new Object[][]{
- { new BigInteger("-62167219200000000000"), Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000000Z")), true },
- { new BigInteger("-62131377719000000000"), Timestamp.from(Instant.parse("0001-02-18T19:58:01.000000000Z")), true },
- { BigInteger.valueOf(-1000000000), Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000000Z")), true },
- { BigInteger.valueOf(-999999999), Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000001Z")), true },
- { BigInteger.valueOf(-900000000), Timestamp.from(Instant.parse("1969-12-31T23:59:59.100000000Z")), true },
- { BigInteger.valueOf(-100000000), Timestamp.from(Instant.parse("1969-12-31T23:59:59.900000000Z")), true },
- { BigInteger.valueOf(-1), Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), true },
- { BigInteger.ZERO, Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), true },
- { BigInteger.valueOf(1), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), true },
- { BigInteger.valueOf(100000000), Timestamp.from(Instant.parse("1970-01-01T00:00:00.100000000Z")), true },
- { BigInteger.valueOf(900000000), Timestamp.from(Instant.parse("1970-01-01T00:00:00.900000000Z")), true },
- { BigInteger.valueOf(999999999), Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), true },
- { BigInteger.valueOf(1000000000), Timestamp.from(Instant.parse("1970-01-01T00:00:01.000000000Z")), true },
- { new BigInteger("253374983881000000000"), Timestamp.from(Instant.parse("9999-02-18T19:58:01.000000000Z")), true },
- });
- TEST_DB.put(pair(BigDecimal.class, Timestamp.class), new Object[][] {
- { new BigDecimal("-62167219200"), Timestamp.from(Instant.parse("0000-01-01T00:00:00Z")), true },
- { new BigDecimal("-62167219199.999999999"), Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000001Z")), true },
- { new BigDecimal("-1.000000001"), Timestamp.from(Instant.parse("1969-12-31T23:59:58.999999999Z")), true },
- { new BigDecimal("-1"), Timestamp.from(Instant.parse("1969-12-31T23:59:59Z")), true },
- { new BigDecimal("-0.00000001"), Timestamp.from(Instant.parse("1969-12-31T23:59:59.99999999Z")), true },
- { new BigDecimal("-0.000000001"), Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), true },
- { BigDecimal.ZERO, Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), true },
- { new BigDecimal("0.000000001"), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), true },
- { new BigDecimal(".999999999"), Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), true },
- { new BigDecimal("1"), Timestamp.from(Instant.parse("1970-01-01T00:00:01Z")), true },
- });
- TEST_DB.put(pair(Duration.class, Timestamp.class), new Object[][] {
- { Duration.ofSeconds(-62167219200L), Timestamp.from(Instant.parse("0000-01-01T00:00:00Z")), true},
- { Duration.ofSeconds(-62167219200L, 1), Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000001Z")), true},
- { Duration.ofNanos(-1000000001), Timestamp.from(Instant.parse("1969-12-31T23:59:58.999999999Z")), true},
- { Duration.ofNanos(-1000000000), Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000000Z")), true},
- { Duration.ofNanos(-999999999), Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000001Z")), true},
- { Duration.ofNanos(-1), Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), true},
- { Duration.ofNanos(0), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), true},
- { Duration.ofNanos(1), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), true},
- { Duration.ofNanos(999999999), Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), true},
- { Duration.ofNanos(1000000000), Timestamp.from(Instant.parse("1970-01-01T00:00:01.000000000Z")), true},
- { Duration.ofNanos(1000000001), Timestamp.from(Instant.parse("1970-01-01T00:00:01.000000001Z")), true},
- { Duration.ofNanos(686629800000000001L), Timestamp.from(Instant.parse("1991-10-05T02:30:00.000000001Z")), true },
- { Duration.ofNanos(1199145600000000001L), Timestamp.from(Instant.parse("2008-01-01T00:00:00.000000001Z")), true },
- { Duration.ofNanos(1708255140987654321L), Timestamp.from(Instant.parse("2024-02-18T11:19:00.987654321Z")), true },
- { Duration.ofNanos(2682374400000000001L), Timestamp.from(Instant.parse("2055-01-01T00:00:00.000000001Z")), true },
+ {new BigInteger("-62167219200000000000"), Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000000Z")), true},
+ {new BigInteger("-62131377719000000000"), Timestamp.from(Instant.parse("0001-02-18T19:58:01.000000000Z")), true},
+ {BigInteger.valueOf(-1000000000), Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000000Z")), true},
+ {BigInteger.valueOf(-999999999), Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000001Z")), true},
+ {BigInteger.valueOf(-900000000), Timestamp.from(Instant.parse("1969-12-31T23:59:59.100000000Z")), true},
+ {BigInteger.valueOf(-100000000), Timestamp.from(Instant.parse("1969-12-31T23:59:59.900000000Z")), true},
+ {BigInteger.valueOf(-1), Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), true},
+ {BigInteger.ZERO, Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), true},
+ {BigInteger.valueOf(1), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), true},
+ {BigInteger.valueOf(100000000), Timestamp.from(Instant.parse("1970-01-01T00:00:00.100000000Z")), true},
+ {BigInteger.valueOf(900000000), Timestamp.from(Instant.parse("1970-01-01T00:00:00.900000000Z")), true},
+ {BigInteger.valueOf(999999999), Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), true},
+ {BigInteger.valueOf(1000000000), Timestamp.from(Instant.parse("1970-01-01T00:00:01.000000000Z")), true},
+ {new BigInteger("253374983881000000000"), Timestamp.from(Instant.parse("9999-02-18T19:58:01.000000000Z")), true},
+ });
+ TEST_DB.put(pair(BigDecimal.class, Timestamp.class), new Object[][]{
+ {new BigDecimal("-62167219200"), Timestamp.from(Instant.parse("0000-01-01T00:00:00Z")), true},
+ {new BigDecimal("-62167219199.999999999"), Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000001Z")), true},
+ {new BigDecimal("-1.000000001"), Timestamp.from(Instant.parse("1969-12-31T23:59:58.999999999Z")), true},
+ {new BigDecimal("-1"), Timestamp.from(Instant.parse("1969-12-31T23:59:59Z")), true},
+ {new BigDecimal("-0.00000001"), Timestamp.from(Instant.parse("1969-12-31T23:59:59.99999999Z")), true},
+ {new BigDecimal("-0.000000001"), Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), true},
+ {BigDecimal.ZERO, Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), true},
+ {new BigDecimal("0.000000001"), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), true},
+ {new BigDecimal(".999999999"), Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), true},
+ {new BigDecimal("1"), Timestamp.from(Instant.parse("1970-01-01T00:00:01Z")), true},
+ });
+ TEST_DB.put(pair(Duration.class, Timestamp.class), new Object[][]{
+ {Duration.ofSeconds(-62167219200L), Timestamp.from(Instant.parse("0000-01-01T00:00:00Z")), true},
+ {Duration.ofSeconds(-62167219200L, 1), Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000001Z")), true},
+ {Duration.ofNanos(-1000000001), Timestamp.from(Instant.parse("1969-12-31T23:59:58.999999999Z")), true},
+ {Duration.ofNanos(-1000000000), Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000000Z")), true},
+ {Duration.ofNanos(-999999999), Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000001Z")), true},
+ {Duration.ofNanos(-1), Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), true},
+ {Duration.ofNanos(0), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), true},
+ {Duration.ofNanos(1), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), true},
+ {Duration.ofNanos(999999999), Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), true},
+ {Duration.ofNanos(1000000000), Timestamp.from(Instant.parse("1970-01-01T00:00:01.000000000Z")), true},
+ {Duration.ofNanos(1000000001), Timestamp.from(Instant.parse("1970-01-01T00:00:01.000000001Z")), true},
+ {Duration.ofNanos(686629800000000001L), Timestamp.from(Instant.parse("1991-10-05T02:30:00.000000001Z")), true},
+ {Duration.ofNanos(1199145600000000001L), Timestamp.from(Instant.parse("2008-01-01T00:00:00.000000001Z")), true},
+ {Duration.ofNanos(1708255140987654321L), Timestamp.from(Instant.parse("2024-02-18T11:19:00.987654321Z")), true},
+ {Duration.ofNanos(2682374400000000001L), Timestamp.from(Instant.parse("2055-01-01T00:00:00.000000001Z")), true},
});
// No symmetry checks - because an OffsetDateTime of "2024-02-18T06:31:55.987654321+00:00" and "2024-02-18T15:31:55.987654321+09:00" are equivalent but not equals. They both describe the same Instant.
TEST_DB.put(pair(OffsetDateTime.class, Timestamp.class), new Object[][]{
- {OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z"), Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")) },
- {OffsetDateTime.parse("1970-01-01T00:00:00.000000000Z"), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")) },
- {OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z"), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")) },
- {OffsetDateTime.parse("2024-02-18T06:31:55.987654321Z"), Timestamp.from(Instant.parse("2024-02-18T06:31:55.987654321Z")) },
+ {OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z"), Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z"))},
+ {OffsetDateTime.parse("1970-01-01T00:00:00.000000000Z"), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z"))},
+ {OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z"), Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z"))},
+ {OffsetDateTime.parse("2024-02-18T06:31:55.987654321Z"), Timestamp.from(Instant.parse("2024-02-18T06:31:55.987654321Z"))},
});
}
@@ -801,27 +787,27 @@ private static void loadMonthDayTests() {
*/
private static void loadOffsetDateTimeTests() {
ZoneOffset tokyoOffset = ZonedDateTime.now(TOKYO_Z).getOffset();
-
+
TEST_DB.put(pair(Void.class, OffsetDateTime.class), new Object[][]{
- { null, null }
+ {null, null}
});
TEST_DB.put(pair(OffsetDateTime.class, OffsetDateTime.class), new Object[][]{
- {OffsetDateTime.parse("2024-02-18T06:31:55.987654321Z"), OffsetDateTime.parse("2024-02-18T06:31:55.987654321Z"), true },
+ {OffsetDateTime.parse("2024-02-18T06:31:55.987654321Z"), OffsetDateTime.parse("2024-02-18T06:31:55.987654321Z"), true},
});
TEST_DB.put(pair(Double.class, OffsetDateTime.class), new Object[][]{
- {-0.000000001, OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z").withOffsetSameInstant(tokyoOffset) }, // IEEE-754 resolution prevents perfect symmetry (close)
- {0d, OffsetDateTime.parse("1970-01-01T00:00:00Z").withOffsetSameInstant(tokyoOffset), true },
- {0.000000001, OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z").withOffsetSameInstant(tokyoOffset), true },
+ {-0.000000001, OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z").withOffsetSameInstant(tokyoOffset)}, // IEEE-754 resolution prevents perfect symmetry (close)
+ {0d, OffsetDateTime.parse("1970-01-01T00:00:00Z").withOffsetSameInstant(tokyoOffset), true},
+ {0.000000001, OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z").withOffsetSameInstant(tokyoOffset), true},
});
TEST_DB.put(pair(BigInteger.class, OffsetDateTime.class), new Object[][]{
- { new BigInteger("-1"), OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z").withOffsetSameInstant(tokyoOffset) },
- { BigInteger.ZERO, OffsetDateTime.parse("1970-01-01T00:00:00Z").withOffsetSameInstant(tokyoOffset) },
- { new BigInteger("1"), OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z").withOffsetSameInstant(tokyoOffset) },
+ {new BigInteger("-1"), OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z").withOffsetSameInstant(tokyoOffset)},
+ {BigInteger.ZERO, OffsetDateTime.parse("1970-01-01T00:00:00Z").withOffsetSameInstant(tokyoOffset)},
+ {new BigInteger("1"), OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z").withOffsetSameInstant(tokyoOffset)},
});
TEST_DB.put(pair(BigDecimal.class, OffsetDateTime.class), new Object[][]{
- {new BigDecimal("-0.000000001"), OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z").withOffsetSameInstant(ZonedDateTime.now(TOKYO_Z).getOffset()) }, // IEEE-754 resolution prevents perfect symmetry (close)
- {BigDecimal.ZERO, OffsetDateTime.parse("1970-01-01T00:00:00Z").withOffsetSameInstant(ZonedDateTime.now(TOKYO_Z).getOffset()), true },
- {new BigDecimal(".000000001"), OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z").withOffsetSameInstant(ZonedDateTime.now(TOKYO_Z).getOffset()), true },
+ {new BigDecimal("-0.000000001"), OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z").withOffsetSameInstant(ZonedDateTime.now(TOKYO_Z).getOffset())}, // IEEE-754 resolution prevents perfect symmetry (close)
+ {BigDecimal.ZERO, OffsetDateTime.parse("1970-01-01T00:00:00Z").withOffsetSameInstant(ZonedDateTime.now(TOKYO_Z).getOffset()), true},
+ {new BigDecimal(".000000001"), OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z").withOffsetSameInstant(ZonedDateTime.now(TOKYO_Z).getOffset()), true},
});
}
@@ -830,7 +816,7 @@ private static void loadOffsetDateTimeTests() {
*/
private static void loadDurationTests() {
TEST_DB.put(pair(Void.class, Duration.class), new Object[][]{
- { null, null }
+ {null, null}
});
TEST_DB.put(pair(String.class, Duration.class), new Object[][]{
{"PT1S", Duration.ofSeconds(1), true},
@@ -840,54 +826,40 @@ private static void loadDurationTests() {
{"PT2H46M40S", Duration.ofSeconds(10000), true},
});
TEST_DB.put(pair(Long.class, Duration.class), new Object[][]{
- { Long.MIN_VALUE / 2, Duration.ofMillis(Long.MIN_VALUE / 2), true },
- { (long)Integer.MIN_VALUE, Duration.ofMillis(Integer.MIN_VALUE), true },
- { -1L, Duration.ofMillis(-1), true },
- { 0L, Duration.ofMillis(0), true },
- { 1L, Duration.ofMillis(1), true },
- { (long)Integer.MAX_VALUE, Duration.ofMillis(Integer.MAX_VALUE), true },
- { Long.MAX_VALUE / 2, Duration.ofMillis(Long.MAX_VALUE / 2), true },
- });
- TEST_DB.put(pair(AtomicLong.class, Duration.class), new Object[][]{
- { new AtomicLong(Long.MIN_VALUE / 2), Duration.ofMillis(Long.MIN_VALUE / 2), true },
- { new AtomicLong(Integer.MIN_VALUE), Duration.ofMillis(Integer.MIN_VALUE), true },
- { new AtomicLong(-1), Duration.ofMillis(-1), true },
- { new AtomicLong(0), Duration.ofMillis(0), true },
- { new AtomicLong(1), Duration.ofMillis(1), true },
- { new AtomicLong(Integer.MAX_VALUE), Duration.ofMillis(Integer.MAX_VALUE), true },
- { new AtomicLong(Long.MAX_VALUE / 2), Duration.ofMillis(Long.MAX_VALUE / 2), true },
+ {Long.MIN_VALUE / 2, Duration.ofMillis(Long.MIN_VALUE / 2), true},
+ {(long) Integer.MIN_VALUE, Duration.ofMillis(Integer.MIN_VALUE), true},
+ {-1L, Duration.ofMillis(-1), true},
+ {0L, Duration.ofMillis(0), true},
+ {1L, Duration.ofMillis(1), true},
+ {(long) Integer.MAX_VALUE, Duration.ofMillis(Integer.MAX_VALUE), true},
+ {Long.MAX_VALUE / 2, Duration.ofMillis(Long.MAX_VALUE / 2), true},
});
TEST_DB.put(pair(Double.class, Duration.class), new Object[][]{
- {-0.000000001, Duration.ofNanos(-1) }, // IEEE 754 prevents reverse
- {0d, Duration.ofNanos(0), true},
- {0.000000001, Duration.ofNanos(1), true },
- {1d, Duration.ofSeconds(1), true},
- {10d, Duration.ofSeconds(10), true},
- {100d, Duration.ofSeconds(100), true},
- {3.000000006d, Duration.ofSeconds(3, 6) }, // IEEE 754 prevents reverse
- });
- TEST_DB.put(pair(BigInteger.class, Duration.class), new Object[][] {
- { BigInteger.valueOf(-1000000), Duration.ofNanos(-1000000), true },
- { BigInteger.valueOf(-1000), Duration.ofNanos(-1000), true },
- { BigInteger.valueOf(-1), Duration.ofNanos(-1), true },
- { BigInteger.ZERO, Duration.ofNanos(0), true },
- { BigInteger.valueOf(1), Duration.ofNanos(1), true },
- { BigInteger.valueOf(1000), Duration.ofNanos(1000), true },
- { BigInteger.valueOf(1000000), Duration.ofNanos(1000000), true },
- { BigInteger.valueOf(Integer.MAX_VALUE), Duration.ofNanos(Integer.MAX_VALUE), true },
- { BigInteger.valueOf(Integer.MIN_VALUE), Duration.ofNanos(Integer.MIN_VALUE), true },
- { BigInteger.valueOf(Long.MAX_VALUE), Duration.ofNanos(Long.MAX_VALUE), true },
- { BigInteger.valueOf(Long.MIN_VALUE), Duration.ofNanos(Long.MIN_VALUE), true },
+ {-0.000000001, Duration.ofNanos(-1)}, // IEEE 754 prevents reverse
+ {3.000000006d, Duration.ofSeconds(3, 6)}, // IEEE 754 prevents reverse
+ });
+ TEST_DB.put(pair(BigInteger.class, Duration.class), new Object[][]{
+ {BigInteger.valueOf(-1000000), Duration.ofNanos(-1000000), true},
+ {BigInteger.valueOf(-1000), Duration.ofNanos(-1000), true},
+ {BigInteger.valueOf(-1), Duration.ofNanos(-1), true},
+ {BigInteger.ZERO, Duration.ofNanos(0), true},
+ {BigInteger.valueOf(1), Duration.ofNanos(1), true},
+ {BigInteger.valueOf(1000), Duration.ofNanos(1000), true},
+ {BigInteger.valueOf(1000000), Duration.ofNanos(1000000), true},
+ {BigInteger.valueOf(Integer.MAX_VALUE), Duration.ofNanos(Integer.MAX_VALUE), true},
+ {BigInteger.valueOf(Integer.MIN_VALUE), Duration.ofNanos(Integer.MIN_VALUE), true},
+ {BigInteger.valueOf(Long.MAX_VALUE), Duration.ofNanos(Long.MAX_VALUE), true},
+ {BigInteger.valueOf(Long.MIN_VALUE), Duration.ofNanos(Long.MIN_VALUE), true},
});
TEST_DB.put(pair(BigDecimal.class, Duration.class), new Object[][]{
- {new BigDecimal("-0.000000001"), Duration.ofNanos(-1), true },
+ {new BigDecimal("-0.000000001"), Duration.ofNanos(-1), true},
{BigDecimal.ZERO, Duration.ofNanos(0), true},
- {new BigDecimal("0.000000001"), Duration.ofNanos(1), true },
+ {new BigDecimal("0.000000001"), Duration.ofNanos(1), true},
{new BigDecimal("100"), Duration.ofSeconds(100), true},
{new BigDecimal("1"), Duration.ofSeconds(1), true},
{new BigDecimal("100"), Duration.ofSeconds(100), true},
{new BigDecimal("100"), Duration.ofSeconds(100), true},
- {new BigDecimal("3.000000006"), Duration.ofSeconds(3, 6), true },
+ {new BigDecimal("3.000000006"), Duration.ofSeconds(3, 6), true},
});
}
@@ -896,31 +868,31 @@ private static void loadDurationTests() {
*/
private static void loadSqlDateTests() {
TEST_DB.put(pair(Void.class, java.sql.Date.class), new Object[][]{
- { null, null }
+ {null, null}
});
// No identity test for Date, as it is mutable
- TEST_DB.put(pair(Double.class, java.sql.Date.class), new Object[][] {
- { -62167219200.0, new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), true },
- { -62167219199.999, new java.sql.Date(Instant.parse("0000-01-01T00:00:00.001Z").toEpochMilli()), true },
- { -1.002d, new java.sql.Date(Instant.parse("1969-12-31T23:59:58.998Z").toEpochMilli()), true }, // IEEE754 resolution issue on -1.001 (-1.0009999999)
- { -1d, new java.sql.Date(Instant.parse("1969-12-31T23:59:59Z").toEpochMilli()), true },
- { -0.002, new java.sql.Date(Instant.parse("1969-12-31T23:59:59.998Z").toEpochMilli()), true },
- { -0.001, new java.sql.Date(Instant.parse("1969-12-31T23:59:59.999Z").toEpochMilli()), true },
- { 0d, new java.sql.Date(Instant.parse("1970-01-01T00:00:00.000000000Z").toEpochMilli()), true },
- { 0.001, new java.sql.Date(Instant.parse("1970-01-01T00:00:00.001Z").toEpochMilli()), true },
- { 0.999, new java.sql.Date(Instant.parse("1970-01-01T00:00:00.999Z").toEpochMilli()), true },
- { 1d, new java.sql.Date(Instant.parse("1970-01-01T00:00:01Z").toEpochMilli()), true },
- });
- TEST_DB.put(pair(BigDecimal.class, java.sql.Date.class), new Object[][] {
- { new BigDecimal("-62167219200"), new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), true },
- { new BigDecimal("-62167219199.999"), new java.sql.Date(Instant.parse("0000-01-01T00:00:00.001Z").toEpochMilli()), true },
- { new BigDecimal("-1.001"), new java.sql.Date(Instant.parse("1969-12-31T23:59:58.999Z").toEpochMilli()), true },
- { new BigDecimal("-1"), new java.sql.Date(Instant.parse("1969-12-31T23:59:59Z").toEpochMilli()), true },
- { new BigDecimal("-0.001"), new java.sql.Date(Instant.parse("1969-12-31T23:59:59.999Z").toEpochMilli()), true },
- { BigDecimal.ZERO, new java.sql.Date(Instant.parse("1970-01-01T00:00:00.000000000Z").toEpochMilli()), true },
- { new BigDecimal("0.001"), new java.sql.Date(Instant.parse("1970-01-01T00:00:00.001Z").toEpochMilli()), true },
- { new BigDecimal(".999"), new java.sql.Date(Instant.parse("1970-01-01T00:00:00.999Z").toEpochMilli()), true },
- { new BigDecimal("1"), new java.sql.Date(Instant.parse("1970-01-01T00:00:01Z").toEpochMilli()), true },
+ TEST_DB.put(pair(Double.class, java.sql.Date.class), new Object[][]{
+ {-62167219200.0, new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), true},
+ {-62167219199.999, new java.sql.Date(Instant.parse("0000-01-01T00:00:00.001Z").toEpochMilli()), true},
+ {-1.002d, new java.sql.Date(Instant.parse("1969-12-31T23:59:58.998Z").toEpochMilli()), true}, // IEEE754 resolution issue on -1.001 (-1.0009999999)
+ {-1d, new java.sql.Date(Instant.parse("1969-12-31T23:59:59Z").toEpochMilli()), true},
+ {-0.002, new java.sql.Date(Instant.parse("1969-12-31T23:59:59.998Z").toEpochMilli()), true},
+ {-0.001, new java.sql.Date(Instant.parse("1969-12-31T23:59:59.999Z").toEpochMilli()), true},
+ {0d, new java.sql.Date(Instant.parse("1970-01-01T00:00:00.000000000Z").toEpochMilli()), true},
+ {0.001, new java.sql.Date(Instant.parse("1970-01-01T00:00:00.001Z").toEpochMilli()), true},
+ {0.999, new java.sql.Date(Instant.parse("1970-01-01T00:00:00.999Z").toEpochMilli()), true},
+ {1d, new java.sql.Date(Instant.parse("1970-01-01T00:00:01Z").toEpochMilli()), true},
+ });
+ TEST_DB.put(pair(BigDecimal.class, java.sql.Date.class), new Object[][]{
+ {new BigDecimal("-62167219200"), new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), true},
+ {new BigDecimal("-62167219199.999"), new java.sql.Date(Instant.parse("0000-01-01T00:00:00.001Z").toEpochMilli()), true},
+ {new BigDecimal("-1.001"), new java.sql.Date(Instant.parse("1969-12-31T23:59:58.999Z").toEpochMilli()), true},
+ {new BigDecimal("-1"), new java.sql.Date(Instant.parse("1969-12-31T23:59:59Z").toEpochMilli()), true},
+ {new BigDecimal("-0.001"), new java.sql.Date(Instant.parse("1969-12-31T23:59:59.999Z").toEpochMilli()), true},
+ {BigDecimal.ZERO, new java.sql.Date(Instant.parse("1970-01-01T00:00:00.000000000Z").toEpochMilli()), true},
+ {new BigDecimal("0.001"), new java.sql.Date(Instant.parse("1970-01-01T00:00:00.001Z").toEpochMilli()), true},
+ {new BigDecimal(".999"), new java.sql.Date(Instant.parse("1970-01-01T00:00:00.999Z").toEpochMilli()), true},
+ {new BigDecimal("1"), new java.sql.Date(Instant.parse("1970-01-01T00:00:01Z").toEpochMilli()), true},
});
}
@@ -929,44 +901,9 @@ private static void loadSqlDateTests() {
*/
private static void loadDateTests() {
TEST_DB.put(pair(Void.class, Date.class), new Object[][]{
- { null, null }
+ {null, null}
});
// No identity test for Date, as it is mutable
- TEST_DB.put(pair(BigInteger.class, Date.class), new Object[][]{
- {new BigInteger("-62167219200000000000"), Date.from(Instant.parse("0000-01-01T00:00:00Z")), true},
- {new BigInteger("-62131377719000000000"), Date.from(Instant.parse("0001-02-18T19:58:01Z")), true},
- {BigInteger.valueOf(-1_000_000_000), Date.from(Instant.parse("1969-12-31T23:59:59Z")), true},
- {BigInteger.valueOf(-900_000_000), Date.from(Instant.parse("1969-12-31T23:59:59.1Z")), true},
- {BigInteger.valueOf(-100_000_000), Date.from(Instant.parse("1969-12-31T23:59:59.9Z")), true},
- {BigInteger.ZERO, Date.from(Instant.parse("1970-01-01T00:00:00Z")), true},
- {BigInteger.valueOf(100_000_000), Date.from(Instant.parse("1970-01-01T00:00:00.1Z")), true},
- {BigInteger.valueOf(900_000_000), Date.from(Instant.parse("1970-01-01T00:00:00.9Z")), true},
- {BigInteger.valueOf(1000_000_000), Date.from(Instant.parse("1970-01-01T00:00:01Z")), true},
- {new BigInteger("253374983881000000000"), Date.from(Instant.parse("9999-02-18T19:58:01Z")), true}
- });
- TEST_DB.put(pair(BigInteger.class, java.sql.Date.class), new Object[][]{
- {new BigInteger("-62167219200000000000"), new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), true},
- {new BigInteger("-62131377719000000000"), new java.sql.Date(Instant.parse("0001-02-18T19:58:01Z").toEpochMilli()), true},
- {BigInteger.valueOf(-1_000_000_000), new java.sql.Date(Instant.parse("1969-12-31T23:59:59Z").toEpochMilli()), true},
- {BigInteger.valueOf(-900_000_000), new java.sql.Date(Instant.parse("1969-12-31T23:59:59.1Z").toEpochMilli()), true},
- {BigInteger.valueOf(-100_000_000), new java.sql.Date(Instant.parse("1969-12-31T23:59:59.9Z").toEpochMilli()), true},
- {BigInteger.ZERO, new java.sql.Date(Instant.parse("1970-01-01T00:00:00Z").toEpochMilli()), true},
- {BigInteger.valueOf(100_000_000), new java.sql.Date(Instant.parse("1970-01-01T00:00:00.1Z").toEpochMilli()), true},
- {BigInteger.valueOf(900_000_000), new java.sql.Date(Instant.parse("1970-01-01T00:00:00.9Z").toEpochMilli()), true},
- {BigInteger.valueOf(1000_000_000), new java.sql.Date(Instant.parse("1970-01-01T00:00:01Z").toEpochMilli()), true},
- {new BigInteger("253374983881000000000"), new java.sql.Date(Instant.parse("9999-02-18T19:58:01Z").toEpochMilli()), true}
- });
- TEST_DB.put(pair(BigDecimal.class, Date.class), new Object[][] {
- { new BigDecimal("-62167219200"), Date.from(Instant.parse("0000-01-01T00:00:00Z")), true },
- { new BigDecimal("-62167219199.999"), Date.from(Instant.parse("0000-01-01T00:00:00.001Z")), true },
- { new BigDecimal("-1.001"), Date.from(Instant.parse("1969-12-31T23:59:58.999Z")), true },
- { new BigDecimal("-1"), Date.from(Instant.parse("1969-12-31T23:59:59Z")), true },
- { new BigDecimal("-0.001"), Date.from(Instant.parse("1969-12-31T23:59:59.999Z")), true },
- { BigDecimal.ZERO, Date.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), true },
- { new BigDecimal("0.001"), Date.from(Instant.parse("1970-01-01T00:00:00.001Z")), true },
- { new BigDecimal(".999"), Date.from(Instant.parse("1970-01-01T00:00:00.999Z")), true },
- { new BigDecimal("1"), Date.from(Instant.parse("1970-01-01T00:00:01Z")), true },
- });
}
/**
@@ -974,60 +911,22 @@ private static void loadDateTests() {
*/
private static void loadInstantTests() {
TEST_DB.put(pair(Void.class, Instant.class), new Object[][]{
- { null, null }
+ {null, null}
+ });
+ TEST_DB.put(pair(Instant.class, Instant.class), new Object[][]{
+ {Instant.parse("1996-12-24T00:00:00Z"), Instant.parse("1996-12-24T00:00:00Z")}
});
TEST_DB.put(pair(String.class, Instant.class), new Object[][]{
- { "", null},
- { " ", null},
- { "1980-01-01T00:00:00Z", Instant.parse("1980-01-01T00:00:00Z"), true},
- { "2024-12-31T23:59:59.999999999Z", Instant.parse("2024-12-31T23:59:59.999999999Z")},
- });
- TEST_DB.put(pair(Long.class, Instant.class), new Object[][]{
- {-62167219200000L, Instant.parse("0000-01-01T00:00:00Z"), true},
- {-62167219199999L, Instant.parse("0000-01-01T00:00:00.001Z"), true},
- {-1000L, Instant.parse("1969-12-31T23:59:59Z"), true},
- {-1L, Instant.parse("1969-12-31T23:59:59.999Z"), true},
- {0L, Instant.parse("1970-01-01T00:00:00Z"), true},
- {1L, Instant.parse("1970-01-01T00:00:00.001Z"), true},
- {999L, Instant.parse("1970-01-01T00:00:00.999Z"), true},
- });
- TEST_DB.put(pair(AtomicLong.class, Instant.class), new Object[][]{
- {new AtomicLong(-62167219200000L), Instant.parse("0000-01-01T00:00:00Z"), true},
- {new AtomicLong(-62167219199999L), Instant.parse("0000-01-01T00:00:00.001Z"), true},
- {new AtomicLong(-1000L), Instant.parse("1969-12-31T23:59:59Z"), true},
- {new AtomicLong(-1L), Instant.parse("1969-12-31T23:59:59.999Z"), true},
- {new AtomicLong(0L), Instant.parse("1970-01-01T00:00:00Z"), true},
- {new AtomicLong(1L), Instant.parse("1970-01-01T00:00:00.001Z"), true},
- {new AtomicLong(999L), Instant.parse("1970-01-01T00:00:00.999Z"), true},
+ {"", null},
+ {" ", null},
+ {"1980-01-01T00:00:00Z", Instant.parse("1980-01-01T00:00:00Z"), true},
+ {"2024-12-31T23:59:59.999999999Z", Instant.parse("2024-12-31T23:59:59.999999999Z"), true},
});
TEST_DB.put(pair(Double.class, Instant.class), new Object[][]{
- { -62167219200d, Instant.parse("0000-01-01T00:00:00Z"), true},
- { -0.000000001, Instant.parse("1969-12-31T23:59:59.999999999Z")}, // IEEE-754 precision not good enough for reverse
- { 0d, Instant.parse("1970-01-01T00:00:00Z"), true},
- { 0.000000001, Instant.parse("1970-01-01T00:00:00.000000001Z"), true},
- });
- TEST_DB.put(pair(BigInteger.class, Instant.class), new Object[][]{
- { new BigInteger("-62167219200000000000"), Instant.parse("0000-01-01T00:00:00.000000000Z"), true },
- { new BigInteger("-62167219199999999999"), Instant.parse("0000-01-01T00:00:00.000000001Z"), true },
- { BigInteger.valueOf(-1000000000), Instant.parse("1969-12-31T23:59:59.000000000Z"), true },
- { BigInteger.valueOf(-999999999), Instant.parse("1969-12-31T23:59:59.000000001Z"), true },
- { BigInteger.valueOf(-900000000), Instant.parse("1969-12-31T23:59:59.100000000Z"), true },
- { BigInteger.valueOf(-100000000), Instant.parse("1969-12-31T23:59:59.900000000Z"), true },
- { BigInteger.valueOf(-1), Instant.parse("1969-12-31T23:59:59.999999999Z"), true },
- { BigInteger.ZERO, Instant.parse("1970-01-01T00:00:00.000000000Z"), true },
- { BigInteger.valueOf(1), Instant.parse("1970-01-01T00:00:00.000000001Z"), true },
- { BigInteger.valueOf(100000000), Instant.parse("1970-01-01T00:00:00.100000000Z"), true },
- { BigInteger.valueOf(900000000), Instant.parse("1970-01-01T00:00:00.900000000Z"), true },
- { BigInteger.valueOf(999999999), Instant.parse("1970-01-01T00:00:00.999999999Z"), true },
- { BigInteger.valueOf(1000000000), Instant.parse("1970-01-01T00:00:01.000000000Z"), true },
- { new BigInteger("253374983881000000000"), Instant.parse("9999-02-18T19:58:01.000000000Z"), true },
- });
- TEST_DB.put(pair(BigDecimal.class, Instant.class), new Object[][]{
- { new BigDecimal("-62167219200"), Instant.parse("0000-01-01T00:00:00Z"), true},
- { new BigDecimal("-62167219199.999999999"), Instant.parse("0000-01-01T00:00:00.000000001Z"), true},
- { new BigDecimal("-0.000000001"), Instant.parse("1969-12-31T23:59:59.999999999Z"), true},
- { BigDecimal.ZERO, Instant.parse("1970-01-01T00:00:00Z"), true},
- { new BigDecimal("0.000000001"), Instant.parse("1970-01-01T00:00:00.000000001Z"), true},
+ {-62167219200d, Instant.parse("0000-01-01T00:00:00Z"), true},
+ {-0.000000001, Instant.parse("1969-12-31T23:59:59.999999999Z")}, // IEEE-754 precision not good enough for reverse
+ {0d, Instant.parse("1970-01-01T00:00:00Z"), true},
+ {0.000000001, Instant.parse("1970-01-01T00:00:00.000000001Z"), true},
});
}
@@ -1036,86 +935,79 @@ private static void loadInstantTests() {
*/
private static void loadBigDecimalTests() {
TEST_DB.put(pair(Void.class, BigDecimal.class), new Object[][]{
- { null, null }
+ {null, null}
});
TEST_DB.put(pair(String.class, BigDecimal.class), new Object[][]{
- { "3.1415926535897932384626433", new BigDecimal("3.1415926535897932384626433"), true}
- });
- TEST_DB.put(pair(Date.class, BigDecimal.class), new Object[][] {
- { Date.from(Instant.parse("0000-01-01T00:00:00Z")), new BigDecimal("-62167219200"), true },
- { Date.from(Instant.parse("0000-01-01T00:00:00.001Z")), new BigDecimal("-62167219199.999"), true },
- { Date.from(Instant.parse("1969-12-31T23:59:59.999Z")), new BigDecimal("-0.001"), true },
- { Date.from(Instant.parse("1970-01-01T00:00:00Z")), BigDecimal.ZERO, true },
- { Date.from(Instant.parse("1970-01-01T00:00:00.001Z")), new BigDecimal("0.001"), true },
- });
- TEST_DB.put(pair(java.sql.Date.class, BigDecimal.class), new Object[][] {
- { new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), new BigDecimal("-62167219200"), true },
- { new java.sql.Date(Instant.parse("0000-01-01T00:00:00.001Z").toEpochMilli()), new BigDecimal("-62167219199.999"), true },
- { new java.sql.Date(Instant.parse("1969-12-31T23:59:59.999Z").toEpochMilli()), new BigDecimal("-0.001"), true },
- { new java.sql.Date(Instant.parse("1970-01-01T00:00:00Z").toEpochMilli()), BigDecimal.ZERO, true },
- { new java.sql.Date(Instant.parse("1970-01-01T00:00:00.001Z").toEpochMilli()), new BigDecimal("0.001"), true },
- });
- TEST_DB.put(pair(Timestamp.class, BigDecimal.class), new Object[][] {
- { Timestamp.from(Instant.parse("0000-01-01T00:00:00Z")), new BigDecimal("-62167219200"), true },
- { Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000001Z")), new BigDecimal("-62167219199.999999999"), true },
- { Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), new BigDecimal("-0.000000001"), true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00Z")), BigDecimal.ZERO, true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), new BigDecimal("0.000000001"), true },
+ {"3.1415926535897932384626433", new BigDecimal("3.1415926535897932384626433"), true}
+ });
+ TEST_DB.put(pair(Date.class, BigDecimal.class), new Object[][]{
+ {Date.from(Instant.parse("0000-01-01T00:00:00Z")), new BigDecimal("-62167219200"), true},
+ {Date.from(Instant.parse("0000-01-01T00:00:00.001Z")), new BigDecimal("-62167219199.999"), true},
+ {Date.from(Instant.parse("1969-12-31T23:59:59.999Z")), new BigDecimal("-0.001"), true},
+ {Date.from(Instant.parse("1970-01-01T00:00:00Z")), BigDecimal.ZERO, true},
+ {Date.from(Instant.parse("1970-01-01T00:00:00.001Z")), new BigDecimal("0.001"), true},
+ });
+ TEST_DB.put(pair(java.sql.Date.class, BigDecimal.class), new Object[][]{
+ {new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), new BigDecimal("-62167219200"), true},
+ {new java.sql.Date(Instant.parse("0000-01-01T00:00:00.001Z").toEpochMilli()), new BigDecimal("-62167219199.999"), true},
+ {new java.sql.Date(Instant.parse("1969-12-31T23:59:59.999Z").toEpochMilli()), new BigDecimal("-0.001"), true},
+ {new java.sql.Date(Instant.parse("1970-01-01T00:00:00Z").toEpochMilli()), BigDecimal.ZERO, true},
+ {new java.sql.Date(Instant.parse("1970-01-01T00:00:00.001Z").toEpochMilli()), new BigDecimal("0.001"), true},
+ });
+ TEST_DB.put(pair(Timestamp.class, BigDecimal.class), new Object[][]{
+ {Timestamp.from(Instant.parse("0000-01-01T00:00:00Z")), new BigDecimal("-62167219200"), true},
+ {Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000001Z")), new BigDecimal("-62167219199.999999999"), true},
+ {Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), new BigDecimal("-0.000000001"), true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00Z")), BigDecimal.ZERO, true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), new BigDecimal("0.000000001"), true},
});
TEST_DB.put(pair(LocalDate.class, BigDecimal.class), new Object[][]{
- { LocalDate.parse("0000-01-01"), new BigDecimal("-62167252739"), true}, // Proves it always works from "startOfDay", using the zoneId from options
- { LocalDate.parse("1969-12-31"), new BigDecimal("-118800"), true},
- { LocalDate.parse("1970-01-01"), new BigDecimal("-32400"), true},
- { LocalDate.parse("1970-01-02"), new BigDecimal("54000"), true},
- { ZonedDateTime.parse("1969-12-31T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigDecimal("-118800"), true}, // Proves it always works from "startOfDay", using the zoneId from options
- { ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigDecimal("-118800"), true}, // Proves it always works from "startOfDay", using the zoneId from options
- { ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigDecimal("-32400"), true}, // Proves it always works from "startOfDay", using the zoneId from options
- { ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), new BigDecimal("-32400"), true},
- { ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), new BigDecimal("-32400"), true},
+ {LocalDate.parse("0000-01-01"), new BigDecimal("-62167252739"), true}, // Proves it always works from "startOfDay", using the zoneId from options
+ {LocalDate.parse("1969-12-31"), new BigDecimal("-118800"), true},
+ {LocalDate.parse("1970-01-01"), new BigDecimal("-32400"), true},
+ {LocalDate.parse("1970-01-02"), new BigDecimal("54000"), true},
+ {ZonedDateTime.parse("1969-12-31T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigDecimal("-118800"), true}, // Proves it always works from "startOfDay", using the zoneId from options
+ {ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigDecimal("-118800"), true}, // Proves it always works from "startOfDay", using the zoneId from options
+ {ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigDecimal("-32400"), true}, // Proves it always works from "startOfDay", using the zoneId from options
+ {ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), new BigDecimal("-32400"), true},
+ {ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), new BigDecimal("-32400"), true},
});
TEST_DB.put(pair(LocalDateTime.class, BigDecimal.class), new Object[][]{
- { ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigDecimal("-62167219200.0"), true},
- { ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigDecimal("-62167219199.999999999"), true},
- { ZonedDateTime.parse("1969-12-31T00:00:00.999999999Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigDecimal("-86399.000000001"), true},
- { ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigDecimal("-32400"), true}, // Time portion affects the answer unlike LocalDate
- { ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), BigDecimal.ZERO, true},
- { ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigDecimal("0.000000001"), true},
- });
- TEST_DB.put(pair(ZonedDateTime.class, BigDecimal.class), new Object[][] { // no reverse due to .toString adding zone offset
- { ZonedDateTime.parse("0000-01-01T00:00:00Z"), new BigDecimal("-62167219200") },
- { ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z"), new BigDecimal("-62167219199.999999999") },
- { ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z"), new BigDecimal("-0.000000001") },
- { ZonedDateTime.parse("1970-01-01T00:00:00Z"), BigDecimal.ZERO },
- { ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z"), new BigDecimal("0.000000001") },
- });
- TEST_DB.put(pair(OffsetDateTime.class, BigDecimal.class), new Object[][] { // no reverse due to .toString adding zone offset
- { OffsetDateTime.parse("0000-01-01T00:00:00Z"), new BigDecimal("-62167219200") },
- { OffsetDateTime.parse("0000-01-01T00:00:00.000000001Z"), new BigDecimal("-62167219199.999999999") },
- { OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z"), new BigDecimal("-0.000000001") },
- { OffsetDateTime.parse("1970-01-01T00:00:00Z"), BigDecimal.ZERO },
- { OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z"), new BigDecimal("0.000000001") },
- });
- TEST_DB.put(pair(Duration.class, BigDecimal.class), new Object[][] {
- { Duration.ofSeconds(-1, -1), new BigDecimal("-1.000000001"), true },
- { Duration.ofSeconds(-1), new BigDecimal("-1"), true },
- { Duration.ofSeconds(0), BigDecimal.ZERO, true },
- { Duration.ofSeconds(1), new BigDecimal("1"), true },
- { Duration.ofNanos(1), new BigDecimal("0.000000001"), true },
- { Duration.ofNanos(1_000_000_000), new BigDecimal("1"), true },
- { Duration.ofNanos(2_000_000_001), new BigDecimal("2.000000001"), true },
- { Duration.ofSeconds(10, 9), new BigDecimal("10.000000009"), true },
- { Duration.ofDays(1), new BigDecimal("86400"), true},
+ {ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigDecimal("-62167219200.0"), true},
+ {ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigDecimal("-62167219199.999999999"), true},
+ {ZonedDateTime.parse("1969-12-31T00:00:00.999999999Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigDecimal("-86399.000000001"), true},
+ {ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigDecimal("-32400"), true}, // Time portion affects the answer unlike LocalDate
+ {ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), BigDecimal.ZERO, true},
+ {ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigDecimal("0.000000001"), true},
+ });
+ TEST_DB.put(pair(OffsetDateTime.class, BigDecimal.class), new Object[][]{ // no reverse due to .toString adding zone offset
+ {OffsetDateTime.parse("0000-01-01T00:00:00Z"), new BigDecimal("-62167219200")},
+ {OffsetDateTime.parse("0000-01-01T00:00:00.000000001Z"), new BigDecimal("-62167219199.999999999")},
+ {OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z"), new BigDecimal("-0.000000001")},
+ {OffsetDateTime.parse("1970-01-01T00:00:00Z"), BigDecimal.ZERO},
+ {OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z"), new BigDecimal("0.000000001")},
+ });
+ TEST_DB.put(pair(Duration.class, BigDecimal.class), new Object[][]{
+ {Duration.ofSeconds(-1, -1), new BigDecimal("-1.000000001"), true},
+ {Duration.ofSeconds(-1), new BigDecimal("-1"), true},
+ {Duration.ofSeconds(0), BigDecimal.ZERO, true},
+ {Duration.ofSeconds(1), new BigDecimal("1"), true},
+ {Duration.ofNanos(1), new BigDecimal("0.000000001"), true},
+ {Duration.ofNanos(1_000_000_000), new BigDecimal("1"), true},
+ {Duration.ofNanos(2_000_000_001), new BigDecimal("2.000000001"), true},
+ {Duration.ofSeconds(10, 9), new BigDecimal("10.000000009"), true},
+ {Duration.ofDays(1), new BigDecimal("86400"), true},
});
TEST_DB.put(pair(Instant.class, BigDecimal.class), new Object[][]{ // JDK 1.8 cannot handle the format +01:00 in Instant.parse(). JDK11+ handles it fine.
- { Instant.parse("0000-01-01T00:00:00Z"), new BigDecimal("-62167219200.0"), true},
- { Instant.parse("0000-01-01T00:00:00.000000001Z"), new BigDecimal("-62167219199.999999999"), true},
- { Instant.parse("1969-12-31T00:00:00Z"), new BigDecimal("-86400"), true},
- { Instant.parse("1969-12-31T00:00:00.999999999Z"), new BigDecimal("-86399.000000001"), true },
- { Instant.parse("1969-12-31T23:59:59.999999999Z"), new BigDecimal("-0.000000001"), true },
- { Instant.parse("1970-01-01T00:00:00Z"), BigDecimal.ZERO, true},
- { Instant.parse("1970-01-01T00:00:00.000000001Z"), new BigDecimal("0.000000001"), true},
- { Instant.parse("1970-01-02T00:00:00Z"), new BigDecimal("86400"), true},
- { Instant.parse("1970-01-02T00:00:00.000000001Z"), new BigDecimal("86400.000000001"), true},
+ {Instant.parse("0000-01-01T00:00:00Z"), new BigDecimal("-62167219200.0"), true},
+ {Instant.parse("0000-01-01T00:00:00.000000001Z"), new BigDecimal("-62167219199.999999999"), true},
+ {Instant.parse("1969-12-31T00:00:00Z"), new BigDecimal("-86400"), true},
+ {Instant.parse("1969-12-31T00:00:00.999999999Z"), new BigDecimal("-86399.000000001"), true},
+ {Instant.parse("1969-12-31T23:59:59.999999999Z"), new BigDecimal("-0.000000001"), true},
+ {Instant.parse("1970-01-01T00:00:00Z"), BigDecimal.ZERO, true},
+ {Instant.parse("1970-01-01T00:00:00.000000001Z"), new BigDecimal("0.000000001"), true},
+ {Instant.parse("1970-01-02T00:00:00Z"), new BigDecimal("86400"), true},
+ {Instant.parse("1970-01-02T00:00:00.000000001Z"), new BigDecimal("86400.000000001"), true},
});
}
@@ -1124,192 +1016,172 @@ private static void loadBigDecimalTests() {
*/
private static void loadBigIntegerTests() {
TEST_DB.put(pair(Void.class, BigInteger.class), new Object[][]{
- { null, null },
+ {null, null},
});
TEST_DB.put(pair(Byte.class, BigInteger.class), new Object[][]{
- { (byte) -1, BigInteger.valueOf(-1), true },
- { (byte) 0, BigInteger.ZERO, true },
- { Byte.MIN_VALUE, BigInteger.valueOf(Byte.MIN_VALUE), true },
- { Byte.MAX_VALUE, BigInteger.valueOf(Byte.MAX_VALUE), true },
+ {(byte) -1, BigInteger.valueOf(-1), true},
+ {(byte) 0, BigInteger.ZERO, true},
+ {Byte.MIN_VALUE, BigInteger.valueOf(Byte.MIN_VALUE), true},
+ {Byte.MAX_VALUE, BigInteger.valueOf(Byte.MAX_VALUE), true},
});
TEST_DB.put(pair(Short.class, BigInteger.class), new Object[][]{
- { (short) -1, BigInteger.valueOf(-1), true },
- { (short) 0, BigInteger.ZERO, true },
- { Short.MIN_VALUE, BigInteger.valueOf(Short.MIN_VALUE), true },
- { Short.MAX_VALUE, BigInteger.valueOf(Short.MAX_VALUE), true },
+ {(short) -1, BigInteger.valueOf(-1), true},
+ {(short) 0, BigInteger.ZERO, true},
+ {Short.MIN_VALUE, BigInteger.valueOf(Short.MIN_VALUE), true},
+ {Short.MAX_VALUE, BigInteger.valueOf(Short.MAX_VALUE), true},
});
TEST_DB.put(pair(Integer.class, BigInteger.class), new Object[][]{
- { -1, BigInteger.valueOf(-1), true },
- { 0, BigInteger.ZERO, true },
- { Integer.MIN_VALUE, BigInteger.valueOf(Integer.MIN_VALUE), true },
- { Integer.MAX_VALUE, BigInteger.valueOf(Integer.MAX_VALUE), true },
+ {-1, BigInteger.valueOf(-1), true},
+ {0, BigInteger.ZERO, true},
+ {Integer.MIN_VALUE, BigInteger.valueOf(Integer.MIN_VALUE), true},
+ {Integer.MAX_VALUE, BigInteger.valueOf(Integer.MAX_VALUE), true},
});
TEST_DB.put(pair(Long.class, BigInteger.class), new Object[][]{
- { -1L, BigInteger.valueOf(-1), true },
- { 0L, BigInteger.ZERO, true },
- { Long.MIN_VALUE, BigInteger.valueOf(Long.MIN_VALUE), true },
- { Long.MAX_VALUE, BigInteger.valueOf(Long.MAX_VALUE), true },
+ {-1L, BigInteger.valueOf(-1), true},
+ {0L, BigInteger.ZERO, true},
+ {Long.MIN_VALUE, BigInteger.valueOf(Long.MIN_VALUE), true},
+ {Long.MAX_VALUE, BigInteger.valueOf(Long.MAX_VALUE), true},
});
TEST_DB.put(pair(Float.class, BigInteger.class), new Object[][]{
- { -1f, BigInteger.valueOf(-1), true },
- { 0f, BigInteger.ZERO, true },
- { 1.0e6f, new BigInteger("1000000"), true },
- { -16777216f, BigInteger.valueOf(-16777216), true },
- { 16777216f, BigInteger.valueOf(16777216), true },
+ {-1f, BigInteger.valueOf(-1), true},
+ {0f, BigInteger.ZERO, true},
+ {1.0e6f, new BigInteger("1000000"), true},
+ {-16777216f, BigInteger.valueOf(-16777216), true},
+ {16777216f, BigInteger.valueOf(16777216), true},
});
TEST_DB.put(pair(Double.class, BigInteger.class), new Object[][]{
- { -1d, BigInteger.valueOf(-1), true },
- { 0d, BigInteger.ZERO, true },
- { 1.0e9d, new BigInteger("1000000000"), true },
- { -9007199254740991d, BigInteger.valueOf(-9007199254740991L), true },
- { 9007199254740991d, BigInteger.valueOf(9007199254740991L), true },
+ {-1d, BigInteger.valueOf(-1), true},
+ {0d, BigInteger.ZERO, true},
+ {1.0e9d, new BigInteger("1000000000"), true},
+ {-9007199254740991d, BigInteger.valueOf(-9007199254740991L), true},
+ {9007199254740991d, BigInteger.valueOf(9007199254740991L), true},
});
TEST_DB.put(pair(Boolean.class, BigInteger.class), new Object[][]{
- { false, BigInteger.ZERO, true },
- { true, BigInteger.valueOf(1), true },
+ {false, BigInteger.ZERO, true},
+ {true, BigInteger.valueOf(1), true},
});
TEST_DB.put(pair(Character.class, BigInteger.class), new Object[][]{
- { (char) 0, BigInteger.ZERO, true },
- { (char) 1, BigInteger.valueOf(1), true },
- { (char) 65535, BigInteger.valueOf(65535), true },
+ {(char) 0, BigInteger.ZERO, true},
+ {(char) 1, BigInteger.valueOf(1), true},
+ {(char) 65535, BigInteger.valueOf(65535), true},
});
TEST_DB.put(pair(BigInteger.class, BigInteger.class), new Object[][]{
- { new BigInteger("16"), BigInteger.valueOf(16), true },
+ {new BigInteger("16"), BigInteger.valueOf(16), true},
});
TEST_DB.put(pair(BigDecimal.class, BigInteger.class), new Object[][]{
- { BigDecimal.ZERO, BigInteger.ZERO, true },
- { BigDecimal.valueOf(-1), BigInteger.valueOf(-1), true },
- { BigDecimal.valueOf(-1.1), BigInteger.valueOf(-1) },
- { BigDecimal.valueOf(-1.9), BigInteger.valueOf(-1) },
- { BigDecimal.valueOf(1.9), BigInteger.valueOf(1) },
- { BigDecimal.valueOf(1.1), BigInteger.valueOf(1) },
- { BigDecimal.valueOf(1.0e6d), new BigInteger("1000000") },
- { BigDecimal.valueOf(-16777216), BigInteger.valueOf(-16777216), true },
+ {BigDecimal.ZERO, BigInteger.ZERO, true},
+ {BigDecimal.valueOf(-1), BigInteger.valueOf(-1), true},
+ {BigDecimal.valueOf(-1.1), BigInteger.valueOf(-1)},
+ {BigDecimal.valueOf(-1.9), BigInteger.valueOf(-1)},
+ {BigDecimal.valueOf(1.9), BigInteger.valueOf(1)},
+ {BigDecimal.valueOf(1.1), BigInteger.valueOf(1)},
+ {BigDecimal.valueOf(1.0e6d), new BigInteger("1000000")},
+ {BigDecimal.valueOf(-16777216), BigInteger.valueOf(-16777216), true},
});
TEST_DB.put(pair(AtomicBoolean.class, BigInteger.class), new Object[][]{
- { new AtomicBoolean(false), BigInteger.ZERO },
- { new AtomicBoolean(true), BigInteger.valueOf(1) },
+ {new AtomicBoolean(false), BigInteger.ZERO},
+ {new AtomicBoolean(true), BigInteger.valueOf(1)},
});
TEST_DB.put(pair(AtomicInteger.class, BigInteger.class), new Object[][]{
- { new AtomicInteger(-1), BigInteger.valueOf(-1) },
- { new AtomicInteger(0), BigInteger.ZERO },
- { new AtomicInteger(Integer.MIN_VALUE), BigInteger.valueOf(Integer.MIN_VALUE) },
- { new AtomicInteger(Integer.MAX_VALUE), BigInteger.valueOf(Integer.MAX_VALUE) },
+ {new AtomicInteger(-1), BigInteger.valueOf(-1)},
+ {new AtomicInteger(0), BigInteger.ZERO},
+ {new AtomicInteger(Integer.MIN_VALUE), BigInteger.valueOf(Integer.MIN_VALUE)},
+ {new AtomicInteger(Integer.MAX_VALUE), BigInteger.valueOf(Integer.MAX_VALUE)},
});
TEST_DB.put(pair(AtomicLong.class, BigInteger.class), new Object[][]{
- { new AtomicLong(-1), BigInteger.valueOf(-1) },
- { new AtomicLong(0), BigInteger.ZERO },
- { new AtomicLong(Long.MIN_VALUE), BigInteger.valueOf(Long.MIN_VALUE) },
- { new AtomicLong(Long.MAX_VALUE), BigInteger.valueOf(Long.MAX_VALUE) },
+ {new AtomicLong(-1), BigInteger.valueOf(-1)},
+ {new AtomicLong(0), BigInteger.ZERO},
+ {new AtomicLong(Long.MIN_VALUE), BigInteger.valueOf(Long.MIN_VALUE)},
+ {new AtomicLong(Long.MAX_VALUE), BigInteger.valueOf(Long.MAX_VALUE)},
});
TEST_DB.put(pair(Date.class, BigInteger.class), new Object[][]{
- { Date.from(Instant.parse("0000-01-01T00:00:00Z")), new BigInteger("-62167219200000000000"), true },
- { Date.from(Instant.parse("0001-02-18T19:58:01Z")), new BigInteger("-62131377719000000000"), true },
- { Date.from(Instant.parse("1969-12-31T23:59:59Z")), BigInteger.valueOf(-1_000_000_000), true },
- { Date.from(Instant.parse("1969-12-31T23:59:59.1Z")), BigInteger.valueOf(-900000000), true },
- { Date.from(Instant.parse("1969-12-31T23:59:59.9Z")), BigInteger.valueOf(-100000000), true },
- { Date.from(Instant.parse("1970-01-01T00:00:00Z")), BigInteger.ZERO, true },
- { Date.from(Instant.parse("1970-01-01T00:00:00.1Z")), BigInteger.valueOf(100000000), true },
- { Date.from(Instant.parse("1970-01-01T00:00:00.9Z")), BigInteger.valueOf(900000000), true },
- { Date.from(Instant.parse("1970-01-01T00:00:01Z")), BigInteger.valueOf(1000000000), true },
- { Date.from(Instant.parse("9999-02-18T19:58:01Z")), new BigInteger("253374983881000000000"), true },
+ {Date.from(Instant.parse("0000-01-01T00:00:00Z")), new BigInteger("-62167219200000000000"), true},
+ {Date.from(Instant.parse("0001-02-18T19:58:01Z")), new BigInteger("-62131377719000000000"), true},
+ {Date.from(Instant.parse("1969-12-31T23:59:59Z")), BigInteger.valueOf(-1_000_000_000), true},
+ {Date.from(Instant.parse("1969-12-31T23:59:59.1Z")), BigInteger.valueOf(-900000000), true},
+ {Date.from(Instant.parse("1969-12-31T23:59:59.9Z")), BigInteger.valueOf(-100000000), true},
+ {Date.from(Instant.parse("1970-01-01T00:00:00Z")), BigInteger.ZERO, true},
+ {Date.from(Instant.parse("1970-01-01T00:00:00.1Z")), BigInteger.valueOf(100000000), true},
+ {Date.from(Instant.parse("1970-01-01T00:00:00.9Z")), BigInteger.valueOf(900000000), true},
+ {Date.from(Instant.parse("1970-01-01T00:00:01Z")), BigInteger.valueOf(1000000000), true},
+ {Date.from(Instant.parse("9999-02-18T19:58:01Z")), new BigInteger("253374983881000000000"), true},
});
TEST_DB.put(pair(java.sql.Date.class, BigInteger.class), new Object[][]{
- { new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), new BigInteger("-62167219200000000000"), true },
- { new java.sql.Date(Instant.parse("0001-02-18T19:58:01Z").toEpochMilli()), new BigInteger("-62131377719000000000"), true },
- { new java.sql.Date(Instant.parse("1969-12-31T23:59:59Z").toEpochMilli()), BigInteger.valueOf(-1_000_000_000), true },
- { new java.sql.Date(Instant.parse("1969-12-31T23:59:59.1Z").toEpochMilli()), BigInteger.valueOf(-900000000), true },
- { new java.sql.Date(Instant.parse("1969-12-31T23:59:59.9Z").toEpochMilli()), BigInteger.valueOf(-100000000), true },
- { new java.sql.Date(Instant.parse("1970-01-01T00:00:00Z").toEpochMilli()), BigInteger.ZERO, true },
- { new java.sql.Date(Instant.parse("1970-01-01T00:00:00.1Z").toEpochMilli()), BigInteger.valueOf(100000000), true },
- { new java.sql.Date(Instant.parse("1970-01-01T00:00:00.9Z").toEpochMilli()), BigInteger.valueOf(900000000), true },
- { new java.sql.Date(Instant.parse("1970-01-01T00:00:01Z").toEpochMilli()), BigInteger.valueOf(1000000000), true },
- { new java.sql.Date(Instant.parse("9999-02-18T19:58:01Z").toEpochMilli()), new BigInteger("253374983881000000000"), true },
+ {new java.sql.Date(Instant.parse("0000-01-01T00:00:00Z").toEpochMilli()), new BigInteger("-62167219200000000000"), true},
+ {new java.sql.Date(Instant.parse("0001-02-18T19:58:01Z").toEpochMilli()), new BigInteger("-62131377719000000000"), true},
+ {new java.sql.Date(Instant.parse("1969-12-31T23:59:59Z").toEpochMilli()), BigInteger.valueOf(-1_000_000_000), true},
+ {new java.sql.Date(Instant.parse("1969-12-31T23:59:59.1Z").toEpochMilli()), BigInteger.valueOf(-900000000), true},
+ {new java.sql.Date(Instant.parse("1969-12-31T23:59:59.9Z").toEpochMilli()), BigInteger.valueOf(-100000000), true},
+ {new java.sql.Date(Instant.parse("1970-01-01T00:00:00Z").toEpochMilli()), BigInteger.ZERO, true},
+ {new java.sql.Date(Instant.parse("1970-01-01T00:00:00.1Z").toEpochMilli()), BigInteger.valueOf(100000000), true},
+ {new java.sql.Date(Instant.parse("1970-01-01T00:00:00.9Z").toEpochMilli()), BigInteger.valueOf(900000000), true},
+ {new java.sql.Date(Instant.parse("1970-01-01T00:00:01Z").toEpochMilli()), BigInteger.valueOf(1000000000), true},
+ {new java.sql.Date(Instant.parse("9999-02-18T19:58:01Z").toEpochMilli()), new BigInteger("253374983881000000000"), true},
});
TEST_DB.put(pair(Timestamp.class, BigInteger.class), new Object[][]{
- { Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000000Z")), new BigInteger("-62167219200000000000"), true },
- { Timestamp.from(Instant.parse("0001-02-18T19:58:01.000000000Z")), new BigInteger("-62131377719000000000"), true },
- { Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000000Z")), BigInteger.valueOf(-1000000000), true },
- { Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000001Z")), BigInteger.valueOf(-999999999), true },
- { Timestamp.from(Instant.parse("1969-12-31T23:59:59.100000000Z")), BigInteger.valueOf(-900000000), true },
- { Timestamp.from(Instant.parse("1969-12-31T23:59:59.900000000Z")), BigInteger.valueOf(-100000000), true },
- { Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), BigInteger.valueOf(-1), true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), BigInteger.ZERO, true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), BigInteger.valueOf(1), true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.100000000Z")), BigInteger.valueOf(100000000), true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.900000000Z")), BigInteger.valueOf(900000000), true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), BigInteger.valueOf(999999999), true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:01.000000000Z")), BigInteger.valueOf(1000000000), true },
- { Timestamp.from(Instant.parse("9999-02-18T19:58:01.000000000Z")), new BigInteger("253374983881000000000"), true },
- });
- TEST_DB.put(pair(Duration.class, BigInteger.class), new Object[][] {
- { Duration.ofNanos(-1000000), BigInteger.valueOf(-1000000), true},
- { Duration.ofNanos(-1000), BigInteger.valueOf(-1000), true},
- { Duration.ofNanos(-1), BigInteger.valueOf(-1), true},
- { Duration.ofNanos(0), BigInteger.ZERO, true},
- { Duration.ofNanos(1), BigInteger.valueOf(1), true},
- { Duration.ofNanos(1000), BigInteger.valueOf(1000), true},
- { Duration.ofNanos(1000000), BigInteger.valueOf(1000000), true},
- { Duration.ofNanos(Integer.MAX_VALUE), BigInteger.valueOf(Integer.MAX_VALUE), true},
- { Duration.ofNanos(Integer.MIN_VALUE), BigInteger.valueOf(Integer.MIN_VALUE), true},
- { Duration.ofNanos(Long.MAX_VALUE), BigInteger.valueOf(Long.MAX_VALUE), true},
- { Duration.ofNanos(Long.MIN_VALUE), BigInteger.valueOf(Long.MIN_VALUE), true},
+ {Timestamp.from(Instant.parse("0000-01-01T00:00:00.000000000Z")), new BigInteger("-62167219200000000000"), true},
+ {Timestamp.from(Instant.parse("0001-02-18T19:58:01.000000000Z")), new BigInteger("-62131377719000000000"), true},
+ {Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000000Z")), BigInteger.valueOf(-1000000000), true},
+ {Timestamp.from(Instant.parse("1969-12-31T23:59:59.000000001Z")), BigInteger.valueOf(-999999999), true},
+ {Timestamp.from(Instant.parse("1969-12-31T23:59:59.100000000Z")), BigInteger.valueOf(-900000000), true},
+ {Timestamp.from(Instant.parse("1969-12-31T23:59:59.900000000Z")), BigInteger.valueOf(-100000000), true},
+ {Timestamp.from(Instant.parse("1969-12-31T23:59:59.999999999Z")), BigInteger.valueOf(-1), true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000000Z")), BigInteger.ZERO, true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), BigInteger.valueOf(1), true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.100000000Z")), BigInteger.valueOf(100000000), true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.900000000Z")), BigInteger.valueOf(900000000), true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), BigInteger.valueOf(999999999), true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:01.000000000Z")), BigInteger.valueOf(1000000000), true},
+ {Timestamp.from(Instant.parse("9999-02-18T19:58:01.000000000Z")), new BigInteger("253374983881000000000"), true},
});
TEST_DB.put(pair(Instant.class, BigInteger.class), new Object[][]{
- { Instant.parse("0000-01-01T00:00:00.000000000Z"), new BigInteger("-62167219200000000000"), true },
- { Instant.parse("0000-01-01T00:00:00.000000001Z"), new BigInteger("-62167219199999999999"), true },
- { Instant.parse("1969-12-31T23:59:59.000000000Z"), BigInteger.valueOf(-1000000000), true },
- { Instant.parse("1969-12-31T23:59:59.000000001Z"), BigInteger.valueOf(-999999999), true },
- { Instant.parse("1969-12-31T23:59:59.100000000Z"), BigInteger.valueOf(-900000000), true },
- { Instant.parse("1969-12-31T23:59:59.900000000Z"), BigInteger.valueOf(-100000000), true },
- { Instant.parse("1969-12-31T23:59:59.999999999Z"), BigInteger.valueOf(-1), true },
- { Instant.parse("1970-01-01T00:00:00.000000000Z"), BigInteger.ZERO, true },
- { Instant.parse("1970-01-01T00:00:00.000000001Z"), BigInteger.valueOf(1), true },
- { Instant.parse("1970-01-01T00:00:00.100000000Z"), BigInteger.valueOf(100000000), true },
- { Instant.parse("1970-01-01T00:00:00.900000000Z"), BigInteger.valueOf(900000000), true },
- { Instant.parse("1970-01-01T00:00:00.999999999Z"), BigInteger.valueOf(999999999), true },
- { Instant.parse("1970-01-01T00:00:01.000000000Z"), BigInteger.valueOf(1000000000), true },
- { Instant.parse("9999-02-18T19:58:01.000000000Z"), new BigInteger("253374983881000000000"), true },
+ {Instant.parse("0000-01-01T00:00:00.000000000Z"), new BigInteger("-62167219200000000000"), true},
+ {Instant.parse("0000-01-01T00:00:00.000000001Z"), new BigInteger("-62167219199999999999"), true},
+ {Instant.parse("1969-12-31T23:59:59.000000000Z"), BigInteger.valueOf(-1000000000), true},
+ {Instant.parse("1969-12-31T23:59:59.000000001Z"), BigInteger.valueOf(-999999999), true},
+ {Instant.parse("1969-12-31T23:59:59.100000000Z"), BigInteger.valueOf(-900000000), true},
+ {Instant.parse("1969-12-31T23:59:59.900000000Z"), BigInteger.valueOf(-100000000), true},
+ {Instant.parse("1969-12-31T23:59:59.999999999Z"), BigInteger.valueOf(-1), true},
+ {Instant.parse("1970-01-01T00:00:00.000000000Z"), BigInteger.ZERO, true},
+ {Instant.parse("1970-01-01T00:00:00.000000001Z"), BigInteger.valueOf(1), true},
+ {Instant.parse("1970-01-01T00:00:00.100000000Z"), BigInteger.valueOf(100000000), true},
+ {Instant.parse("1970-01-01T00:00:00.900000000Z"), BigInteger.valueOf(900000000), true},
+ {Instant.parse("1970-01-01T00:00:00.999999999Z"), BigInteger.valueOf(999999999), true},
+ {Instant.parse("1970-01-01T00:00:01.000000000Z"), BigInteger.valueOf(1000000000), true},
+ {Instant.parse("9999-02-18T19:58:01.000000000Z"), new BigInteger("253374983881000000000"), true},
});
TEST_DB.put(pair(LocalDate.class, BigInteger.class), new Object[][]{
- { ZonedDateTime.parse("1969-12-31T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigInteger("-118800000000000"), true}, // Proves it always works from "startOfDay", using the zoneId from options
- { ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigInteger("-118800000000000"), true}, // Proves it always works from "startOfDay", using the zoneId from options
- { ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigInteger("-32400000000000"), true}, // Proves it always works from "startOfDay", using the zoneId from options
- { ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), new BigInteger("-32400000000000"), true},
- { ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), new BigInteger("-32400000000000"), true},
+ {ZonedDateTime.parse("1969-12-31T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigInteger("-118800000000000"), true}, // Proves it always works from "startOfDay", using the zoneId from options
+ {ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigInteger("-118800000000000"), true}, // Proves it always works from "startOfDay", using the zoneId from options
+ {ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDate(), new BigInteger("-32400000000000"), true}, // Proves it always works from "startOfDay", using the zoneId from options
+ {ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), new BigInteger("-32400000000000"), true},
+ {ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDate(), new BigInteger("-32400000000000"), true},
});
TEST_DB.put(pair(LocalDateTime.class, BigInteger.class), new Object[][]{
- { ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-62167252739000000000"), true},
- { ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-62167252738999999999"), true},
- { ZonedDateTime.parse("1969-12-31T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-118800000000000"), true},
- { ZonedDateTime.parse("1969-12-31T00:00:00.000000001Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-118799999999999"), true},
- { ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-32400000000001"), true},
- { ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-32400000000000"), true},
- { ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigInteger("-1"), true},
- { ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), BigInteger.ZERO, true},
- { ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigInteger("1"), true},
- });
- TEST_DB.put(pair(ZonedDateTime.class, BigInteger.class), new Object[][]{ // ZonedDateTime .toString() prevents reverse test
- { ZonedDateTime.parse("0000-01-01T00:00:00Z"), new BigInteger("-62167219200000000000") },
- { ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z"), new BigInteger("-62167219199999999999") },
- { ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z"), new BigInteger("-1") },
- { ZonedDateTime.parse("1970-01-01T00:00:00Z"), BigInteger.ZERO },
- { ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z"), new BigInteger("1") },
+ {ZonedDateTime.parse("0000-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-62167252739000000000"), true},
+ {ZonedDateTime.parse("0000-01-01T00:00:00.000000001Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-62167252738999999999"), true},
+ {ZonedDateTime.parse("1969-12-31T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-118800000000000"), true},
+ {ZonedDateTime.parse("1969-12-31T00:00:00.000000001Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-118799999999999"), true},
+ {ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-32400000000001"), true},
+ {ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(), new BigInteger("-32400000000000"), true},
+ {ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigInteger("-1"), true},
+ {ZonedDateTime.parse("1970-01-01T00:00:00Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), BigInteger.ZERO, true},
+ {ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), new BigInteger("1"), true},
});
TEST_DB.put(pair(UUID.class, BigInteger.class), new Object[][]{
- { new UUID(0L, 0L), BigInteger.ZERO, true },
- { new UUID(1L, 1L), new BigInteger("18446744073709551617"), true },
- { new UUID(Long.MAX_VALUE, Long.MAX_VALUE), new BigInteger("170141183460469231722463931679029329919"), true },
- { UUID.fromString("00000000-0000-0000-0000-000000000000"), BigInteger.ZERO, true },
- { UUID.fromString("00000000-0000-0000-0000-000000000001"), BigInteger.valueOf(1), true },
- { UUID.fromString("00000000-0000-0001-0000-000000000001"), new BigInteger("18446744073709551617"), true },
- { UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"), new BigInteger("340282366920938463463374607431768211455"), true },
- { UUID.fromString("ffffffff-ffff-ffff-ffff-fffffffffffe"), new BigInteger("340282366920938463463374607431768211454"), true },
- { UUID.fromString("f0000000-0000-0000-0000-000000000000"), new BigInteger("319014718988379809496913694467282698240"), true },
- { UUID.fromString("f0000000-0000-0000-0000-000000000001"), new BigInteger("319014718988379809496913694467282698241"), true },
- { UUID.fromString("7fffffff-ffff-ffff-ffff-fffffffffffe"), new BigInteger("170141183460469231731687303715884105726"), true },
- { UUID.fromString("7fffffff-ffff-ffff-ffff-ffffffffffff"), new BigInteger("170141183460469231731687303715884105727"), true },
- { UUID.fromString("80000000-0000-0000-0000-000000000000"), new BigInteger("170141183460469231731687303715884105728"), true },
+ {new UUID(0L, 0L), BigInteger.ZERO, true},
+ {new UUID(1L, 1L), new BigInteger("18446744073709551617"), true},
+ {new UUID(Long.MAX_VALUE, Long.MAX_VALUE), new BigInteger("170141183460469231722463931679029329919"), true},
+ {UUID.fromString("00000000-0000-0000-0000-000000000000"), BigInteger.ZERO, true},
+ {UUID.fromString("00000000-0000-0000-0000-000000000001"), BigInteger.valueOf(1), true},
+ {UUID.fromString("00000000-0000-0001-0000-000000000001"), new BigInteger("18446744073709551617"), true},
+ {UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"), new BigInteger("340282366920938463463374607431768211455"), true},
+ {UUID.fromString("ffffffff-ffff-ffff-ffff-fffffffffffe"), new BigInteger("340282366920938463463374607431768211454"), true},
+ {UUID.fromString("f0000000-0000-0000-0000-000000000000"), new BigInteger("319014718988379809496913694467282698240"), true},
+ {UUID.fromString("f0000000-0000-0000-0000-000000000001"), new BigInteger("319014718988379809496913694467282698241"), true},
+ {UUID.fromString("7fffffff-ffff-ffff-ffff-fffffffffffe"), new BigInteger("170141183460469231731687303715884105726"), true},
+ {UUID.fromString("7fffffff-ffff-ffff-ffff-ffffffffffff"), new BigInteger("170141183460469231731687303715884105727"), true},
+ {UUID.fromString("80000000-0000-0000-0000-000000000000"), new BigInteger("170141183460469231731687303715884105728"), true},
});
TEST_DB.put(pair(Calendar.class, BigInteger.class), new Object[][]{
{(Supplier) () -> {
@@ -1331,11 +1203,11 @@ private static void loadBigIntegerTests() {
{"0.0", BigInteger.ZERO},
});
TEST_DB.put(pair(OffsetDateTime.class, BigInteger.class), new Object[][]{
- { OffsetDateTime.parse("0000-01-01T00:00:00Z"), new BigInteger("-62167219200000000000") },
- { OffsetDateTime.parse("0000-01-01T00:00:00.000000001Z"), new BigInteger("-62167219199999999999") },
- { OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z"), new BigInteger("-1") },
- { OffsetDateTime.parse("1970-01-01T00:00:00Z"), BigInteger.ZERO },
- { OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z"), new BigInteger("1") },
+ {OffsetDateTime.parse("0000-01-01T00:00:00Z"), new BigInteger("-62167219200000000000")},
+ {OffsetDateTime.parse("0000-01-01T00:00:00.000000001Z"), new BigInteger("-62167219199999999999")},
+ {OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z"), new BigInteger("-1")},
+ {OffsetDateTime.parse("1970-01-01T00:00:00Z"), BigInteger.ZERO},
+ {OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z"), new BigInteger("1")},
});
TEST_DB.put(pair(Year.class, BigInteger.class), new Object[][]{
{Year.of(2024), BigInteger.valueOf(2024)},
@@ -1657,22 +1529,22 @@ private static void loadDoubleTests(long now) {
{(char) 1, 1d},
{(char) 0, 0d},
});
- TEST_DB.put(pair(Duration.class, Double.class), new Object[][] {
- { Duration.ofSeconds(-1, -1), -1.000000001, true },
- { Duration.ofSeconds(-1), -1d, true },
- { Duration.ofSeconds(0), 0d, true },
- { Duration.ofSeconds(1), 1d, true },
- { Duration.ofNanos(1), 0.000000001, true },
- { Duration.ofNanos(1_000_000_000), 1d, true },
- { Duration.ofNanos(2_000_000_001), 2.000000001, true },
- { Duration.ofSeconds(10, 9), 10.000000009, true },
- { Duration.ofDays(1), 86400d, true},
+ TEST_DB.put(pair(Duration.class, Double.class), new Object[][]{
+ {Duration.ofSeconds(-1, -1), -1.000000001, true},
+ {Duration.ofSeconds(-1), -1d, true},
+ {Duration.ofSeconds(0), 0d, true},
+ {Duration.ofSeconds(1), 1d, true},
+ {Duration.ofNanos(1), 0.000000001, true},
+ {Duration.ofNanos(1_000_000_000), 1d, true},
+ {Duration.ofNanos(2_000_000_001), 2.000000001, true},
+ {Duration.ofSeconds(10, 9), 10.000000009, true},
+ {Duration.ofDays(1), 86400d, true},
});
TEST_DB.put(pair(Instant.class, Double.class), new Object[][]{ // JDK 1.8 cannot handle the format +01:00 in Instant.parse(). JDK11+ handles it fine.
{Instant.parse("0000-01-01T00:00:00Z"), -62167219200.0, true},
{Instant.parse("1969-12-31T00:00:00Z"), -86400d, true},
{Instant.parse("1969-12-31T00:00:00Z"), -86400d, true},
- {Instant.parse("1969-12-31T00:00:00.999999999Z"), -86399.000000001, true },
+ {Instant.parse("1969-12-31T00:00:00.999999999Z"), -86399.000000001, true},
// {Instant.parse("1969-12-31T23:59:59.999999999Z"), -0.000000001 }, // IEEE-754 double cannot represent this number precisely
{Instant.parse("1970-01-01T00:00:00Z"), 0d, true},
{Instant.parse("1970-01-01T00:00:00.000000001Z"), 0.000000001, true},
@@ -1698,29 +1570,29 @@ private static void loadDoubleTests(long now) {
{ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z").withZoneSameInstant(TOKYO_Z).toLocalDateTime(), 0.000000001, true},
});
TEST_DB.put(pair(ZonedDateTime.class, Double.class), new Object[][]{ // no reverse due to .toString adding zone name
- {ZonedDateTime.parse("0000-01-01T00:00:00Z"), -62167219200.0 },
- {ZonedDateTime.parse("1969-12-31T23:59:58.9Z"), -1.1 },
- {ZonedDateTime.parse("1969-12-31T23:59:59Z"), -1d },
+ {ZonedDateTime.parse("0000-01-01T00:00:00Z"), -62167219200.0},
+ {ZonedDateTime.parse("1969-12-31T23:59:58.9Z"), -1.1},
+ {ZonedDateTime.parse("1969-12-31T23:59:59Z"), -1d},
// {ZonedDateTime.parse("1969-12-31T23:59:59.999999999Z"), -0.000000001}, // IEEE-754 double resolution not quite good enough to represent, but very close.
{ZonedDateTime.parse("1970-01-01T00:00:00Z"), 0d},
{ZonedDateTime.parse("1970-01-01T00:00:00.000000001Z"), 0.000000001},
});
TEST_DB.put(pair(OffsetDateTime.class, Double.class), new Object[][]{ // OffsetDateTime .toString() method prevents reverse
- {OffsetDateTime.parse("0000-01-01T00:00:00Z"), -62167219200.0 },
- {OffsetDateTime.parse("1969-12-31T23:59:58.9Z"), -1.1 },
- {OffsetDateTime.parse("1969-12-31T23:59:59.000000001Z"), -0.999999999 },
- {OffsetDateTime.parse("1969-12-31T23:59:59Z"), -1d },
+ {OffsetDateTime.parse("0000-01-01T00:00:00Z"), -62167219200.0},
+ {OffsetDateTime.parse("1969-12-31T23:59:58.9Z"), -1.1},
+ {OffsetDateTime.parse("1969-12-31T23:59:59.000000001Z"), -0.999999999},
+ {OffsetDateTime.parse("1969-12-31T23:59:59Z"), -1d},
// {OffsetDateTime.parse("1969-12-31T23:59:59.999999999Z"), -0.000000001}, // IEEE-754 double resolution not quite good enough to represent, but very close.
- {OffsetDateTime.parse("1970-01-01T00:00:00Z"), 0d },
- {OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z"), 0.000000001 },
+ {OffsetDateTime.parse("1970-01-01T00:00:00Z"), 0d},
+ {OffsetDateTime.parse("1970-01-01T00:00:00.000000001Z"), 0.000000001},
});
TEST_DB.put(pair(Date.class, Double.class), new Object[][]{
{new Date(Long.MIN_VALUE), (double) Long.MIN_VALUE / 1000d, true},
{new Date(Integer.MIN_VALUE), (double) Integer.MIN_VALUE / 1000d, true},
{new Date(0), 0d, true},
{new Date(now), (double) now / 1000d, true},
- {Date.from(Instant.parse("2024-02-18T06:31:55.987654321Z")), 1708237915.987, true }, // Date only has millisecond resolution
- {Date.from(Instant.parse("2024-02-18T06:31:55.123456789Z")), 1708237915.123, true }, // Date only has millisecond resolution
+ {Date.from(Instant.parse("2024-02-18T06:31:55.987654321Z")), 1708237915.987, true}, // Date only has millisecond resolution
+ {Date.from(Instant.parse("2024-02-18T06:31:55.123456789Z")), 1708237915.123, true}, // Date only has millisecond resolution
{new Date(Integer.MAX_VALUE), (double) Integer.MAX_VALUE / 1000d, true},
{new Date(Long.MAX_VALUE), (double) Long.MAX_VALUE / 1000d, true},
});
@@ -1729,22 +1601,22 @@ private static void loadDoubleTests(long now) {
{new java.sql.Date(Integer.MIN_VALUE), (double) Integer.MIN_VALUE / 1000d, true},
{new java.sql.Date(0), 0d, true},
{new java.sql.Date(now), (double) now / 1000d, true},
- {new java.sql.Date(Instant.parse("2024-02-18T06:31:55.987654321Z").toEpochMilli()), 1708237915.987, true }, // java.sql.Date only has millisecond resolution
- {new java.sql.Date(Instant.parse("2024-02-18T06:31:55.123456789Z").toEpochMilli()), 1708237915.123, true }, // java.sql.Date only has millisecond resolution
+ {new java.sql.Date(Instant.parse("2024-02-18T06:31:55.987654321Z").toEpochMilli()), 1708237915.987, true}, // java.sql.Date only has millisecond resolution
+ {new java.sql.Date(Instant.parse("2024-02-18T06:31:55.123456789Z").toEpochMilli()), 1708237915.123, true}, // java.sql.Date only has millisecond resolution
{new java.sql.Date(Integer.MAX_VALUE), (double) Integer.MAX_VALUE / 1000d, true},
{new java.sql.Date(Long.MAX_VALUE), (double) Long.MAX_VALUE / 1000d, true},
});
TEST_DB.put(pair(Timestamp.class, Double.class), new Object[][]{
{new Timestamp(0), 0d, true},
- { Timestamp.from(Instant.parse("1969-12-31T00:00:00Z")), -86400d, true},
- { Timestamp.from(Instant.parse("1969-12-31T00:00:00.000000001Z")), -86399.999999999}, // IEEE-754 resolution issue (almost symmetrical)
- { Timestamp.from(Instant.parse("1969-12-31T00:00:01Z")), -86399d, true },
- { Timestamp.from(Instant.parse("1969-12-31T23:59:58.9Z")), -1.1, true },
- { Timestamp.from(Instant.parse("1969-12-31T23:59:59Z")), -1.0, true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00Z")), 0d, true},
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), 0.000000001, true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.9Z")), 0.9, true },
- { Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), 0.999999999, true },
+ {Timestamp.from(Instant.parse("1969-12-31T00:00:00Z")), -86400d, true},
+ {Timestamp.from(Instant.parse("1969-12-31T00:00:00.000000001Z")), -86399.999999999}, // IEEE-754 resolution issue (almost symmetrical)
+ {Timestamp.from(Instant.parse("1969-12-31T00:00:01Z")), -86399d, true},
+ {Timestamp.from(Instant.parse("1969-12-31T23:59:58.9Z")), -1.1, true},
+ {Timestamp.from(Instant.parse("1969-12-31T23:59:59Z")), -1.0, true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00Z")), 0d, true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.000000001Z")), 0.000000001, true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.9Z")), 0.9, true},
+ {Timestamp.from(Instant.parse("1970-01-01T00:00:00.999999999Z")), 0.999999999, true},
});
TEST_DB.put(pair(Calendar.class, Double.class), new Object[][]{
{(Supplier) () -> {
@@ -2206,13 +2078,13 @@ private static void loadLongTests(long now) {
{new Timestamp(Long.MAX_VALUE), Long.MAX_VALUE, true},
});
TEST_DB.put(pair(Duration.class, Long.class), new Object[][]{
- { Duration.ofMillis(Long.MIN_VALUE / 2), Long.MIN_VALUE / 2, true },
- { Duration.ofMillis(Integer.MIN_VALUE), (long)Integer.MIN_VALUE, true },
- { Duration.ofMillis(-1), -1L, true },
- { Duration.ofMillis(0), 0L, true },
- { Duration.ofMillis(1), 1L, true },
- { Duration.ofMillis(Integer.MAX_VALUE), (long)Integer.MAX_VALUE, true },
- { Duration.ofMillis(Long.MAX_VALUE / 2), Long.MAX_VALUE / 2, true },
+ {Duration.ofMillis(Long.MIN_VALUE / 2), Long.MIN_VALUE / 2, true},
+ {Duration.ofMillis(Integer.MIN_VALUE), (long) Integer.MIN_VALUE, true},
+ {Duration.ofMillis(-1), -1L, true},
+ {Duration.ofMillis(0), 0L, true},
+ {Duration.ofMillis(1), 1L, true},
+ {Duration.ofMillis(Integer.MAX_VALUE), (long) Integer.MAX_VALUE, true},
+ {Duration.ofMillis(Long.MAX_VALUE / 2), Long.MAX_VALUE / 2, true},
});
TEST_DB.put(pair(Instant.class, Long.class), new Object[][]{
{Instant.parse("0000-01-01T00:00:00Z"), -62167219200000L, true},
@@ -2359,13 +2231,11 @@ private static void loadIntegerTests() {
{new AtomicInteger(2147483647), Integer.MAX_VALUE},
});
TEST_DB.put(pair(AtomicLong.class, Integer.class), new Object[][]{
- {new AtomicLong(-1), -1},
- {new AtomicLong(0), 0},
- {new AtomicLong(1), 1},
- {new AtomicLong(-2147483648), Integer.MIN_VALUE},
- {new AtomicLong(2147483647), Integer.MAX_VALUE},
- {new AtomicLong(-2147483649L), Integer.MAX_VALUE},
- {new AtomicLong(2147483648L), Integer.MIN_VALUE},
+ {new AtomicLong(-1), -1, true},
+ {new AtomicLong(0), 0, true},
+ {new AtomicLong(1), 1, true},
+ {new AtomicLong(-2147483648), Integer.MIN_VALUE, true},
+ {new AtomicLong(2147483647), Integer.MAX_VALUE, true},
});
TEST_DB.put(pair(BigInteger.class, Integer.class), new Object[][]{
{new BigInteger("-1"), -1},
@@ -2828,45 +2698,7 @@ void before() {
// create converter with default options
converter = new Converter(options);
}
-
- @Test
- void testForMissingTests() {
- Map, Set>> map = converter.allSupportedConversions();
- int neededTests = 0;
- int conversionPairCount = 0;
- int testCount = 0;
-
- for (Map.Entry, Set>> entry : map.entrySet()) {
- Class> sourceClass = entry.getKey();
- Set> targetClasses = entry.getValue();
-
- for (Class> targetClass : targetClasses) {
- Object[][] testData = TEST_DB.get(pair(sourceClass, targetClass));
- conversionPairCount++;
-
- if (testData == null) { // data set needs added
- // Change to throw exception, so that when new conversions are added, the tests will fail until
- // an "everything" test entry is added.
- System.err.println("No test data for: " + getShortName(sourceClass) + " ==> " + getShortName(targetClass));
- neededTests++;
- } else {
- if (testData.length == 0) {
- throw new IllegalStateException("No test instances for given pairing: " + Converter.getShortName(sourceClass) + " ==> " + Converter.getShortName(targetClass));
- }
- testCount += testData.length;
- }
- }
- }
-
- System.out.println("Total conversion pairs = " + conversionPairCount);
- System.out.println("Total tests = " + testCount);
- if (neededTests > 0) {
- System.err.println("Conversion pairs not tested = " + neededTests);
- System.err.flush();
- // fail(neededTests + " tests need to be added.");
- }
- }
-
+
private static Object possiblyConvertSupplier(Object possibleSupplier) {
if (possibleSupplier instanceof Supplier) {
return ((Supplier>) possibleSupplier).get();
@@ -2882,7 +2714,6 @@ private static Stream generateTestEverythingParams() {
for (Map.Entry, Class>>, Object[][]> entry : TEST_DB.entrySet()) {
Class> sourceClass = entry.getKey().getKey();
Class> targetClass = entry.getKey().getValue();
-
String sourceName = Converter.getShortName(sourceClass);
String targetName = Converter.getShortName(targetClass);
Object[][] testData = entry.getValue();
@@ -2938,7 +2769,7 @@ void testConvert(String shortNameSource, String shortNameTarget, Object source,
assert ClassUtilities.toPrimitiveWrapperClass(sourceClass).isInstance(source) : "source type mismatch ==> Expected: " + shortNameSource + ", Actual: " + Converter.getShortName(source.getClass());
}
assert target == null || target instanceof Throwable || ClassUtilities.toPrimitiveWrapperClass(targetClass).isInstance(target) : "target type mismatch ==> Expected: " + shortNameTarget + ", Actual: " + Converter.getShortName(target.getClass());
-
+
// if the source/target are the same Class, then ensure identity lambda is used.
if (sourceClass.equals(targetClass)) {
assertSame(source, converter.convert(source, targetClass));
@@ -2955,12 +2786,15 @@ void testConvert(String shortNameSource, String shortNameTarget, Object source,
try {
if (target instanceof AtomicLong) {
assertEquals(((AtomicLong) target).get(), ((AtomicLong) actual).get());
+ updateStat(pair(sourceClass, targetClass), true);
} else if (target instanceof BigDecimal) {
if (((BigDecimal) target).compareTo((BigDecimal) actual) != 0) {
assertEquals(target, actual);
}
+ updateStat(pair(sourceClass, targetClass), true);
} else {
assertEquals(target, actual);
+ updateStat(pair(sourceClass, targetClass), true);
}
}
catch (Throwable e) {
@@ -2970,6 +2804,44 @@ void testConvert(String shortNameSource, String shortNameTarget, Object source,
}
}
+ private static void updateStat(Map.Entry, Class>> pair, boolean state) {
+ STAT_DB.put(pair, state);
+ }
+
+ @BeforeAll
+ static void statPrep() {
+ Map, Set>> map = com.cedarsoftware.util.Converter.allSupportedConversions();
+
+ for (Map.Entry, Set>> entry : map.entrySet()) {
+ Class> sourceClass = entry.getKey();
+ Set> targetClasses = entry.getValue();
+ for (Class> targetClass : targetClasses) {
+ updateStat(pair(sourceClass, targetClass), false);
+ }
+ }
+ }
+
+ @AfterAll
+ static void printStats() {
+ Set testPairNames = new TreeSet<>();
+ int missing = 0;
+
+ for (Map.Entry, Class>>, Boolean> entry : STAT_DB.entrySet()) {
+ Map.Entry, Class>> pair = entry.getKey();
+ boolean value = entry.getValue();
+ if (!value) {
+ missing++;
+ testPairNames.add("\n " + Converter.getShortName(pair.getKey()) + " ==> " + Converter.getShortName(pair.getValue()));
+ }
+ }
+
+ System.out.println("Total conversion pairs = " + STAT_DB.size());
+ System.out.println("Conversion pairs tested = " + (STAT_DB.size() - missing));
+ System.out.println("Conversion pairs not tested = " + missing);
+ System.out.print("Tests needed ");
+ System.out.println(testPairNames);
+ }
+
@ParameterizedTest(name = "{0}[{2}] ==> {1}[{3}]")
@MethodSource("generateTestEverythingParamsInReverse")
void testConvertReverse(String shortNameSource, String shortNameTarget, Object source, Object target, Class> sourceClass, Class> targetClass) {