Always use static imports for assertion methods to be consistent with other tests classes.
This commit is contained in:
parent
729bcc46b5
commit
1f0dfc31b5
|
@ -33,7 +33,6 @@ import java.util.Comparator;
|
|||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -4968,12 +4967,12 @@ public class ArrayUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testCreatePrimitiveArray() {
|
||||
Assert.assertNull(ArrayUtils.toPrimitive((Object[]) null));
|
||||
Assert.assertArrayEquals(new int[]{}, ArrayUtils.toPrimitive(new Integer[]{}));
|
||||
Assert.assertArrayEquals(new short[]{2}, ArrayUtils.toPrimitive(new Short[]{2}));
|
||||
Assert.assertArrayEquals(new long[]{2, 3}, ArrayUtils.toPrimitive(new Long[]{2L, 3L}));
|
||||
Assert.assertArrayEquals(new float[]{3.14f}, ArrayUtils.toPrimitive(new Float[]{3.14f}), 0.1f);
|
||||
Assert.assertArrayEquals(new double[]{2.718}, ArrayUtils.toPrimitive(new Double[]{2.718}), 0.1);
|
||||
assertNull(ArrayUtils.toPrimitive((Object[]) null));
|
||||
assertArrayEquals(new int[]{}, ArrayUtils.toPrimitive(new Integer[]{}));
|
||||
assertArrayEquals(new short[]{2}, ArrayUtils.toPrimitive(new Short[]{2}));
|
||||
assertArrayEquals(new long[]{2, 3}, ArrayUtils.toPrimitive(new Long[]{2L, 3L}));
|
||||
assertArrayEquals(new float[]{3.14f}, ArrayUtils.toPrimitive(new Float[]{3.14f}), 0.1f);
|
||||
assertArrayEquals(new double[]{2.718}, ArrayUtils.toPrimitive(new Double[]{2.718}), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -5009,9 +5008,9 @@ public class ArrayUtilsTest {
|
|||
String[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
for (String element : array2) {
|
||||
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5021,8 +5020,8 @@ public class ArrayUtilsTest {
|
|||
boolean[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
Assert.assertEquals(5, ArrayUtils.removeAllOccurences(array1, true).length);
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
assertEquals(5, ArrayUtils.removeAllOccurences(array1, true).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -5031,9 +5030,9 @@ public class ArrayUtilsTest {
|
|||
byte[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
for (byte element : array2) {
|
||||
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5043,9 +5042,9 @@ public class ArrayUtilsTest {
|
|||
char[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
for (char element : array2) {
|
||||
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5055,9 +5054,9 @@ public class ArrayUtilsTest {
|
|||
short[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
for (short element : array2) {
|
||||
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5067,9 +5066,9 @@ public class ArrayUtilsTest {
|
|||
int[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
for (int element : array2) {
|
||||
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5079,9 +5078,9 @@ public class ArrayUtilsTest {
|
|||
long[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
for (long element : array2) {
|
||||
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5091,9 +5090,9 @@ public class ArrayUtilsTest {
|
|||
float[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
for (float element : array2) {
|
||||
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5103,9 +5102,9 @@ public class ArrayUtilsTest {
|
|||
double[] array2 = ArrayUtils.clone(array1);
|
||||
|
||||
ArrayUtils.shuffle(array1);
|
||||
Assert.assertFalse(Arrays.equals(array1, array2));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
for (double element : array2) {
|
||||
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -211,7 +210,7 @@ public class SerializationUtilsTest {
|
|||
public void testDeserializeClassCastException() {
|
||||
final String value = "Hello";
|
||||
final byte[] serialized = SerializationUtils.serialize(value);
|
||||
Assert.assertEquals(value, SerializationUtils.deserialize(serialized));
|
||||
assertEquals(value, SerializationUtils.deserialize(serialized));
|
||||
// Causes ClassCastException in call site, not in SerializationUtils.deserialize
|
||||
@SuppressWarnings("unused") // needed to cause Exception
|
||||
final Integer i = SerializationUtils.deserialize(serialized);
|
||||
|
|
|
@ -38,7 +38,6 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -62,7 +61,7 @@ public class SystemUtilsTest {
|
|||
public void testGetHostName() {
|
||||
final String hostName = SystemUtils.getHostName();
|
||||
String expected = SystemUtils.IS_OS_WINDOWS ? System.getenv("COMPUTERNAME") : System.getenv("HOSTNAME");
|
||||
Assert.assertEquals(expected, hostName);
|
||||
assertEquals(expected, hostName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,8 +70,8 @@ public class SystemUtilsTest {
|
|||
@Test
|
||||
public void testGetJavaHome() {
|
||||
final File dir = SystemUtils.getJavaHome();
|
||||
Assert.assertNotNull(dir);
|
||||
Assert.assertTrue(dir.exists());
|
||||
assertNotNull(dir);
|
||||
assertTrue(dir.exists());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,8 +80,8 @@ public class SystemUtilsTest {
|
|||
@Test
|
||||
public void testGetJavaIoTmpDir() {
|
||||
final File dir = SystemUtils.getJavaIoTmpDir();
|
||||
Assert.assertNotNull(dir);
|
||||
Assert.assertTrue(dir.exists());
|
||||
assertNotNull(dir);
|
||||
assertTrue(dir.exists());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,8 +90,8 @@ public class SystemUtilsTest {
|
|||
@Test
|
||||
public void testGetUserDir() {
|
||||
final File dir = SystemUtils.getUserDir();
|
||||
Assert.assertNotNull(dir);
|
||||
Assert.assertTrue(dir.exists());
|
||||
assertNotNull(dir);
|
||||
assertTrue(dir.exists());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,8 +100,8 @@ public class SystemUtilsTest {
|
|||
@Test
|
||||
public void testGetUserHome() {
|
||||
final File dir = SystemUtils.getUserHome();
|
||||
Assert.assertNotNull(dir);
|
||||
Assert.assertTrue(dir.exists());
|
||||
assertNotNull(dir);
|
||||
assertTrue(dir.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
@ -113,7 +115,7 @@ public class ReflectionToStringBuilderConcurrencyTest {
|
|||
tasks.add(producer);
|
||||
final List<Future<Integer>> futures = threadPool.invokeAll(tasks);
|
||||
for (final Future<Integer> future : futures) {
|
||||
Assert.assertEquals(REPEAT, future.get().intValue());
|
||||
assertEquals(REPEAT, future.get().intValue());
|
||||
}
|
||||
threadPool.shutdown();
|
||||
threadPool.awaitTermination(1, TimeUnit.SECONDS);
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
|
||||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -120,17 +121,17 @@ public class ReflectionToStringBuilderExcludeTest {
|
|||
}
|
||||
|
||||
private void validateNonSecretField(final String toString) {
|
||||
Assert.assertTrue(toString.contains(NOT_SECRET_FIELD));
|
||||
Assert.assertTrue(toString.contains(NOT_SECRET_VALUE));
|
||||
assertTrue(toString.contains(NOT_SECRET_FIELD));
|
||||
assertTrue(toString.contains(NOT_SECRET_VALUE));
|
||||
}
|
||||
|
||||
private void validateSecretFieldAbsent(final String toString) {
|
||||
Assert.assertEquals(ArrayUtils.INDEX_NOT_FOUND, toString.indexOf(SECRET_VALUE));
|
||||
assertEquals(ArrayUtils.INDEX_NOT_FOUND, toString.indexOf(SECRET_VALUE));
|
||||
this.validateNonSecretField(toString);
|
||||
}
|
||||
|
||||
private void validateSecretFieldPresent(final String toString) {
|
||||
Assert.assertTrue(toString.indexOf(SECRET_VALUE) > 0);
|
||||
assertTrue(toString.indexOf(SECRET_VALUE) > 0);
|
||||
this.validateNonSecretField(toString);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.util.List;
|
|||
|
||||
import org.apache.commons.lang3.test.NotVisibleExceptionFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -544,9 +543,9 @@ public class ExceptionUtilsTest {
|
|||
final Exception expected = new InterruptedException();
|
||||
try {
|
||||
ExceptionUtils.rethrow(expected);
|
||||
Assert.fail("Exception not thrown");
|
||||
fail("Exception not thrown");
|
||||
} catch (final Exception actual) {
|
||||
Assert.assertSame(expected, actual);
|
||||
assertSame(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -554,7 +553,7 @@ public class ExceptionUtilsTest {
|
|||
public void testCatchTechniques() {
|
||||
try {
|
||||
throwsCheckedException();
|
||||
Assert.fail("Exception not thrown");
|
||||
fail("Exception not thrown");
|
||||
} catch (final Exception ioe) {
|
||||
assertTrue(ioe instanceof IOException);
|
||||
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
|
||||
|
@ -562,7 +561,7 @@ public class ExceptionUtilsTest {
|
|||
|
||||
try {
|
||||
redeclareCheckedException();
|
||||
Assert.fail("Exception not thrown");
|
||||
fail("Exception not thrown");
|
||||
} catch (final IOException ioe) {
|
||||
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
|
||||
}
|
||||
|
@ -588,9 +587,9 @@ public class ExceptionUtilsTest {
|
|||
public void testWrapAndUnwrapError() {
|
||||
try {
|
||||
ExceptionUtils.wrapAndThrow(new OutOfMemoryError());
|
||||
Assert.fail("Error not thrown");
|
||||
fail("Error not thrown");
|
||||
} catch (final Throwable t) {
|
||||
Assert.assertTrue(ExceptionUtils.hasCause(t, Error.class));
|
||||
assertTrue(ExceptionUtils.hasCause(t, Error.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -598,9 +597,9 @@ public class ExceptionUtilsTest {
|
|||
public void testWrapAndUnwrapRuntimeException() {
|
||||
try {
|
||||
ExceptionUtils.wrapAndThrow(new IllegalArgumentException());
|
||||
Assert.fail("RuntimeException not thrown");
|
||||
fail("RuntimeException not thrown");
|
||||
} catch (final Throwable t) {
|
||||
Assert.assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class));
|
||||
assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -608,9 +607,9 @@ public class ExceptionUtilsTest {
|
|||
public void testWrapAndUnwrapCheckedException() {
|
||||
try {
|
||||
ExceptionUtils.wrapAndThrow(new IOException());
|
||||
Assert.fail("Checked Exception not thrown");
|
||||
fail("Checked Exception not thrown");
|
||||
} catch (final Throwable t) {
|
||||
Assert.assertTrue(ExceptionUtils.hasCause(t, IOException.class));
|
||||
assertTrue(ExceptionUtils.hasCause(t, IOException.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -618,9 +617,9 @@ public class ExceptionUtilsTest {
|
|||
public void testWrapAndUnwrapThrowable() {
|
||||
try {
|
||||
ExceptionUtils.wrapAndThrow(new TestThrowable());
|
||||
Assert.fail("Checked Exception not thrown");
|
||||
fail("Checked Exception not thrown");
|
||||
} catch (final Throwable t) {
|
||||
Assert.assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class));
|
||||
assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@ import org.apache.commons.lang3.reflect.testbed.GenericParent;
|
|||
import org.apache.commons.lang3.reflect.testbed.PublicChild;
|
||||
import org.apache.commons.lang3.reflect.testbed.StringParameterizedChild;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -986,20 +985,20 @@ public class MethodUtilsTest {
|
|||
public void testVarArgsUnboxing() throws Exception {
|
||||
final TestBean testBean = new TestBean();
|
||||
final int[] actual = (int[]) MethodUtils.invokeMethod(testBean, "unboxing", Integer.valueOf(1), Integer.valueOf(2));
|
||||
Assert.assertArrayEquals(new int[]{1, 2}, actual);
|
||||
assertArrayEquals(new int[]{1, 2}, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeMethodForceAccessNoArgs() throws Exception {
|
||||
Assert.assertEquals("privateStringStuff()", MethodUtils.invokeMethod(testBean, true, "privateStringStuff"));
|
||||
assertEquals("privateStringStuff()", MethodUtils.invokeMethod(testBean, true, "privateStringStuff"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeMethodForceAccessWithArgs() throws Exception {
|
||||
Assert.assertEquals("privateStringStuff(Integer)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", 5));
|
||||
Assert.assertEquals("privateStringStuff(double)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", 5.0d));
|
||||
Assert.assertEquals("privateStringStuff(String)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", "Hi There"));
|
||||
Assert.assertEquals("privateStringStuff(Object)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", new Date()));
|
||||
assertEquals("privateStringStuff(Integer)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", 5));
|
||||
assertEquals("privateStringStuff(double)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", 5.0d));
|
||||
assertEquals("privateStringStuff(String)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", "Hi There"));
|
||||
assertEquals("privateStringStuff(Object)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", new Date()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1007,10 +1006,10 @@ public class MethodUtilsTest {
|
|||
final Method distanceMethod = MethodUtils.getMatchingMethod(MethodUtils.class, "distance", Class[].class, Class[].class);
|
||||
distanceMethod.setAccessible(true);
|
||||
|
||||
Assert.assertEquals(-1, distanceMethod.invoke(null, new Class[]{String.class}, new Class[]{Date.class}));
|
||||
Assert.assertEquals(0, distanceMethod.invoke(null, new Class[]{Date.class}, new Class[]{Date.class}));
|
||||
Assert.assertEquals(1, distanceMethod.invoke(null, new Class[]{Integer.class}, new Class[]{ClassUtils.wrapperToPrimitive(Integer.class)}));
|
||||
Assert.assertEquals(2, distanceMethod.invoke(null, new Class[]{Integer.class}, new Class[]{Object.class}));
|
||||
assertEquals(-1, distanceMethod.invoke(null, new Class[]{String.class}, new Class[]{Date.class}));
|
||||
assertEquals(0, distanceMethod.invoke(null, new Class[]{Date.class}, new Class[]{Date.class}));
|
||||
assertEquals(1, distanceMethod.invoke(null, new Class[]{Integer.class}, new Class[]{ClassUtils.wrapperToPrimitive(Integer.class)}));
|
||||
assertEquals(2, distanceMethod.invoke(null, new Class[]{Integer.class}, new Class[]{Object.class}));
|
||||
|
||||
distanceMethod.setAccessible(false);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,12 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.reflect;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
|
@ -37,7 +43,6 @@ import org.apache.commons.lang3.reflect.testbed.Foo;
|
|||
import org.apache.commons.lang3.reflect.testbed.GenericParent;
|
||||
import org.apache.commons.lang3.reflect.testbed.GenericTypeHolder;
|
||||
import org.apache.commons.lang3.reflect.testbed.StringParameterizedChild;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -341,24 +346,24 @@ public class TypeUtilsTest<B> {
|
|||
final Type dat2Type = getClass().getField("dat2").getGenericType();
|
||||
final Type dat3Type = getClass().getField("dat3").getGenericType();
|
||||
dis = dat;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(datType, disType));
|
||||
assertTrue(TypeUtils.isAssignable(datType, disType));
|
||||
// dis = da;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(daType, disType));
|
||||
assertFalse(TypeUtils.isAssignable(daType, disType));
|
||||
dis = uhder;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(uhderType, disType));
|
||||
assertTrue(TypeUtils.isAssignable(uhderType, disType));
|
||||
dis = ding;
|
||||
Assert.assertFalse(String.format("type %s not assignable to %s!", dingType, disType),
|
||||
assertFalse(String.format("type %s not assignable to %s!", dingType, disType),
|
||||
TypeUtils.isAssignable(dingType, disType));
|
||||
dis = tester;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(testerType, disType));
|
||||
assertTrue(TypeUtils.isAssignable(testerType, disType));
|
||||
// dis = tester2;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(tester2Type, disType));
|
||||
assertFalse(TypeUtils.isAssignable(tester2Type, disType));
|
||||
// dat = dat2;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(dat2Type, datType));
|
||||
assertFalse(TypeUtils.isAssignable(dat2Type, datType));
|
||||
// dat2 = dat;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(datType, dat2Type));
|
||||
assertFalse(TypeUtils.isAssignable(datType, dat2Type));
|
||||
// dat = dat3;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(dat3Type, datType));
|
||||
assertFalse(TypeUtils.isAssignable(dat3Type, datType));
|
||||
final char ch = 0;
|
||||
final boolean bo = false;
|
||||
final byte by = 0;
|
||||
|
@ -368,57 +373,57 @@ public class TypeUtilsTest<B> {
|
|||
final float fl = 0;
|
||||
double du = 0;
|
||||
du = ch;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(char.class, double.class));
|
||||
assertTrue(TypeUtils.isAssignable(char.class, double.class));
|
||||
du = by;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(byte.class, double.class));
|
||||
assertTrue(TypeUtils.isAssignable(byte.class, double.class));
|
||||
du = sh;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(short.class, double.class));
|
||||
assertTrue(TypeUtils.isAssignable(short.class, double.class));
|
||||
du = in;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(int.class, double.class));
|
||||
assertTrue(TypeUtils.isAssignable(int.class, double.class));
|
||||
du = lo;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(long.class, double.class));
|
||||
assertTrue(TypeUtils.isAssignable(long.class, double.class));
|
||||
du = fl;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(float.class, double.class));
|
||||
assertTrue(TypeUtils.isAssignable(float.class, double.class));
|
||||
lo = in;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(int.class, long.class));
|
||||
assertTrue(TypeUtils.isAssignable(int.class, long.class));
|
||||
lo = Integer.valueOf(0);
|
||||
Assert.assertTrue(TypeUtils.isAssignable(Integer.class, long.class));
|
||||
assertTrue(TypeUtils.isAssignable(Integer.class, long.class));
|
||||
// Long lngW = 1;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(int.class, Long.class));
|
||||
assertFalse(TypeUtils.isAssignable(int.class, Long.class));
|
||||
// lngW = Integer.valueOf( 0 );
|
||||
Assert.assertFalse(TypeUtils.isAssignable(Integer.class, Long.class));
|
||||
assertFalse(TypeUtils.isAssignable(Integer.class, Long.class));
|
||||
in = Integer.valueOf(0);
|
||||
Assert.assertTrue(TypeUtils.isAssignable(Integer.class, int.class));
|
||||
assertTrue(TypeUtils.isAssignable(Integer.class, int.class));
|
||||
final Integer inte = in;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(int.class, Integer.class));
|
||||
Assert.assertTrue(TypeUtils.isAssignable(int.class, Number.class));
|
||||
Assert.assertTrue(TypeUtils.isAssignable(int.class, Object.class));
|
||||
assertTrue(TypeUtils.isAssignable(int.class, Integer.class));
|
||||
assertTrue(TypeUtils.isAssignable(int.class, Number.class));
|
||||
assertTrue(TypeUtils.isAssignable(int.class, Object.class));
|
||||
final Type intComparableType = getClass().getField("intComparable").getGenericType();
|
||||
intComparable = 1;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(int.class, intComparableType));
|
||||
Assert.assertTrue(TypeUtils.isAssignable(int.class, Comparable.class));
|
||||
assertTrue(TypeUtils.isAssignable(int.class, intComparableType));
|
||||
assertTrue(TypeUtils.isAssignable(int.class, Comparable.class));
|
||||
final Serializable ser = 1;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(int.class, Serializable.class));
|
||||
assertTrue(TypeUtils.isAssignable(int.class, Serializable.class));
|
||||
final Type longComparableType = getClass().getField("longComparable").getGenericType();
|
||||
// longComparable = 1;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(int.class, longComparableType));
|
||||
assertFalse(TypeUtils.isAssignable(int.class, longComparableType));
|
||||
// longComparable = Integer.valueOf( 0 );
|
||||
Assert.assertFalse(TypeUtils.isAssignable(Integer.class, longComparableType));
|
||||
assertFalse(TypeUtils.isAssignable(Integer.class, longComparableType));
|
||||
// int[] ia;
|
||||
// long[] la = ia;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(int[].class, long[].class));
|
||||
assertFalse(TypeUtils.isAssignable(int[].class, long[].class));
|
||||
final Integer[] ia = null;
|
||||
final Type caType = getClass().getField("intWildcardComparable").getGenericType();
|
||||
intWildcardComparable = ia;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(Integer[].class, caType));
|
||||
assertTrue(TypeUtils.isAssignable(Integer[].class, caType));
|
||||
// int[] ina = ia;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(Integer[].class, int[].class));
|
||||
assertFalse(TypeUtils.isAssignable(Integer[].class, int[].class));
|
||||
final int[] ina = null;
|
||||
Object[] oa;
|
||||
// oa = ina;
|
||||
Assert.assertFalse(TypeUtils.isAssignable(int[].class, Object[].class));
|
||||
assertFalse(TypeUtils.isAssignable(int[].class, Object[].class));
|
||||
oa = new Integer[0];
|
||||
Assert.assertTrue(TypeUtils.isAssignable(Integer[].class, Object[].class));
|
||||
assertTrue(TypeUtils.isAssignable(Integer[].class, Object[].class));
|
||||
final Type bClassType = AClass.class.getField("bClass").getGenericType();
|
||||
final Type cClassType = AClass.class.getField("cClass").getGenericType();
|
||||
final Type dClassType = AClass.class.getField("dClass").getGenericType();
|
||||
|
@ -426,25 +431,25 @@ public class TypeUtilsTest<B> {
|
|||
final Type fClassType = AClass.class.getField("fClass").getGenericType();
|
||||
final AClass aClass = new AClass(new AAClass<String>());
|
||||
aClass.bClass = aClass.cClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(cClassType, bClassType));
|
||||
assertTrue(TypeUtils.isAssignable(cClassType, bClassType));
|
||||
aClass.bClass = aClass.dClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(dClassType, bClassType));
|
||||
assertTrue(TypeUtils.isAssignable(dClassType, bClassType));
|
||||
aClass.bClass = aClass.eClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(eClassType, bClassType));
|
||||
assertTrue(TypeUtils.isAssignable(eClassType, bClassType));
|
||||
aClass.bClass = aClass.fClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(fClassType, bClassType));
|
||||
assertTrue(TypeUtils.isAssignable(fClassType, bClassType));
|
||||
aClass.cClass = aClass.dClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(dClassType, cClassType));
|
||||
assertTrue(TypeUtils.isAssignable(dClassType, cClassType));
|
||||
aClass.cClass = aClass.eClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(eClassType, cClassType));
|
||||
assertTrue(TypeUtils.isAssignable(eClassType, cClassType));
|
||||
aClass.cClass = aClass.fClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(fClassType, cClassType));
|
||||
assertTrue(TypeUtils.isAssignable(fClassType, cClassType));
|
||||
aClass.dClass = aClass.eClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(eClassType, dClassType));
|
||||
assertTrue(TypeUtils.isAssignable(eClassType, dClassType));
|
||||
aClass.dClass = aClass.fClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(fClassType, dClassType));
|
||||
assertTrue(TypeUtils.isAssignable(fClassType, dClassType));
|
||||
aClass.eClass = aClass.fClass;
|
||||
Assert.assertTrue(TypeUtils.isAssignable(fClassType, eClassType));
|
||||
assertTrue(TypeUtils.isAssignable(fClassType, eClassType));
|
||||
}
|
||||
|
||||
public void delegateBooleanAssertion(final Type[] types, final int i2, final int i1, final boolean expected) {
|
||||
|
@ -453,11 +458,11 @@ public class TypeUtilsTest<B> {
|
|||
final boolean isAssignable = TypeUtils.isAssignable(type2, type1);
|
||||
|
||||
if (expected) {
|
||||
Assert.assertTrue("[" + i1 + ", " + i2 + "]: From "
|
||||
assertTrue("[" + i1 + ", " + i2 + "]: From "
|
||||
+ String.valueOf(type2) + " to "
|
||||
+ String.valueOf(type1), isAssignable);
|
||||
} else {
|
||||
Assert.assertFalse("[" + i1 + ", " + i2 + "]: From "
|
||||
assertFalse("[" + i1 + ", " + i2 + "]: From "
|
||||
+ String.valueOf(type2) + " to "
|
||||
+ String.valueOf(type1), isAssignable);
|
||||
}
|
||||
|
@ -469,9 +474,9 @@ public class TypeUtilsTest<B> {
|
|||
final Type intComparableType = getClass().getField("intComparable").getGenericType();
|
||||
final Type uriComparableType = getClass().getField("uriComparable").getGenericType();
|
||||
intComparable = 1;
|
||||
Assert.assertTrue(TypeUtils.isInstance(1, intComparableType));
|
||||
assertTrue(TypeUtils.isInstance(1, intComparableType));
|
||||
// uriComparable = 1;
|
||||
Assert.assertFalse(TypeUtils.isInstance(1, uriComparableType));
|
||||
assertFalse(TypeUtils.isInstance(1, uriComparableType));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -482,45 +487,45 @@ public class TypeUtilsTest<B> {
|
|||
|
||||
typeVarAssigns = TypeUtils.getTypeArguments(Integer.class, Comparable.class);
|
||||
treeSetTypeVar = Comparable.class.getTypeParameters()[0];
|
||||
Assert.assertTrue("Type var assigns for Comparable from Integer: " + typeVarAssigns,
|
||||
assertTrue("Type var assigns for Comparable from Integer: " + typeVarAssigns,
|
||||
typeVarAssigns.containsKey(treeSetTypeVar));
|
||||
typeArg = typeVarAssigns.get(treeSetTypeVar);
|
||||
Assert.assertEquals("Type argument of Comparable from Integer: " + typeArg, Integer.class,
|
||||
assertEquals("Type argument of Comparable from Integer: " + typeArg, Integer.class,
|
||||
typeVarAssigns.get(treeSetTypeVar));
|
||||
|
||||
typeVarAssigns = TypeUtils.getTypeArguments(int.class, Comparable.class);
|
||||
treeSetTypeVar = Comparable.class.getTypeParameters()[0];
|
||||
Assert.assertTrue("Type var assigns for Comparable from int: " + typeVarAssigns,
|
||||
assertTrue("Type var assigns for Comparable from int: " + typeVarAssigns,
|
||||
typeVarAssigns.containsKey(treeSetTypeVar));
|
||||
typeArg = typeVarAssigns.get(treeSetTypeVar);
|
||||
Assert.assertEquals("Type argument of Comparable from int: " + typeArg, Integer.class,
|
||||
assertEquals("Type argument of Comparable from int: " + typeArg, Integer.class,
|
||||
typeVarAssigns.get(treeSetTypeVar));
|
||||
|
||||
final Collection<Integer> col = Arrays.asList(new Integer[0]);
|
||||
typeVarAssigns = TypeUtils.getTypeArguments(List.class, Collection.class);
|
||||
treeSetTypeVar = Comparable.class.getTypeParameters()[0];
|
||||
Assert.assertFalse("Type var assigns for Collection from List: " + typeVarAssigns,
|
||||
assertFalse("Type var assigns for Collection from List: " + typeVarAssigns,
|
||||
typeVarAssigns.containsKey(treeSetTypeVar));
|
||||
|
||||
typeVarAssigns = TypeUtils.getTypeArguments(AAAClass.BBBClass.class, AAClass.BBClass.class);
|
||||
Assert.assertTrue(typeVarAssigns.size() == 2);
|
||||
Assert.assertEquals(String.class, typeVarAssigns.get(AAClass.class.getTypeParameters()[0]));
|
||||
Assert.assertEquals(String.class, typeVarAssigns.get(AAClass.BBClass.class.getTypeParameters()[0]));
|
||||
assertEquals(2, typeVarAssigns.size());
|
||||
assertEquals(String.class, typeVarAssigns.get(AAClass.class.getTypeParameters()[0]));
|
||||
assertEquals(String.class, typeVarAssigns.get(AAClass.BBClass.class.getTypeParameters()[0]));
|
||||
|
||||
typeVarAssigns = TypeUtils.getTypeArguments(Other.class, This.class);
|
||||
Assert.assertEquals(2, typeVarAssigns.size());
|
||||
Assert.assertEquals(String.class, typeVarAssigns.get(This.class.getTypeParameters()[0]));
|
||||
Assert.assertEquals(Other.class.getTypeParameters()[0], typeVarAssigns.get(This.class.getTypeParameters()[1]));
|
||||
assertEquals(2, typeVarAssigns.size());
|
||||
assertEquals(String.class, typeVarAssigns.get(This.class.getTypeParameters()[0]));
|
||||
assertEquals(Other.class.getTypeParameters()[0], typeVarAssigns.get(This.class.getTypeParameters()[1]));
|
||||
|
||||
typeVarAssigns = TypeUtils.getTypeArguments(And.class, This.class);
|
||||
Assert.assertEquals(2, typeVarAssigns.size());
|
||||
Assert.assertEquals(Number.class, typeVarAssigns.get(This.class.getTypeParameters()[0]));
|
||||
Assert.assertEquals(Number.class, typeVarAssigns.get(This.class.getTypeParameters()[1]));
|
||||
assertEquals(2, typeVarAssigns.size());
|
||||
assertEquals(Number.class, typeVarAssigns.get(This.class.getTypeParameters()[0]));
|
||||
assertEquals(Number.class, typeVarAssigns.get(This.class.getTypeParameters()[1]));
|
||||
|
||||
typeVarAssigns = TypeUtils.getTypeArguments(Thing.class, Other.class);
|
||||
Assert.assertEquals(2, typeVarAssigns.size());
|
||||
Assert.assertEquals(getClass().getTypeParameters()[0], typeVarAssigns.get(getClass().getTypeParameters()[0]));
|
||||
Assert.assertEquals(getClass().getTypeParameters()[0], typeVarAssigns.get(Other.class.getTypeParameters()[0]));
|
||||
assertEquals(2, typeVarAssigns.size());
|
||||
assertEquals(getClass().getTypeParameters()[0], typeVarAssigns.get(getClass().getTypeParameters()[0]));
|
||||
assertEquals(getClass().getTypeParameters()[0], typeVarAssigns.get(Other.class.getTypeParameters()[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -529,13 +534,13 @@ public class TypeUtilsTest<B> {
|
|||
final Map<TypeVariable<?>, Type> typeVarAssigns = new HashMap<>();
|
||||
final Integer max = TypeUtilsTest.<Integer> stub();
|
||||
typeVarAssigns.put(getClass().getMethod("stub").getTypeParameters()[0], Integer.class);
|
||||
Assert.assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns));
|
||||
assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns));
|
||||
typeVarAssigns.clear();
|
||||
typeVarAssigns.put(getClass().getMethod("stub2").getTypeParameters()[0], Integer.class);
|
||||
Assert.assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns));
|
||||
assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns));
|
||||
typeVarAssigns.clear();
|
||||
typeVarAssigns.put(getClass().getMethod("stub3").getTypeParameters()[0], Integer.class);
|
||||
Assert.assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns));
|
||||
assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -546,8 +551,8 @@ public class TypeUtilsTest<B> {
|
|||
final Map<TypeVariable<?>, Type> typeVarAssigns = TypeUtils.determineTypeArguments(TreeSet.class,
|
||||
iterableType);
|
||||
final TypeVariable<?> treeSetTypeVar = TreeSet.class.getTypeParameters()[0];
|
||||
Assert.assertTrue(typeVarAssigns.containsKey(treeSetTypeVar));
|
||||
Assert.assertEquals(iterableType.getActualTypeArguments()[0], typeVarAssigns
|
||||
assertTrue(typeVarAssigns.containsKey(treeSetTypeVar));
|
||||
assertEquals(iterableType.getActualTypeArguments()[0], typeVarAssigns
|
||||
.get(treeSetTypeVar));
|
||||
}
|
||||
|
||||
|
@ -559,47 +564,46 @@ public class TypeUtilsTest<B> {
|
|||
.getGenericType();
|
||||
final Type foosFieldType = GenericTypeHolder.class.getDeclaredField("foos").getGenericType();
|
||||
final Type genericParentT = GenericParent.class.getTypeParameters()[0];
|
||||
Assert.assertEquals(GenericParent.class, TypeUtils.getRawType(stringParentFieldType, null));
|
||||
Assert
|
||||
.assertEquals(GenericParent.class, TypeUtils.getRawType(integerParentFieldType,
|
||||
assertEquals(GenericParent.class, TypeUtils.getRawType(stringParentFieldType, null));
|
||||
assertEquals(GenericParent.class, TypeUtils.getRawType(integerParentFieldType,
|
||||
null));
|
||||
Assert.assertEquals(List.class, TypeUtils.getRawType(foosFieldType, null));
|
||||
Assert.assertEquals(String.class, TypeUtils.getRawType(genericParentT,
|
||||
assertEquals(List.class, TypeUtils.getRawType(foosFieldType, null));
|
||||
assertEquals(String.class, TypeUtils.getRawType(genericParentT,
|
||||
StringParameterizedChild.class));
|
||||
Assert.assertEquals(String.class, TypeUtils.getRawType(genericParentT,
|
||||
assertEquals(String.class, TypeUtils.getRawType(genericParentT,
|
||||
stringParentFieldType));
|
||||
Assert.assertEquals(Foo.class, TypeUtils.getRawType(Iterable.class.getTypeParameters()[0],
|
||||
assertEquals(Foo.class, TypeUtils.getRawType(Iterable.class.getTypeParameters()[0],
|
||||
foosFieldType));
|
||||
Assert.assertEquals(Foo.class, TypeUtils.getRawType(List.class.getTypeParameters()[0],
|
||||
assertEquals(Foo.class, TypeUtils.getRawType(List.class.getTypeParameters()[0],
|
||||
foosFieldType));
|
||||
Assert.assertNull(TypeUtils.getRawType(genericParentT, GenericParent.class));
|
||||
Assert.assertEquals(GenericParent[].class, TypeUtils.getRawType(GenericTypeHolder.class
|
||||
assertNull(TypeUtils.getRawType(genericParentT, GenericParent.class));
|
||||
assertEquals(GenericParent[].class, TypeUtils.getRawType(GenericTypeHolder.class
|
||||
.getDeclaredField("barParents").getGenericType(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsArrayTypeClasses() {
|
||||
Assert.assertTrue(TypeUtils.isArrayType(boolean[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(byte[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(short[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(int[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(char[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(long[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(float[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(double[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(Object[].class));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(String[].class));
|
||||
assertTrue(TypeUtils.isArrayType(boolean[].class));
|
||||
assertTrue(TypeUtils.isArrayType(byte[].class));
|
||||
assertTrue(TypeUtils.isArrayType(short[].class));
|
||||
assertTrue(TypeUtils.isArrayType(int[].class));
|
||||
assertTrue(TypeUtils.isArrayType(char[].class));
|
||||
assertTrue(TypeUtils.isArrayType(long[].class));
|
||||
assertTrue(TypeUtils.isArrayType(float[].class));
|
||||
assertTrue(TypeUtils.isArrayType(double[].class));
|
||||
assertTrue(TypeUtils.isArrayType(Object[].class));
|
||||
assertTrue(TypeUtils.isArrayType(String[].class));
|
||||
|
||||
Assert.assertFalse(TypeUtils.isArrayType(boolean.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(byte.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(short.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(int.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(char.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(long.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(float.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(double.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(Object.class));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(String.class));
|
||||
assertFalse(TypeUtils.isArrayType(boolean.class));
|
||||
assertFalse(TypeUtils.isArrayType(byte.class));
|
||||
assertFalse(TypeUtils.isArrayType(short.class));
|
||||
assertFalse(TypeUtils.isArrayType(int.class));
|
||||
assertFalse(TypeUtils.isArrayType(char.class));
|
||||
assertFalse(TypeUtils.isArrayType(long.class));
|
||||
assertFalse(TypeUtils.isArrayType(float.class));
|
||||
assertFalse(TypeUtils.isArrayType(double.class));
|
||||
assertFalse(TypeUtils.isArrayType(Object.class));
|
||||
assertFalse(TypeUtils.isArrayType(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -610,41 +614,41 @@ public class TypeUtilsTest<B> {
|
|||
|
||||
final Type[] types = method.getGenericParameterTypes();
|
||||
|
||||
Assert.assertFalse(TypeUtils.isArrayType(types[0]));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(types[1]));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(types[2]));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(types[3]));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(types[4]));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(types[5]));
|
||||
Assert.assertFalse(TypeUtils.isArrayType(types[6]));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(types[7]));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(types[8]));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(types[9]));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(types[10]));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(types[11]));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(types[12]));
|
||||
Assert.assertTrue(TypeUtils.isArrayType(types[13]));
|
||||
assertFalse(TypeUtils.isArrayType(types[0]));
|
||||
assertFalse(TypeUtils.isArrayType(types[1]));
|
||||
assertFalse(TypeUtils.isArrayType(types[2]));
|
||||
assertFalse(TypeUtils.isArrayType(types[3]));
|
||||
assertFalse(TypeUtils.isArrayType(types[4]));
|
||||
assertFalse(TypeUtils.isArrayType(types[5]));
|
||||
assertFalse(TypeUtils.isArrayType(types[6]));
|
||||
assertTrue(TypeUtils.isArrayType(types[7]));
|
||||
assertTrue(TypeUtils.isArrayType(types[8]));
|
||||
assertTrue(TypeUtils.isArrayType(types[9]));
|
||||
assertTrue(TypeUtils.isArrayType(types[10]));
|
||||
assertTrue(TypeUtils.isArrayType(types[11]));
|
||||
assertTrue(TypeUtils.isArrayType(types[12]));
|
||||
assertTrue(TypeUtils.isArrayType(types[13]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPrimitiveArrayComponentType() throws Exception {
|
||||
Assert.assertEquals(boolean.class, TypeUtils.getArrayComponentType(boolean[].class));
|
||||
Assert.assertEquals(byte.class, TypeUtils.getArrayComponentType(byte[].class));
|
||||
Assert.assertEquals(short.class, TypeUtils.getArrayComponentType(short[].class));
|
||||
Assert.assertEquals(int.class, TypeUtils.getArrayComponentType(int[].class));
|
||||
Assert.assertEquals(char.class, TypeUtils.getArrayComponentType(char[].class));
|
||||
Assert.assertEquals(long.class, TypeUtils.getArrayComponentType(long[].class));
|
||||
Assert.assertEquals(float.class, TypeUtils.getArrayComponentType(float[].class));
|
||||
Assert.assertEquals(double.class, TypeUtils.getArrayComponentType(double[].class));
|
||||
assertEquals(boolean.class, TypeUtils.getArrayComponentType(boolean[].class));
|
||||
assertEquals(byte.class, TypeUtils.getArrayComponentType(byte[].class));
|
||||
assertEquals(short.class, TypeUtils.getArrayComponentType(short[].class));
|
||||
assertEquals(int.class, TypeUtils.getArrayComponentType(int[].class));
|
||||
assertEquals(char.class, TypeUtils.getArrayComponentType(char[].class));
|
||||
assertEquals(long.class, TypeUtils.getArrayComponentType(long[].class));
|
||||
assertEquals(float.class, TypeUtils.getArrayComponentType(float[].class));
|
||||
assertEquals(double.class, TypeUtils.getArrayComponentType(double[].class));
|
||||
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(boolean.class));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(byte.class));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(short.class));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(int.class));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(char.class));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(long.class));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(float.class));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(double.class));
|
||||
assertNull(TypeUtils.getArrayComponentType(boolean.class));
|
||||
assertNull(TypeUtils.getArrayComponentType(byte.class));
|
||||
assertNull(TypeUtils.getArrayComponentType(short.class));
|
||||
assertNull(TypeUtils.getArrayComponentType(int.class));
|
||||
assertNull(TypeUtils.getArrayComponentType(char.class));
|
||||
assertNull(TypeUtils.getArrayComponentType(long.class));
|
||||
assertNull(TypeUtils.getArrayComponentType(float.class));
|
||||
assertNull(TypeUtils.getArrayComponentType(double.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -655,74 +659,74 @@ public class TypeUtilsTest<B> {
|
|||
|
||||
final Type[] types = method.getGenericParameterTypes();
|
||||
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(types[0]));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(types[1]));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(types[2]));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(types[3]));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(types[4]));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(types[5]));
|
||||
Assert.assertNull(TypeUtils.getArrayComponentType(types[6]));
|
||||
Assert.assertEquals(types[0], TypeUtils.getArrayComponentType(types[7]));
|
||||
Assert.assertEquals(types[1], TypeUtils.getArrayComponentType(types[8]));
|
||||
Assert.assertEquals(types[2], TypeUtils.getArrayComponentType(types[9]));
|
||||
Assert.assertEquals(types[3], TypeUtils.getArrayComponentType(types[10]));
|
||||
Assert.assertEquals(types[4], TypeUtils.getArrayComponentType(types[11]));
|
||||
Assert.assertEquals(types[5], TypeUtils.getArrayComponentType(types[12]));
|
||||
Assert.assertEquals(types[6], TypeUtils.getArrayComponentType(types[13]));
|
||||
assertNull(TypeUtils.getArrayComponentType(types[0]));
|
||||
assertNull(TypeUtils.getArrayComponentType(types[1]));
|
||||
assertNull(TypeUtils.getArrayComponentType(types[2]));
|
||||
assertNull(TypeUtils.getArrayComponentType(types[3]));
|
||||
assertNull(TypeUtils.getArrayComponentType(types[4]));
|
||||
assertNull(TypeUtils.getArrayComponentType(types[5]));
|
||||
assertNull(TypeUtils.getArrayComponentType(types[6]));
|
||||
assertEquals(types[0], TypeUtils.getArrayComponentType(types[7]));
|
||||
assertEquals(types[1], TypeUtils.getArrayComponentType(types[8]));
|
||||
assertEquals(types[2], TypeUtils.getArrayComponentType(types[9]));
|
||||
assertEquals(types[3], TypeUtils.getArrayComponentType(types[10]));
|
||||
assertEquals(types[4], TypeUtils.getArrayComponentType(types[11]));
|
||||
assertEquals(types[5], TypeUtils.getArrayComponentType(types[12]));
|
||||
assertEquals(types[6], TypeUtils.getArrayComponentType(types[13]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLang820() throws Exception {
|
||||
final Type[] typeArray = {String.class, String.class};
|
||||
final Type[] expectedArray = {String.class};
|
||||
Assert.assertArrayEquals(expectedArray, TypeUtils.normalizeUpperBounds(typeArray));
|
||||
assertArrayEquals(expectedArray, TypeUtils.normalizeUpperBounds(typeArray));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterize() throws Exception {
|
||||
final ParameterizedType stringComparableType = TypeUtils.parameterize(Comparable.class, String.class);
|
||||
Assert.assertTrue(TypeUtils.equals(getClass().getField("stringComparable").getGenericType(),
|
||||
assertTrue(TypeUtils.equals(getClass().getField("stringComparable").getGenericType(),
|
||||
stringComparableType));
|
||||
Assert.assertEquals("java.lang.Comparable<java.lang.String>", stringComparableType.toString());
|
||||
assertEquals("java.lang.Comparable<java.lang.String>", stringComparableType.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizeWithOwner() throws Exception {
|
||||
final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class);
|
||||
final ParameterizedType dat2Type = TypeUtils.parameterizeWithOwner(owner, That.class, String.class, String.class);
|
||||
Assert.assertTrue(TypeUtils.equals(getClass().getField("dat2").getGenericType(), dat2Type));
|
||||
assertTrue(TypeUtils.equals(getClass().getField("dat2").getGenericType(), dat2Type));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcardType() throws Exception {
|
||||
final WildcardType simpleWildcard = TypeUtils.wildcardType().withUpperBounds(String.class).build();
|
||||
final Field cClass = AClass.class.getField("cClass");
|
||||
Assert.assertTrue(TypeUtils.equals(((ParameterizedType) cClass.getGenericType()).getActualTypeArguments()[0],
|
||||
assertTrue(TypeUtils.equals(((ParameterizedType) cClass.getGenericType()).getActualTypeArguments()[0],
|
||||
simpleWildcard));
|
||||
Assert.assertEquals(String.format("? extends %s", String.class.getName()), TypeUtils.toString(simpleWildcard));
|
||||
Assert.assertEquals(String.format("? extends %s", String.class.getName()), simpleWildcard.toString());
|
||||
assertEquals(String.format("? extends %s", String.class.getName()), TypeUtils.toString(simpleWildcard));
|
||||
assertEquals(String.format("? extends %s", String.class.getName()), simpleWildcard.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnboundedWildcardType() {
|
||||
final WildcardType unbounded = TypeUtils.wildcardType().withLowerBounds((Type) null).withUpperBounds().build();
|
||||
Assert.assertTrue(TypeUtils.equals(TypeUtils.WILDCARD_ALL, unbounded));
|
||||
Assert.assertArrayEquals(new Type[] { Object.class }, TypeUtils.getImplicitUpperBounds(unbounded));
|
||||
Assert.assertArrayEquals(new Type[] { null }, TypeUtils.getImplicitLowerBounds(unbounded));
|
||||
Assert.assertEquals("?", TypeUtils.toString(unbounded));
|
||||
Assert.assertEquals("?", unbounded.toString());
|
||||
assertTrue(TypeUtils.equals(TypeUtils.WILDCARD_ALL, unbounded));
|
||||
assertArrayEquals(new Type[] { Object.class }, TypeUtils.getImplicitUpperBounds(unbounded));
|
||||
assertArrayEquals(new Type[] { null }, TypeUtils.getImplicitLowerBounds(unbounded));
|
||||
assertEquals("?", TypeUtils.toString(unbounded));
|
||||
assertEquals("?", unbounded.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowerBoundedWildcardType() {
|
||||
final WildcardType lowerBounded = TypeUtils.wildcardType().withLowerBounds(java.sql.Date.class).build();
|
||||
Assert.assertEquals(String.format("? super %s", java.sql.Date.class.getName()), TypeUtils.toString(lowerBounded));
|
||||
Assert.assertEquals(String.format("? super %s", java.sql.Date.class.getName()), lowerBounded.toString());
|
||||
assertEquals(String.format("? super %s", java.sql.Date.class.getName()), TypeUtils.toString(lowerBounded));
|
||||
assertEquals(String.format("? super %s", java.sql.Date.class.getName()), lowerBounded.toString());
|
||||
|
||||
final TypeVariable<Class<Iterable>> iterableT0 = Iterable.class.getTypeParameters()[0];
|
||||
final WildcardType lowerTypeVariable = TypeUtils.wildcardType().withLowerBounds(iterableT0).build();
|
||||
Assert.assertEquals(String.format("? super %s", iterableT0.getName()), TypeUtils.toString(lowerTypeVariable));
|
||||
Assert.assertEquals(String.format("? super %s", iterableT0.getName()), lowerTypeVariable.toString());
|
||||
assertEquals(String.format("? super %s", iterableT0.getName()), TypeUtils.toString(lowerTypeVariable));
|
||||
assertEquals(String.format("? super %s", iterableT0.getName()), lowerTypeVariable.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -730,8 +734,8 @@ public class TypeUtilsTest<B> {
|
|||
final Type nonWildcardType = getClass().getDeclaredField("wildcardComparable").getGenericType();
|
||||
final Type wildcardType = ((ParameterizedType)nonWildcardType).getActualTypeArguments()[0];
|
||||
|
||||
Assert.assertFalse(TypeUtils.equals(wildcardType, nonWildcardType));
|
||||
Assert.assertFalse(TypeUtils.equals(nonWildcardType, wildcardType));
|
||||
assertFalse(TypeUtils.equals(wildcardType, nonWildcardType));
|
||||
assertFalse(TypeUtils.equals(nonWildcardType, wildcardType));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -740,29 +744,29 @@ public class TypeUtilsTest<B> {
|
|||
final GenericArrayType actual =
|
||||
TypeUtils.genericArrayType(TypeUtils.parameterize(Comparable.class, TypeUtils.wildcardType()
|
||||
.withUpperBounds(Integer.class).build()));
|
||||
Assert.assertTrue(TypeUtils.equals(expected, actual));
|
||||
Assert.assertEquals("java.lang.Comparable<? extends java.lang.Integer>[]", actual.toString());
|
||||
assertTrue(TypeUtils.equals(expected, actual));
|
||||
assertEquals("java.lang.Comparable<? extends java.lang.Integer>[]", actual.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringLang1311() {
|
||||
Assert.assertEquals("int[]", TypeUtils.toString(int[].class));
|
||||
Assert.assertEquals("java.lang.Integer[]", TypeUtils.toString(Integer[].class));
|
||||
assertEquals("int[]", TypeUtils.toString(int[].class));
|
||||
assertEquals("java.lang.Integer[]", TypeUtils.toString(Integer[].class));
|
||||
Field stringListField = FieldUtils.getDeclaredField(getClass(), "stringListArray");
|
||||
Assert.assertEquals("java.util.List<java.lang.String>[]", TypeUtils.toString(stringListField.getGenericType()));
|
||||
assertEquals("java.util.List<java.lang.String>[]", TypeUtils.toString(stringListField.getGenericType()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToLongString() {
|
||||
Assert.assertEquals(getClass().getName() + ":B", TypeUtils.toLongString(getClass().getTypeParameters()[0]));
|
||||
assertEquals(getClass().getName() + ":B", TypeUtils.toLongString(getClass().getTypeParameters()[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrap() {
|
||||
final Type t = getClass().getTypeParameters()[0];
|
||||
Assert.assertTrue(TypeUtils.equals(t, TypeUtils.wrap(t).getType()));
|
||||
assertTrue(TypeUtils.equals(t, TypeUtils.wrap(t).getType()));
|
||||
|
||||
Assert.assertEquals(String.class, TypeUtils.wrap(String.class).getType());
|
||||
assertEquals(String.class, TypeUtils.wrap(String.class).getType());
|
||||
}
|
||||
|
||||
public static class ClassWithSuperClassWithGenericType extends ArrayList<Object> {
|
||||
|
@ -778,13 +782,13 @@ public class TypeUtilsTest<B> {
|
|||
final Type fromType = ClassWithSuperClassWithGenericType.class.getDeclaredMethod("methodWithGenericReturnType").getGenericReturnType();
|
||||
final Type failingToType = TypeUtils.wildcardType().withLowerBounds(ClassWithSuperClassWithGenericType.class).build();
|
||||
|
||||
Assert.assertTrue(TypeUtils.isAssignable(fromType, failingToType));
|
||||
assertTrue(TypeUtils.isAssignable(fromType, failingToType));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLANG1348() throws Exception {
|
||||
final Method method = Enum.class.getMethod("valueOf", Class.class, String.class);
|
||||
Assert.assertEquals("T extends java.lang.Enum<T>", TypeUtils.toString(method.getGenericReturnType()));
|
||||
assertEquals("T extends java.lang.Enum<T>", TypeUtils.toString(method.getGenericReturnType()));
|
||||
}
|
||||
|
||||
public Iterable<? extends Map<Integer, ? extends Collection<?>>> iterable;
|
||||
|
|
|
@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicLongArray;
|
|||
|
||||
import org.apache.commons.lang3.test.SystemDefaults;
|
||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -315,10 +314,10 @@ public class FastDateFormatTest {
|
|||
final Date date = new Date(Long.MAX_VALUE);
|
||||
|
||||
String dateAsString = FastDateFormat.getInstance("yyyy-MM-dd", utc, Locale.US).format(date);
|
||||
Assert.assertEquals("292278994-08-17", dateAsString);
|
||||
assertEquals("292278994-08-17", dateAsString);
|
||||
|
||||
dateAsString = FastDateFormat.getInstance("dd/MM/yyyy", utc, Locale.US).format(date);
|
||||
Assert.assertEquals("17/08/292278994", dateAsString);
|
||||
assertEquals("17/08/292278994", dateAsString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.commons.lang3.time;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.ParseException;
|
||||
|
@ -34,7 +35,6 @@ import java.util.TimeZone;
|
|||
|
||||
import org.apache.commons.lang3.LocaleUtils;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -272,7 +272,7 @@ public class FastDateParserTest {
|
|||
final Date expected= cal.getTime();
|
||||
|
||||
final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale));
|
||||
Assert.assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual);
|
||||
assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ public class FastDateParserTest {
|
|||
try {
|
||||
checkParse(locale, cal, sdf, fdf);
|
||||
} catch(final ParseException ex) {
|
||||
Assert.fail("Locale "+locale+ " failed with "+format+" era "+(eraBC?"BC":"AD")+"\n" + trimMessage(ex.toString()));
|
||||
fail("Locale "+locale+ " failed with "+format+" era "+(eraBC?"BC":"AD")+"\n" + trimMessage(ex.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ public class FastDateParserTest {
|
|||
try {
|
||||
checkParse(locale, cal, sdf, fdf);
|
||||
} catch(final ParseException ex) {
|
||||
Assert.fail("Locale "+locale+ " failed with "+LONG_FORMAT+"\n" + trimMessage(ex.toString()));
|
||||
fail("Locale "+locale+ " failed with "+LONG_FORMAT+"\n" + trimMessage(ex.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ public class FastDateParserTest {
|
|||
sdf.setTimeZone(NEW_YORK);
|
||||
dsdf = sdf.parse(date);
|
||||
if (shouldFail) {
|
||||
Assert.fail("Expected SDF failure, but got " + dsdf + " for ["+format+","+date+"]");
|
||||
fail("Expected SDF failure, but got " + dsdf + " for ["+format+","+date+"]");
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
s = e;
|
||||
|
@ -465,7 +465,7 @@ public class FastDateParserTest {
|
|||
final DateParser fdp = getInstance(format, NEW_YORK, Locale.US);
|
||||
dfdp = fdp.parse(date);
|
||||
if (shouldFail) {
|
||||
Assert.fail("Expected FDF failure, but got " + dfdp + " for ["+format+","+date+"]");
|
||||
fail("Expected FDF failure, but got " + dfdp + " for ["+format+","+date+"]");
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
f = e;
|
||||
|
@ -670,7 +670,7 @@ public class FastDateParserTest {
|
|||
|
||||
try {
|
||||
fdp.parse("2015");
|
||||
Assert.fail("expected parse exception");
|
||||
fail("expected parse exception");
|
||||
} catch (final ParseException pe) {
|
||||
// expected parse exception
|
||||
}
|
||||
|
@ -681,7 +681,7 @@ public class FastDateParserTest {
|
|||
cal.clear();
|
||||
cal.set(2015, 3, 29);
|
||||
Date expected = cal.getTime();
|
||||
Assert.assertEquals(expected, actual);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd", Locale.KOREA);
|
||||
df.setTimeZone(kst);
|
||||
|
@ -689,7 +689,7 @@ public class FastDateParserTest {
|
|||
|
||||
// Thu Mar 16 00:00:00 KST 81724
|
||||
actual = fdp.parse("20150429113100");
|
||||
Assert.assertEquals(expected, actual);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -700,7 +700,7 @@ public class FastDateParserTest {
|
|||
final Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(2015, Calendar.JULY, 4);
|
||||
Assert.assertEquals(cal.getTime(), date);
|
||||
assertEquals(cal.getTime(), date);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -709,12 +709,12 @@ public class FastDateParserTest {
|
|||
final Calendar calendar = Calendar.getInstance();
|
||||
|
||||
calendar.setTime(parser.parse("1"));
|
||||
Assert.assertEquals(Calendar.MONDAY, calendar.get(Calendar.DAY_OF_WEEK));
|
||||
assertEquals(Calendar.MONDAY, calendar.get(Calendar.DAY_OF_WEEK));
|
||||
|
||||
calendar.setTime(parser.parse("6"));
|
||||
Assert.assertEquals(Calendar.SATURDAY, calendar.get(Calendar.DAY_OF_WEEK));
|
||||
assertEquals(Calendar.SATURDAY, calendar.get(Calendar.DAY_OF_WEEK));
|
||||
|
||||
calendar.setTime(parser.parse("7"));
|
||||
Assert.assertEquals(Calendar.SUNDAY, calendar.get(Calendar.DAY_OF_WEEK));
|
||||
assertEquals(Calendar.SUNDAY, calendar.get(Calendar.DAY_OF_WEEK));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,16 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FastDateParser_MoreOrLessTest {
|
||||
|
@ -34,9 +37,9 @@ public class FastDateParser_MoreOrLessTest {
|
|||
final FastDateParser parser = new FastDateParser("MM/dd", TimeZone.getDefault(), Locale.getDefault());
|
||||
final ParsePosition parsePosition = new ParsePosition(0);
|
||||
final Date date = parser.parse("A 3/23/61", parsePosition);
|
||||
Assert.assertNull(date);
|
||||
Assert.assertEquals(0, parsePosition.getIndex());
|
||||
Assert.assertEquals(0, parsePosition.getErrorIndex());
|
||||
assertNull(date);
|
||||
assertEquals(0, parsePosition.getIndex());
|
||||
assertEquals(0, parsePosition.getErrorIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -45,13 +48,13 @@ public class FastDateParser_MoreOrLessTest {
|
|||
//SimpleDateFormat parser = new SimpleDateFormat("M/d/y");
|
||||
final ParsePosition parsePosition = new ParsePosition(0);
|
||||
final Date date = parser.parse(" 3/ 23/ 1961", parsePosition);
|
||||
Assert.assertEquals(12, parsePosition.getIndex());
|
||||
assertEquals(12, parsePosition.getIndex());
|
||||
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
Assert.assertEquals(1961, calendar.get(Calendar.YEAR));
|
||||
Assert.assertEquals(2, calendar.get(Calendar.MONTH));
|
||||
Assert.assertEquals(23, calendar.get(Calendar.DATE));
|
||||
assertEquals(1961, calendar.get(Calendar.YEAR));
|
||||
assertEquals(2, calendar.get(Calendar.MONTH));
|
||||
assertEquals(23, calendar.get(Calendar.DATE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -59,28 +62,28 @@ public class FastDateParser_MoreOrLessTest {
|
|||
final FastDateParser parser = new FastDateParser("MM/dd", TimeZone.getDefault(), Locale.getDefault());
|
||||
final ParsePosition parsePosition = new ParsePosition(0);
|
||||
final Date date = parser.parse("3/23/61", parsePosition);
|
||||
Assert.assertEquals(4, parsePosition.getIndex());
|
||||
assertEquals(4, parsePosition.getIndex());
|
||||
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
Assert.assertEquals(2, calendar.get(Calendar.MONTH));
|
||||
Assert.assertEquals(23, calendar.get(Calendar.DATE));
|
||||
assertEquals(2, calendar.get(Calendar.MONTH));
|
||||
assertEquals(23, calendar.get(Calendar.DATE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputHasWrongCharacters() {
|
||||
final FastDateParser parser = new FastDateParser("MM-dd-yyy", TimeZone.getDefault(), Locale.getDefault());
|
||||
final ParsePosition parsePosition = new ParsePosition(0);
|
||||
Assert.assertNull(parser.parse("03/23/1961", parsePosition));
|
||||
Assert.assertEquals(2, parsePosition.getErrorIndex());
|
||||
assertNull(parser.parse("03/23/1961", parsePosition));
|
||||
assertEquals(2, parsePosition.getErrorIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputHasLessCharacters() {
|
||||
final FastDateParser parser = new FastDateParser("MM/dd/yyy", TimeZone.getDefault(), Locale.getDefault());
|
||||
final ParsePosition parsePosition = new ParsePosition(0);
|
||||
Assert.assertNull(parser.parse("03/23", parsePosition));
|
||||
Assert.assertEquals(5, parsePosition.getErrorIndex());
|
||||
assertNull(parser.parse("03/23", parsePosition));
|
||||
assertEquals(5, parsePosition.getErrorIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,12 +92,12 @@ public class FastDateParser_MoreOrLessTest {
|
|||
|
||||
final String input = "11:23 Pacific Standard Time";
|
||||
final ParsePosition parsePosition = new ParsePosition(0);
|
||||
Assert.assertNotNull(parser.parse(input, parsePosition));
|
||||
Assert.assertEquals(input.length(), parsePosition.getIndex());
|
||||
assertNotNull(parser.parse(input, parsePosition));
|
||||
assertEquals(input.length(), parsePosition.getIndex());
|
||||
|
||||
parsePosition.setIndex(0);
|
||||
Assert.assertNull(parser.parse( "11:23 Pacific Standard ", parsePosition));
|
||||
Assert.assertEquals(6, parsePosition.getErrorIndex());
|
||||
assertNull(parser.parse( "11:23 Pacific Standard ", parsePosition));
|
||||
assertEquals(6, parsePosition.getErrorIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -102,11 +105,11 @@ public class FastDateParser_MoreOrLessTest {
|
|||
final FastDateParser parser = new FastDateParser("EEEE, MM/dd/yyy", NEW_YORK, Locale.US);
|
||||
final String input = "Thursday, 03/23/61";
|
||||
final ParsePosition parsePosition = new ParsePosition(0);
|
||||
Assert.assertNotNull(parser.parse(input, parsePosition));
|
||||
Assert.assertEquals(input.length(), parsePosition.getIndex());
|
||||
assertNotNull(parser.parse(input, parsePosition));
|
||||
assertEquals(input.length(), parsePosition.getIndex());
|
||||
|
||||
parsePosition.setIndex(0);
|
||||
Assert.assertNull(parser.parse( "Thorsday, 03/23/61", parsePosition));
|
||||
Assert.assertEquals(0, parsePosition.getErrorIndex());
|
||||
assertNull(parser.parse( "Thorsday, 03/23/61", parsePosition));
|
||||
assertEquals(0, parsePosition.getErrorIndex());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,15 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FastDateParser_TimeZoneStrategyTest {
|
||||
|
@ -41,7 +43,7 @@ public class FastDateParser_TimeZoneStrategyTest {
|
|||
try {
|
||||
parser.parse(tzDisplay);
|
||||
} catch(final Exception ex) {
|
||||
Assert.fail("'" + tzDisplay + "'"
|
||||
fail("'" + tzDisplay + "'"
|
||||
+ " Locale: '" + locale.getDisplayName() + "'"
|
||||
+ " TimeZone: " + zone[0]
|
||||
+ " offset: " + t
|
||||
|
@ -60,6 +62,6 @@ public class FastDateParser_TimeZoneStrategyTest {
|
|||
|
||||
final Date summer = parser.parse("26.10.2014 02:00:00 MESZ");
|
||||
final Date standard = parser.parse("26.10.2014 02:00:00 MEZ");
|
||||
Assert.assertNotEquals(summer.getTime(), standard.getTime());
|
||||
assertNotEquals(summer.getTime(), standard.getTime());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
|
@ -33,67 +34,67 @@ public class FastTimeZoneTest {
|
|||
|
||||
@Test
|
||||
public void testGetGmtTimeZone() {
|
||||
Assert.assertEquals(0, FastTimeZone.getGmtTimeZone().getRawOffset());
|
||||
assertEquals(0, FastTimeZone.getGmtTimeZone().getRawOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBareGmt() {
|
||||
Assert.assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("GMT"));
|
||||
assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZ() {
|
||||
Assert.assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("Z"));
|
||||
assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("Z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUTC() {
|
||||
Assert.assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("UTC"));
|
||||
assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroOffsetsReturnSingleton() {
|
||||
Assert.assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("+0"));
|
||||
Assert.assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("-0"));
|
||||
assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("+0"));
|
||||
assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("-0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOlson() {
|
||||
Assert.assertEquals(TimeZone.getTimeZone("America/New_York"), FastTimeZone.getTimeZone("America/New_York"));
|
||||
assertEquals(TimeZone.getTimeZone("America/New_York"), FastTimeZone.getTimeZone("America/New_York"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGmtPrefix() {
|
||||
Assert.assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("GMT+23:00").getRawOffset());
|
||||
Assert.assertEquals(-HOURS_23, FastTimeZone.getGmtTimeZone("GMT-23:00").getRawOffset());
|
||||
assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("GMT+23:00").getRawOffset());
|
||||
assertEquals(-HOURS_23, FastTimeZone.getGmtTimeZone("GMT-23:00").getRawOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSign() {
|
||||
Assert.assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("+23:00").getRawOffset());
|
||||
Assert.assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("+2:00").getRawOffset());
|
||||
Assert.assertEquals(-HOURS_23, FastTimeZone.getGmtTimeZone("-23:00").getRawOffset());
|
||||
Assert.assertEquals(-HOURS_2, FastTimeZone.getGmtTimeZone("-2:00").getRawOffset());
|
||||
assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("+23:00").getRawOffset());
|
||||
assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("+2:00").getRawOffset());
|
||||
assertEquals(-HOURS_23, FastTimeZone.getGmtTimeZone("-23:00").getRawOffset());
|
||||
assertEquals(-HOURS_2, FastTimeZone.getGmtTimeZone("-2:00").getRawOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHoursColonMinutes() {
|
||||
Assert.assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("23:00").getRawOffset());
|
||||
Assert.assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("2:00").getRawOffset());
|
||||
Assert.assertEquals(MINUTES_59, FastTimeZone.getGmtTimeZone("00:59").getRawOffset());
|
||||
Assert.assertEquals(MINUTES_5, FastTimeZone.getGmtTimeZone("00:5").getRawOffset());
|
||||
Assert.assertEquals(HOURS_23+MINUTES_59, FastTimeZone.getGmtTimeZone("23:59").getRawOffset());
|
||||
Assert.assertEquals(HOURS_2+MINUTES_5, FastTimeZone.getGmtTimeZone("2:5").getRawOffset());
|
||||
assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("23:00").getRawOffset());
|
||||
assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("2:00").getRawOffset());
|
||||
assertEquals(MINUTES_59, FastTimeZone.getGmtTimeZone("00:59").getRawOffset());
|
||||
assertEquals(MINUTES_5, FastTimeZone.getGmtTimeZone("00:5").getRawOffset());
|
||||
assertEquals(HOURS_23+MINUTES_59, FastTimeZone.getGmtTimeZone("23:59").getRawOffset());
|
||||
assertEquals(HOURS_2+MINUTES_5, FastTimeZone.getGmtTimeZone("2:5").getRawOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHoursMinutes() {
|
||||
Assert.assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("2300").getRawOffset());
|
||||
Assert.assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("0200").getRawOffset());
|
||||
Assert.assertEquals(MINUTES_59, FastTimeZone.getGmtTimeZone("0059").getRawOffset());
|
||||
Assert.assertEquals(MINUTES_5, FastTimeZone.getGmtTimeZone("0005").getRawOffset());
|
||||
Assert.assertEquals(HOURS_23+MINUTES_59, FastTimeZone.getGmtTimeZone("2359").getRawOffset());
|
||||
Assert.assertEquals(HOURS_2+MINUTES_5, FastTimeZone.getGmtTimeZone("0205").getRawOffset());
|
||||
assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("2300").getRawOffset());
|
||||
assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("0200").getRawOffset());
|
||||
assertEquals(MINUTES_59, FastTimeZone.getGmtTimeZone("0059").getRawOffset());
|
||||
assertEquals(MINUTES_5, FastTimeZone.getGmtTimeZone("0005").getRawOffset());
|
||||
assertEquals(HOURS_23+MINUTES_59, FastTimeZone.getGmtTimeZone("2359").getRawOffset());
|
||||
assertEquals(HOURS_2+MINUTES_5, FastTimeZone.getGmtTimeZone("0205").getRawOffset());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import org.junit.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +33,7 @@ public class GmtTimeZoneTest {
|
|||
|
||||
@Test
|
||||
public void hoursInRange() {
|
||||
Assert.assertEquals(23 * 60 * 60 * 1000, new GmtTimeZone(false, 23, 0).getRawOffset());
|
||||
assertEquals(23 * 60 * 60 * 1000, new GmtTimeZone(false, 23, 0).getRawOffset());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
@ -41,12 +43,12 @@ public class GmtTimeZoneTest {
|
|||
|
||||
@Test
|
||||
public void minutesInRange() {
|
||||
Assert.assertEquals(59 * 60 * 1000, new GmtTimeZone(false, 0, 59).getRawOffset());
|
||||
assertEquals(59 * 60 * 1000, new GmtTimeZone(false, 0, 59).getRawOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOffset() {
|
||||
Assert.assertEquals(0, new GmtTimeZone(false, 0, 0).getOffset(234304));
|
||||
assertEquals(0, new GmtTimeZone(false, 0, 0).getOffset(234304));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
|
@ -56,37 +58,37 @@ public class GmtTimeZoneTest {
|
|||
|
||||
@Test
|
||||
public void getRawOffset() {
|
||||
Assert.assertEquals(0, new GmtTimeZone(false, 0, 0).getRawOffset());
|
||||
assertEquals(0, new GmtTimeZone(false, 0, 0).getRawOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getID() {
|
||||
Assert.assertEquals("GMT+00:00", new GmtTimeZone(false, 0, 0).getID());
|
||||
Assert.assertEquals("GMT+01:02", new GmtTimeZone(false, 1, 2).getID());
|
||||
Assert.assertEquals("GMT+11:22", new GmtTimeZone(false, 11, 22).getID());
|
||||
Assert.assertEquals("GMT-01:02", new GmtTimeZone(true, 1, 2).getID());
|
||||
Assert.assertEquals("GMT-11:22", new GmtTimeZone(true, 11, 22).getID());
|
||||
assertEquals("GMT+00:00", new GmtTimeZone(false, 0, 0).getID());
|
||||
assertEquals("GMT+01:02", new GmtTimeZone(false, 1, 2).getID());
|
||||
assertEquals("GMT+11:22", new GmtTimeZone(false, 11, 22).getID());
|
||||
assertEquals("GMT-01:02", new GmtTimeZone(true, 1, 2).getID());
|
||||
assertEquals("GMT-11:22", new GmtTimeZone(true, 11, 22).getID());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useDaylightTime() {
|
||||
Assert.assertFalse(new GmtTimeZone(false, 0, 0).useDaylightTime());
|
||||
assertFalse(new GmtTimeZone(false, 0, 0).useDaylightTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inDaylightTime() {
|
||||
Assert.assertFalse(new GmtTimeZone(false, 0, 0).useDaylightTime());
|
||||
assertFalse(new GmtTimeZone(false, 0, 0).useDaylightTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
Assert.assertEquals("[GmtTimeZone id=\"GMT-12:00\",offset=-43200000]",
|
||||
assertEquals("[GmtTimeZone id=\"GMT-12:00\",offset=-43200000]",
|
||||
new GmtTimeZone(true, 12, 0).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOffset() {
|
||||
Assert.assertEquals(-(6 * 60 + 30) * 60 * 1000,
|
||||
assertEquals(-(6 * 60 + 30) * 60 * 1000,
|
||||
new GmtTimeZone(true, 6, 30).getOffset(1, 1, 1, 1, 1, 1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.junit.Assert.fail;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -264,7 +263,7 @@ public class StopWatchTest {
|
|||
watch.start();
|
||||
try {
|
||||
watch.getStartTime();
|
||||
Assert.assertTrue(watch.getStartTime() >= beforeStopWatch);
|
||||
assertTrue(watch.getStartTime() >= beforeStopWatch);
|
||||
} catch (final IllegalStateException ex) {
|
||||
fail("Start time should be available: " + ex.getMessage());
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.time;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.Arrays;
|
||||
|
@ -25,7 +27,6 @@ import java.util.GregorianCalendar;
|
|||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
@ -75,7 +76,7 @@ public class WeekYearTest {
|
|||
cal.clear();
|
||||
|
||||
parser.parse(isoForm, new ParsePosition(0), cal);
|
||||
Assert.assertEquals(vulgar.getTime(), cal.getTime());
|
||||
assertEquals(vulgar.getTime(), cal.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,6 +86,6 @@ public class WeekYearTest {
|
|||
vulgar.setMinimalDaysInFirstWeek(4);
|
||||
vulgar.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
|
||||
Assert.assertEquals(isoForm, printer.format(vulgar));
|
||||
assertEquals(isoForm, printer.format(vulgar));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue