Clean up testing of exceptions
Now that the entire project is ported to JUnit Jupiter, there are more elegant ways to test for exceptions, which this patch applies throughtout the code base. If throwing an exception is supposed to fail a test, just throwing it outside of the method cleans up the code and makes it more elegant, instead of catching it and calling Assertions#fail. If an exception is supposed to be thrown, calling Assertions#assertThrows is a more elegant option than calling Assertions#fail in the try block and then catching and ignoring the expected exception. Note that assertThrows uses a lambda block, so the variables inside it should be final or effectively final. Reusing variables is a common practice in the tests, so where needed new final variables were introduced, or the variables used were inlined.
This commit is contained in:
parent
0fa0bfd8bb
commit
3387734b4f
|
@ -21,8 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@ -40,12 +40,9 @@ public class ArrayUtilsAddTest {
|
||||||
n = ArrayUtils.addAll(new Number[]{Integer.valueOf(1)}, new Long[]{Long.valueOf(2)});
|
n = ArrayUtils.addAll(new Number[]{Integer.valueOf(1)}, new Long[]{Long.valueOf(2)});
|
||||||
assertEquals(2,n.length);
|
assertEquals(2,n.length);
|
||||||
assertEquals(Number.class,n.getClass().getComponentType());
|
assertEquals(Number.class,n.getClass().getComponentType());
|
||||||
try {
|
// Invalid - can't store Long in Integer array
|
||||||
// Invalid - can't store Long in Integer array
|
assertThrows(IllegalArgumentException.class,
|
||||||
n = ArrayUtils.addAll(new Integer[]{Integer.valueOf(1)}, new Long[]{Long.valueOf(2)});
|
() -> ArrayUtils.addAll(new Integer[]{Integer.valueOf(1)}, new Long[]{Long.valueOf(2)}));
|
||||||
fail("Should have generated IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -226,25 +223,12 @@ public class ArrayUtilsAddTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testLANG571(){
|
public void testLANG571(){
|
||||||
final String[] stringArray=null;
|
final String[] stringArray=null;
|
||||||
final String aString=null;
|
final String aString=null;
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.add(stringArray, aString));
|
||||||
@SuppressWarnings("unused")
|
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.add(stringArray, 0, aString));
|
||||||
final
|
|
||||||
String[] sa = ArrayUtils.add(stringArray, aString);
|
|
||||||
fail("Should have caused IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException iae){
|
|
||||||
//expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
@SuppressWarnings({ "unused", "deprecation" })
|
|
||||||
final
|
|
||||||
String[] sa = ArrayUtils.add(stringArray, 0, aString);
|
|
||||||
fail("Should have caused IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException iae){
|
|
||||||
//expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -408,36 +392,25 @@ public class ArrayUtilsAddTest {
|
||||||
// boolean tests
|
// boolean tests
|
||||||
boolean[] booleanArray = ArrayUtils.add( null, 0, true );
|
boolean[] booleanArray = ArrayUtils.add( null, 0, true );
|
||||||
assertTrue( Arrays.equals( new boolean[] { true }, booleanArray ) );
|
assertTrue( Arrays.equals( new boolean[] { true }, booleanArray ) );
|
||||||
try {
|
IndexOutOfBoundsException e =
|
||||||
booleanArray = ArrayUtils.add( null, -1, true );
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( null, -1, true));
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
|
||||||
}
|
|
||||||
booleanArray = ArrayUtils.add( new boolean[] { true }, 0, false);
|
booleanArray = ArrayUtils.add( new boolean[] { true }, 0, false);
|
||||||
assertTrue( Arrays.equals( new boolean[] { false, true }, booleanArray ) );
|
assertTrue( Arrays.equals( new boolean[] { false, true }, booleanArray ) );
|
||||||
booleanArray = ArrayUtils.add( new boolean[] { false }, 1, true);
|
booleanArray = ArrayUtils.add( new boolean[] { false }, 1, true);
|
||||||
assertTrue( Arrays.equals( new boolean[] { false, true }, booleanArray ) );
|
assertTrue( Arrays.equals( new boolean[] { false, true }, booleanArray ) );
|
||||||
booleanArray = ArrayUtils.add( new boolean[] { true, false }, 1, true);
|
booleanArray = ArrayUtils.add( new boolean[] { true, false }, 1, true);
|
||||||
assertTrue( Arrays.equals( new boolean[] { true, true, false }, booleanArray ) );
|
assertTrue( Arrays.equals( new boolean[] { true, true, false }, booleanArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add(new boolean[] { true, false }, 4, true));
|
||||||
booleanArray = ArrayUtils.add( new boolean[] { true, false }, 4, true);
|
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add(new boolean[] { true, false }, -1, true));
|
||||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||||
}
|
|
||||||
try {
|
|
||||||
booleanArray = ArrayUtils.add( new boolean[] { true, false }, -1, true);
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// char tests
|
// char tests
|
||||||
char[] charArray = ArrayUtils.add( (char[]) null, 0, 'a' );
|
char[] charArray = ArrayUtils.add( (char[]) null, 0, 'a' );
|
||||||
assertTrue( Arrays.equals( new char[] { 'a' }, charArray ) );
|
assertTrue( Arrays.equals( new char[] { 'a' }, charArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( (char[]) null, -1, 'a' ));
|
||||||
charArray = ArrayUtils.add( (char[]) null, -1, 'a' );
|
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
|
||||||
}
|
|
||||||
charArray = ArrayUtils.add( new char[] { 'a' }, 0, 'b');
|
charArray = ArrayUtils.add( new char[] { 'a' }, 0, 'b');
|
||||||
assertTrue( Arrays.equals( new char[] { 'b', 'a' }, charArray ) );
|
assertTrue( Arrays.equals( new char[] { 'b', 'a' }, charArray ) );
|
||||||
charArray = ArrayUtils.add( new char[] { 'a', 'b' }, 0, 'c');
|
charArray = ArrayUtils.add( new char[] { 'a', 'b' }, 0, 'c');
|
||||||
|
@ -446,166 +419,106 @@ public class ArrayUtilsAddTest {
|
||||||
assertTrue( Arrays.equals( new char[] { 'a', 'k', 'b' }, charArray ) );
|
assertTrue( Arrays.equals( new char[] { 'a', 'k', 'b' }, charArray ) );
|
||||||
charArray = ArrayUtils.add( new char[] { 'a', 'b', 'c' }, 1, 't');
|
charArray = ArrayUtils.add( new char[] { 'a', 'b', 'c' }, 1, 't');
|
||||||
assertTrue( Arrays.equals( new char[] { 'a', 't', 'b', 'c' }, charArray ) );
|
assertTrue( Arrays.equals( new char[] { 'a', 't', 'b', 'c' }, charArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new char[] { 'a', 'b' }, 4, 'c'));
|
||||||
charArray = ArrayUtils.add( new char[] { 'a', 'b' }, 4, 'c');
|
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new char[] { 'a', 'b' }, -1, 'c'));
|
||||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||||
}
|
|
||||||
try {
|
|
||||||
charArray = ArrayUtils.add( new char[] { 'a', 'b' }, -1, 'c');
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// short tests
|
// short tests
|
||||||
short[] shortArray = ArrayUtils.add( new short[] { 1 }, 0, (short) 2);
|
short[] shortArray = ArrayUtils.add( new short[] { 1 }, 0, (short) 2);
|
||||||
assertTrue( Arrays.equals( new short[] { 2, 1 }, shortArray ) );
|
assertTrue( Arrays.equals( new short[] { 2, 1 }, shortArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( (short[]) null, -1, (short) 2));
|
||||||
shortArray = ArrayUtils.add( (short[]) null, -1, (short) 2);
|
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
|
||||||
}
|
|
||||||
shortArray = ArrayUtils.add( new short[] { 2, 6 }, 2, (short) 10);
|
shortArray = ArrayUtils.add( new short[] { 2, 6 }, 2, (short) 10);
|
||||||
assertTrue( Arrays.equals( new short[] { 2, 6, 10 }, shortArray ) );
|
assertTrue( Arrays.equals( new short[] { 2, 6, 10 }, shortArray ) );
|
||||||
shortArray = ArrayUtils.add( new short[] { 2, 6 }, 0, (short) -4);
|
shortArray = ArrayUtils.add( new short[] { 2, 6 }, 0, (short) -4);
|
||||||
assertTrue( Arrays.equals( new short[] { -4, 2, 6 }, shortArray ) );
|
assertTrue( Arrays.equals( new short[] { -4, 2, 6 }, shortArray ) );
|
||||||
shortArray = ArrayUtils.add( new short[] { 2, 6, 3 }, 2, (short) 1);
|
shortArray = ArrayUtils.add( new short[] { 2, 6, 3 }, 2, (short) 1);
|
||||||
assertTrue( Arrays.equals( new short[] { 2, 6, 1, 3 }, shortArray ) );
|
assertTrue( Arrays.equals( new short[] { 2, 6, 1, 3 }, shortArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new short[] { 2, 6 }, 4, (short) 10));
|
||||||
shortArray = ArrayUtils.add( new short[] { 2, 6 }, 4, (short) 10);
|
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new short[] { 2, 6 }, -1, (short) 10));
|
||||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||||
}
|
|
||||||
try {
|
|
||||||
shortArray = ArrayUtils.add( new short[] { 2, 6 }, -1, (short) 10);
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// byte tests
|
// byte tests
|
||||||
byte[] byteArray = ArrayUtils.add( new byte[] { 1 }, 0, (byte) 2);
|
byte[] byteArray = ArrayUtils.add( new byte[] { 1 }, 0, (byte) 2);
|
||||||
assertTrue( Arrays.equals( new byte[] { 2, 1 }, byteArray ) );
|
assertTrue( Arrays.equals( new byte[] { 2, 1 }, byteArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( (byte[]) null, -1, (byte) 2));
|
||||||
byteArray = ArrayUtils.add( (byte[]) null, -1, (byte) 2);
|
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
|
||||||
}
|
|
||||||
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 2, (byte) 3);
|
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 2, (byte) 3);
|
||||||
assertTrue( Arrays.equals( new byte[] { 2, 6, 3 }, byteArray ) );
|
assertTrue( Arrays.equals( new byte[] { 2, 6, 3 }, byteArray ) );
|
||||||
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 0, (byte) 1);
|
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 0, (byte) 1);
|
||||||
assertTrue( Arrays.equals( new byte[] { 1, 2, 6 }, byteArray ) );
|
assertTrue( Arrays.equals( new byte[] { 1, 2, 6 }, byteArray ) );
|
||||||
byteArray = ArrayUtils.add( new byte[] { 2, 6, 3 }, 2, (byte) 1);
|
byteArray = ArrayUtils.add( new byte[] { 2, 6, 3 }, 2, (byte) 1);
|
||||||
assertTrue( Arrays.equals( new byte[] { 2, 6, 1, 3 }, byteArray ) );
|
assertTrue( Arrays.equals( new byte[] { 2, 6, 1, 3 }, byteArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new byte[] { 2, 6 }, 4, (byte) 3));
|
||||||
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, 4, (byte) 3);
|
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new byte[] { 2, 6 }, -1, (byte) 3));
|
||||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||||
}
|
|
||||||
try {
|
|
||||||
byteArray = ArrayUtils.add( new byte[] { 2, 6 }, -1, (byte) 3);
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// int tests
|
// int tests
|
||||||
int[] intArray = ArrayUtils.add( new int[] { 1 }, 0, 2);
|
int[] intArray = ArrayUtils.add( new int[] { 1 }, 0, 2);
|
||||||
assertTrue( Arrays.equals( new int[] { 2, 1 }, intArray ) );
|
assertTrue( Arrays.equals( new int[] { 2, 1 }, intArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( (int[]) null, -1, 2));
|
||||||
intArray = ArrayUtils.add( (int[]) null, -1, 2);
|
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
|
||||||
}
|
|
||||||
intArray = ArrayUtils.add( new int[] { 2, 6 }, 2, 10);
|
intArray = ArrayUtils.add( new int[] { 2, 6 }, 2, 10);
|
||||||
assertTrue( Arrays.equals( new int[] { 2, 6, 10 }, intArray ) );
|
assertTrue( Arrays.equals( new int[] { 2, 6, 10 }, intArray ) );
|
||||||
intArray = ArrayUtils.add( new int[] { 2, 6 }, 0, -4);
|
intArray = ArrayUtils.add( new int[] { 2, 6 }, 0, -4);
|
||||||
assertTrue( Arrays.equals( new int[] { -4, 2, 6 }, intArray ) );
|
assertTrue( Arrays.equals( new int[] { -4, 2, 6 }, intArray ) );
|
||||||
intArray = ArrayUtils.add( new int[] { 2, 6, 3 }, 2, 1);
|
intArray = ArrayUtils.add( new int[] { 2, 6, 3 }, 2, 1);
|
||||||
assertTrue( Arrays.equals( new int[] { 2, 6, 1, 3 }, intArray ) );
|
assertTrue( Arrays.equals( new int[] { 2, 6, 1, 3 }, intArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new int[] { 2, 6 }, 4, 10));
|
||||||
intArray = ArrayUtils.add( new int[] { 2, 6 }, 4, 10);
|
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new int[] { 2, 6 }, -1, 10));
|
||||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||||
}
|
|
||||||
try {
|
|
||||||
intArray = ArrayUtils.add( new int[] { 2, 6 }, -1, 10);
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// long tests
|
// long tests
|
||||||
long[] longArray = ArrayUtils.add( new long[] { 1L }, 0, 2L);
|
long[] longArray = ArrayUtils.add( new long[] { 1L }, 0, 2L);
|
||||||
assertTrue( Arrays.equals( new long[] { 2L, 1L }, longArray ) );
|
assertTrue( Arrays.equals( new long[] { 2L, 1L }, longArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( (long[]) null, -1, 2L));
|
||||||
longArray = ArrayUtils.add( (long[]) null, -1, 2L);
|
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
|
||||||
}
|
|
||||||
longArray = ArrayUtils.add( new long[] { 2L, 6L }, 2, 10L);
|
longArray = ArrayUtils.add( new long[] { 2L, 6L }, 2, 10L);
|
||||||
assertTrue( Arrays.equals( new long[] { 2L, 6L, 10L }, longArray ) );
|
assertTrue( Arrays.equals( new long[] { 2L, 6L, 10L }, longArray ) );
|
||||||
longArray = ArrayUtils.add( new long[] { 2L, 6L }, 0, -4L);
|
longArray = ArrayUtils.add( new long[] { 2L, 6L }, 0, -4L);
|
||||||
assertTrue( Arrays.equals( new long[] { -4L, 2L, 6L }, longArray ) );
|
assertTrue( Arrays.equals( new long[] { -4L, 2L, 6L }, longArray ) );
|
||||||
longArray = ArrayUtils.add( new long[] { 2L, 6L, 3L }, 2, 1L);
|
longArray = ArrayUtils.add( new long[] { 2L, 6L, 3L }, 2, 1L);
|
||||||
assertTrue( Arrays.equals( new long[] { 2L, 6L, 1L, 3L }, longArray ) );
|
assertTrue( Arrays.equals( new long[] { 2L, 6L, 1L, 3L }, longArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new long[] { 2L, 6L }, 4, 10L));
|
||||||
longArray = ArrayUtils.add( new long[] { 2L, 6L }, 4, 10L);
|
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new long[] { 2L, 6L }, -1, 10L));
|
||||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||||
}
|
|
||||||
try {
|
|
||||||
longArray = ArrayUtils.add( new long[] { 2L, 6L }, -1, 10L);
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// float tests
|
// float tests
|
||||||
float[] floatArray = ArrayUtils.add( new float[] { 1.1f }, 0, 2.2f);
|
float[] floatArray = ArrayUtils.add( new float[] { 1.1f }, 0, 2.2f);
|
||||||
assertTrue( Arrays.equals( new float[] { 2.2f, 1.1f }, floatArray ) );
|
assertTrue( Arrays.equals( new float[] { 2.2f, 1.1f }, floatArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( (float[]) null, -1, 2.2f));
|
||||||
floatArray = ArrayUtils.add( (float[]) null, -1, 2.2f);
|
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
|
||||||
}
|
|
||||||
floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, 2, 10.5f);
|
floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, 2, 10.5f);
|
||||||
assertTrue( Arrays.equals( new float[] { 2.3f, 6.4f, 10.5f }, floatArray ) );
|
assertTrue( Arrays.equals( new float[] { 2.3f, 6.4f, 10.5f }, floatArray ) );
|
||||||
floatArray = ArrayUtils.add( new float[] { 2.6f, 6.7f }, 0, -4.8f);
|
floatArray = ArrayUtils.add( new float[] { 2.6f, 6.7f }, 0, -4.8f);
|
||||||
assertTrue( Arrays.equals( new float[] { -4.8f, 2.6f, 6.7f }, floatArray ) );
|
assertTrue( Arrays.equals( new float[] { -4.8f, 2.6f, 6.7f }, floatArray ) );
|
||||||
floatArray = ArrayUtils.add( new float[] { 2.9f, 6.0f, 0.3f }, 2, 1.0f);
|
floatArray = ArrayUtils.add( new float[] { 2.9f, 6.0f, 0.3f }, 2, 1.0f);
|
||||||
assertTrue( Arrays.equals( new float[] { 2.9f, 6.0f, 1.0f, 0.3f }, floatArray ) );
|
assertTrue( Arrays.equals( new float[] { 2.9f, 6.0f, 1.0f, 0.3f }, floatArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new float[] { 2.3f, 6.4f }, 4, 10.5f));
|
||||||
floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, 4, 10.5f);
|
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new float[] { 2.3f, 6.4f }, -1, 10.5f));
|
||||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||||
}
|
|
||||||
try {
|
|
||||||
floatArray = ArrayUtils.add( new float[] { 2.3f, 6.4f }, -1, 10.5f);
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// double tests
|
// double tests
|
||||||
double[] doubleArray = ArrayUtils.add( new double[] { 1.1 }, 0, 2.2);
|
double[] doubleArray = ArrayUtils.add( new double[] { 1.1 }, 0, 2.2);
|
||||||
assertTrue( Arrays.equals( new double[] { 2.2, 1.1 }, doubleArray ) );
|
assertTrue( Arrays.equals( new double[] { 2.2, 1.1 }, doubleArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add(null, -1, 2.2));
|
||||||
doubleArray = ArrayUtils.add(null, -1, 2.2);
|
assertEquals("Index: -1, Length: 0", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 0", e.getMessage());
|
|
||||||
}
|
|
||||||
doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, 2, 10.5);
|
doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, 2, 10.5);
|
||||||
assertTrue( Arrays.equals( new double[] { 2.3, 6.4, 10.5 }, doubleArray ) );
|
assertTrue( Arrays.equals( new double[] { 2.3, 6.4, 10.5 }, doubleArray ) );
|
||||||
doubleArray = ArrayUtils.add( new double[] { 2.6, 6.7 }, 0, -4.8);
|
doubleArray = ArrayUtils.add( new double[] { 2.6, 6.7 }, 0, -4.8);
|
||||||
assertTrue( Arrays.equals( new double[] { -4.8, 2.6, 6.7 }, doubleArray ) );
|
assertTrue( Arrays.equals( new double[] { -4.8, 2.6, 6.7 }, doubleArray ) );
|
||||||
doubleArray = ArrayUtils.add( new double[] { 2.9, 6.0, 0.3 }, 2, 1.0);
|
doubleArray = ArrayUtils.add( new double[] { 2.9, 6.0, 0.3 }, 2, 1.0);
|
||||||
assertTrue( Arrays.equals( new double[] { 2.9, 6.0, 1.0, 0.3 }, doubleArray ) );
|
assertTrue( Arrays.equals( new double[] { 2.9, 6.0, 1.0, 0.3 }, doubleArray ) );
|
||||||
try {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new double[] { 2.3, 6.4 }, 4, 10.5));
|
||||||
doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, 4, 10.5);
|
assertEquals("Index: 4, Length: 2", e.getMessage());
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
e = assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.add( new double[] { 2.3, 6.4 }, -1, 10.5));
|
||||||
assertEquals("Index: 4, Length: 2", e.getMessage());
|
assertEquals("Index: -1, Length: 2", e.getMessage());
|
||||||
}
|
|
||||||
try {
|
|
||||||
doubleArray = ArrayUtils.add( new double[] { 2.3, 6.4 }, -1, 10.5);
|
|
||||||
} catch(final IndexOutOfBoundsException e) {
|
|
||||||
assertEquals("Index: -1, Length: 2", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.commons.lang3;
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -42,19 +42,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new boolean[0], ArrayUtils.insert(0, new boolean[0], null));
|
assertArrayEquals(new boolean[0], ArrayUtils.insert(0, new boolean[0], null));
|
||||||
assertNull(ArrayUtils.insert(42, (boolean[]) null, null));
|
assertNull(ArrayUtils.insert(42, (boolean[]) null, null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new boolean[]{false,true,false,true}, ArrayUtils.insert(0, array, false));
|
assertArrayEquals(new boolean[]{false,true,false,true}, ArrayUtils.insert(0, array, false));
|
||||||
assertArrayEquals(new boolean[]{true,false,false,true}, ArrayUtils.insert(1, array, false));
|
assertArrayEquals(new boolean[]{true,false,false,true}, ArrayUtils.insert(1, array, false));
|
||||||
|
@ -78,19 +67,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new byte[0], ArrayUtils.insert(0, new byte[0], null));
|
assertArrayEquals(new byte[0], ArrayUtils.insert(0, new byte[0], null));
|
||||||
assertNull(ArrayUtils.insert(42, (byte[]) null, null));
|
assertNull(ArrayUtils.insert(42, (byte[]) null, null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new byte[]{0,1,2,3}, ArrayUtils.insert(0, array, (byte) 0));
|
assertArrayEquals(new byte[]{0,1,2,3}, ArrayUtils.insert(0, array, (byte) 0));
|
||||||
assertArrayEquals(new byte[]{1,0,2,3}, ArrayUtils.insert(1, array, (byte) 0));
|
assertArrayEquals(new byte[]{1,0,2,3}, ArrayUtils.insert(1, array, (byte) 0));
|
||||||
|
@ -113,19 +91,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new char[0], ArrayUtils.insert(0, new char[0], null));
|
assertArrayEquals(new char[0], ArrayUtils.insert(0, new char[0], null));
|
||||||
assertNull(ArrayUtils.insert(42, (char[]) null, null));
|
assertNull(ArrayUtils.insert(42, (char[]) null, null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new char[]{'z','a','b','c'}, ArrayUtils.insert(0, array, 'z'));
|
assertArrayEquals(new char[]{'z','a','b','c'}, ArrayUtils.insert(0, array, 'z'));
|
||||||
assertArrayEquals(new char[]{'a','z','b','c'}, ArrayUtils.insert(1, array, 'z'));
|
assertArrayEquals(new char[]{'a','z','b','c'}, ArrayUtils.insert(1, array, 'z'));
|
||||||
|
@ -149,19 +116,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new double[0], ArrayUtils.insert(0, new double[0], null), delta);
|
assertArrayEquals(new double[0], ArrayUtils.insert(0, new double[0], null), delta);
|
||||||
assertNull(ArrayUtils.insert(42, (double[]) null, null));
|
assertNull(ArrayUtils.insert(42, (double[]) null, null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new double[]{0,1,2,3}, ArrayUtils.insert(0, array, 0), delta);
|
assertArrayEquals(new double[]{0,1,2,3}, ArrayUtils.insert(0, array, 0), delta);
|
||||||
assertArrayEquals(new double[]{1,0,2,3}, ArrayUtils.insert(1, array, 0), delta);
|
assertArrayEquals(new double[]{1,0,2,3}, ArrayUtils.insert(1, array, 0), delta);
|
||||||
|
@ -185,19 +141,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new float[0], ArrayUtils.insert(0, new float[0], null), delta);
|
assertArrayEquals(new float[0], ArrayUtils.insert(0, new float[0], null), delta);
|
||||||
assertNull(ArrayUtils.insert(42, (float[]) null, null));
|
assertNull(ArrayUtils.insert(42, (float[]) null, null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new float[]{0,1,2,3}, ArrayUtils.insert(0, array, 0), delta);
|
assertArrayEquals(new float[]{0,1,2,3}, ArrayUtils.insert(0, array, 0), delta);
|
||||||
assertArrayEquals(new float[]{1,0,2,3}, ArrayUtils.insert(1, array, 0), delta);
|
assertArrayEquals(new float[]{1,0,2,3}, ArrayUtils.insert(1, array, 0), delta);
|
||||||
|
@ -220,19 +165,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new int[0], ArrayUtils.insert(0, new int[0], null));
|
assertArrayEquals(new int[0], ArrayUtils.insert(0, new int[0], null));
|
||||||
assertNull(ArrayUtils.insert(42, (int[]) null, null));
|
assertNull(ArrayUtils.insert(42, (int[]) null, null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new int[]{0,1,2,3}, ArrayUtils.insert(0, array, 0));
|
assertArrayEquals(new int[]{0,1,2,3}, ArrayUtils.insert(0, array, 0));
|
||||||
assertArrayEquals(new int[]{1,0,2,3}, ArrayUtils.insert(1, array, 0));
|
assertArrayEquals(new int[]{1,0,2,3}, ArrayUtils.insert(1, array, 0));
|
||||||
|
@ -256,19 +190,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new long[0], ArrayUtils.insert(0, new long[0], null));
|
assertArrayEquals(new long[0], ArrayUtils.insert(0, new long[0], null));
|
||||||
assertNull(ArrayUtils.insert(42, (long[]) null, null));
|
assertNull(ArrayUtils.insert(42, (long[]) null, null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new long[]{0,1,2,3}, ArrayUtils.insert(0, array, 0));
|
assertArrayEquals(new long[]{0,1,2,3}, ArrayUtils.insert(0, array, 0));
|
||||||
assertArrayEquals(new long[]{1,0,2,3}, ArrayUtils.insert(1, array, 0));
|
assertArrayEquals(new long[]{1,0,2,3}, ArrayUtils.insert(1, array, 0));
|
||||||
|
@ -292,19 +215,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new short[0], ArrayUtils.insert(0, new short[0], null));
|
assertArrayEquals(new short[0], ArrayUtils.insert(0, new short[0], null));
|
||||||
assertNull(ArrayUtils.insert(42, (short[]) null, null));
|
assertNull(ArrayUtils.insert(42, (short[]) null, null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new short[]{0,1,2,3}, ArrayUtils.insert(0, array, (short) 0));
|
assertArrayEquals(new short[]{0,1,2,3}, ArrayUtils.insert(0, array, (short) 0));
|
||||||
assertArrayEquals(new short[]{1,0,2,3}, ArrayUtils.insert(1, array, (short) 0));
|
assertArrayEquals(new short[]{1,0,2,3}, ArrayUtils.insert(1, array, (short) 0));
|
||||||
|
@ -328,19 +240,8 @@ public class ArrayUtilsInsertTest {
|
||||||
assertArrayEquals(new String[0], ArrayUtils.insert(0, new String[0], (String[]) null));
|
assertArrayEquals(new String[0], ArrayUtils.insert(0, new String[0], (String[]) null));
|
||||||
assertNull(ArrayUtils.insert(42, null, (String[]) null));
|
assertNull(ArrayUtils.insert(42, null, (String[]) null));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(-1, array, array));
|
||||||
ArrayUtils.insert(-1, array, array);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.insert(array.length + 1, array, array));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayUtils.insert(array.length + 1, array, array);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertArrayEquals(new String[]{"z","a","b","c"}, ArrayUtils.insert(0, array, "z"));
|
assertArrayEquals(new String[]{"z","a","b","c"}, ArrayUtils.insert(0, array, "z"));
|
||||||
assertArrayEquals(new String[]{"a","z","b","c"}, ArrayUtils.insert(1, array, "z"));
|
assertArrayEquals(new String[]{"a","z","b","c"}, ArrayUtils.insert(1, array, "z"));
|
||||||
|
|
|
@ -19,8 +19,8 @@ package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@ -46,18 +46,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new Object[] {"a", "b", "c"}, 1);
|
array = ArrayUtils.remove(new Object[] {"a", "b", "c"}, 1);
|
||||||
assertTrue(Arrays.equals(new Object[] {"a", "c"}, array));
|
assertTrue(Arrays.equals(new Object[] {"a", "c"}, array));
|
||||||
assertEquals(Object.class, array.getClass().getComponentType());
|
assertEquals(Object.class, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new Object[] {"a", "b"}, -1));
|
||||||
ArrayUtils.remove(new Object[] {"a", "b"}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new Object[] {"a", "b"}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((Object[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new Object[] {"a", "b"}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((Object[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -91,18 +82,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new boolean[] {true, false, true}, 1);
|
array = ArrayUtils.remove(new boolean[] {true, false, true}, 1);
|
||||||
assertTrue(Arrays.equals(new boolean[] {true, true}, array));
|
assertTrue(Arrays.equals(new boolean[] {true, true}, array));
|
||||||
assertEquals(Boolean.TYPE, array.getClass().getComponentType());
|
assertEquals(Boolean.TYPE, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new boolean[] {true, false}, -1));
|
||||||
ArrayUtils.remove(new boolean[] {true, false}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new boolean[] {true, false}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((boolean[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new boolean[] {true, false}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((boolean[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -120,18 +102,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new byte[] {1, 2, 1}, 1);
|
array = ArrayUtils.remove(new byte[] {1, 2, 1}, 1);
|
||||||
assertTrue(Arrays.equals(new byte[] {1, 1}, array));
|
assertTrue(Arrays.equals(new byte[] {1, 1}, array));
|
||||||
assertEquals(Byte.TYPE, array.getClass().getComponentType());
|
assertEquals(Byte.TYPE, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new byte[] {1, 2}, -1));
|
||||||
ArrayUtils.remove(new byte[] {1, 2}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new byte[] {1, 2}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((byte[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new byte[] {1, 2}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((byte[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -149,18 +122,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new char[] {'a', 'b', 'c'}, 1);
|
array = ArrayUtils.remove(new char[] {'a', 'b', 'c'}, 1);
|
||||||
assertTrue(Arrays.equals(new char[] {'a', 'c'}, array));
|
assertTrue(Arrays.equals(new char[] {'a', 'c'}, array));
|
||||||
assertEquals(Character.TYPE, array.getClass().getComponentType());
|
assertEquals(Character.TYPE, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new char[] {'a', 'b'}, -1));
|
||||||
ArrayUtils.remove(new char[] {'a', 'b'}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new char[] {'a', 'b'}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((char[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new char[] {'a', 'b'}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((char[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -178,18 +142,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new double[] {1, 2, 1}, 1);
|
array = ArrayUtils.remove(new double[] {1, 2, 1}, 1);
|
||||||
assertTrue(Arrays.equals(new double[] {1, 1}, array));
|
assertTrue(Arrays.equals(new double[] {1, 1}, array));
|
||||||
assertEquals(Double.TYPE, array.getClass().getComponentType());
|
assertEquals(Double.TYPE, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new double[] {1, 2}, -1));
|
||||||
ArrayUtils.remove(new double[] {1, 2}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new double[] {1, 2}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((double[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new double[] {1, 2}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((double[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -207,18 +162,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new float[] {1, 2, 1}, 1);
|
array = ArrayUtils.remove(new float[] {1, 2, 1}, 1);
|
||||||
assertTrue(Arrays.equals(new float[] {1, 1}, array));
|
assertTrue(Arrays.equals(new float[] {1, 1}, array));
|
||||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new float[] {1, 2}, -1));
|
||||||
ArrayUtils.remove(new float[] {1, 2}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new float[] {1, 2}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((float[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new float[] {1, 2}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((float[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -236,18 +182,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new int[] {1, 2, 1}, 1);
|
array = ArrayUtils.remove(new int[] {1, 2, 1}, 1);
|
||||||
assertTrue(Arrays.equals(new int[] {1, 1}, array));
|
assertTrue(Arrays.equals(new int[] {1, 1}, array));
|
||||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new int[] {1, 2}, -1));
|
||||||
ArrayUtils.remove(new int[] {1, 2}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new int[] {1, 2}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((int[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new int[] {1, 2}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((int[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -265,18 +202,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new long[] {1, 2, 1}, 1);
|
array = ArrayUtils.remove(new long[] {1, 2, 1}, 1);
|
||||||
assertTrue(Arrays.equals(new long[] {1, 1}, array));
|
assertTrue(Arrays.equals(new long[] {1, 1}, array));
|
||||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new long[] {1, 2}, -1));
|
||||||
ArrayUtils.remove(new long[] {1, 2}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new long[] {1, 2}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((long[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new long[] {1, 2}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((long[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -294,18 +222,9 @@ public class ArrayUtilsRemoveTest {
|
||||||
array = ArrayUtils.remove(new short[] {1, 2, 1}, 1);
|
array = ArrayUtils.remove(new short[] {1, 2, 1}, 1);
|
||||||
assertTrue(Arrays.equals(new short[] {1, 1}, array));
|
assertTrue(Arrays.equals(new short[] {1, 1}, array));
|
||||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new short[] {1, 2}, -1));
|
||||||
ArrayUtils.remove(new short[] {1, 2}, -1);
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new short[] {1, 2}, 2));
|
||||||
fail("IndexOutOfBoundsException expected");
|
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((short[]) null, 0));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove(new short[] {1, 2}, 2);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
ArrayUtils.remove((short[]) null, 0);
|
|
||||||
fail("IndexOutOfBoundsException expected");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -230,21 +229,12 @@ public class ArrayUtilsTest {
|
||||||
assertEquals("world", map.get("hello"));
|
assertEquals("world", map.get("hello"));
|
||||||
|
|
||||||
assertNull(ArrayUtils.toMap(null));
|
assertNull(ArrayUtils.toMap(null));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
ArrayUtils.toMap(new String[][]{{"foo", "bar"}, {"short"}});
|
ArrayUtils.toMap(new String[][]{{"foo", "bar"}, {"short"}}));
|
||||||
fail("exception expected");
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
} catch (final IllegalArgumentException ex) {
|
ArrayUtils.toMap(new Object[]{new Object[]{"foo", "bar"}, "illegal type"}));
|
||||||
}
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
try {
|
ArrayUtils.toMap(new Object[]{new Object[]{"foo", "bar"}, null}));
|
||||||
ArrayUtils.toMap(new Object[]{new Object[]{"foo", "bar"}, "illegal type"});
|
|
||||||
fail("exception expected");
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ArrayUtils.toMap(new Object[]{new Object[]{"foo", "bar"}, null});
|
|
||||||
fail("exception expected");
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
map = ArrayUtils.toMap(new Object[]{new Map.Entry<Object, Object>() {
|
map = ArrayUtils.toMap(new Object[]{new Map.Entry<Object, Object>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -795,11 +785,9 @@ public class ArrayUtilsTest {
|
||||||
"java.util.Date type");
|
"java.util.Date type");
|
||||||
assertNotSame(java.sql.Date.class, ArrayUtils.subarray(dateArray, 1, 4).getClass().getComponentType(),
|
assertNotSame(java.sql.Date.class, ArrayUtils.subarray(dateArray, 1, 4).getClass().getComponentType(),
|
||||||
"java.sql.Date type");
|
"java.sql.Date type");
|
||||||
try {
|
assertThrows(ClassCastException.class,
|
||||||
@SuppressWarnings("unused") final java.sql.Date[] dummy = (java.sql.Date[]) ArrayUtils.subarray(dateArray, 1, 3);
|
() -> java.sql.Date[].class.cast(ArrayUtils.subarray(dateArray, 1, 3)),
|
||||||
fail("Invalid downcast");
|
"Invalid downcast");
|
||||||
} catch (final ClassCastException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1406,21 +1394,9 @@ public class ArrayUtilsTest {
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@Test
|
@Test
|
||||||
public void testSameType() {
|
public void testSameType() {
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.isSameType(null, null));
|
||||||
ArrayUtils.isSameType(null, null);
|
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.isSameType(null, new Object[0]));
|
||||||
fail();
|
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.isSameType(new Object[0], null));
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ArrayUtils.isSameType(null, new Object[0]);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ArrayUtils.isSameType(new Object[0], null);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isSameType(new Object[0], new Object[0]));
|
assertTrue(ArrayUtils.isSameType(new Object[0], new Object[0]));
|
||||||
assertFalse(ArrayUtils.isSameType(new String[0], new Object[0]));
|
assertFalse(ArrayUtils.isSameType(new String[0], new Object[0]));
|
||||||
|
@ -3901,11 +3877,7 @@ public class ArrayUtilsTest {
|
||||||
ArrayUtils.toPrimitive(new Boolean[]{Boolean.TRUE, Boolean.FALSE, Boolean.TRUE}))
|
ArrayUtils.toPrimitive(new Boolean[]{Boolean.TRUE, Boolean.FALSE, Boolean.TRUE}))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> ArrayUtils.toPrimitive(new Boolean[]{Boolean.TRUE, null}));
|
||||||
ArrayUtils.toPrimitive(new Boolean[]{Boolean.TRUE, null});
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -3952,11 +3924,8 @@ public class ArrayUtilsTest {
|
||||||
new Character(Character.MAX_VALUE), new Character('0')}))
|
new Character(Character.MAX_VALUE), new Character('0')}))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class,
|
||||||
ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), null});
|
() -> ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), null}));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4012,11 +3981,8 @@ public class ArrayUtilsTest {
|
||||||
Byte.valueOf(Byte.MAX_VALUE), Byte.valueOf((byte) 9999999)}))
|
Byte.valueOf(Byte.MAX_VALUE), Byte.valueOf((byte) 9999999)}))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class,
|
||||||
ArrayUtils.toPrimitive(new Byte[]{Byte.valueOf(Byte.MIN_VALUE), null});
|
() -> ArrayUtils.toPrimitive(new Byte[]{Byte.valueOf(Byte.MIN_VALUE), null}));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4072,11 +4038,8 @@ public class ArrayUtilsTest {
|
||||||
Short.valueOf(Short.MAX_VALUE), Short.valueOf((short) 9999999)}))
|
Short.valueOf(Short.MAX_VALUE), Short.valueOf((short) 9999999)}))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class,
|
||||||
ArrayUtils.toPrimitive(new Short[]{Short.valueOf(Short.MIN_VALUE), null});
|
() -> ArrayUtils.toPrimitive(new Short[]{Short.valueOf(Short.MIN_VALUE), null}));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4129,11 +4092,8 @@ public class ArrayUtilsTest {
|
||||||
Integer.valueOf(Integer.MAX_VALUE), Integer.valueOf(9999999)}))
|
Integer.valueOf(Integer.MAX_VALUE), Integer.valueOf(9999999)}))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class,
|
||||||
ArrayUtils.toPrimitive(new Integer[]{Integer.valueOf(Integer.MIN_VALUE), null});
|
() -> ArrayUtils.toPrimitive(new Integer[]{Integer.valueOf(Integer.MIN_VALUE), null}));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4194,11 +4154,8 @@ public class ArrayUtilsTest {
|
||||||
Long.valueOf(Long.MAX_VALUE), Long.valueOf(9999999)}))
|
Long.valueOf(Long.MAX_VALUE), Long.valueOf(9999999)}))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class,
|
||||||
ArrayUtils.toPrimitive(new Long[]{Long.valueOf(Long.MIN_VALUE), null});
|
() -> ArrayUtils.toPrimitive(new Long[]{Long.valueOf(Long.MIN_VALUE), null}));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4256,11 +4213,8 @@ public class ArrayUtilsTest {
|
||||||
Float.valueOf(Float.MAX_VALUE), Float.valueOf(9999999)}))
|
Float.valueOf(Float.MAX_VALUE), Float.valueOf(9999999)}))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class,
|
||||||
ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE), null});
|
() -> ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE), null}));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4318,11 +4272,8 @@ public class ArrayUtilsTest {
|
||||||
Double.valueOf(Double.MAX_VALUE), Double.valueOf(9999999)}))
|
Double.valueOf(Double.MAX_VALUE), Double.valueOf(9999999)}))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class,
|
||||||
ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE), null});
|
() -> ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE), null}));
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4565,11 +4516,7 @@ public class ArrayUtilsTest {
|
||||||
assertEquals(0, ArrayUtils.getLength(emptyBooleanArray));
|
assertEquals(0, ArrayUtils.getLength(emptyBooleanArray));
|
||||||
assertEquals(1, ArrayUtils.getLength(notEmptyBooleanArray));
|
assertEquals(1, ArrayUtils.getLength(notEmptyBooleanArray));
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> ArrayUtils.getLength("notAnArray"));
|
||||||
ArrayUtils.getLength("notAnArray");
|
|
||||||
fail("IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4753,11 +4700,7 @@ public class ArrayUtilsTest {
|
||||||
final Object[] array = new Object[]{1, 2, 3, "array", "test"};
|
final Object[] array = new Object[]{1, 2, 3, "array", "test"};
|
||||||
assertArrayEquals(new String[]{"1", "2", "3", "array", "test"}, ArrayUtils.toStringArray(array));
|
assertArrayEquals(new String[]{"1", "2", "3", "array", "test"}, ArrayUtils.toStringArray(array));
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> ArrayUtils.toStringArray(new Object[]{null}));
|
||||||
ArrayUtils.toStringArray(new Object[]{null});
|
|
||||||
fail("NullPointerException expected!");
|
|
||||||
} catch (final NullPointerException expected) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -311,13 +310,8 @@ public class CharRangeTest {
|
||||||
@Test
|
@Test
|
||||||
public void testContainsNullArg() {
|
public void testContainsNullArg() {
|
||||||
final CharRange range = CharRange.is('a');
|
final CharRange range = CharRange.is('a');
|
||||||
try {
|
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> range.contains(null));
|
||||||
@SuppressWarnings("unused")
|
assertEquals("The Range must not be null", e.getMessage());
|
||||||
final
|
|
||||||
boolean contains = range.contains(null);
|
|
||||||
} catch(final IllegalArgumentException e) {
|
|
||||||
assertEquals("The Range must not be null", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -355,36 +349,21 @@ public class CharRangeTest {
|
||||||
final Iterator<Character> emptySetIt = emptySet.iterator();
|
final Iterator<Character> emptySetIt = emptySet.iterator();
|
||||||
assertNotNull(emptySetIt);
|
assertNotNull(emptySetIt);
|
||||||
assertFalse(emptySetIt.hasNext());
|
assertFalse(emptySetIt.hasNext());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, emptySetIt::next);
|
||||||
emptySetIt.next();
|
|
||||||
fail("Should throw NoSuchElementException");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Iterator<Character> notFirstIt = notFirst.iterator();
|
final Iterator<Character> notFirstIt = notFirst.iterator();
|
||||||
assertNotNull(notFirstIt);
|
assertNotNull(notFirstIt);
|
||||||
assertTrue(notFirstIt.hasNext());
|
assertTrue(notFirstIt.hasNext());
|
||||||
assertEquals(Character.valueOf((char) 0), notFirstIt.next());
|
assertEquals(Character.valueOf((char) 0), notFirstIt.next());
|
||||||
assertFalse(notFirstIt.hasNext());
|
assertFalse(notFirstIt.hasNext());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, notFirstIt::next);
|
||||||
notFirstIt.next();
|
|
||||||
fail("Should throw NoSuchElementException");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Iterator<Character> notLastIt = notLast.iterator();
|
final Iterator<Character> notLastIt = notLast.iterator();
|
||||||
assertNotNull(notLastIt);
|
assertNotNull(notLastIt);
|
||||||
assertTrue(notLastIt.hasNext());
|
assertTrue(notLastIt.hasNext());
|
||||||
assertEquals(Character.valueOf(Character.MAX_VALUE), notLastIt.next());
|
assertEquals(Character.valueOf(Character.MAX_VALUE), notLastIt.next());
|
||||||
assertFalse(notLastIt.hasNext());
|
assertFalse(notLastIt.hasNext());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, notLastIt::next);
|
||||||
notLastIt.next();
|
|
||||||
fail("Should throw NoSuchElementException");
|
|
||||||
} catch (final NoSuchElementException e) {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -83,7 +82,7 @@ public class CharSequenceUtilsTest {
|
||||||
final int ooffset;
|
final int ooffset;
|
||||||
final int len;
|
final int len;
|
||||||
final boolean expected;
|
final boolean expected;
|
||||||
final Class<?> throwable;
|
final Class<? extends Throwable> throwable;
|
||||||
TestData(final String source, final boolean ignoreCase, final int toffset,
|
TestData(final String source, final boolean ignoreCase, final int toffset,
|
||||||
final String other, final int ooffset, final int len, final boolean expected){
|
final String other, final int ooffset, final int len, final boolean expected){
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
@ -96,7 +95,7 @@ public class CharSequenceUtilsTest {
|
||||||
this.throwable = null;
|
this.throwable = null;
|
||||||
}
|
}
|
||||||
TestData(final String source, final boolean ignoreCase, final int toffset,
|
TestData(final String source, final boolean ignoreCase, final int toffset,
|
||||||
final String other, final int ooffset, final int len, final Class<?> throwable){
|
final String other, final int ooffset, final int len, final Class<? extends Throwable> throwable){
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.ignoreCase = ignoreCase;
|
this.ignoreCase = ignoreCase;
|
||||||
this.toffset = toffset;
|
this.toffset = toffset;
|
||||||
|
@ -145,14 +144,7 @@ public class CharSequenceUtilsTest {
|
||||||
|
|
||||||
void run(final TestData data, final String id) {
|
void run(final TestData data, final String id) {
|
||||||
if (data.throwable != null) {
|
if (data.throwable != null) {
|
||||||
try {
|
assertThrows(data.throwable, this::invoke, id + " Expected " + data.throwable);
|
||||||
invoke();
|
|
||||||
fail(id + " Expected " + data.throwable);
|
|
||||||
} catch (final Exception e) {
|
|
||||||
if (!e.getClass().equals(data.throwable)) {
|
|
||||||
fail(id + " Expected " + data.throwable + " got " + e.getClass());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
final boolean stringCheck = invoke();
|
final boolean stringCheck = invoke();
|
||||||
assertEquals(data.expected, stringCheck, id + " Failed test " + data);
|
assertEquals(data.expected, stringCheck, id + " Failed test " + data);
|
||||||
|
|
|
@ -21,8 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -199,10 +199,7 @@ public class CharUtilsTest {
|
||||||
public void testToChar_Character() {
|
public void testToChar_Character() {
|
||||||
assertEquals('A', CharUtils.toChar(CHARACTER_A));
|
assertEquals('A', CharUtils.toChar(CHARACTER_A));
|
||||||
assertEquals('B', CharUtils.toChar(CHARACTER_B));
|
assertEquals('B', CharUtils.toChar(CHARACTER_B));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> CharUtils.toChar((Character) null));
|
||||||
CharUtils.toChar((Character) null);
|
|
||||||
fail("An IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -216,14 +213,8 @@ public class CharUtilsTest {
|
||||||
public void testToChar_String() {
|
public void testToChar_String() {
|
||||||
assertEquals('A', CharUtils.toChar("A"));
|
assertEquals('A', CharUtils.toChar("A"));
|
||||||
assertEquals('B', CharUtils.toChar("BA"));
|
assertEquals('B', CharUtils.toChar("BA"));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> CharUtils.toChar((String) null));
|
||||||
CharUtils.toChar((String) null);
|
assertThrows(IllegalArgumentException.class, () -> CharUtils.toChar(""));
|
||||||
fail("An IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
CharUtils.toChar("");
|
|
||||||
fail("An IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -278,10 +269,7 @@ public class CharUtilsTest {
|
||||||
assertEquals(7, CharUtils.toIntValue('7'));
|
assertEquals(7, CharUtils.toIntValue('7'));
|
||||||
assertEquals(8, CharUtils.toIntValue('8'));
|
assertEquals(8, CharUtils.toIntValue('8'));
|
||||||
assertEquals(9, CharUtils.toIntValue('9'));
|
assertEquals(9, CharUtils.toIntValue('9'));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue('a'));
|
||||||
CharUtils.toIntValue('a');
|
|
||||||
fail("An IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -295,14 +283,8 @@ public class CharUtilsTest {
|
||||||
public void testToIntValue_Character() {
|
public void testToIntValue_Character() {
|
||||||
assertEquals(0, CharUtils.toIntValue(new Character('0')));
|
assertEquals(0, CharUtils.toIntValue(new Character('0')));
|
||||||
assertEquals(3, CharUtils.toIntValue(new Character('3')));
|
assertEquals(3, CharUtils.toIntValue(new Character('3')));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue(null));
|
||||||
CharUtils.toIntValue(null);
|
assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue(CHARACTER_A));
|
||||||
fail("An IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
CharUtils.toIntValue(CHARACTER_A);
|
|
||||||
fail("An IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -97,13 +96,10 @@ public class ClassUtilsTest {
|
||||||
assertGetClassThrowsException( className, ClassNotFoundException.class );
|
assertGetClassThrowsException( className, ClassNotFoundException.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertGetClassThrowsException( final String className, final Class<?> exceptionType ) throws Exception {
|
private void assertGetClassThrowsException(final String className, final Class<? extends Exception> exceptionType) {
|
||||||
try {
|
assertThrows(exceptionType,
|
||||||
ClassUtils.getClass( className );
|
() -> ClassUtils.getClass(className),
|
||||||
fail( "ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\"." );
|
"ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\"." );
|
||||||
} catch( final Exception e ) {
|
|
||||||
assertTrue( exceptionType.isAssignableFrom( e.getClass() ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertGetClassThrowsNullPointerException( final String className ) throws Exception {
|
private void assertGetClassThrowsNullPointerException( final String className ) throws Exception {
|
||||||
|
@ -128,12 +124,9 @@ public class ClassUtilsTest {
|
||||||
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
|
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
|
||||||
final List<Object> olist = (List<Object>) (List<?>) list;
|
final List<Object> olist = (List<Object>) (List<?>) list;
|
||||||
olist.add(new Object());
|
olist.add(new Object());
|
||||||
try {
|
assertThrows(ClassCastException.class,
|
||||||
ClassUtils.convertClassesToClassNames(list);
|
() -> ClassUtils.convertClassesToClassNames(list),
|
||||||
fail("Should not have been able to convert list");
|
"Should not have been able to convert list");
|
||||||
} catch (final ClassCastException expected) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
assertNull(ClassUtils.convertClassesToClassNames(null));
|
assertNull(ClassUtils.convertClassesToClassNames(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,12 +149,9 @@ public class ClassUtilsTest {
|
||||||
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
|
@SuppressWarnings("unchecked") // test what happens when non-generic code adds wrong type of element
|
||||||
final List<Object> olist = (List<Object>) (List<?>) list;
|
final List<Object> olist = (List<Object>) (List<?>) list;
|
||||||
olist.add(new Object());
|
olist.add(new Object());
|
||||||
try {
|
assertThrows(ClassCastException.class,
|
||||||
ClassUtils.convertClassNamesToClasses(list);
|
() -> ClassUtils.convertClassNamesToClasses(list),
|
||||||
fail("Should not have been able to convert list");
|
"Should not have been able to convert list");
|
||||||
} catch (final ClassCastException expected) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
assertNull(ClassUtils.convertClassNamesToClasses(null));
|
assertNull(ClassUtils.convertClassNamesToClasses(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1208,17 +1198,12 @@ public class ClassUtilsTest {
|
||||||
// Tests with Collections$UnmodifiableSet
|
// Tests with Collections$UnmodifiableSet
|
||||||
final Set<?> set = Collections.unmodifiableSet(new HashSet<>());
|
final Set<?> set = Collections.unmodifiableSet(new HashSet<>());
|
||||||
final Method isEmptyMethod = ClassUtils.getPublicMethod(set.getClass(), "isEmpty");
|
final Method isEmptyMethod = ClassUtils.getPublicMethod(set.getClass(), "isEmpty");
|
||||||
assertTrue(Modifier.isPublic(isEmptyMethod.getDeclaringClass().getModifiers()));
|
assertTrue(Modifier.isPublic(isEmptyMethod.getDeclaringClass().getModifiers()));
|
||||||
|
assertTrue((Boolean) isEmptyMethod.invoke(set));
|
||||||
try {
|
|
||||||
isEmptyMethod.invoke(set);
|
|
||||||
} catch(final java.lang.IllegalAccessException iae) {
|
|
||||||
fail("Should not have thrown IllegalAccessException");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests with a public Class
|
// Tests with a public Class
|
||||||
final Method toStringMethod = ClassUtils.getPublicMethod(Object.class, "toString");
|
final Method toStringMethod = ClassUtils.getPublicMethod(Object.class, "toString");
|
||||||
assertEquals(Object.class.getMethod("toString", new Class[0]), toStringMethod);
|
assertEquals(Object.class.getMethod("toString", new Class[0]), toStringMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1370,12 +1355,7 @@ public class ClassUtilsTest {
|
||||||
// Tests with Collections$UnmodifiableSet
|
// Tests with Collections$UnmodifiableSet
|
||||||
final Set<?> set = Collections.unmodifiableSet(new HashSet<>());
|
final Set<?> set = Collections.unmodifiableSet(new HashSet<>());
|
||||||
final Method isEmptyMethod = set.getClass().getMethod("isEmpty");
|
final Method isEmptyMethod = set.getClass().getMethod("isEmpty");
|
||||||
try {
|
assertThrows(IllegalAccessException.class, () -> isEmptyMethod.invoke(set));
|
||||||
isEmptyMethod.invoke(set);
|
|
||||||
fail("Failed to throw IllegalAccessException as expected");
|
|
||||||
} catch(final IllegalAccessException iae) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -57,12 +57,7 @@ public class ConversionTest {
|
||||||
assertEquals(14, Conversion.hexDigitToInt('e'));
|
assertEquals(14, Conversion.hexDigitToInt('e'));
|
||||||
assertEquals(15, Conversion.hexDigitToInt('F'));
|
assertEquals(15, Conversion.hexDigitToInt('F'));
|
||||||
assertEquals(15, Conversion.hexDigitToInt('f'));
|
assertEquals(15, Conversion.hexDigitToInt('f'));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.hexDigitToInt('G'));
|
||||||
Conversion.hexDigitToInt('G');
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,12 +87,7 @@ public class ConversionTest {
|
||||||
assertEquals(0x7, Conversion.hexDigitMsb0ToInt('e'));
|
assertEquals(0x7, Conversion.hexDigitMsb0ToInt('e'));
|
||||||
assertEquals(0xF, Conversion.hexDigitMsb0ToInt('F'));
|
assertEquals(0xF, Conversion.hexDigitMsb0ToInt('F'));
|
||||||
assertEquals(0xF, Conversion.hexDigitMsb0ToInt('f'));
|
assertEquals(0xF, Conversion.hexDigitMsb0ToInt('f'));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.hexDigitMsb0ToInt('G'));
|
||||||
Conversion.hexDigitMsb0ToInt('G');
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,12 +139,7 @@ public class ConversionTest {
|
||||||
new boolean[]{true, true, true, true}, Conversion.hexDigitToBinary('F'));
|
new boolean[]{true, true, true, true}, Conversion.hexDigitToBinary('F'));
|
||||||
assertArrayEquals(
|
assertArrayEquals(
|
||||||
new boolean[]{true, true, true, true}, Conversion.hexDigitToBinary('f'));
|
new boolean[]{true, true, true, true}, Conversion.hexDigitToBinary('f'));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.hexDigitToBinary('G'));
|
||||||
Conversion.hexDigitToBinary('G');
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,12 +191,7 @@ public class ConversionTest {
|
||||||
new boolean[]{true, true, true, true}, Conversion.hexDigitMsb0ToBinary('F'));
|
new boolean[]{true, true, true, true}, Conversion.hexDigitMsb0ToBinary('F'));
|
||||||
assertArrayEquals(
|
assertArrayEquals(
|
||||||
new boolean[]{true, true, true, true}, Conversion.hexDigitMsb0ToBinary('f'));
|
new boolean[]{true, true, true, true}, Conversion.hexDigitMsb0ToBinary('f'));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.hexDigitMsb0ToBinary('G'));
|
||||||
Conversion.hexDigitMsb0ToBinary('G');
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -239,12 +219,7 @@ public class ConversionTest {
|
||||||
assertEquals('1', Conversion.binaryToHexDigit(new boolean[]{true}));
|
assertEquals('1', Conversion.binaryToHexDigit(new boolean[]{true}));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
'f', Conversion.binaryToHexDigit(new boolean[]{true, true, true, true, true}));
|
'f', Conversion.binaryToHexDigit(new boolean[]{true, true, true, true, true}));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.binaryToHexDigit(new boolean[]{}));
|
||||||
Conversion.binaryToHexDigit(new boolean[]{});
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -308,12 +283,7 @@ public class ConversionTest {
|
||||||
'e', Conversion.binaryToHexDigitMsb0_4bits(new boolean[]{true, true, true, false}));
|
'e', Conversion.binaryToHexDigitMsb0_4bits(new boolean[]{true, true, true, false}));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
'f', Conversion.binaryToHexDigitMsb0_4bits(new boolean[]{true, true, true, true}));
|
'f', Conversion.binaryToHexDigitMsb0_4bits(new boolean[]{true, true, true, true}));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.binaryToHexDigitMsb0_4bits(new boolean[]{}));
|
||||||
Conversion.binaryToHexDigitMsb0_4bits(new boolean[]{});
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -393,12 +363,7 @@ public class ConversionTest {
|
||||||
Conversion.binaryBeMsb0ToHexDigit(new boolean[]{
|
Conversion.binaryBeMsb0ToHexDigit(new boolean[]{
|
||||||
true, false, false, false, false, false, false, false, false, false, false,
|
true, false, false, false, false, false, false, false, false, false, false,
|
||||||
false, false, true, false, false}));
|
false, false, true, false, false}));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.binaryBeMsb0ToHexDigit(new boolean[]{}));
|
||||||
Conversion.binaryBeMsb0ToHexDigit(new boolean[]{});
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -469,12 +434,7 @@ public class ConversionTest {
|
||||||
assertEquals('d', Conversion.intToHexDigit(13));
|
assertEquals('d', Conversion.intToHexDigit(13));
|
||||||
assertEquals('e', Conversion.intToHexDigit(14));
|
assertEquals('e', Conversion.intToHexDigit(14));
|
||||||
assertEquals('f', Conversion.intToHexDigit(15));
|
assertEquals('f', Conversion.intToHexDigit(15));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.intToHexDigit(16));
|
||||||
Conversion.intToHexDigit(16);
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -498,12 +458,7 @@ public class ConversionTest {
|
||||||
assertEquals('b', Conversion.intToHexDigitMsb0(13));
|
assertEquals('b', Conversion.intToHexDigitMsb0(13));
|
||||||
assertEquals('7', Conversion.intToHexDigitMsb0(14));
|
assertEquals('7', Conversion.intToHexDigitMsb0(14));
|
||||||
assertEquals('f', Conversion.intToHexDigitMsb0(15));
|
assertEquals('f', Conversion.intToHexDigitMsb0(15));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> Conversion.intToHexDigitMsb0(16));
|
||||||
Conversion.intToHexDigitMsb0(16);
|
|
||||||
fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static String dbgPrint(final boolean[] src) {
|
static String dbgPrint(final boolean[] src) {
|
||||||
|
@ -1276,12 +1231,7 @@ public class ConversionTest {
|
||||||
Conversion.longToHex(0x1234567890ABCDEFL, 4, "ffffffffffffffffffffffff", 3, 15));
|
Conversion.longToHex(0x1234567890ABCDEFL, 4, "ffffffffffffffffffffffff", 3, 15));
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"fedcba0987654321", Conversion.longToHex(0x1234567890ABCDEFL, 0, "", 0, 16));
|
"fedcba0987654321", Conversion.longToHex(0x1234567890ABCDEFL, 0, "", 0, 16));
|
||||||
try {
|
assertThrows(StringIndexOutOfBoundsException.class, () -> Conversion.longToHex(0x1234567890ABCDEFL, 0, "", 1, 8));
|
||||||
Conversion.longToHex(0x1234567890ABCDEFL, 0, "", 1, 8);
|
|
||||||
fail("Thrown " + StringIndexOutOfBoundsException.class.getName() + " expected");
|
|
||||||
} catch (final StringIndexOutOfBoundsException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1340,12 +1290,7 @@ public class ConversionTest {
|
||||||
"fffedcba09ffffffffffffff",
|
"fffedcba09ffffffffffffff",
|
||||||
Conversion.intToHex(0x90ABCDEF, 4, "ffffffffffffffffffffffff", 3, 7));
|
Conversion.intToHex(0x90ABCDEF, 4, "ffffffffffffffffffffffff", 3, 7));
|
||||||
assertEquals("fedcba09", Conversion.intToHex(0x90ABCDEF, 0, "", 0, 8));
|
assertEquals("fedcba09", Conversion.intToHex(0x90ABCDEF, 0, "", 0, 8));
|
||||||
try {
|
assertThrows(StringIndexOutOfBoundsException.class, () -> Conversion.intToHex(0x90ABCDEF, 0, "", 1, 8));
|
||||||
Conversion.intToHex(0x90ABCDEF, 0, "", 1, 8);
|
|
||||||
fail("Thrown " + StringIndexOutOfBoundsException.class.getName() + " expected");
|
|
||||||
} catch (final StringIndexOutOfBoundsException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1392,12 +1337,7 @@ public class ConversionTest {
|
||||||
"fffedcffffffffffffffffff",
|
"fffedcffffffffffffffffff",
|
||||||
Conversion.shortToHex((short)0xCDEF, 4, "ffffffffffffffffffffffff", 3, 3));
|
Conversion.shortToHex((short)0xCDEF, 4, "ffffffffffffffffffffffff", 3, 3));
|
||||||
assertEquals("fedc", Conversion.shortToHex((short)0xCDEF, 0, "", 0, 4));
|
assertEquals("fedc", Conversion.shortToHex((short)0xCDEF, 0, "", 0, 4));
|
||||||
try {
|
assertThrows(StringIndexOutOfBoundsException.class, () -> Conversion.shortToHex((short)0xCDEF, 0, "", 1, 4));
|
||||||
Conversion.shortToHex((short)0xCDEF, 0, "", 1, 4);
|
|
||||||
fail("Thrown " + StringIndexOutOfBoundsException.class.getName() + " expected");
|
|
||||||
} catch (final StringIndexOutOfBoundsException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1420,12 +1360,7 @@ public class ConversionTest {
|
||||||
// assertion
|
// assertion
|
||||||
assertEquals("000e0", Conversion.byteToHex((byte)0xEF, 4, "00000", 3, 1));
|
assertEquals("000e0", Conversion.byteToHex((byte)0xEF, 4, "00000", 3, 1));
|
||||||
assertEquals("fe", Conversion.byteToHex((byte)0xEF, 0, "", 0, 2));
|
assertEquals("fe", Conversion.byteToHex((byte)0xEF, 0, "", 0, 2));
|
||||||
try {
|
assertThrows(StringIndexOutOfBoundsException.class, () -> Conversion.byteToHex((byte)0xEF, 0, "", 1, 2));
|
||||||
Conversion.byteToHex((byte)0xEF, 0, "", 1, 2);
|
|
||||||
fail("Thrown " + StringIndexOutOfBoundsException.class.getName() + " expected");
|
|
||||||
} catch (final StringIndexOutOfBoundsException e) {
|
|
||||||
// OK
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
@ -138,32 +139,13 @@ public class LocaleUtilsTest {
|
||||||
// LANG-941: JDK 8 introduced the empty locale as one of the default locales
|
// LANG-941: JDK 8 introduced the empty locale as one of the default locales
|
||||||
assertValidToLocale("");
|
assertValidToLocale("");
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> LocaleUtils.toLocale("Us"), "Should fail if not lowercase");
|
||||||
LocaleUtils.toLocale("Us");
|
assertThrows(IllegalArgumentException.class, () -> LocaleUtils.toLocale("uS"), "Should fail if not lowercase");
|
||||||
fail("Should fail if not lowercase");
|
assertThrows(IllegalArgumentException.class, () -> LocaleUtils.toLocale("u#"), "Should fail if not lowercase");
|
||||||
} catch (final IllegalArgumentException iae) {}
|
assertThrows(
|
||||||
try {
|
IllegalArgumentException.class, () -> LocaleUtils.toLocale("u"), "Must be 2 chars if less than 5");
|
||||||
LocaleUtils.toLocale("US");
|
assertThrows(
|
||||||
fail("Should fail if not lowercase");
|
IllegalArgumentException.class, () -> LocaleUtils.toLocale("uu_U"), "Must be 2 chars if less than 5");
|
||||||
} catch (final IllegalArgumentException iae) {}
|
|
||||||
try {
|
|
||||||
LocaleUtils.toLocale("uS");
|
|
||||||
fail("Should fail if not lowercase");
|
|
||||||
} catch (final IllegalArgumentException iae) {}
|
|
||||||
try {
|
|
||||||
LocaleUtils.toLocale("u#");
|
|
||||||
fail("Should fail if not lowercase");
|
|
||||||
} catch (final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
LocaleUtils.toLocale("u");
|
|
||||||
fail("Must be 2 chars if less than 5");
|
|
||||||
} catch (final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
LocaleUtils.toLocale("uu_U");
|
|
||||||
fail("Must be 2 chars if less than 5");
|
|
||||||
} catch (final IllegalArgumentException iae) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,30 +157,28 @@ public class LocaleUtilsTest {
|
||||||
//valid though doesn't exist
|
//valid though doesn't exist
|
||||||
assertValidToLocale("us_ZH", "us", "ZH");
|
assertValidToLocale("us_ZH", "us", "ZH");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
LocaleUtils.toLocale("us-EN");
|
IllegalArgumentException.class, () -> LocaleUtils.toLocale("us-EN"), "Should fail as not underscore");
|
||||||
fail("Should fail as not underscore");
|
assertThrows(
|
||||||
} catch (final IllegalArgumentException iae) {}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> LocaleUtils.toLocale("us_En"),
|
||||||
LocaleUtils.toLocale("us_En");
|
"Should fail second part not uppercase");
|
||||||
fail("Should fail second part not uppercase");
|
assertThrows(
|
||||||
} catch (final IllegalArgumentException iae) {}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> LocaleUtils.toLocale("us_en"),
|
||||||
LocaleUtils.toLocale("us_en");
|
"Should fail second part not uppercase");
|
||||||
fail("Should fail second part not uppercase");
|
assertThrows(
|
||||||
} catch (final IllegalArgumentException iae) {}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> LocaleUtils.toLocale("us_eN"),
|
||||||
LocaleUtils.toLocale("us_eN");
|
"Should fail second part not uppercase");
|
||||||
fail("Should fail second part not uppercase");
|
assertThrows(
|
||||||
} catch (final IllegalArgumentException iae) {}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> LocaleUtils.toLocale("uS_EN"),
|
||||||
LocaleUtils.toLocale("uS_EN");
|
"Should fail first part not lowercase");
|
||||||
fail("Should fail first part not lowercase");
|
assertThrows(
|
||||||
} catch (final IllegalArgumentException iae) {}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> LocaleUtils.toLocale("us_E3"),
|
||||||
LocaleUtils.toLocale("us_E3");
|
"Should fail second part not uppercase");
|
||||||
fail("Should fail second part not uppercase");
|
|
||||||
} catch (final IllegalArgumentException iae) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,14 +197,10 @@ public class LocaleUtilsTest {
|
||||||
assertValidToLocale("us_EN_SFsafdFDsdfF", "us", "EN", "SFSAFDFDSDFF");
|
assertValidToLocale("us_EN_SFsafdFDsdfF", "us", "EN", "SFSAFDFDSDFF");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
LocaleUtils.toLocale("us_EN-a");
|
IllegalArgumentException.class, () -> LocaleUtils.toLocale("us_EN-a"), "Should fail as not underscore");
|
||||||
fail("Should fail as not underscore");
|
assertThrows(
|
||||||
} catch (final IllegalArgumentException iae) {}
|
IllegalArgumentException.class, () -> LocaleUtils.toLocale("uu_UU_"), "Must be 3, 5 or 7+ in length");
|
||||||
try {
|
|
||||||
LocaleUtils.toLocale("uu_UU_");
|
|
||||||
fail("Must be 3, 5 or 7+ in length");
|
|
||||||
} catch (final IllegalArgumentException iae) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -492,10 +468,7 @@ public class LocaleUtilsTest {
|
||||||
* @param coll the collection to check
|
* @param coll the collection to check
|
||||||
*/
|
*/
|
||||||
private static void assertUnmodifiableCollection(final Collection<?> coll) {
|
private static void assertUnmodifiableCollection(final Collection<?> coll) {
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> coll.add(null));
|
||||||
coll.add(null);
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -526,41 +499,34 @@ public class LocaleUtilsTest {
|
||||||
assertValidToLocale("_GB", "", "GB", "");
|
assertValidToLocale("_GB", "", "GB", "");
|
||||||
assertValidToLocale("_GB_P", "", "GB", "P");
|
assertValidToLocale("_GB_P", "", "GB", "P");
|
||||||
assertValidToLocale("_GB_POSIX", "", "GB", "POSIX");
|
assertValidToLocale("_GB_POSIX", "", "GB", "POSIX");
|
||||||
try {
|
assertThrows(
|
||||||
LocaleUtils.toLocale("_G");
|
IllegalArgumentException.class,
|
||||||
fail("Must be at least 3 chars if starts with underscore");
|
() -> LocaleUtils.toLocale("_G"),
|
||||||
} catch (final IllegalArgumentException iae) {
|
"Must be at least 3 chars if starts with underscore");
|
||||||
}
|
assertThrows(
|
||||||
try {
|
IllegalArgumentException.class,
|
||||||
LocaleUtils.toLocale("_Gb");
|
() -> LocaleUtils.toLocale("_Gb"),
|
||||||
fail("Must be uppercase if starts with underscore");
|
"Must be uppercase if starts with underscore");
|
||||||
} catch (final IllegalArgumentException iae) {
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> LocaleUtils.toLocale("_gB"),
|
||||||
LocaleUtils.toLocale("_gB");
|
"Must be uppercase if starts with underscore");
|
||||||
fail("Must be uppercase if starts with underscore");
|
assertThrows(
|
||||||
} catch (final IllegalArgumentException iae) {
|
IllegalArgumentException.class,
|
||||||
}
|
() -> LocaleUtils.toLocale("_1B"),
|
||||||
try {
|
"Must be letter if starts with underscore");
|
||||||
LocaleUtils.toLocale("_1B");
|
assertThrows(
|
||||||
fail("Must be letter if starts with underscore");
|
IllegalArgumentException.class,
|
||||||
} catch (final IllegalArgumentException iae) {
|
() -> LocaleUtils.toLocale("_G1"),
|
||||||
}
|
"Must be letter if starts with underscore");
|
||||||
try {
|
assertThrows(
|
||||||
LocaleUtils.toLocale("_G1");
|
IllegalArgumentException.class,
|
||||||
fail("Must be letter if starts with underscore");
|
() -> LocaleUtils.toLocale("_GB_"),
|
||||||
} catch (final IllegalArgumentException iae) {
|
"Must be at least 5 chars if starts with underscore");
|
||||||
}
|
assertThrows(
|
||||||
try {
|
IllegalArgumentException.class,
|
||||||
LocaleUtils.toLocale("_GB_");
|
() -> LocaleUtils.toLocale("_GBAP"),
|
||||||
fail("Must be at least 5 chars if starts with underscore");
|
"Must have underscore after the country if starts with underscore and is at least 5 chars");
|
||||||
} catch (final IllegalArgumentException iae) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
LocaleUtils.toLocale("_GBAP");
|
|
||||||
fail("Must have underscore after the country if starts with underscore and is at least 5 chars");
|
|
||||||
} catch (final IllegalArgumentException iae) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -569,22 +535,19 @@ public class LocaleUtilsTest {
|
||||||
// Check if it's possible to recreate the Locale using just the standard constructor
|
// Check if it's possible to recreate the Locale using just the standard constructor
|
||||||
final Locale locale = new Locale(l.getLanguage(), l.getCountry(), l.getVariant());
|
final Locale locale = new Locale(l.getLanguage(), l.getCountry(), l.getVariant());
|
||||||
if (l.equals(locale)) { // it is possible for LocaleUtils.toLocale to handle these Locales
|
if (l.equals(locale)) { // it is possible for LocaleUtils.toLocale to handle these Locales
|
||||||
String str = l.toString();
|
final String str = l.toString();
|
||||||
// Look for the script/extension suffix
|
// Look for the script/extension suffix
|
||||||
int suff = str.indexOf("_#");
|
int suff = str.indexOf("_#");
|
||||||
if (suff == - 1) {
|
if (suff == - 1) {
|
||||||
suff = str.indexOf("#");
|
suff = str.indexOf("#");
|
||||||
}
|
}
|
||||||
|
String localeStr = str;
|
||||||
if (suff >= 0) { // we have a suffix
|
if (suff >= 0) { // we have a suffix
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> LocaleUtils.toLocale(str));
|
||||||
LocaleUtils.toLocale(str); // should cause IAE
|
// try without suffix
|
||||||
fail("Should not have parsed: " + str);
|
localeStr = str.substring(0, suff);
|
||||||
} catch (final IllegalArgumentException iae) {
|
|
||||||
// expected; try without suffix
|
|
||||||
str = str.substring(0, suff);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final Locale loc = LocaleUtils.toLocale(str);
|
final Locale loc = LocaleUtils.toLocale(localeStr);
|
||||||
assertEquals(l, loc);
|
assertEquals(l, loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
@ -227,16 +226,8 @@ public class ObjectUtilsTest {
|
||||||
ObjectUtils.identityToString(buffer, i);
|
ObjectUtils.identityToString(buffer, i);
|
||||||
assertEquals(expected, buffer.toString());
|
assertEquals(expected, buffer.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> ObjectUtils.identityToString((StringBuffer)null, "tmp"));
|
||||||
ObjectUtils.identityToString((StringBuffer)null, "tmp");
|
assertThrows(NullPointerException.class, () -> ObjectUtils.identityToString(new StringBuffer(), null));
|
||||||
fail("NullPointerException expected");
|
|
||||||
} catch(final NullPointerException npe) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ObjectUtils.identityToString(new StringBuffer(), null);
|
|
||||||
fail("NullPointerException expected");
|
|
||||||
} catch(final NullPointerException npe) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -281,20 +272,12 @@ public class ObjectUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIdentityToStringStringBuilderNullValue() {
|
public void testIdentityToStringStringBuilderNullValue() {
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> ObjectUtils.identityToString(new StringBuilder(), null));
|
||||||
ObjectUtils.identityToString(new StringBuilder(), null);
|
|
||||||
fail("NullPointerException expected");
|
|
||||||
} catch(final NullPointerException npe) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIdentityToStringStringBuilderNullStringBuilder() {
|
public void testIdentityToStringStringBuilderNullStringBuilder() {
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> ObjectUtils.identityToString((StringBuilder)null, "tmp"));
|
||||||
ObjectUtils.identityToString((StringBuilder)null, "tmp");
|
|
||||||
fail("NullPointerException expected");
|
|
||||||
} catch(final NullPointerException npe) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -306,47 +289,25 @@ public class ObjectUtilsTest {
|
||||||
ObjectUtils.identityToString(builder, i);
|
ObjectUtils.identityToString(builder, i);
|
||||||
assertEquals(expected, builder.toString());
|
assertEquals(expected, builder.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> ObjectUtils.identityToString((StrBuilder)null, "tmp"));
|
||||||
ObjectUtils.identityToString((StrBuilder)null, "tmp");
|
|
||||||
fail("NullPointerException expected");
|
|
||||||
} catch(final NullPointerException npe) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> ObjectUtils.identityToString(new StrBuilder(), null));
|
||||||
ObjectUtils.identityToString(new StrBuilder(), null);
|
|
||||||
fail("NullPointerException expected");
|
|
||||||
} catch(final NullPointerException npe) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIdentityToStringAppendable() {
|
public void testIdentityToStringAppendable() throws IOException {
|
||||||
final Integer i = Integer.valueOf(121);
|
final Integer i = Integer.valueOf(121);
|
||||||
final String expected = "java.lang.Integer@" + Integer.toHexString(System.identityHashCode(i));
|
final String expected = "java.lang.Integer@" + Integer.toHexString(System.identityHashCode(i));
|
||||||
|
|
||||||
try {
|
final Appendable appendable = new StringBuilder();
|
||||||
final Appendable appendable = new StringBuilder();
|
ObjectUtils.identityToString(appendable, i);
|
||||||
ObjectUtils.identityToString(appendable, i);
|
assertEquals(expected, appendable.toString());
|
||||||
assertEquals(expected, appendable.toString());
|
|
||||||
} catch(final IOException ex) {
|
|
||||||
fail("IOException unexpected");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> ObjectUtils.identityToString((Appendable)null, "tmp"));
|
||||||
ObjectUtils.identityToString((Appendable)null, "tmp");
|
|
||||||
fail("NullPointerException expected");
|
|
||||||
} catch(final NullPointerException expectedException) {
|
|
||||||
} catch(final IOException ex) {
|
|
||||||
fail("IOException unexpected");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
ObjectUtils.identityToString((Appendable)(new StringBuilder()), null);
|
NullPointerException.class,
|
||||||
fail("NullPointerException expected");
|
() -> ObjectUtils.identityToString((Appendable)(new StringBuilder()), null));
|
||||||
} catch(final NullPointerException expectedException) {
|
|
||||||
} catch(final IOException ex) {
|
|
||||||
fail("IOException unexpected");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -641,32 +602,22 @@ public class ObjectUtilsTest {
|
||||||
assertTrue(1.0f == MAGIC_FLOAT);
|
assertTrue(1.0f == MAGIC_FLOAT);
|
||||||
assertTrue(1.0 == MAGIC_DOUBLE);
|
assertTrue(1.0 == MAGIC_DOUBLE);
|
||||||
assertEquals("abc", MAGIC_STRING);
|
assertEquals("abc", MAGIC_STRING);
|
||||||
|
assertThrows(
|
||||||
try {
|
IllegalArgumentException.class,
|
||||||
ObjectUtils.CONST_BYTE(-129);
|
() -> ObjectUtils.CONST_BYTE(-129),
|
||||||
fail("CONST_BYTE(-129): IllegalArgumentException should have been thrown.");
|
"CONST_BYTE(-129): IllegalArgumentException should have been thrown.");
|
||||||
} catch (final IllegalArgumentException iae) {
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
}
|
() -> ObjectUtils.CONST_BYTE(128),
|
||||||
try {
|
"CONST_BYTE(128): IllegalArgumentException should have been thrown.");
|
||||||
ObjectUtils.CONST_BYTE(128);
|
assertThrows(
|
||||||
fail("CONST_BYTE(128): IllegalArgumentException should have been thrown.");
|
IllegalArgumentException.class,
|
||||||
} catch (final IllegalArgumentException iae) {
|
() -> ObjectUtils.CONST_SHORT(-32769),
|
||||||
|
"CONST_SHORT(-32769): IllegalArgumentException should have been thrown.");
|
||||||
}
|
assertThrows(
|
||||||
try {
|
IllegalArgumentException.class,
|
||||||
ObjectUtils.CONST_SHORT(-32769);
|
() -> ObjectUtils.CONST_BYTE(32768),
|
||||||
fail("CONST_SHORT(-32769): IllegalArgumentException should have been thrown.");
|
"CONST_SHORT(32768): IllegalArgumentException should have been thrown.");
|
||||||
} catch (final IllegalArgumentException iae) {
|
|
||||||
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ObjectUtils.CONST_BYTE(32768);
|
|
||||||
fail("CONST_SHORT(32768): IllegalArgumentException should have been thrown.");
|
|
||||||
} catch (final IllegalArgumentException iae) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
@ -157,63 +158,29 @@ public class RandomStringUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLANG807() {
|
public void testLANG807() {
|
||||||
try {
|
IllegalArgumentException ex =
|
||||||
RandomStringUtils.random(3,5,5,false,false);
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(3,5,5,false,false));
|
||||||
fail("Expected IllegalArgumentException");
|
final String msg = ex.getMessage();
|
||||||
} catch (final IllegalArgumentException ex) { // distinguish from Random#nextInt message
|
assertTrue(msg.contains("start"), "Message (" + msg + ") must contain 'start'");
|
||||||
final String msg = ex.getMessage();
|
assertTrue(msg.contains("end"), "Message (" + msg + ") must contain 'end'");
|
||||||
assertTrue(msg.contains("start"), "Message (" + msg + ") must contain 'start'");
|
|
||||||
assertTrue(msg.contains("end"), "Message (" + msg + ") must contain 'end'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExceptions() {
|
public void testExceptions() {
|
||||||
final char[] DUMMY = new char[]{'a'}; // valid char array
|
final char[] DUMMY = new char[]{'a'}; // valid char array
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(-1));
|
||||||
RandomStringUtils.random(-1);
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(-1, true, true));
|
||||||
fail();
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(-1, DUMMY));
|
||||||
} catch (final IllegalArgumentException ex) {}
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(1, new char[0]));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(-1, ""));
|
||||||
RandomStringUtils.random(-1, true, true);
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(-1, (String) null));
|
||||||
fail();
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(-1, 'a', 'z', false, false));
|
||||||
} catch (final IllegalArgumentException ex) {}
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(-1, 'a', 'z', false, false, DUMMY));
|
||||||
try {
|
assertThrows(
|
||||||
RandomStringUtils.random(-1, DUMMY);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> RandomStringUtils.random(-1, 'a', 'z', false, false, DUMMY, new Random()));
|
||||||
} catch (final IllegalArgumentException ex) {}
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(8, 32, 48, false, true));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(8, 32, 65, true, false));
|
||||||
RandomStringUtils.random(1, new char[0]); // must not provide empty array => IAE
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
RandomStringUtils.random(-1, "");
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
RandomStringUtils.random(-1, (String)null);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
RandomStringUtils.random(-1, 'a', 'z', false, false);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
RandomStringUtils.random(-1, 'a', 'z', false, false, DUMMY);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
RandomStringUtils.random(-1, 'a', 'z', false, false, DUMMY, new Random());
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
RandomStringUtils.random(8, 32, 48, false, true);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
RandomStringUtils.random(8, 32, 65, true, false);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
@ -254,12 +253,7 @@ public class RangeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testElementCompareTo() {
|
public void testElementCompareTo() {
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> intRange.elementCompareTo(null));
|
||||||
intRange.elementCompareTo(null);
|
|
||||||
fail("NullPointerException should have been thrown");
|
|
||||||
} catch (final NullPointerException npe) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(-1, intRange.elementCompareTo(5));
|
assertEquals(-1, intRange.elementCompareTo(5));
|
||||||
assertEquals(0, intRange.elementCompareTo(10));
|
assertEquals(0, intRange.elementCompareTo(10));
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.commons.lang3;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
@ -64,12 +64,10 @@ public class RegExUtilsTest {
|
||||||
assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", "(?s)<.*>"));
|
assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", "(?s)<.*>"));
|
||||||
assertEquals("ABC123", RegExUtils.removeAll("ABCabc123abc", "[a-z]"));
|
assertEquals("ABC123", RegExUtils.removeAll("ABCabc123abc", "[a-z]"));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
RegExUtils.removeAll("any", "{badRegexSyntax}");
|
PatternSyntaxException.class,
|
||||||
fail("RegExUtils.removeAll expecting PatternSyntaxException");
|
() -> RegExUtils.removeAll("any", "{badRegexSyntax}"),
|
||||||
} catch (final PatternSyntaxException ex) {
|
"RegExUtils.removeAll expecting PatternSyntaxException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -103,12 +101,10 @@ public class RegExUtilsTest {
|
||||||
assertEquals("ABCbc123", RegExUtils.removeFirst("ABCabc123", "[a-z]"));
|
assertEquals("ABCbc123", RegExUtils.removeFirst("ABCabc123", "[a-z]"));
|
||||||
assertEquals("ABC123abc", RegExUtils.removeFirst("ABCabc123abc", "[a-z]+"));
|
assertEquals("ABC123abc", RegExUtils.removeFirst("ABCabc123abc", "[a-z]+"));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
RegExUtils.removeFirst("any", "{badRegexSyntax}");
|
PatternSyntaxException.class,
|
||||||
fail("RegExUtils.removeFirst expecting PatternSyntaxException");
|
() -> RegExUtils.removeFirst("any", "{badRegexSyntax}"),
|
||||||
} catch (final PatternSyntaxException ex) {
|
"RegExUtils.removeFirst expecting PatternSyntaxException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -174,12 +170,10 @@ public class RegExUtilsTest {
|
||||||
assertEquals("ABC123", RegExUtils.replaceAll("ABCabc123", "[^A-Z0-9]+", ""));
|
assertEquals("ABC123", RegExUtils.replaceAll("ABCabc123", "[^A-Z0-9]+", ""));
|
||||||
assertEquals("Lorem_ipsum_dolor_sit", RegExUtils.replaceAll("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2"));
|
assertEquals("Lorem_ipsum_dolor_sit", RegExUtils.replaceAll("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2"));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
RegExUtils.replaceAll("any", "{badRegexSyntax}", "");
|
PatternSyntaxException.class,
|
||||||
fail("RegExUtils.replaceAll expecting PatternSyntaxException");
|
() -> RegExUtils.replaceAll("any", "{badRegexSyntax}", ""),
|
||||||
} catch (final PatternSyntaxException ex) {
|
"RegExUtils.replaceAll expecting PatternSyntaxException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -225,12 +219,10 @@ public class RegExUtilsTest {
|
||||||
assertEquals("Lorem_ipsum dolor sit",
|
assertEquals("Lorem_ipsum dolor sit",
|
||||||
RegExUtils.replaceFirst("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2"));
|
RegExUtils.replaceFirst("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2"));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
RegExUtils.replaceFirst("any", "{badRegexSyntax}", "");
|
PatternSyntaxException.class,
|
||||||
fail("RegExUtils.replaceFirst expecting PatternSyntaxException");
|
() -> RegExUtils.replaceFirst("any", "{badRegexSyntax}", ""),
|
||||||
} catch (final PatternSyntaxException ex) {
|
"RegExUtils.replaceFirst expecting PatternSyntaxException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -159,11 +159,9 @@ public class SerializationUtilsTest {
|
||||||
throw new IOException(SERIALIZE_IO_EXCEPTION_MESSAGE);
|
throw new IOException(SERIALIZE_IO_EXCEPTION_MESSAGE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
SerializationException e =
|
||||||
SerializationUtils.serialize(iMap, streamTest);
|
assertThrows(SerializationException.class, () -> SerializationUtils.serialize(iMap, streamTest));
|
||||||
} catch(final SerializationException e) {
|
assertEquals("java.io.IOException: " + SERIALIZE_IO_EXCEPTION_MESSAGE, e.getMessage());
|
||||||
assertEquals("java.io.IOException: " + SERIALIZE_IO_EXCEPTION_MESSAGE, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -234,13 +232,9 @@ public class SerializationUtilsTest {
|
||||||
oos.close();
|
oos.close();
|
||||||
|
|
||||||
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
|
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
|
||||||
try {
|
SerializationException se =
|
||||||
@SuppressWarnings("unused")
|
assertThrows(SerializationException.class, () -> SerializationUtils.deserialize(inTest));
|
||||||
final
|
assertEquals("java.lang.ClassNotFoundException: " + CLASS_NOT_FOUND_MESSAGE, se.getMessage());
|
||||||
Object test = SerializationUtils.deserialize(inTest);
|
|
||||||
} catch(final SerializationException se) {
|
|
||||||
assertEquals("java.lang.ClassNotFoundException: " + CLASS_NOT_FOUND_MESSAGE, se.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -57,20 +56,8 @@ public class StringEscapeUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEscapeJava() throws IOException {
|
public void testEscapeJava() throws IOException {
|
||||||
assertNull(StringEscapeUtils.escapeJava(null));
|
assertNull(StringEscapeUtils.escapeJava(null));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_JAVA.translate(null, null));
|
||||||
StringEscapeUtils.ESCAPE_JAVA.translate(null, null);
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_JAVA.translate("", null));
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringEscapeUtils.ESCAPE_JAVA.translate("", null);
|
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEscapeJava("empty string", "", "");
|
assertEscapeJava("empty string", "", "");
|
||||||
assertEscapeJava(FOO, FOO);
|
assertEscapeJava(FOO, FOO);
|
||||||
|
@ -126,25 +113,9 @@ public class StringEscapeUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUnescapeJava() throws IOException {
|
public void testUnescapeJava() throws IOException {
|
||||||
assertNull(StringEscapeUtils.unescapeJava(null));
|
assertNull(StringEscapeUtils.unescapeJava(null));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_JAVA.translate(null, null));
|
||||||
StringEscapeUtils.UNESCAPE_JAVA.translate(null, null);
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_JAVA.translate("", null));
|
||||||
fail();
|
assertThrows(RuntimeException.class, () -> StringEscapeUtils.unescapeJava("\\u02-3"));
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringEscapeUtils.UNESCAPE_JAVA.translate("", null);
|
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringEscapeUtils.unescapeJava("\\u02-3");
|
|
||||||
fail();
|
|
||||||
} catch (final RuntimeException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertUnescapeJava("", "");
|
assertUnescapeJava("", "");
|
||||||
assertUnescapeJava("test", "test");
|
assertUnescapeJava("test", "test");
|
||||||
|
@ -182,20 +153,8 @@ public class StringEscapeUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEscapeEcmaScript() {
|
public void testEscapeEcmaScript() {
|
||||||
assertNull(StringEscapeUtils.escapeEcmaScript(null));
|
assertNull(StringEscapeUtils.escapeEcmaScript(null));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(null, null));
|
||||||
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(null, null);
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_ECMASCRIPT.translate("", null));
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringEscapeUtils.ESCAPE_ECMASCRIPT.translate("", null);
|
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("He didn\\'t say, \\\"stop!\\\"", StringEscapeUtils.escapeEcmaScript("He didn't say, \"stop!\""));
|
assertEquals("He didn\\'t say, \\\"stop!\\\"", StringEscapeUtils.escapeEcmaScript("He didn't say, \"stop!\""));
|
||||||
assertEquals("document.getElementById(\\\"test\\\").value = \\'<script>alert(\\'aaa\\');<\\/script>\\';",
|
assertEquals("document.getElementById(\\\"test\\\").value = \\'<script>alert(\\'aaa\\');<\\/script>\\';",
|
||||||
|
@ -205,20 +164,8 @@ public class StringEscapeUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUnescapeEcmaScript() {
|
public void testUnescapeEcmaScript() {
|
||||||
assertNull(StringEscapeUtils.escapeEcmaScript(null));
|
assertNull(StringEscapeUtils.escapeEcmaScript(null));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate(null, null));
|
||||||
StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate(null, null);
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate("", null));
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate("", null);
|
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("He didn't say, \"stop!\"", StringEscapeUtils.unescapeEcmaScript("He didn\\'t say, \\\"stop!\\\""));
|
assertEquals("He didn't say, \"stop!\"", StringEscapeUtils.unescapeEcmaScript("He didn\\'t say, \\\"stop!\\\""));
|
||||||
assertEquals("document.getElementById(\"test\").value = '<script>alert('aaa');</script>';",
|
assertEquals("document.getElementById(\"test\").value = '<script>alert('aaa');</script>';",
|
||||||
|
@ -244,24 +191,21 @@ public class StringEscapeUtilsTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEscapeHtml() {
|
public void testEscapeHtml() throws IOException {
|
||||||
for (final String[] element : HTML_ESCAPES) {
|
for (final String[] element : HTML_ESCAPES) {
|
||||||
final String message = element[0];
|
final String message = element[0];
|
||||||
final String expected = element[1];
|
final String expected = element[1];
|
||||||
final String original = element[2];
|
final String original = element[2];
|
||||||
assertEquals(expected, StringEscapeUtils.escapeHtml4(original), message);
|
assertEquals(expected, StringEscapeUtils.escapeHtml4(original), message);
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
try {
|
StringEscapeUtils.ESCAPE_HTML4.translate(original, sw);
|
||||||
StringEscapeUtils.ESCAPE_HTML4.translate(original, sw);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
}
|
|
||||||
final String actual = original == null ? null : sw.toString();
|
final String actual = original == null ? null : sw.toString();
|
||||||
assertEquals(expected, actual, message);
|
assertEquals(expected, actual, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnescapeHtml4() {
|
public void testUnescapeHtml4() throws IOException {
|
||||||
for (final String[] element : HTML_ESCAPES) {
|
for (final String[] element : HTML_ESCAPES) {
|
||||||
final String message = element[0];
|
final String message = element[0];
|
||||||
final String expected = element[2];
|
final String expected = element[2];
|
||||||
|
@ -269,10 +213,7 @@ public class StringEscapeUtilsTest {
|
||||||
assertEquals(expected, StringEscapeUtils.unescapeHtml4(original), message);
|
assertEquals(expected, StringEscapeUtils.unescapeHtml4(original), message);
|
||||||
|
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
try {
|
StringEscapeUtils.UNESCAPE_HTML4.translate(original, sw);
|
||||||
StringEscapeUtils.UNESCAPE_HTML4.translate(original, sw);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
}
|
|
||||||
final String actual = original == null ? null : sw.toString();
|
final String actual = original == null ? null : sw.toString();
|
||||||
assertEquals(expected, actual, message);
|
assertEquals(expected, actual, message);
|
||||||
}
|
}
|
||||||
|
@ -337,17 +278,11 @@ public class StringEscapeUtilsTest {
|
||||||
assertNull(StringEscapeUtils.unescapeXml(null));
|
assertNull(StringEscapeUtils.unescapeXml(null));
|
||||||
|
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
try {
|
StringEscapeUtils.ESCAPE_XML.translate("<abc>", sw);
|
||||||
StringEscapeUtils.ESCAPE_XML.translate("<abc>", sw);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
}
|
|
||||||
assertEquals("<abc>", sw.toString(), "XML was escaped incorrectly");
|
assertEquals("<abc>", sw.toString(), "XML was escaped incorrectly");
|
||||||
|
|
||||||
sw = new StringWriter();
|
sw = new StringWriter();
|
||||||
try {
|
StringEscapeUtils.UNESCAPE_XML.translate("<abc>", sw);
|
||||||
StringEscapeUtils.UNESCAPE_XML.translate("<abc>", sw);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
}
|
|
||||||
assertEquals("<abc>", sw.toString(), "XML was unescaped incorrectly");
|
assertEquals("<abc>", sw.toString(), "XML was unescaped incorrectly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,14 +416,10 @@ public class StringEscapeUtilsTest {
|
||||||
checkCsvEscapeWriter("", "");
|
checkCsvEscapeWriter("", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCsvEscapeWriter(final String expected, final String value) {
|
private void checkCsvEscapeWriter(final String expected, final String value) throws IOException {
|
||||||
try {
|
final StringWriter writer = new StringWriter();
|
||||||
final StringWriter writer = new StringWriter();
|
StringEscapeUtils.ESCAPE_CSV.translate(value, writer);
|
||||||
StringEscapeUtils.ESCAPE_CSV.translate(value, writer);
|
assertEquals(expected, writer.toString());
|
||||||
assertEquals(expected, writer.toString());
|
|
||||||
} catch (final IOException e) {
|
|
||||||
fail("Threw: " + e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -525,14 +456,10 @@ public class StringEscapeUtilsTest {
|
||||||
checkCsvUnescapeWriter("\"foo.bar\"", "\"foo.bar\"");
|
checkCsvUnescapeWriter("\"foo.bar\"", "\"foo.bar\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCsvUnescapeWriter(final String expected, final String value) {
|
private void checkCsvUnescapeWriter(final String expected, final String value) throws IOException {
|
||||||
try {
|
final StringWriter writer = new StringWriter();
|
||||||
final StringWriter writer = new StringWriter();
|
StringEscapeUtils.UNESCAPE_CSV.translate(value, writer);
|
||||||
StringEscapeUtils.UNESCAPE_CSV.translate(value, writer);
|
assertEquals(expected, writer.toString());
|
||||||
assertEquals(expected, writer.toString());
|
|
||||||
} catch (final IOException e) {
|
|
||||||
fail("Threw: " + e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -622,20 +549,8 @@ public class StringEscapeUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEscapeJson() {
|
public void testEscapeJson() {
|
||||||
assertNull(StringEscapeUtils.escapeJson(null));
|
assertNull(StringEscapeUtils.escapeJson(null));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_JSON.translate(null, null));
|
||||||
StringEscapeUtils.ESCAPE_JSON.translate(null, null);
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.ESCAPE_JSON.translate("", null));
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringEscapeUtils.ESCAPE_JSON.translate("", null);
|
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("He didn't say, \\\"stop!\\\"", StringEscapeUtils.escapeJson("He didn't say, \"stop!\""));
|
assertEquals("He didn't say, \\\"stop!\\\"", StringEscapeUtils.escapeJson("He didn't say, \"stop!\""));
|
||||||
|
|
||||||
|
@ -648,20 +563,8 @@ public class StringEscapeUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUnescapeJson() {
|
public void testUnescapeJson() {
|
||||||
assertNull(StringEscapeUtils.unescapeJson(null));
|
assertNull(StringEscapeUtils.unescapeJson(null));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_JSON.translate(null, null));
|
||||||
StringEscapeUtils.UNESCAPE_JSON.translate(null, null);
|
assertThrows(IllegalArgumentException.class, () -> StringEscapeUtils.UNESCAPE_JSON.translate("", null));
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringEscapeUtils.UNESCAPE_JSON.translate("", null);
|
|
||||||
fail();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("He didn't say, \"stop!\"", StringEscapeUtils.unescapeJson("He didn't say, \\\"stop!\\\""));
|
assertEquals("He didn't say, \"stop!\"", StringEscapeUtils.unescapeJson("He didn't say, \\\"stop!\\\""));
|
||||||
|
|
||||||
|
|
|
@ -1273,12 +1273,10 @@ public class StringUtilsTest {
|
||||||
assertEquals("Lorem_ipsum_dolor_sit",
|
assertEquals("Lorem_ipsum_dolor_sit",
|
||||||
StringUtils.replaceAll("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2"));
|
StringUtils.replaceAll("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2"));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.replaceAll("any", "{badRegexSyntax}", "");
|
PatternSyntaxException.class,
|
||||||
fail("StringUtils.replaceAll expecting PatternSyntaxException");
|
() -> StringUtils.replaceAll("any", "{badRegexSyntax}", ""),
|
||||||
} catch (final PatternSyntaxException ex) {
|
"StringUtils.replaceAll expecting PatternSyntaxException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1302,12 +1300,10 @@ public class StringUtilsTest {
|
||||||
assertEquals("Lorem_ipsum dolor sit",
|
assertEquals("Lorem_ipsum dolor sit",
|
||||||
StringUtils.replaceFirst("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2"));
|
StringUtils.replaceFirst("Lorem ipsum dolor sit", "( +)([a-z]+)", "_$2"));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.replaceFirst("any", "{badRegexSyntax}", "");
|
PatternSyntaxException.class,
|
||||||
fail("StringUtils.replaceFirst expecting PatternSyntaxException");
|
() -> StringUtils.replaceFirst("any", "{badRegexSyntax}", ""),
|
||||||
} catch (final PatternSyntaxException ex) {
|
"StringUtils.replaceFirst expecting PatternSyntaxException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1450,12 +1446,10 @@ public class StringUtilsTest {
|
||||||
assertEquals(StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{null}), "aba");
|
assertEquals(StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{null}), "aba");
|
||||||
assertEquals(StringUtils.replaceEach("aba", new String[]{"a", "b"}, new String[]{"c", null}), "cbc");
|
assertEquals(StringUtils.replaceEach("aba", new String[]{"a", "b"}, new String[]{"c", null}), "cbc");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.replaceEach("abba", new String[]{"a"}, new String[]{"b", "a"});
|
IllegalArgumentException.class,
|
||||||
fail("StringUtils.replaceEach(String, String[], String[]) expecting IllegalArgumentException");
|
() -> StringUtils.replaceEach("abba", new String[]{"a"}, new String[]{"b", "a"}),
|
||||||
} catch (final IllegalArgumentException ex) {
|
"StringUtils.replaceEach(String, String[], String[]) expecting IllegalArgumentException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1476,11 +1470,10 @@ public class StringUtilsTest {
|
||||||
assertEquals(StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}), "wcte");
|
assertEquals(StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}), "wcte");
|
||||||
assertEquals(StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}), "tcte");
|
assertEquals(StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}), "tcte");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"});
|
IllegalStateException.class,
|
||||||
fail("Should be a circular reference");
|
() -> StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}),
|
||||||
} catch (final IllegalStateException e) {
|
"Should be a circular reference");
|
||||||
}
|
|
||||||
|
|
||||||
//JAVADOC TESTS END
|
//JAVADOC TESTS END
|
||||||
}
|
}
|
||||||
|
@ -1981,12 +1974,10 @@ public class StringUtilsTest {
|
||||||
assertEquals("a...", StringUtils.abbreviate("abcdefg", 4));
|
assertEquals("a...", StringUtils.abbreviate("abcdefg", 4));
|
||||||
assertEquals("", StringUtils.abbreviate("", 4));
|
assertEquals("", StringUtils.abbreviate("", 4));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.abbreviate("abc", 3);
|
IllegalArgumentException.class,
|
||||||
fail("StringUtils.abbreviate expecting IllegalArgumentException");
|
() -> StringUtils.abbreviate("abc", 3),
|
||||||
} catch (final IllegalArgumentException expected) {
|
"StringUtils.abbreviate expecting IllegalArgumentException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2008,14 +1999,10 @@ public class StringUtilsTest {
|
||||||
assertEquals("abc.", StringUtils.abbreviate("abcdefg", ".", 4));
|
assertEquals("abc.", StringUtils.abbreviate("abcdefg", ".", 4));
|
||||||
assertEquals("", StringUtils.abbreviate("", 4));
|
assertEquals("", StringUtils.abbreviate("", 4));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
@SuppressWarnings("unused")
|
IllegalArgumentException.class,
|
||||||
final
|
() -> StringUtils.abbreviate("abcdefghij", "...", 3),
|
||||||
String res = StringUtils.abbreviate("abcdefghij", "...", 3);
|
"StringUtils.abbreviate expecting IllegalArgumentException");
|
||||||
fail("StringUtils.abbreviate expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2024,19 +2011,14 @@ public class StringUtilsTest {
|
||||||
assertEquals("", StringUtils.abbreviate("", 0, 10));
|
assertEquals("", StringUtils.abbreviate("", 0, 10));
|
||||||
assertEquals("", StringUtils.abbreviate("", 2, 10));
|
assertEquals("", StringUtils.abbreviate("", 2, 10));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.abbreviate("abcdefghij", 0, 3);
|
IllegalArgumentException.class,
|
||||||
fail("StringUtils.abbreviate expecting IllegalArgumentException");
|
() -> StringUtils.abbreviate("abcdefghij", 0, 3),
|
||||||
} catch (final IllegalArgumentException expected) {
|
"StringUtils.abbreviate expecting IllegalArgumentException");
|
||||||
// empty
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> StringUtils.abbreviate("abcdefghij", 5, 6),
|
||||||
StringUtils.abbreviate("abcdefghij", 5, 6);
|
"StringUtils.abbreviate expecting IllegalArgumentException");
|
||||||
fail("StringUtils.abbreviate expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException expected) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final String raspberry = "raspberry peach";
|
final String raspberry = "raspberry peach";
|
||||||
assertEquals("raspberry peach", StringUtils.abbreviate(raspberry, 11, 15));
|
assertEquals("raspberry peach", StringUtils.abbreviate(raspberry, 11, 15));
|
||||||
|
@ -2084,18 +2066,14 @@ public class StringUtilsTest {
|
||||||
assertEquals("", StringUtils.abbreviate("", null, 0, 10));
|
assertEquals("", StringUtils.abbreviate("", null, 0, 10));
|
||||||
assertEquals("", StringUtils.abbreviate("", "...", 2, 10));
|
assertEquals("", StringUtils.abbreviate("", "...", 2, 10));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.abbreviate("abcdefghij", "::", 0, 2);
|
IllegalArgumentException.class,
|
||||||
fail("StringUtils.abbreviate expecting IllegalArgumentException");
|
() -> StringUtils.abbreviate("abcdefghij", "::", 0, 2),
|
||||||
} catch (final IllegalArgumentException expected) {
|
"StringUtils.abbreviate expecting IllegalArgumentException");
|
||||||
// empty
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> StringUtils.abbreviate("abcdefghij", "!!!", 5, 6),
|
||||||
StringUtils.abbreviate("abcdefghij", "!!!", 5, 6);
|
"StringUtils.abbreviate expecting IllegalArgumentException");
|
||||||
fail("StringUtils.abbreviate expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException expected) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
final String raspberry = "raspberry peach";
|
final String raspberry = "raspberry peach";
|
||||||
assertEquals("raspberry peach", StringUtils.abbreviate(raspberry, "--", 12, 15));
|
assertEquals("raspberry peach", StringUtils.abbreviate(raspberry, "--", 12, 15));
|
||||||
|
@ -2181,47 +2159,31 @@ public class StringUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testTruncate_StringInt() {
|
public void testTruncate_StringInt() {
|
||||||
assertNull(StringUtils.truncate(null, 12));
|
assertNull(StringUtils.truncate(null, 12));
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate(null, -1);
|
IllegalArgumentException.class, () -> StringUtils.truncate(null, -1), "maxWith cannot be negative");
|
||||||
fail("maxWith cannot be negative");
|
assertThrows(
|
||||||
} catch (final Exception e) {
|
IllegalArgumentException.class, () -> StringUtils.truncate(null, -10), "maxWith cannot be negative");
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> StringUtils.truncate(null, Integer.MIN_VALUE),
|
||||||
StringUtils.truncate(null, -10);
|
"maxWith cannot be negative");
|
||||||
fail("maxWith cannot be negative");
|
|
||||||
} catch (final Exception e) {
|
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringUtils.truncate(null, Integer.MIN_VALUE);
|
|
||||||
fail("maxWith cannot be negative");
|
|
||||||
} catch (final Exception e) {
|
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
assertEquals("", StringUtils.truncate("", 10));
|
assertEquals("", StringUtils.truncate("", 10));
|
||||||
assertEquals("", StringUtils.truncate("", 10));
|
assertEquals("", StringUtils.truncate("", 10));
|
||||||
assertEquals("abc", StringUtils.truncate("abcdefghij", 3));
|
assertEquals("abc", StringUtils.truncate("abcdefghij", 3));
|
||||||
assertEquals("abcdef", StringUtils.truncate("abcdefghij", 6));
|
assertEquals("abcdef", StringUtils.truncate("abcdefghij", 6));
|
||||||
assertEquals("", StringUtils.truncate("abcdefghij", 0));
|
assertEquals("", StringUtils.truncate("abcdefghij", 0));
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate("abcdefghij", -1);
|
IllegalArgumentException.class,
|
||||||
fail("maxWith cannot be negative");
|
() -> StringUtils.truncate("abcdefghij", -1),
|
||||||
} catch (final Exception e) {
|
"maxWith cannot be negative");
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> StringUtils.truncate("abcdefghij", -100),
|
||||||
StringUtils.truncate("abcdefghij", -100);
|
"maxWith cannot be negative");
|
||||||
fail("maxWith cannot be negative");
|
assertThrows(
|
||||||
} catch (final Exception e) {
|
IllegalArgumentException.class,
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
() -> StringUtils.truncate("abcdefghij", Integer.MIN_VALUE),
|
||||||
}
|
"maxWith cannot be negative");
|
||||||
try {
|
|
||||||
StringUtils.truncate("abcdefghij", Integer.MIN_VALUE);
|
|
||||||
fail("maxWith cannot be negative");
|
|
||||||
} catch (final Exception e) {
|
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
assertEquals("abcdefghij", StringUtils.truncate("abcdefghijklmno", 10));
|
assertEquals("abcdefghij", StringUtils.truncate("abcdefghijklmno", 10));
|
||||||
assertEquals("abcdefghijklmno", StringUtils.truncate("abcdefghijklmno", Integer.MAX_VALUE));
|
assertEquals("abcdefghijklmno", StringUtils.truncate("abcdefghijklmno", Integer.MAX_VALUE));
|
||||||
assertEquals("abcde", StringUtils.truncate("abcdefghijklmno", 5));
|
assertEquals("abcde", StringUtils.truncate("abcdefghijklmno", 5));
|
||||||
|
@ -2231,108 +2193,74 @@ public class StringUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testTruncate_StringIntInt() {
|
public void testTruncate_StringIntInt() {
|
||||||
assertNull(StringUtils.truncate(null, 0, 12));
|
assertNull(StringUtils.truncate(null, 0, 12));
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate(null, -1, 0);
|
IllegalArgumentException.class, () -> StringUtils.truncate(null, -1, 0), "maxWith cannot be negative");
|
||||||
fail("maxWith cannot be negative");
|
assertThrows(
|
||||||
} catch (final Exception e) {
|
IllegalArgumentException.class,
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
() -> StringUtils.truncate(null, -10, -4),
|
||||||
}
|
"maxWith cannot be negative");
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate(null, -10, -4);
|
IllegalArgumentException.class,
|
||||||
fail("maxWith cannot be negative");
|
() -> StringUtils.truncate(null, Integer.MIN_VALUE, Integer.MIN_VALUE),
|
||||||
} catch (final Exception e) {
|
"maxWith cannot be negative");
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringUtils.truncate(null, Integer.MIN_VALUE, Integer.MIN_VALUE);
|
|
||||||
fail("maxWith cannot be negative");
|
|
||||||
} catch (final Exception e) {
|
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
assertNull(StringUtils.truncate(null, 10, 12));
|
assertNull(StringUtils.truncate(null, 10, 12));
|
||||||
assertEquals("", StringUtils.truncate("", 0, 10));
|
assertEquals("", StringUtils.truncate("", 0, 10));
|
||||||
assertEquals("", StringUtils.truncate("", 2, 10));
|
assertEquals("", StringUtils.truncate("", 2, 10));
|
||||||
assertEquals("abc", StringUtils.truncate("abcdefghij", 0, 3));
|
assertEquals("abc", StringUtils.truncate("abcdefghij", 0, 3));
|
||||||
assertEquals("fghij", StringUtils.truncate("abcdefghij", 5, 6));
|
assertEquals("fghij", StringUtils.truncate("abcdefghij", 5, 6));
|
||||||
assertEquals("", StringUtils.truncate("abcdefghij", 0, 0));
|
assertEquals("", StringUtils.truncate("abcdefghij", 0, 0));
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate("abcdefghij", 0, -1);
|
IllegalArgumentException.class,
|
||||||
fail("maxWith cannot be negative");
|
() -> StringUtils.truncate("abcdefghij", 0, -1),
|
||||||
} catch (final Exception e) {
|
"maxWith cannot be negative");
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> StringUtils.truncate("abcdefghij", 0, -10),
|
||||||
StringUtils.truncate("abcdefghij", 0, -10);
|
"maxWith cannot be negative");
|
||||||
fail("maxWith cannot be negative");
|
assertThrows(
|
||||||
} catch (final Exception e) {
|
IllegalArgumentException.class,
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
() -> StringUtils.truncate("abcdefghij", 0, -100),
|
||||||
}
|
"maxWith cannot be negative");
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate("abcdefghij", 0, -100);
|
IllegalArgumentException.class,
|
||||||
fail("maxWith cannot be negative");
|
() -> StringUtils.truncate("abcdefghij", 1, -100),
|
||||||
} catch (final Exception e) {
|
"maxWith cannot be negative");
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> StringUtils.truncate("abcdefghij", 0, Integer.MIN_VALUE),
|
||||||
StringUtils.truncate("abcdefghij", 1, -100);
|
"maxWith cannot be negative");
|
||||||
fail("maxWith cannot be negative");
|
assertThrows(
|
||||||
} catch (final Exception e) {
|
IllegalArgumentException.class,
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
() -> StringUtils.truncate("abcdefghij", -1, 0),
|
||||||
}
|
"offset cannot be negative");
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate("abcdefghij", 0, Integer.MIN_VALUE);
|
IllegalArgumentException.class,
|
||||||
fail("maxWith cannot be negative");
|
() -> StringUtils.truncate("abcdefghij", -10, 0),
|
||||||
} catch (final Exception e) {
|
"offset cannot be negative");
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> StringUtils.truncate("abcdefghij", -100, 1),
|
||||||
StringUtils.truncate("abcdefghij", -1, 0);
|
"offset cannot be negative");
|
||||||
fail("offset cannot be negative");
|
assertThrows(
|
||||||
} catch (final Exception e) {
|
IllegalArgumentException.class,
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
() -> StringUtils.truncate("abcdefghij", Integer.MIN_VALUE, 0),
|
||||||
}
|
"offset cannot be negative");
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate("abcdefghij", -10, 0);
|
IllegalArgumentException.class,
|
||||||
fail("offset cannot be negative");
|
() -> StringUtils.truncate("abcdefghij", -1, -1),
|
||||||
} catch (final Exception e) {
|
"offset cannot be negative");
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
assertThrows(
|
||||||
}
|
IllegalArgumentException.class,
|
||||||
try {
|
() -> StringUtils.truncate("abcdefghij", -10, -10),
|
||||||
StringUtils.truncate("abcdefghij", -100, 1);
|
"offset cannot be negative");
|
||||||
fail("offset cannot be negative");
|
assertThrows(
|
||||||
} catch (final Exception e) {
|
IllegalArgumentException.class,
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
() -> StringUtils.truncate("abcdefghij", -100, -100),
|
||||||
}
|
"offset cannot be negative");
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.truncate("abcdefghij", Integer.MIN_VALUE, 0);
|
IllegalArgumentException.class,
|
||||||
fail("offset cannot be negative");
|
() -> StringUtils.truncate("abcdefghij", Integer.MIN_VALUE, Integer.MIN_VALUE),
|
||||||
} catch (final Exception e) {
|
"offset cannot be negative");
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringUtils.truncate("abcdefghij", -1, -1);
|
|
||||||
fail("offset cannot be negative");
|
|
||||||
} catch (final Exception e) {
|
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringUtils.truncate("abcdefghij", -10, -10);
|
|
||||||
fail("offset cannot be negative");
|
|
||||||
} catch (final Exception e) {
|
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringUtils.truncate("abcdefghij", -100, -100);
|
|
||||||
fail("offset cannot be negative");
|
|
||||||
} catch (final Exception e) {
|
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
StringUtils.truncate("abcdefghij", Integer.MIN_VALUE, Integer.MIN_VALUE);
|
|
||||||
fail("offset cannot be negative");
|
|
||||||
} catch (final Exception e) {
|
|
||||||
assertTrue(e instanceof IllegalArgumentException);
|
|
||||||
}
|
|
||||||
final String raspberry = "raspberry peach";
|
final String raspberry = "raspberry peach";
|
||||||
assertEquals("peach", StringUtils.truncate(raspberry, 10, 15));
|
assertEquals("peach", StringUtils.truncate(raspberry, 10, 15));
|
||||||
assertEquals("abcdefghij", StringUtils.truncate("abcdefghijklmno", 0, 10));
|
assertEquals("abcdefghij", StringUtils.truncate("abcdefghijklmno", 0, 10));
|
||||||
|
@ -2795,12 +2723,10 @@ public class StringUtilsTest {
|
||||||
assertEquals("AB", StringUtils.removeAll("A<__>\n<__>B", "(?s)<.*>"));
|
assertEquals("AB", StringUtils.removeAll("A<__>\n<__>B", "(?s)<.*>"));
|
||||||
assertEquals("ABC123", StringUtils.removeAll("ABCabc123abc", "[a-z]"));
|
assertEquals("ABC123", StringUtils.removeAll("ABCabc123abc", "[a-z]"));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.removeAll("any", "{badRegexSyntax}");
|
PatternSyntaxException.class,
|
||||||
fail("StringUtils.removeAll expecting PatternSyntaxException");
|
() -> StringUtils.removeAll("any", "{badRegexSyntax}"),
|
||||||
} catch (final PatternSyntaxException ex) {
|
"StringUtils.removeAll expecting PatternSyntaxException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2818,12 +2744,10 @@ public class StringUtilsTest {
|
||||||
assertEquals("ABCbc123", StringUtils.removeFirst("ABCabc123", "[a-z]"));
|
assertEquals("ABCbc123", StringUtils.removeFirst("ABCabc123", "[a-z]"));
|
||||||
assertEquals("ABC123abc", StringUtils.removeFirst("ABCabc123abc", "[a-z]+"));
|
assertEquals("ABC123abc", StringUtils.removeFirst("ABCabc123abc", "[a-z]+"));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
StringUtils.removeFirst("any", "{badRegexSyntax}");
|
PatternSyntaxException.class,
|
||||||
fail("StringUtils.removeFirst expecting PatternSyntaxException");
|
() -> StringUtils.removeFirst("any", "{badRegexSyntax}"),
|
||||||
} catch (final PatternSyntaxException ex) {
|
"StringUtils.removeFirst expecting PatternSyntaxException");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class DiffResultTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNullLhs() {
|
public void testNullLhs() {
|
||||||
assertThrows(IllegalArgumentException.class,
|
assertThrows(IllegalArgumentException.class,
|
||||||
() -> new DiffResult(null, SIMPLE_FALSE, SIMPLE_TRUE.diff(SIMPLE_FALSE).getDiffs(), SHORT_STYLE));
|
() -> new DiffResult(null, SIMPLE_FALSE, SIMPLE_TRUE.diff(SIMPLE_FALSE).getDiffs(), SHORT_STYLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package org.apache.commons.lang3.builder;
|
package org.apache.commons.lang3.builder;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -91,11 +91,7 @@ public class JsonToStringStyleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChar() {
|
public void testChar() {
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> new ToStringBuilder(base).append('A').toString());
|
||||||
new ToStringBuilder(base).append('A').toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("{\"a\":\"A\"}", new ToStringBuilder(base).append("a", 'A')
|
assertEquals("{\"a\":\"A\"}", new ToStringBuilder(base).append("a", 'A')
|
||||||
.toString());
|
.toString());
|
||||||
|
@ -108,11 +104,7 @@ public class JsonToStringStyleTest {
|
||||||
final Date now = new Date();
|
final Date now = new Date();
|
||||||
final Date afterNow = new Date(System.currentTimeMillis() + 1);
|
final Date afterNow = new Date(System.currentTimeMillis() + 1);
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> new ToStringBuilder(base).append(now).toString());
|
||||||
new ToStringBuilder(base).append(now).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("{\"now\":\"" + now.toString() +"\"}", new ToStringBuilder(base).append("now", now)
|
assertEquals("{\"now\":\"" + now.toString() +"\"}", new ToStringBuilder(base).append("now", now)
|
||||||
.toString());
|
.toString());
|
||||||
|
@ -126,17 +118,10 @@ public class JsonToStringStyleTest {
|
||||||
final Integer i3 = Integer.valueOf(3);
|
final Integer i3 = Integer.valueOf(3);
|
||||||
final Integer i4 = Integer.valueOf(4);
|
final Integer i4 = Integer.valueOf(4);
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append((Object) null).toString();
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((Object) null).toString());
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> new ToStringBuilder(base).append(i3).toString());
|
||||||
new ToStringBuilder(base).append(i3).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("{\"a\":null}",
|
assertEquals("{\"a\":null}",
|
||||||
new ToStringBuilder(base).append("a", (Object) null).toString());
|
new ToStringBuilder(base).append("a", (Object) null).toString());
|
||||||
|
@ -146,63 +131,48 @@ public class JsonToStringStyleTest {
|
||||||
new ToStringBuilder(base).append("a", i3).append("b", i4)
|
new ToStringBuilder(base).append("a", i3).append("b", i4)
|
||||||
.toString());
|
.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append("a", i3, false).toString();
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append("a", i3, false).toString());
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString();
|
UnsupportedOperationException.class,
|
||||||
fail("Should have generated UnsupportedOperationException");
|
() -> new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString());
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"a\":[]}",
|
"{\"a\":[]}",
|
||||||
new ToStringBuilder(base).append("a", new ArrayList<>(),
|
new ToStringBuilder(base).append("a", new ArrayList<>(),
|
||||||
true).toString());
|
true).toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append("a", new HashMap<>(), false).toString();
|
UnsupportedOperationException.class,
|
||||||
fail("Should have generated UnsupportedOperationException");
|
() -> new ToStringBuilder(base).append("a", new HashMap<>(), false).toString());
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"a\":{}}",
|
"{\"a\":{}}",
|
||||||
new ToStringBuilder(base).append("a",
|
new ToStringBuilder(base).append("a",
|
||||||
new HashMap<>(), true).toString());
|
new HashMap<>(), true).toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append("a", (Object) new String[0], false).toString();
|
UnsupportedOperationException.class,
|
||||||
fail("Should have generated UnsupportedOperationException");
|
() -> new ToStringBuilder(base).append("a", (Object) new String[0], false).toString());
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"a\":[]}",
|
"{\"a\":[]}",
|
||||||
new ToStringBuilder(base).append("a", (Object) new String[0],
|
new ToStringBuilder(base).append("a", (Object) new String[0],
|
||||||
true).toString());
|
true).toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append("a", (Object) new int[]{1, 2, 3}, false).toString();
|
UnsupportedOperationException.class,
|
||||||
fail("Should have generated UnsupportedOperationException");
|
() -> new ToStringBuilder(base).append("a", (Object) new int[]{1, 2, 3}, false).toString());
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"a\":[1,2,3]}",
|
"{\"a\":[1,2,3]}",
|
||||||
new ToStringBuilder(base).append("a",
|
new ToStringBuilder(base).append("a",
|
||||||
(Object) new int[]{1, 2, 3}, true).toString());
|
(Object) new int[]{1, 2, 3}, true).toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append("a", (Object) new String[]{"v", "x", "y", "z"}, false).toString();
|
UnsupportedOperationException.class,
|
||||||
fail("Should have generated UnsupportedOperationException");
|
() -> new ToStringBuilder(base).append("a", (Object) new String[]{"v", "x", "y", "z"}, false).toString());
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"a\":[\"v\",\"x\",\"y\",\"z\"]}",
|
"{\"a\":[\"v\",\"x\",\"y\",\"z\"]}",
|
||||||
|
@ -252,12 +222,7 @@ public class JsonToStringStyleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLong() {
|
public void testLong() {
|
||||||
|
assertThrows(UnsupportedOperationException.class, () -> new ToStringBuilder(base).append(3L).toString());
|
||||||
try {
|
|
||||||
new ToStringBuilder(base).append(3L).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("{\"a\":3}", new ToStringBuilder(base).append("a", 3L)
|
assertEquals("{\"a\":3}", new ToStringBuilder(base).append("a", 3L)
|
||||||
.toString());
|
.toString());
|
||||||
|
@ -270,92 +235,48 @@ public class JsonToStringStyleTest {
|
||||||
public void testObjectArray() {
|
public void testObjectArray() {
|
||||||
Object[] array = new Object[]{null, base, new int[]{3, 6}};
|
Object[] array = new Object[]{null, base, new int[]{3, 6}};
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> new ToStringBuilder(base).append(array).toString());
|
||||||
new ToStringBuilder(base).append(array).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append((Object) array).toString();
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((Object) array).toString());
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
array = null;
|
assertThrows(
|
||||||
try {
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((Object[]) null).toString());
|
||||||
new ToStringBuilder(base).append(array).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append((Object) array).toString();
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((Object) array).toString());
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLongArray() {
|
public void testLongArray() {
|
||||||
long[] array = new long[]{1, 2, -3, 4};
|
long[] array = new long[]{1, 2, -3, 4};
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> new ToStringBuilder(base).append(array).toString());
|
||||||
new ToStringBuilder(base).append(array).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append((Object) array).toString();
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((Object) array).toString());
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
array = null;
|
assertThrows(
|
||||||
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((long[]) null).toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append(array).toString();
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((Object) array).toString());
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
new ToStringBuilder(base).append((Object) array).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLongArrayArray() {
|
public void testLongArrayArray() {
|
||||||
long[][] array = new long[][]{{1, 2}, null, {5}};
|
long[][] array = new long[][]{{1, 2}, null, {5}};
|
||||||
|
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, () -> new ToStringBuilder(base).append(array).toString());
|
||||||
new ToStringBuilder(base).append(array).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append((Object) array).toString();
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((Object) array).toString());
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
array = null;
|
assertThrows(
|
||||||
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((long[][]) null).toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
new ToStringBuilder(base).append(array).toString();
|
UnsupportedOperationException.class, () -> new ToStringBuilder(base).append((Object) array).toString());
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
new ToStringBuilder(base).append((Object) array).toString();
|
|
||||||
fail("Should have generated UnsupportedOperationException");
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -40,22 +39,18 @@ public class BackgroundInitializerTest {
|
||||||
*
|
*
|
||||||
* @param init the initializer to test
|
* @param init the initializer to test
|
||||||
*/
|
*/
|
||||||
private void checkInitialize(final BackgroundInitializerTestImpl init) {
|
private void checkInitialize(final BackgroundInitializerTestImpl init) throws ConcurrentException {
|
||||||
try {
|
final Integer result = init.get();
|
||||||
final Integer result = init.get();
|
assertEquals(1, result.intValue(), "Wrong result");
|
||||||
assertEquals(1, result.intValue(), "Wrong result");
|
assertEquals(1, init.initializeCalls, "Wrong number of invocations");
|
||||||
assertEquals(1, init.initializeCalls, "Wrong number of invocations");
|
assertNotNull(init.getFuture(), "No future");
|
||||||
assertNotNull(init.getFuture(), "No future");
|
|
||||||
} catch (final ConcurrentException cex) {
|
|
||||||
fail("Unexpected exception: " + cex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether initialize() is invoked.
|
* Tests whether initialize() is invoked.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInitialize() {
|
public void testInitialize() throws ConcurrentException {
|
||||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||||
init.start();
|
init.start();
|
||||||
checkInitialize(init);
|
checkInitialize(init);
|
||||||
|
@ -75,7 +70,7 @@ public class BackgroundInitializerTest {
|
||||||
* Tests whether an external executor is correctly detected.
|
* Tests whether an external executor is correctly detected.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetActiveExecutorExternal() throws InterruptedException {
|
public void testGetActiveExecutorExternal() throws InterruptedException, ConcurrentException {
|
||||||
final ExecutorService exec = Executors.newSingleThreadExecutor();
|
final ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||||
try {
|
try {
|
||||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl(
|
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl(
|
||||||
|
@ -93,7 +88,7 @@ public class BackgroundInitializerTest {
|
||||||
* Tests getActiveExecutor() for a temporary executor.
|
* Tests getActiveExecutor() for a temporary executor.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetActiveExecutorTemp() {
|
public void testGetActiveExecutorTemp() throws ConcurrentException {
|
||||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||||
init.start();
|
init.start();
|
||||||
assertNotNull(init.getActiveExecutor(), "No active executor");
|
assertNotNull(init.getActiveExecutor(), "No active executor");
|
||||||
|
@ -105,7 +100,7 @@ public class BackgroundInitializerTest {
|
||||||
* be created.
|
* be created.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInitializeTempExecutor() {
|
public void testInitializeTempExecutor() throws ConcurrentException {
|
||||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||||
assertTrue(init.start(), "Wrong result of start()");
|
assertTrue(init.start(), "Wrong result of start()");
|
||||||
checkInitialize(init);
|
checkInitialize(init);
|
||||||
|
@ -117,7 +112,7 @@ public class BackgroundInitializerTest {
|
||||||
* setExternalExecutor() method.
|
* setExternalExecutor() method.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetExternalExecutor() {
|
public void testSetExternalExecutor() throws ConcurrentException {
|
||||||
final ExecutorService exec = Executors.newCachedThreadPool();
|
final ExecutorService exec = Executors.newCachedThreadPool();
|
||||||
try {
|
try {
|
||||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||||
|
@ -143,9 +138,7 @@ public class BackgroundInitializerTest {
|
||||||
init.start();
|
init.start();
|
||||||
final ExecutorService exec = Executors.newSingleThreadExecutor();
|
final ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||||
try {
|
try {
|
||||||
init.setExternalExecutor(exec);
|
assertThrows(IllegalStateException.class, () -> init.setExternalExecutor(exec));
|
||||||
fail("Could set executor after start()!");
|
|
||||||
} catch (final IllegalStateException istex) {
|
|
||||||
init.get();
|
init.get();
|
||||||
} finally {
|
} finally {
|
||||||
exec.shutdown();
|
exec.shutdown();
|
||||||
|
@ -158,7 +151,7 @@ public class BackgroundInitializerTest {
|
||||||
* have an effect.
|
* have an effect.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testStartMultipleTimes() {
|
public void testStartMultipleTimes() throws ConcurrentException {
|
||||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||||
assertTrue(init.start(), "Wrong result for start()");
|
assertTrue(init.start(), "Wrong result for start()");
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
@ -188,12 +181,8 @@ public class BackgroundInitializerTest {
|
||||||
final RuntimeException rex = new RuntimeException();
|
final RuntimeException rex = new RuntimeException();
|
||||||
init.ex = rex;
|
init.ex = rex;
|
||||||
init.start();
|
init.start();
|
||||||
try {
|
Exception ex = assertThrows(Exception.class, init::get);
|
||||||
init.get();
|
assertEquals(rex, ex, "Runtime exception not thrown");
|
||||||
fail("Exception not thrown!");
|
|
||||||
} catch (final Exception ex) {
|
|
||||||
assertEquals(rex, ex, "Runtime exception not thrown");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,12 +195,8 @@ public class BackgroundInitializerTest {
|
||||||
final Exception ex = new Exception();
|
final Exception ex = new Exception();
|
||||||
init.ex = ex;
|
init.ex = ex;
|
||||||
init.start();
|
init.start();
|
||||||
try {
|
ConcurrentException cex = assertThrows(ConcurrentException.class, init::get);
|
||||||
init.get();
|
assertEquals(ex, cex.getCause(), "Exception not thrown");
|
||||||
fail("Exception not thrown!");
|
|
||||||
} catch (final ConcurrentException cex) {
|
|
||||||
assertEquals(ex, cex.getCause(), "Exception not thrown");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -274,7 +259,7 @@ public class BackgroundInitializerTest {
|
||||||
* Tests isStarted() after the background task has finished.
|
* Tests isStarted() after the background task has finished.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIsStartedAfterGet() {
|
public void testIsStartedAfterGet() throws ConcurrentException {
|
||||||
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
final BackgroundInitializerTestImpl init = new BackgroundInitializerTestImpl();
|
||||||
init.start();
|
init.start();
|
||||||
checkInitialize(init);
|
checkInitialize(init);
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
@ -108,12 +107,9 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testExtractCauseError() {
|
public void testExtractCauseError() {
|
||||||
final Error err = new AssertionError("Test");
|
final Error err = new AssertionError("Test");
|
||||||
try {
|
AssertionError e =
|
||||||
ConcurrentUtils.extractCause(new ExecutionException(err));
|
assertThrows(AssertionError.class, () -> ConcurrentUtils.extractCause(new ExecutionException(err)));
|
||||||
fail("Error not thrown!");
|
assertEquals(err, e, "Wrong error");
|
||||||
} catch (final Error e) {
|
|
||||||
assertEquals(err, e, "Wrong error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,12 +118,8 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testExtractCauseUncheckedException() {
|
public void testExtractCauseUncheckedException() {
|
||||||
final RuntimeException rex = new RuntimeException("Test");
|
final RuntimeException rex = new RuntimeException("Test");
|
||||||
try {
|
RuntimeException r =
|
||||||
ConcurrentUtils.extractCause(new ExecutionException(rex));
|
assertThrows(RuntimeException.class, () -> ConcurrentUtils.extractCause(new ExecutionException(rex)));
|
||||||
fail("Runtime exception not thrown!");
|
|
||||||
} catch (final RuntimeException r) {
|
|
||||||
assertEquals(rex, r, "Wrong exception");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,12 +155,8 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testExtractCauseUncheckedError() {
|
public void testExtractCauseUncheckedError() {
|
||||||
final Error err = new AssertionError("Test");
|
final Error err = new AssertionError("Test");
|
||||||
try {
|
Error e = assertThrows(Error.class, () -> ConcurrentUtils.extractCauseUnchecked(new ExecutionException(err)));
|
||||||
ConcurrentUtils.extractCauseUnchecked(new ExecutionException(err));
|
assertEquals(err, e, "Wrong error");
|
||||||
fail("Error not thrown!");
|
|
||||||
} catch (final Error e) {
|
|
||||||
assertEquals(err, e, "Wrong error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,12 +165,9 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testExtractCauseUncheckedUncheckedException() {
|
public void testExtractCauseUncheckedUncheckedException() {
|
||||||
final RuntimeException rex = new RuntimeException("Test");
|
final RuntimeException rex = new RuntimeException("Test");
|
||||||
try {
|
RuntimeException r =
|
||||||
ConcurrentUtils.extractCauseUnchecked(new ExecutionException(rex));
|
assertThrows(RuntimeException.class, () -> ConcurrentUtils.extractCauseUnchecked(new ExecutionException(rex)));
|
||||||
fail("Runtime exception not thrown!");
|
assertEquals(rex, r, "Wrong exception");
|
||||||
} catch (final RuntimeException r) {
|
|
||||||
assertEquals(rex, r, "Wrong exception");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,12 +189,8 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testHandleCauseError() throws ConcurrentException {
|
public void testHandleCauseError() throws ConcurrentException {
|
||||||
final Error err = new AssertionError("Test");
|
final Error err = new AssertionError("Test");
|
||||||
try {
|
Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCause(new ExecutionException(err)));
|
||||||
ConcurrentUtils.handleCause(new ExecutionException(err));
|
assertEquals(err, e, "Wrong error");
|
||||||
fail("Error not thrown!");
|
|
||||||
} catch (final Error e) {
|
|
||||||
assertEquals(err, e, "Wrong error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,12 +201,9 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testHandleCauseUncheckedException() throws ConcurrentException {
|
public void testHandleCauseUncheckedException() throws ConcurrentException {
|
||||||
final RuntimeException rex = new RuntimeException("Test");
|
final RuntimeException rex = new RuntimeException("Test");
|
||||||
try {
|
RuntimeException r =
|
||||||
ConcurrentUtils.handleCause(new ExecutionException(rex));
|
assertThrows(RuntimeException.class, () -> ConcurrentUtils.handleCause(new ExecutionException(rex)));
|
||||||
fail("Runtime exception not thrown!");
|
assertEquals(rex, r, "Wrong exception");
|
||||||
} catch (final RuntimeException r) {
|
|
||||||
assertEquals(rex, r, "Wrong exception");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,12 +212,9 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testHandleCauseChecked() {
|
public void testHandleCauseChecked() {
|
||||||
final Exception ex = new Exception("Test");
|
final Exception ex = new Exception("Test");
|
||||||
try {
|
ConcurrentException cex =
|
||||||
ConcurrentUtils.handleCause(new ExecutionException(ex));
|
assertThrows(ConcurrentException.class, () -> ConcurrentUtils.handleCause(new ExecutionException(ex)));
|
||||||
fail("ConcurrentException not thrown!");
|
assertEquals(ex, cex.getCause(), "Wrong cause");
|
||||||
} catch (final ConcurrentException cex) {
|
|
||||||
assertEquals(ex, cex.getCause(), "Wrong cause");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -261,12 +236,8 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testHandleCauseUncheckedError() {
|
public void testHandleCauseUncheckedError() {
|
||||||
final Error err = new AssertionError("Test");
|
final Error err = new AssertionError("Test");
|
||||||
try {
|
Error e = assertThrows(Error.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(err)));
|
||||||
ConcurrentUtils.handleCauseUnchecked(new ExecutionException(err));
|
assertEquals(err, e, "Wrong error");
|
||||||
fail("Error not thrown!");
|
|
||||||
} catch (final Error e) {
|
|
||||||
assertEquals(err, e, "Wrong error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -275,12 +246,9 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testHandleCauseUncheckedUncheckedException() {
|
public void testHandleCauseUncheckedUncheckedException() {
|
||||||
final RuntimeException rex = new RuntimeException("Test");
|
final RuntimeException rex = new RuntimeException("Test");
|
||||||
try {
|
RuntimeException r =
|
||||||
ConcurrentUtils.handleCauseUnchecked(new ExecutionException(rex));
|
assertThrows(RuntimeException.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(rex)));
|
||||||
fail("Runtime exception not thrown!");
|
assertEquals(rex, r, "Wrong exception");
|
||||||
} catch (final RuntimeException r) {
|
|
||||||
assertEquals(rex, r, "Wrong exception");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -289,12 +257,9 @@ public class ConcurrentUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testHandleCauseUncheckedChecked() {
|
public void testHandleCauseUncheckedChecked() {
|
||||||
final Exception ex = new Exception("Test");
|
final Exception ex = new Exception("Test");
|
||||||
try {
|
ConcurrentRuntimeException crex =
|
||||||
ConcurrentUtils.handleCauseUnchecked(new ExecutionException(ex));
|
assertThrows(ConcurrentRuntimeException.class, () -> ConcurrentUtils.handleCauseUnchecked(new ExecutionException(ex)));
|
||||||
fail("ConcurrentRuntimeException not thrown!");
|
assertEquals(ex, crex.getCause(), "Wrong cause");
|
||||||
} catch (final ConcurrentRuntimeException crex) {
|
|
||||||
assertEquals(ex, crex.getCause(), "Wrong cause");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -386,12 +351,9 @@ public class ConcurrentUtilsTest {
|
||||||
final Exception cause = new Exception();
|
final Exception cause = new Exception();
|
||||||
EasyMock.expect(init.get()).andThrow(new ConcurrentException(cause));
|
EasyMock.expect(init.get()).andThrow(new ConcurrentException(cause));
|
||||||
EasyMock.replay(init);
|
EasyMock.replay(init);
|
||||||
try {
|
ConcurrentRuntimeException crex =
|
||||||
ConcurrentUtils.initializeUnchecked(init);
|
assertThrows(ConcurrentRuntimeException.class, () -> ConcurrentUtils.initializeUnchecked(init));
|
||||||
fail("Exception not thrown!");
|
assertSame(cause, crex.getCause(), "Wrong cause");
|
||||||
} catch (final ConcurrentRuntimeException crex) {
|
|
||||||
assertSame(cause, crex.getCause(), "Wrong cause");
|
|
||||||
}
|
|
||||||
EasyMock.verify(init);
|
EasyMock.verify(init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,13 +529,11 @@ public class ConcurrentUtilsTest {
|
||||||
final Exception ex = new Exception();
|
final Exception ex = new Exception();
|
||||||
EasyMock.expect(init.get()).andThrow(new ConcurrentException(ex));
|
EasyMock.expect(init.get()).andThrow(new ConcurrentException(ex));
|
||||||
EasyMock.replay(init);
|
EasyMock.replay(init);
|
||||||
try {
|
ConcurrentRuntimeException crex =
|
||||||
ConcurrentUtils.createIfAbsentUnchecked(
|
assertThrows(
|
||||||
new ConcurrentHashMap<>(), "test", init);
|
ConcurrentRuntimeException.class,
|
||||||
fail("Exception not thrown!");
|
() -> ConcurrentUtils.createIfAbsentUnchecked(new ConcurrentHashMap<>(), "test", init));
|
||||||
} catch (final ConcurrentRuntimeException crex) {
|
assertEquals(ex, crex.getCause(), "Wrong cause");
|
||||||
assertEquals(ex, crex.getCause(), "Wrong cause");
|
|
||||||
}
|
|
||||||
EasyMock.verify(init);
|
EasyMock.verify(init);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
public class MemoizerTest {
|
public class MemoizerTest {
|
||||||
|
|
||||||
|
@ -54,13 +53,7 @@ public class MemoizerTest {
|
||||||
expect(computable.compute(input)).andThrow(interruptedException);
|
expect(computable.compute(input)).andThrow(interruptedException);
|
||||||
replay(computable);
|
replay(computable);
|
||||||
|
|
||||||
try {
|
assertThrows(Throwable.class, () -> memoizer.compute(input));
|
||||||
memoizer.compute(input);
|
|
||||||
fail("Expected Throwable to be thrown!");
|
|
||||||
} catch (final Throwable expected) {
|
|
||||||
// Should always be thrown the first time
|
|
||||||
}
|
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class, () -> memoizer.compute(input));
|
assertThrows(IllegalStateException.class, () -> memoizer.compute(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,13 +65,7 @@ public class MemoizerTest {
|
||||||
expect(computable.compute(input)).andThrow(interruptedException);
|
expect(computable.compute(input)).andThrow(interruptedException);
|
||||||
replay(computable);
|
replay(computable);
|
||||||
|
|
||||||
try {
|
assertThrows(Throwable.class, () -> memoizer.compute(input));
|
||||||
memoizer.compute(input);
|
|
||||||
fail("Expected Throwable to be thrown!");
|
|
||||||
} catch (final Throwable expected) {
|
|
||||||
// Should always be thrown the first time
|
|
||||||
}
|
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class, () -> memoizer.compute(input));
|
assertThrows(IllegalStateException.class, () -> memoizer.compute(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,13 +78,7 @@ public class MemoizerTest {
|
||||||
expect(computable.compute(input)).andThrow(interruptedException).andReturn(answer);
|
expect(computable.compute(input)).andThrow(interruptedException).andReturn(answer);
|
||||||
replay(computable);
|
replay(computable);
|
||||||
|
|
||||||
try {
|
assertThrows(Throwable.class, () -> memoizer.compute(input));
|
||||||
memoizer.compute(input);
|
|
||||||
fail("Expected Throwable to be thrown!");
|
|
||||||
} catch (final Throwable expected) {
|
|
||||||
// Should always be thrown the first time
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(answer, memoizer.compute(input));
|
assertEquals(answer, memoizer.compute(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
@ -194,13 +193,11 @@ public class MultiBackgroundInitializerTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAddInitializerAfterStart() throws ConcurrentException {
|
public void testAddInitializerAfterStart() throws ConcurrentException {
|
||||||
initializer.start();
|
initializer.start();
|
||||||
try {
|
assertThrows(
|
||||||
initializer.addInitializer(CHILD_INIT,
|
IllegalStateException.class,
|
||||||
new ChildBackgroundInitializer());
|
() -> initializer.addInitializer(CHILD_INIT, new ChildBackgroundInitializer()),
|
||||||
fail("Could add initializer after start()!");
|
"Could add initializer after start()!");
|
||||||
} catch (final IllegalStateException istex) {
|
initializer.get();
|
||||||
initializer.get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,12 +273,8 @@ public class MultiBackgroundInitializerTest {
|
||||||
child.ex = new RuntimeException();
|
child.ex = new RuntimeException();
|
||||||
initializer.addInitializer(CHILD_INIT, child);
|
initializer.addInitializer(CHILD_INIT, child);
|
||||||
initializer.start();
|
initializer.start();
|
||||||
try {
|
Exception ex = assertThrows(Exception.class, initializer::get);
|
||||||
initializer.get();
|
assertEquals(child.ex, ex, "Wrong exception");
|
||||||
fail("Runtime exception not thrown!");
|
|
||||||
} catch (final Exception ex) {
|
|
||||||
assertEquals(child.ex, ex, "Wrong exception");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -379,11 +378,9 @@ public class ExceptionUtilsTest {
|
||||||
assertEquals(0, out.toString().length());
|
assertEquals(0, out.toString().length());
|
||||||
|
|
||||||
out = new ByteArrayOutputStream(1024);
|
out = new ByteArrayOutputStream(1024);
|
||||||
try {
|
assertThrows(
|
||||||
ExceptionUtils.printRootCauseStackTrace(withCause, (PrintStream) null);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> ExceptionUtils.printRootCauseStackTrace(withCause, (PrintStream) null));
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
out = new ByteArrayOutputStream(1024);
|
out = new ByteArrayOutputStream(1024);
|
||||||
final Throwable cause = createExceptionWithCause();
|
final Throwable cause = createExceptionWithCause();
|
||||||
|
@ -405,11 +402,9 @@ public class ExceptionUtilsTest {
|
||||||
assertEquals(0, writer.getBuffer().length());
|
assertEquals(0, writer.getBuffer().length());
|
||||||
|
|
||||||
writer = new StringWriter(1024);
|
writer = new StringWriter(1024);
|
||||||
try {
|
assertThrows(
|
||||||
ExceptionUtils.printRootCauseStackTrace(withCause, (PrintWriter) null);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> ExceptionUtils.printRootCauseStackTrace(withCause, (PrintWriter) null));
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
writer = new StringWriter(1024);
|
writer = new StringWriter(1024);
|
||||||
final Throwable cause = createExceptionWithCause();
|
final Throwable cause = createExceptionWithCause();
|
||||||
|
@ -542,30 +537,17 @@ public class ExceptionUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testThrow() {
|
public void testThrow() {
|
||||||
final Exception expected = new InterruptedException();
|
final Exception expected = new InterruptedException();
|
||||||
try {
|
Exception actual = assertThrows(Exception.class, () -> ExceptionUtils.rethrow(expected));
|
||||||
ExceptionUtils.rethrow(expected);
|
assertSame(expected, actual);
|
||||||
fail("Exception not thrown");
|
|
||||||
} catch (final Exception actual) {
|
|
||||||
assertSame(expected, actual);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCatchTechniques() {
|
public void testCatchTechniques() {
|
||||||
try {
|
IOException ioe = assertThrows(IOException.class, ExceptionUtilsTest::throwsCheckedException);
|
||||||
throwsCheckedException();
|
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
|
||||||
fail("Exception not thrown");
|
|
||||||
} catch (final Exception ioe) {
|
|
||||||
assertTrue(ioe instanceof IOException);
|
|
||||||
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
ioe = assertThrows(IOException.class, ExceptionUtilsTest::redeclareCheckedException);
|
||||||
redeclareCheckedException();
|
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
|
||||||
fail("Exception not thrown");
|
|
||||||
} catch (final IOException ioe) {
|
|
||||||
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int redeclareCheckedException() throws IOException {
|
private static int redeclareCheckedException() throws IOException {
|
||||||
|
@ -586,41 +568,25 @@ public class ExceptionUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapAndUnwrapError() {
|
public void testWrapAndUnwrapError() {
|
||||||
try {
|
Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new OutOfMemoryError()));
|
||||||
ExceptionUtils.wrapAndThrow(new OutOfMemoryError());
|
assertTrue(ExceptionUtils.hasCause(t, Error.class));
|
||||||
fail("Error not thrown");
|
|
||||||
} catch (final Throwable t) {
|
|
||||||
assertTrue(ExceptionUtils.hasCause(t, Error.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapAndUnwrapRuntimeException() {
|
public void testWrapAndUnwrapRuntimeException() {
|
||||||
try {
|
Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IllegalArgumentException()));
|
||||||
ExceptionUtils.wrapAndThrow(new IllegalArgumentException());
|
assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class));
|
||||||
fail("RuntimeException not thrown");
|
|
||||||
} catch (final Throwable t) {
|
|
||||||
assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapAndUnwrapCheckedException() {
|
public void testWrapAndUnwrapCheckedException() {
|
||||||
try {
|
Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new IOException()));
|
||||||
ExceptionUtils.wrapAndThrow(new IOException());
|
assertTrue(ExceptionUtils.hasCause(t, IOException.class));
|
||||||
fail("Checked Exception not thrown");
|
|
||||||
} catch (final Throwable t) {
|
|
||||||
assertTrue(ExceptionUtils.hasCause(t, IOException.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapAndUnwrapThrowable() {
|
public void testWrapAndUnwrapThrowable() {
|
||||||
try {
|
Throwable t = assertThrows(Throwable.class, () -> ExceptionUtils.wrapAndThrow(new TestThrowable()));
|
||||||
ExceptionUtils.wrapAndThrow(new TestThrowable());
|
assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class));
|
||||||
fail("Checked Exception not thrown");
|
|
||||||
} catch (final Throwable t) {
|
|
||||||
assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -119,30 +118,13 @@ public class FractionTest {
|
||||||
assertEquals(10, f.getDenominator());
|
assertEquals(10, f.getDenominator());
|
||||||
|
|
||||||
// zero denominator
|
// zero denominator
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(1, 0));
|
||||||
f = Fraction.getFraction(1, 0);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(2, 0));
|
||||||
fail("expecting ArithmeticException");
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(-3, 0));
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(2, 0);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(-3, 0);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// very large: can't represent as unsimplified fraction, although
|
// very large: can't represent as unsimplified fraction, although
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(4, Integer.MIN_VALUE));
|
||||||
f = Fraction.getFraction(4, Integer.MIN_VALUE);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(1, Integer.MIN_VALUE));
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(1, Integer.MIN_VALUE);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -168,86 +150,37 @@ public class FractionTest {
|
||||||
assertEquals(2, f.getDenominator());
|
assertEquals(2, f.getDenominator());
|
||||||
|
|
||||||
// negatives
|
// negatives
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(1, -6, -10));
|
||||||
f = Fraction.getFraction(1, -6, -10);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(1, -6, -10));
|
||||||
fail("expecting ArithmeticException");
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(1, -6, -10));
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(1, -6, -10);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(1, -6, -10);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// negative whole
|
// negative whole
|
||||||
f = Fraction.getFraction(-1, 6, 10);
|
f = Fraction.getFraction(-1, 6, 10);
|
||||||
assertEquals(-16, f.getNumerator());
|
assertEquals(-16, f.getNumerator());
|
||||||
assertEquals(10, f.getDenominator());
|
assertEquals(10, f.getDenominator());
|
||||||
|
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(-1, -6, 10));
|
||||||
f = Fraction.getFraction(-1, -6, 10);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(-1, 6, -10));
|
||||||
fail("expecting ArithmeticException");
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(-1, -6, -10));
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(-1, 6, -10);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(-1, -6, -10);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// zero denominator
|
// zero denominator
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(0, 1, 0));
|
||||||
f = Fraction.getFraction(0, 1, 0);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(1, 2, 0));
|
||||||
fail("expecting ArithmeticException");
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(-1, -3, 0));
|
||||||
} catch (final ArithmeticException ex) {}
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Integer.MAX_VALUE, 1, 2));
|
||||||
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(-Integer.MAX_VALUE, 1, 2));
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(1, 2, 0);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(-1, -3, 0);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(Integer.MAX_VALUE, 1, 2);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(-Integer.MAX_VALUE, 1, 2);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// very large
|
// very large
|
||||||
f = Fraction.getFraction(-1, 0, Integer.MAX_VALUE);
|
f = Fraction.getFraction(-1, 0, Integer.MAX_VALUE);
|
||||||
assertEquals(-Integer.MAX_VALUE, f.getNumerator());
|
assertEquals(-Integer.MAX_VALUE, f.getNumerator());
|
||||||
assertEquals(Integer.MAX_VALUE, f.getDenominator());
|
assertEquals(Integer.MAX_VALUE, f.getDenominator());
|
||||||
|
|
||||||
try {
|
// negative denominators not allowed in this constructor.
|
||||||
// negative denominators not allowed in this constructor.
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(0, 4, Integer.MIN_VALUE));
|
||||||
f = Fraction.getFraction(0, 4, Integer.MIN_VALUE);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(1, 1, Integer.MAX_VALUE));
|
||||||
fail("expecting ArithmeticException");
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(-1, 2, Integer.MAX_VALUE));
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(1, 1, Integer.MAX_VALUE);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(-1, 2, Integer.MAX_VALUE);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReducedFactory_int_int() {
|
public void testReducedFactory_int_int() {
|
||||||
Fraction f = null;
|
Fraction f = null;
|
||||||
|
@ -285,20 +218,9 @@ public class FractionTest {
|
||||||
assertEquals(5, f.getDenominator());
|
assertEquals(5, f.getDenominator());
|
||||||
|
|
||||||
// zero denominator
|
// zero denominator
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getReducedFraction(1, 0));
|
||||||
f = Fraction.getReducedFraction(1, 0);
|
assertThrows(ArithmeticException.class, () -> Fraction.getReducedFraction(2, 0));
|
||||||
fail("expecting ArithmeticException");
|
assertThrows(ArithmeticException.class, () -> Fraction.getReducedFraction(-3, 0));
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getReducedFraction(2, 0);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getReducedFraction(-3, 0);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// reduced
|
// reduced
|
||||||
f = Fraction.getReducedFraction(0, 2);
|
f = Fraction.getReducedFraction(0, 2);
|
||||||
|
@ -328,10 +250,7 @@ public class FractionTest {
|
||||||
assertEquals(-(Integer.MIN_VALUE / 2), f.getDenominator());
|
assertEquals(-(Integer.MIN_VALUE / 2), f.getDenominator());
|
||||||
|
|
||||||
// Can't reduce, negation will throw
|
// Can't reduce, negation will throw
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getReducedFraction(-7, Integer.MIN_VALUE));
|
||||||
f = Fraction.getReducedFraction(-7, Integer.MIN_VALUE);
|
|
||||||
fail("Expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// LANG-662
|
// LANG-662
|
||||||
f = Fraction.getReducedFraction(Integer.MIN_VALUE, 2);
|
f = Fraction.getReducedFraction(Integer.MIN_VALUE, 2);
|
||||||
|
@ -341,30 +260,13 @@ public class FractionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFactory_double() {
|
public void testFactory_double() {
|
||||||
Fraction f = null;
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Double.NaN));
|
||||||
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Double.POSITIVE_INFINITY));
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Double.NEGATIVE_INFINITY));
|
||||||
f = Fraction.getFraction(Double.NaN);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction((double) Integer.MAX_VALUE + 1));
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(Double.POSITIVE_INFINITY);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(Double.NEGATIVE_INFINITY);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction((double) Integer.MAX_VALUE + 1);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// zero
|
// zero
|
||||||
f = Fraction.getFraction(0.0d);
|
Fraction f = Fraction.getFraction(0.0d);
|
||||||
assertEquals(0, f.getNumerator());
|
assertEquals(0, f.getNumerator());
|
||||||
assertEquals(1, f.getDenominator());
|
assertEquals(1, f.getDenominator());
|
||||||
|
|
||||||
|
@ -402,12 +304,8 @@ public class FractionTest {
|
||||||
Fraction f2 = null;
|
Fraction f2 = null;
|
||||||
for (int i = 1; i <= 100; i++) { // denominator
|
for (int i = 1; i <= 100; i++) { // denominator
|
||||||
for (int j = 1; j <= i; j++) { // numerator
|
for (int j = 1; j <= i; j++) { // numerator
|
||||||
try {
|
f = Fraction.getFraction((double) j / (double) i);
|
||||||
f = Fraction.getFraction((double) j / (double) i);
|
|
||||||
} catch (final ArithmeticException ex) {
|
|
||||||
System.err.println(j + " " + i);
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
f2 = Fraction.getReducedFraction(j, i);
|
f2 = Fraction.getReducedFraction(j, i);
|
||||||
assertEquals(f2.getNumerator(), f.getNumerator());
|
assertEquals(f2.getNumerator(), f.getNumerator());
|
||||||
assertEquals(f2.getDenominator(), f.getDenominator());
|
assertEquals(f2.getDenominator(), f.getDenominator());
|
||||||
|
@ -416,12 +314,7 @@ public class FractionTest {
|
||||||
// save time by skipping some tests! (
|
// save time by skipping some tests! (
|
||||||
for (int i = 1001; i <= 10000; i+=SKIP) { // denominator
|
for (int i = 1001; i <= 10000; i+=SKIP) { // denominator
|
||||||
for (int j = 1; j <= i; j++) { // numerator
|
for (int j = 1; j <= i; j++) { // numerator
|
||||||
try {
|
f = Fraction.getFraction((double) j / (double) i);
|
||||||
f = Fraction.getFraction((double) j / (double) i);
|
|
||||||
} catch (final ArithmeticException ex) {
|
|
||||||
System.err.println(j + " " + i);
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
f2 = Fraction.getReducedFraction(j, i);
|
f2 = Fraction.getReducedFraction(j, i);
|
||||||
assertEquals(f2.getNumerator(), f.getNumerator());
|
assertEquals(f2.getNumerator(), f.getNumerator());
|
||||||
assertEquals(f2.getDenominator(), f.getDenominator());
|
assertEquals(f2.getDenominator(), f.getDenominator());
|
||||||
|
@ -455,20 +348,9 @@ public class FractionTest {
|
||||||
assertEquals(2, f.getNumerator());
|
assertEquals(2, f.getNumerator());
|
||||||
assertEquals(3, f.getDenominator());
|
assertEquals(3, f.getDenominator());
|
||||||
|
|
||||||
try {
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("2.3R"));
|
||||||
f = Fraction.getFraction("2.3R");
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("2147483648")); // too big
|
||||||
fail("Expecting NumberFormatException");
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("."));
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction("2147483648"); // too big
|
|
||||||
fail("Expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(".");
|
|
||||||
fail("Expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -499,35 +381,12 @@ public class FractionTest {
|
||||||
assertEquals(-6, f.getNumerator());
|
assertEquals(-6, f.getNumerator());
|
||||||
assertEquals(4, f.getDenominator());
|
assertEquals(4, f.getDenominator());
|
||||||
|
|
||||||
try {
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("2 3"));
|
||||||
f = Fraction.getFraction("2 3");
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("a 3"));
|
||||||
fail("expecting NumberFormatException");
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("2 b/4"));
|
||||||
} catch (final NumberFormatException ex) {}
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("2 "));
|
||||||
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction(" 3"));
|
||||||
try {
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction(" "));
|
||||||
f = Fraction.getFraction("a 3");
|
|
||||||
fail("expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction("2 b/4");
|
|
||||||
fail("expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction("2 ");
|
|
||||||
fail("expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(" 3");
|
|
||||||
fail("expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction(" ");
|
|
||||||
fail("expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -558,25 +417,10 @@ public class FractionTest {
|
||||||
assertEquals(2, f.getNumerator());
|
assertEquals(2, f.getNumerator());
|
||||||
assertEquals(4, f.getDenominator());
|
assertEquals(4, f.getDenominator());
|
||||||
|
|
||||||
try {
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("2/d"));
|
||||||
f = Fraction.getFraction("2/d");
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("2e/3"));
|
||||||
fail("expecting NumberFormatException");
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("2/"));
|
||||||
} catch (final NumberFormatException ex) {}
|
assertThrows(NumberFormatException.class, () -> Fraction.getFraction("/"));
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction("2e/3");
|
|
||||||
fail("expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction("2/");
|
|
||||||
fail("expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
f = Fraction.getFraction("/");
|
|
||||||
fail("expecting NumberFormatException");
|
|
||||||
} catch (final NumberFormatException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -681,18 +525,8 @@ public class FractionTest {
|
||||||
assertEquals(-47, f.getNumerator());
|
assertEquals(-47, f.getNumerator());
|
||||||
assertEquals(15, f.getDenominator());
|
assertEquals(15, f.getDenominator());
|
||||||
|
|
||||||
f = Fraction.getFraction(0, 3);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(0, 3).invert());
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Integer.MIN_VALUE, 1).invert());
|
||||||
f = f.invert();
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// large values
|
|
||||||
f = Fraction.getFraction(Integer.MIN_VALUE, 1);
|
|
||||||
try {
|
|
||||||
f = f.invert();
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
f = Fraction.getFraction(Integer.MAX_VALUE, 1);
|
f = Fraction.getFraction(Integer.MAX_VALUE, 1);
|
||||||
f = f.invert();
|
f = f.invert();
|
||||||
|
@ -720,11 +554,7 @@ public class FractionTest {
|
||||||
assertEquals(Integer.MIN_VALUE+2, f.getNumerator());
|
assertEquals(Integer.MIN_VALUE+2, f.getNumerator());
|
||||||
assertEquals(Integer.MAX_VALUE, f.getDenominator());
|
assertEquals(Integer.MAX_VALUE, f.getDenominator());
|
||||||
|
|
||||||
f = Fraction.getFraction(Integer.MIN_VALUE, 1);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Integer.MIN_VALUE, 1).negate());
|
||||||
try {
|
|
||||||
f = f.negate();
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -751,11 +581,7 @@ public class FractionTest {
|
||||||
assertEquals(Integer.MAX_VALUE, f.getNumerator());
|
assertEquals(Integer.MAX_VALUE, f.getNumerator());
|
||||||
assertEquals(1, f.getDenominator());
|
assertEquals(1, f.getDenominator());
|
||||||
|
|
||||||
f = Fraction.getFraction(Integer.MIN_VALUE, 1);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Integer.MIN_VALUE, 1).abs());
|
||||||
try {
|
|
||||||
f = f.abs();
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -829,14 +655,9 @@ public class FractionTest {
|
||||||
assertEquals(1, f.getDenominator());
|
assertEquals(1, f.getDenominator());
|
||||||
|
|
||||||
// zero to negative powers should throw an exception
|
// zero to negative powers should throw an exception
|
||||||
try {
|
final Fraction fr = f;
|
||||||
f = f.pow(-1);
|
assertThrows(ArithmeticException.class, () -> fr.pow(-1));
|
||||||
fail("expecting ArithmeticException");
|
assertThrows(ArithmeticException.class, () -> fr.pow(Integer.MIN_VALUE));
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
try {
|
|
||||||
f = f.pow(Integer.MIN_VALUE);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// one to any power is still one.
|
// one to any power is still one.
|
||||||
f = Fraction.getFraction(1, 1);
|
f = Fraction.getFraction(1, 1);
|
||||||
|
@ -851,24 +672,12 @@ public class FractionTest {
|
||||||
f = f.pow(Integer.MIN_VALUE);
|
f = f.pow(Integer.MIN_VALUE);
|
||||||
assertEquals(f, Fraction.ONE);
|
assertEquals(f, Fraction.ONE);
|
||||||
|
|
||||||
f = Fraction.getFraction(Integer.MAX_VALUE, 1);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Integer.MAX_VALUE, 1).pow(2));
|
||||||
try {
|
|
||||||
f = f.pow(2);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// Numerator growing too negative during the pow operation.
|
// Numerator growing too negative during the pow operation.
|
||||||
f = Fraction.getFraction(Integer.MIN_VALUE, 1);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(Integer.MIN_VALUE, 1).pow(3));
|
||||||
try {
|
|
||||||
f = f.pow(3);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
f = Fraction.getFraction(65536, 1);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(65536, 1).pow(2));
|
||||||
try {
|
|
||||||
f = f.pow(2);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -928,14 +737,11 @@ public class FractionTest {
|
||||||
|
|
||||||
f1 = Fraction.getFraction(-1, 13*13*2*2);
|
f1 = Fraction.getFraction(-1, 13*13*2*2);
|
||||||
f2 = Fraction.getFraction(-2, 13*17*2);
|
f2 = Fraction.getFraction(-2, 13*17*2);
|
||||||
f = f1.add(f2);
|
final Fraction fr = f1.add(f2);
|
||||||
assertEquals(13*13*17*2*2, f.getDenominator());
|
assertEquals(13*13*17*2*2, fr.getDenominator());
|
||||||
assertEquals(-17 - 2*13*2, f.getNumerator());
|
assertEquals(-17 - 2*13*2, fr.getNumerator());
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> fr.add(null));
|
||||||
f.add(null);
|
|
||||||
fail("expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
|
|
||||||
// if this fraction is added naively, it will overflow.
|
// if this fraction is added naively, it will overflow.
|
||||||
// check that it doesn't.
|
// check that it doesn't.
|
||||||
|
@ -957,37 +763,23 @@ public class FractionTest {
|
||||||
assertEquals(Integer.MAX_VALUE, f.getNumerator());
|
assertEquals(Integer.MAX_VALUE, f.getNumerator());
|
||||||
assertEquals(1, f.getDenominator());
|
assertEquals(1, f.getDenominator());
|
||||||
|
|
||||||
try {
|
final Fraction overflower = f;
|
||||||
f = f.add(Fraction.ONE); // should overflow
|
assertThrows(ArithmeticException.class, () -> overflower.add(Fraction.ONE)); // should overflow
|
||||||
fail("expecting ArithmeticException but got: " + f.toString());
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// denominator should not be a multiple of 2 or 3 to trigger overflow
|
// denominator should not be a multiple of 2 or 3 to trigger overflow
|
||||||
f1 = Fraction.getFraction(Integer.MIN_VALUE, 5);
|
assertThrows(
|
||||||
f2 = Fraction.getFraction(-1,5);
|
ArithmeticException.class,
|
||||||
try {
|
() -> Fraction.getFraction(Integer.MIN_VALUE, 5).add(Fraction.getFraction(-1,5)));
|
||||||
f = f1.add(f2); // should overflow
|
|
||||||
fail("expecting ArithmeticException but got: " + f.toString());
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
final Fraction maxValue = Fraction.getFraction(-Integer.MAX_VALUE, 1);
|
||||||
f= Fraction.getFraction(-Integer.MAX_VALUE, 1);
|
assertThrows(ArithmeticException.class, () -> maxValue.add(maxValue));
|
||||||
f = f.add(f);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
final Fraction negativeMaxValue = Fraction.getFraction(-Integer.MAX_VALUE, 1);
|
||||||
f= Fraction.getFraction(-Integer.MAX_VALUE, 1);
|
assertThrows(ArithmeticException.class, () -> negativeMaxValue.add(negativeMaxValue));
|
||||||
f = f.add(f);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
f1 = Fraction.getFraction(3,327680);
|
final Fraction f3 = Fraction.getFraction(3,327680);
|
||||||
f2 = Fraction.getFraction(2,59049);
|
final Fraction f4 = Fraction.getFraction(2,59049);
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> f3.add(f4)); // should overflow
|
||||||
f = f1.add(f2); // should overflow
|
|
||||||
fail("expecting ArithmeticException but got: " + f.toString());
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1043,10 +835,8 @@ public class FractionTest {
|
||||||
f = f2.subtract(f1);
|
f = f2.subtract(f1);
|
||||||
assertSame(f2, f);
|
assertSame(f2, f);
|
||||||
|
|
||||||
try {
|
final Fraction fr = f;
|
||||||
f.subtract(null);
|
assertThrows(IllegalArgumentException.class, () -> fr.subtract(null));
|
||||||
fail("expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
|
|
||||||
// if this fraction is subtracted naively, it will overflow.
|
// if this fraction is subtracted naively, it will overflow.
|
||||||
// check that it doesn't.
|
// check that it doesn't.
|
||||||
|
@ -1068,39 +858,28 @@ public class FractionTest {
|
||||||
assertEquals(Integer.MAX_VALUE-1, f.getNumerator());
|
assertEquals(Integer.MAX_VALUE-1, f.getNumerator());
|
||||||
assertEquals(1, f.getDenominator());
|
assertEquals(1, f.getDenominator());
|
||||||
|
|
||||||
try {
|
// Should overflow
|
||||||
f1 = Fraction.getFraction(1, Integer.MAX_VALUE);
|
assertThrows(
|
||||||
f2 = Fraction.getFraction(1, Integer.MAX_VALUE - 1);
|
ArithmeticException.class,
|
||||||
|
() -> Fraction.getFraction(1, Integer.MAX_VALUE).subtract(Fraction.getFraction(1, Integer.MAX_VALUE - 1)));
|
||||||
f = f1.subtract(f2);
|
f = f1.subtract(f2);
|
||||||
fail("expecting ArithmeticException"); //should overflow
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
// denominator should not be a multiple of 2 or 3 to trigger overflow
|
// denominator should not be a multiple of 2 or 3 to trigger overflow
|
||||||
f1 = Fraction.getFraction(Integer.MIN_VALUE, 5);
|
assertThrows(
|
||||||
f2 = Fraction.getFraction(1,5);
|
ArithmeticException.class,
|
||||||
try {
|
() -> Fraction.getFraction(Integer.MIN_VALUE, 5).subtract(Fraction.getFraction(1,5)));
|
||||||
f = f1.subtract(f2); // should overflow
|
|
||||||
fail("expecting ArithmeticException but got: " + f.toString());
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
f= Fraction.getFraction(Integer.MIN_VALUE, 1);
|
ArithmeticException.class, () -> Fraction.getFraction(Integer.MIN_VALUE, 1).subtract(Fraction.ONE));
|
||||||
f = f.subtract(Fraction.ONE);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
f= Fraction.getFraction(Integer.MAX_VALUE, 1);
|
ArithmeticException.class,
|
||||||
f = f.subtract(Fraction.ONE.negate());
|
() -> Fraction.getFraction(Integer.MAX_VALUE, 1).subtract(Fraction.ONE.negate()));
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
f1 = Fraction.getFraction(3,327680);
|
// Should overflow
|
||||||
f2 = Fraction.getFraction(2,59049);
|
assertThrows(
|
||||||
try {
|
ArithmeticException.class,
|
||||||
f = f1.subtract(f2); // should overflow
|
() -> Fraction.getFraction(3,327680).subtract(Fraction.getFraction(2,59049)));
|
||||||
fail("expecting ArithmeticException but got: " + f.toString());
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1154,22 +933,14 @@ public class FractionTest {
|
||||||
assertEquals(Integer.MIN_VALUE, f.getNumerator());
|
assertEquals(Integer.MIN_VALUE, f.getNumerator());
|
||||||
assertEquals(1, f.getDenominator());
|
assertEquals(1, f.getDenominator());
|
||||||
|
|
||||||
try {
|
final Fraction fr = f;
|
||||||
f.multiplyBy(null);
|
assertThrows(IllegalArgumentException.class, () -> fr.multiplyBy(null));
|
||||||
fail("expecting IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
|
|
||||||
try {
|
final Fraction fr1 = Fraction.getFraction(1, Integer.MAX_VALUE);
|
||||||
f1 = Fraction.getFraction(1, Integer.MAX_VALUE);
|
assertThrows(ArithmeticException.class, () -> fr1.multiplyBy(fr1));
|
||||||
f = f1.multiplyBy(f1); // should overflow
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
try {
|
final Fraction fr2 = Fraction.getFraction(1, -Integer.MAX_VALUE);
|
||||||
f1 = Fraction.getFraction(1, -Integer.MAX_VALUE);
|
assertThrows(ArithmeticException.class, () -> fr2.multiplyBy(fr2));
|
||||||
f = f1.multiplyBy(f1); // should overflow
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1184,12 +955,7 @@ public class FractionTest {
|
||||||
assertEquals(3, f.getNumerator());
|
assertEquals(3, f.getNumerator());
|
||||||
assertEquals(2, f.getDenominator());
|
assertEquals(2, f.getDenominator());
|
||||||
|
|
||||||
f1 = Fraction.getFraction(3, 5);
|
assertThrows(ArithmeticException.class, () -> Fraction.getFraction(3, 5).divideBy(Fraction.ZERO));
|
||||||
f2 = Fraction.ZERO;
|
|
||||||
try {
|
|
||||||
f = f1.divideBy(f2);
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
|
|
||||||
f1 = Fraction.getFraction(0, 5);
|
f1 = Fraction.getFraction(0, 5);
|
||||||
f2 = Fraction.getFraction(2, 7);
|
f2 = Fraction.getFraction(2, 7);
|
||||||
|
@ -1209,25 +975,17 @@ public class FractionTest {
|
||||||
|
|
||||||
f1 = Fraction.getFraction(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
f1 = Fraction.getFraction(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
f2 = Fraction.getFraction(1, Integer.MAX_VALUE);
|
f2 = Fraction.getFraction(1, Integer.MAX_VALUE);
|
||||||
f = f1.divideBy(f2);
|
final Fraction fr = f1.divideBy(f2);
|
||||||
assertEquals(Integer.MIN_VALUE, f.getNumerator());
|
assertEquals(Integer.MIN_VALUE, fr.getNumerator());
|
||||||
assertEquals(1, f.getDenominator());
|
assertEquals(1, fr.getDenominator());
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> fr.divideBy(null));
|
||||||
f.divideBy(null);
|
|
||||||
fail("IllegalArgumentException");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
|
|
||||||
try {
|
final Fraction smallest = Fraction.getFraction(1, Integer.MAX_VALUE);
|
||||||
f1 = Fraction.getFraction(1, Integer.MAX_VALUE);
|
assertThrows(ArithmeticException.class, () -> smallest.divideBy(smallest.invert())); // Should overflow
|
||||||
f = f1.divideBy(f1.invert()); // should overflow
|
|
||||||
fail("expecting ArithmeticException");
|
final Fraction negative = Fraction.getFraction(1, -Integer.MAX_VALUE);
|
||||||
} catch (final ArithmeticException ex) {}
|
assertThrows(ArithmeticException.class, () -> negative.divideBy(negative.invert())); // Should overflow
|
||||||
try {
|
|
||||||
f1 = Fraction.getFraction(1, -Integer.MAX_VALUE);
|
|
||||||
f = f1.divideBy(f1.invert()); // should overflow
|
|
||||||
fail("expecting ArithmeticException");
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1275,10 +1033,8 @@ public class FractionTest {
|
||||||
f1 = Fraction.getFraction(3, 5);
|
f1 = Fraction.getFraction(3, 5);
|
||||||
assertTrue(f1.compareTo(f1) == 0);
|
assertTrue(f1.compareTo(f1) == 0);
|
||||||
|
|
||||||
try {
|
final Fraction fr = f1;
|
||||||
f1.compareTo(null);
|
assertThrows(NullPointerException.class, () -> fr.compareTo(null));
|
||||||
fail("expecting NullPointerException");
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
|
|
||||||
f2 = Fraction.getFraction(2, 5);
|
f2 = Fraction.getFraction(2, 5);
|
||||||
assertTrue(f1.compareTo(f2) > 0);
|
assertTrue(f1.compareTo(f2) > 0);
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
package org.apache.commons.lang3.math;
|
package org.apache.commons.lang3.math;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -55,46 +55,45 @@ public class IEEE754rUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEnforceExceptions() {
|
public void testEnforceExceptions() {
|
||||||
try {
|
assertThrows(
|
||||||
IEEE754rUtils.min( (float[]) null);
|
IllegalArgumentException.class,
|
||||||
fail("IllegalArgumentException expected for null input");
|
() -> IEEE754rUtils.min( (float[]) null),
|
||||||
} catch(final IllegalArgumentException iae) { /* expected */ }
|
"IllegalArgumentException expected for null input");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
IEEE754rUtils.min();
|
IllegalArgumentException.class,
|
||||||
fail("IllegalArgumentException expected for empty input");
|
() -> IEEE754rUtils.min(),
|
||||||
} catch(final IllegalArgumentException iae) { /* expected */ }
|
"IllegalArgumentException expected for empty input");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
IEEE754rUtils.max( (float[]) null);
|
IllegalArgumentException.class,
|
||||||
fail("IllegalArgumentException expected for null input");
|
() -> IEEE754rUtils.max( (float[]) null),
|
||||||
} catch(final IllegalArgumentException iae) { /* expected */ }
|
"IllegalArgumentException expected for null input");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
IEEE754rUtils.max();
|
IllegalArgumentException.class,
|
||||||
fail("IllegalArgumentException expected for empty input");
|
IEEE754rUtils::max,
|
||||||
} catch(final IllegalArgumentException iae) { /* expected */ }
|
"IllegalArgumentException expected for empty input");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
IEEE754rUtils.min( (double[]) null);
|
IllegalArgumentException.class,
|
||||||
fail("IllegalArgumentException expected for null input");
|
() -> IEEE754rUtils.min( (double[]) null),
|
||||||
} catch(final IllegalArgumentException iae) { /* expected */ }
|
"IllegalArgumentException expected for null input");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
IEEE754rUtils.min(new double[0]);
|
IllegalArgumentException.class,
|
||||||
fail("IllegalArgumentException expected for empty input");
|
() -> IEEE754rUtils.min(new double[0]),
|
||||||
} catch(final IllegalArgumentException iae) { /* expected */ }
|
"IllegalArgumentException expected for empty input");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
IEEE754rUtils.max( (double[]) null);
|
IllegalArgumentException.class,
|
||||||
fail("IllegalArgumentException expected for null input");
|
() -> IEEE754rUtils.max( (double[]) null),
|
||||||
} catch(final IllegalArgumentException iae) { /* expected */ }
|
"IllegalArgumentException expected for null input");
|
||||||
|
|
||||||
try {
|
|
||||||
IEEE754rUtils.max(new double[0]);
|
|
||||||
fail("IllegalArgumentException expected for empty input");
|
|
||||||
} catch(final IllegalArgumentException iae) { /* expected */ }
|
|
||||||
|
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> IEEE754rUtils.max(new double[0]),
|
||||||
|
"IllegalArgumentException expected for empty input");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -616,12 +616,9 @@ public class NumberUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testCreateFloatFailure(final String str) {
|
protected void testCreateFloatFailure(final String str) {
|
||||||
try {
|
assertThrows(
|
||||||
final Float value = NumberUtils.createFloat(str);
|
NumberFormatException.class,
|
||||||
fail("createFloat(\"" + str + "\") should have failed: " + value);
|
() -> NumberUtils.createFloat(str), "createFloat(\"" + str + "\") should have failed.");
|
||||||
} catch (final NumberFormatException ex) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -636,12 +633,10 @@ public class NumberUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testCreateDoubleFailure(final String str) {
|
protected void testCreateDoubleFailure(final String str) {
|
||||||
try {
|
assertThrows(
|
||||||
final Double value = NumberUtils.createDouble(str);
|
NumberFormatException.class,
|
||||||
fail("createDouble(\"" + str + "\") should have failed: " + value);
|
() -> NumberUtils.createDouble(str),
|
||||||
} catch (final NumberFormatException ex) {
|
"createDouble(\"" + str + "\") should have failed.");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -656,12 +651,10 @@ public class NumberUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testCreateIntegerFailure(final String str) {
|
protected void testCreateIntegerFailure(final String str) {
|
||||||
try {
|
assertThrows(
|
||||||
final Integer value = NumberUtils.createInteger(str);
|
NumberFormatException.class,
|
||||||
fail("createInteger(\"" + str + "\") should have failed: " + value);
|
() -> NumberUtils.createInteger(str),
|
||||||
} catch (final NumberFormatException ex) {
|
"createInteger(\"" + str + "\") should have failed.");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -676,12 +669,10 @@ public class NumberUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testCreateLongFailure(final String str) {
|
protected void testCreateLongFailure(final String str) {
|
||||||
try {
|
assertThrows(
|
||||||
final Long value = NumberUtils.createLong(str);
|
NumberFormatException.class,
|
||||||
fail("createLong(\"" + str + "\") should have failed: " + value);
|
() -> NumberUtils.createLong(str),
|
||||||
} catch (final NumberFormatException ex) {
|
"createLong(\"" + str + "\") should have failed.");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -709,12 +700,10 @@ public class NumberUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testCreateBigIntegerFailure(final String str) {
|
protected void testCreateBigIntegerFailure(final String str) {
|
||||||
try {
|
assertThrows(
|
||||||
final BigInteger value = NumberUtils.createBigInteger(str);
|
NumberFormatException.class,
|
||||||
fail("createBigInteger(\"" + str + "\") should have failed: " + value);
|
() -> NumberUtils.createBigInteger(str),
|
||||||
} catch (final NumberFormatException ex) {
|
"createBigInteger(\"" + str + "\") should have failed.");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -735,12 +724,10 @@ public class NumberUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testCreateBigDecimalFailure(final String str) {
|
protected void testCreateBigDecimalFailure(final String str) {
|
||||||
try {
|
assertThrows(
|
||||||
final BigDecimal value = NumberUtils.createBigDecimal(str);
|
NumberFormatException.class,
|
||||||
fail("createBigDecimal(\"" + str + "\") should have failed: " + value);
|
() -> NumberUtils.createBigDecimal(str),
|
||||||
} catch (final NumberFormatException ex) {
|
"createBigDecimal(\"" + str + "\") should have failed.");
|
||||||
// empty
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// min/max tests
|
// min/max tests
|
||||||
|
@ -954,15 +941,13 @@ public class NumberUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMaxDouble() {
|
public void testMaxDouble() {
|
||||||
final double[] d = null;
|
final double[] d = null;
|
||||||
try {
|
assertThrows(
|
||||||
NumberUtils.max(d);
|
IllegalArgumentException.class, () -> NumberUtils.max(d), "No exception was thrown for null input.");
|
||||||
fail("No exception was thrown for null input.");
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
NumberUtils.max(new double[0]);
|
IllegalArgumentException.class,
|
||||||
fail("No exception was thrown for empty input.");
|
() -> NumberUtils.max(new double[0]),
|
||||||
} catch (final IllegalArgumentException ex) {}
|
"No exception was thrown for empty input.");
|
||||||
|
|
||||||
// TODO: JUnit Jupiter 5.3.1 doesn't support delta=0.
|
// TODO: JUnit Jupiter 5.3.1 doesn't support delta=0.
|
||||||
// This should be replaced when it is supported in JUnit Jupiter 5.4.
|
// This should be replaced when it is supported in JUnit Jupiter 5.4.
|
||||||
|
|
|
@ -20,8 +20,8 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit tests.
|
* JUnit tests.
|
||||||
|
@ -42,10 +42,7 @@ public class MutableShortTest {
|
||||||
|
|
||||||
assertEquals((short) 2, new MutableShort("2").shortValue());
|
assertEquals((short) 2, new MutableShort("2").shortValue());
|
||||||
|
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> new MutableShort((Number)null));
|
||||||
new MutableShort((Number)null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -65,10 +62,7 @@ public class MutableShortTest {
|
||||||
mutNum.setValue(new MutableShort((short) 3));
|
mutNum.setValue(new MutableShort((short) 3));
|
||||||
assertEquals((short) 3, mutNum.shortValue());
|
assertEquals((short) 3, mutNum.shortValue());
|
||||||
assertEquals(Short.valueOf((short) 3), mutNum.getValue());
|
assertEquals(Short.valueOf((short) 3), mutNum.getValue());
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> mutNum.setValue(null));
|
||||||
mutNum.setValue(null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -108,10 +102,7 @@ public class MutableShortTest {
|
||||||
assertEquals((short) 0, mutNum.compareTo(new MutableShort((short) 0)));
|
assertEquals((short) 0, mutNum.compareTo(new MutableShort((short) 0)));
|
||||||
assertEquals((short) +1, mutNum.compareTo(new MutableShort((short) -1)));
|
assertEquals((short) +1, mutNum.compareTo(new MutableShort((short) -1)));
|
||||||
assertEquals((short) -1, mutNum.compareTo(new MutableShort((short) 1)));
|
assertEquals((short) -1, mutNum.compareTo(new MutableShort((short) 1)));
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> mutNum.compareTo(null));
|
||||||
mutNum.compareTo(null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -20,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -186,24 +186,15 @@ public class ConstructorUtilsTest {
|
||||||
TestBean.class, new Object[] { NumberUtils.DOUBLE_ONE },
|
TestBean.class, new Object[] { NumberUtils.DOUBLE_ONE },
|
||||||
new Class[] { Double.TYPE }).toString());
|
new Class[] { Double.TYPE }).toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
ConstructorUtils.invokeExactConstructor(TestBean.class,
|
NoSuchMethodException.class,
|
||||||
NumberUtils.BYTE_ONE);
|
() -> ConstructorUtils.invokeExactConstructor(TestBean.class,NumberUtils.BYTE_ONE));
|
||||||
fail("should throw NoSuchMethodException");
|
assertThrows(
|
||||||
} catch (final NoSuchMethodException e) {
|
NoSuchMethodException.class,
|
||||||
}
|
() -> ConstructorUtils.invokeExactConstructor(TestBean.class, NumberUtils.LONG_ONE));
|
||||||
try {
|
assertThrows(
|
||||||
ConstructorUtils.invokeExactConstructor(TestBean.class,
|
NoSuchMethodException.class,
|
||||||
NumberUtils.LONG_ONE);
|
() -> ConstructorUtils.invokeExactConstructor(TestBean.class, Boolean.TRUE));
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ConstructorUtils.invokeExactConstructor(TestBean.class,
|
|
||||||
Boolean.TRUE);
|
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -28,7 +28,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -435,12 +434,7 @@ public class MethodUtilsTest {
|
||||||
assertEquals("foo(long...)", MethodUtils.invokeMethod(testBean, "foo",
|
assertEquals("foo(long...)", MethodUtils.invokeMethod(testBean, "foo",
|
||||||
1L, 2L));
|
1L, 2L));
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchMethodException.class, () -> MethodUtils.invokeMethod(testBean, "foo", 1, 2));
|
||||||
MethodUtils.invokeMethod(testBean, "foo",
|
|
||||||
1, 2);
|
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException expected) {
|
|
||||||
}
|
|
||||||
|
|
||||||
TestBean.verify(new ImmutablePair<>("String...", new String[]{"x", "y"}),
|
TestBean.verify(new ImmutablePair<>("String...", new String[]{"x", "y"}),
|
||||||
MethodUtils.invokeMethod(testBean, "varOverloadEcho", "x", "y"));
|
MethodUtils.invokeMethod(testBean, "varOverloadEcho", "x", "y"));
|
||||||
|
@ -471,23 +465,14 @@ public class MethodUtilsTest {
|
||||||
"foo", new Object[]{NumberUtils.DOUBLE_ONE},
|
"foo", new Object[]{NumberUtils.DOUBLE_ONE},
|
||||||
new Class[]{Double.TYPE}));
|
new Class[]{Double.TYPE}));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
MethodUtils
|
NoSuchMethodException.class,
|
||||||
.invokeExactMethod(testBean, "foo", NumberUtils.BYTE_ONE);
|
() -> MethodUtils.invokeExactMethod(testBean, "foo", NumberUtils.BYTE_ONE));
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException e) {
|
assertThrows(
|
||||||
}
|
NoSuchMethodException.class,
|
||||||
try {
|
() -> MethodUtils.invokeExactMethod(testBean, "foo", NumberUtils.LONG_ONE));
|
||||||
MethodUtils
|
assertThrows(NoSuchMethodException.class, () -> MethodUtils.invokeExactMethod(testBean, "foo", Boolean.TRUE));
|
||||||
.invokeExactMethod(testBean, "foo", NumberUtils.LONG_ONE);
|
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
MethodUtils.invokeExactMethod(testBean, "foo", Boolean.TRUE);
|
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -526,11 +511,8 @@ public class MethodUtilsTest {
|
||||||
TestBean.verify(new ImmutablePair<>("Number...", new Number[]{17, 23, 42}),
|
TestBean.verify(new ImmutablePair<>("Number...", new Number[]{17, 23, 42}),
|
||||||
MethodUtils.invokeStaticMethod(TestBean.class, "varOverloadEchoStatic", 17, 23, 42));
|
MethodUtils.invokeStaticMethod(TestBean.class, "varOverloadEchoStatic", 17, 23, 42));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
MethodUtils.invokeStaticMethod(TestBean.class, "does_not_exist");
|
NoSuchMethodException.class, () -> MethodUtils.invokeStaticMethod(TestBean.class, "does_not_exist"));
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -551,24 +533,15 @@ public class MethodUtilsTest {
|
||||||
TestBean.class, "bar", new Object[]{NumberUtils.DOUBLE_ONE},
|
TestBean.class, "bar", new Object[]{NumberUtils.DOUBLE_ONE},
|
||||||
new Class[]{Double.TYPE}));
|
new Class[]{Double.TYPE}));
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
MethodUtils.invokeExactStaticMethod(TestBean.class, "bar",
|
NoSuchMethodException.class,
|
||||||
NumberUtils.BYTE_ONE);
|
() -> MethodUtils.invokeExactStaticMethod(TestBean.class, "bar", NumberUtils.BYTE_ONE));
|
||||||
fail("should throw NoSuchMethodException");
|
assertThrows(
|
||||||
} catch (final NoSuchMethodException e) {
|
NoSuchMethodException.class,
|
||||||
}
|
() -> MethodUtils.invokeExactStaticMethod(TestBean.class, "bar", NumberUtils.LONG_ONE));
|
||||||
try {
|
assertThrows(
|
||||||
MethodUtils.invokeExactStaticMethod(TestBean.class, "bar",
|
NoSuchMethodException.class,
|
||||||
NumberUtils.LONG_ONE);
|
() -> MethodUtils.invokeExactStaticMethod(TestBean.class, "bar", Boolean.TRUE));
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
MethodUtils.invokeExactStaticMethod(TestBean.class, "bar",
|
|
||||||
Boolean.TRUE);
|
|
||||||
fail("should throw NoSuchMethodException");
|
|
||||||
} catch (final NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.commons.lang3.text;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -165,47 +165,36 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("foo", 0, 3);
|
sb.append("foo", 0, 3);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
|
||||||
try {
|
final StrBuilder sb1 = sb;
|
||||||
sb.append("bar", -1, 1);
|
assertThrows(
|
||||||
fail("append(char[], -1,) expected IndexOutOfBoundsException");
|
IndexOutOfBoundsException.class,
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
() -> sb1.append("bar", -1, 1),
|
||||||
// expected
|
"append(char[], -1,) expected IndexOutOfBoundsException");
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append("bar", 3, 1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 3,) expected IndexOutOfBoundsException");
|
() -> sb1.append("bar", 3, 1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 3,) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append("bar", 1, -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[],, -1) expected IndexOutOfBoundsException");
|
() -> sb1.append("bar", 1, -1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[],, -1) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append("bar", 1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append("bar", 1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append("bar", -1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], -1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append("bar", -1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], -1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append("bar", 4, 0);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 4, 0) expected IndexOutOfBoundsException");
|
() -> sb1.append("bar", 4, 0),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 4, 0) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append("bar", 3, 0);
|
sb.append("bar", 3, 0);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
@ -228,47 +217,36 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append(new StringBuilder("foo"), 0, 3);
|
sb.append(new StringBuilder("foo"), 0, 3);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
|
||||||
try {
|
final StrBuilder sb1 = sb;
|
||||||
sb.append(new StringBuilder("bar"), -1, 1);
|
assertThrows(
|
||||||
fail("append(StringBuilder, -1,) expected IndexOutOfBoundsException");
|
IndexOutOfBoundsException.class,
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
() -> sb1.append(new StringBuilder("bar"), -1, 1),
|
||||||
// expected
|
"append(StringBuilder, -1,) expected IndexOutOfBoundsException");
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuilder("bar"), 3, 1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(StringBuilder, 3,) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuilder("bar"), 3, 1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(StringBuilder, 3,) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuilder("bar"), 1, -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(StringBuilder,, -1) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuilder("bar"), 1, -1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(StringBuilder,, -1) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuilder("bar"), 1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(StringBuilder, 1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuilder("bar"), 1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(StringBuilder, 1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuilder("bar"), -1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(StringBuilder, -1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuilder("bar"), -1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(StringBuilder, -1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuilder("bar"), 4, 0);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(StringBuilder, 4, 0) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuilder("bar"), 4, 0),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(StringBuilder, 4, 0) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(new StringBuilder("bar"), 3, 0);
|
sb.append(new StringBuilder("bar"), 3, 0);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
@ -309,47 +287,36 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append(new StringBuffer("foo"), 0, 3);
|
sb.append(new StringBuffer("foo"), 0, 3);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
|
||||||
try {
|
final StrBuilder sb1 = sb;
|
||||||
sb.append(new StringBuffer("bar"), -1, 1);
|
assertThrows(
|
||||||
fail("append(char[], -1,) expected IndexOutOfBoundsException");
|
IndexOutOfBoundsException.class,
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
() -> sb1.append(new StringBuffer("bar"), -1, 1),
|
||||||
// expected
|
"append(char[], -1,) expected IndexOutOfBoundsException");
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuffer("bar"), 3, 1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 3,) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuffer("bar"), 3, 1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 3,) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuffer("bar"), 1, -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[],, -1) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuffer("bar"), 1, -1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[],, -1) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuffer("bar"), 1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuffer("bar"), 1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuffer("bar"), -1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], -1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuffer("bar"), -1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], -1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StringBuffer("bar"), 4, 0);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 4, 0) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StringBuffer("bar"), 4, 0),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 4, 0) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(new StringBuffer("bar"), 3, 0);
|
sb.append(new StringBuffer("bar"), 3, 0);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
@ -387,47 +354,36 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append(new StrBuilder("foo"), 0, 3);
|
sb.append(new StrBuilder("foo"), 0, 3);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
|
||||||
try {
|
final StrBuilder sb1 = sb;
|
||||||
sb.append(new StrBuilder("bar"), -1, 1);
|
assertThrows(
|
||||||
fail("append(char[], -1,) expected IndexOutOfBoundsException");
|
IndexOutOfBoundsException.class,
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
() -> sb1.append(new StrBuilder("bar"), -1, 1),
|
||||||
// expected
|
"append(char[], -1,) expected IndexOutOfBoundsException");
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StrBuilder("bar"), 3, 1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 3,) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StrBuilder("bar"), 3, 1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 3,) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StrBuilder("bar"), 1, -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[],, -1) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StrBuilder("bar"), 1, -1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[],, -1) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StrBuilder("bar"), 1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StrBuilder("bar"), 1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StrBuilder("bar"), -1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], -1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StrBuilder("bar"), -1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], -1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new StrBuilder("bar"), 4, 0);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 4, 0) expected IndexOutOfBoundsException");
|
() -> sb1.append(new StrBuilder("bar"), 4, 0),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 4, 0) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(new StrBuilder("bar"), 3, 0);
|
sb.append(new StrBuilder("bar"), 3, 0);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
@ -462,47 +418,36 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append(new char[]{'f', 'o', 'o'}, 0, 3);
|
sb.append(new char[]{'f', 'o', 'o'}, 0, 3);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
|
||||||
try {
|
final StrBuilder sb1 = sb;
|
||||||
sb.append(new char[]{'b', 'a', 'r'}, -1, 1);
|
assertThrows(
|
||||||
fail("append(char[], -1,) expected IndexOutOfBoundsException");
|
IndexOutOfBoundsException.class,
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
() -> sb1.append(new char[]{'b', 'a', 'r'}, -1, 1),
|
||||||
// expected
|
"append(char[], -1,) expected IndexOutOfBoundsException");
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new char[]{'b', 'a', 'r'}, 3, 1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 3,) expected IndexOutOfBoundsException");
|
() -> sb1.append(new char[]{'b', 'a', 'r'}, 3, 1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 3,) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new char[]{'b', 'a', 'r'}, 1, -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[],, -1) expected IndexOutOfBoundsException");
|
() -> sb1.append(new char[]{'b', 'a', 'r'}, 1, -1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[],, -1) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new char[]{'b', 'a', 'r'}, 1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append(new char[]{'b', 'a', 'r'}, 1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new char[]{'b', 'a', 'r'}, -1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], -1, 3) expected IndexOutOfBoundsException");
|
() -> sb1.append(new char[]{'b', 'a', 'r'}, -1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], -1, 3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.append(new char[]{'b', 'a', 'r'}, 4, 0);
|
IndexOutOfBoundsException.class,
|
||||||
fail("append(char[], 4, 0) expected IndexOutOfBoundsException");
|
() -> sb1.append(new char[]{'b', 'a', 'r'}, 4, 0),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"append(char[], 4, 0) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append(new char[]{'b', 'a', 'r'}, 3, 0);
|
sb.append(new char[]{'b', 'a', 'r'}, 3, 0);
|
||||||
assertEquals("foo", sb.toString());
|
assertEquals("foo", sb.toString());
|
||||||
|
@ -1288,19 +1233,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, FOO);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, Object) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, FOO),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, Object) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, FOO);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, Object) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, FOO),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, Object) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, (Object) null);
|
sb.insert(0, (Object) null);
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
@ -1312,19 +1253,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, "foo");
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, String) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, "foo"),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, String) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, "foo");
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, String) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, "foo"),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, String) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, (String) null);
|
sb.insert(0, (String) null);
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
@ -1336,19 +1273,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, new char[]{'f', 'o', 'o'});
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, char[]) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, new char[]{'f', 'o', 'o'}),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, char[]) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, new char[]{'f', 'o', 'o'});
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, char[]) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, new char[]{'f', 'o', 'o'}),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, char[]) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, (char[]) null);
|
sb.insert(0, (char[]) null);
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
@ -1363,19 +1296,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 3, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, char[], 3, 3) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 3, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, char[], 3, 3) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 3, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, char[], 3, 3) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 3, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, char[], 3, 3) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, null, 0, 0);
|
sb.insert(0, null, 0, 0);
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
@ -1383,33 +1312,25 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.insert(0, new char[0], 0, 0);
|
sb.insert(0, new char[0], 0, 0);
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, -1, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(0, char[], -1, 3) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, -1, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(0, char[], -1, 3) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 10, 3);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(0, char[], 10, 3) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 10, 3),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(0, char[], 10, 3) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(0, char[], 0, -1) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, -1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(0, char[], 0, -1) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, 10);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(0, char[], 0, 10) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, 10),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(0, char[], 0, 10) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, 0);
|
sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, 0);
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
@ -1421,19 +1342,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, true);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, boolean) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, true),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, boolean) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, true);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, boolean) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, true),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, boolean) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, true);
|
sb.insert(0, true);
|
||||||
assertEquals("truebarbaz", sb.toString());
|
assertEquals("truebarbaz", sb.toString());
|
||||||
|
@ -1445,19 +1362,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, '!');
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, char) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, '!'),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, char) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, '!');
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, char) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, '!'),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, char) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, '!');
|
sb.insert(0, '!');
|
||||||
assertEquals("!barbaz", sb.toString());
|
assertEquals("!barbaz", sb.toString());
|
||||||
|
@ -1466,19 +1379,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, 0);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, int) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, 0),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, int) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, 0);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, int) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, 0),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, int) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, '0');
|
sb.insert(0, '0');
|
||||||
assertEquals("0barbaz", sb.toString());
|
assertEquals("0barbaz", sb.toString());
|
||||||
|
@ -1487,19 +1396,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, 1L);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, long) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, 1L),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, long) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, 1L);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, long) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, 1L),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, long) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, 1L);
|
sb.insert(0, 1L);
|
||||||
assertEquals("1barbaz", sb.toString());
|
assertEquals("1barbaz", sb.toString());
|
||||||
|
@ -1508,19 +1413,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, 2.3F);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, float) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, 2.3F),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, float) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, 2.3F);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, float) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, 2.3F),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, float) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, 2.3F);
|
sb.insert(0, 2.3F);
|
||||||
assertEquals("2.3barbaz", sb.toString());
|
assertEquals("2.3barbaz", sb.toString());
|
||||||
|
@ -1529,19 +1430,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, 4.5D);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, double) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, 4.5D),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, double) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, 4.5D);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, double) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, 4.5D),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, double) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, 4.5D);
|
sb.insert(0, 4.5D);
|
||||||
assertEquals("4.5barbaz", sb.toString());
|
assertEquals("4.5barbaz", sb.toString());
|
||||||
|
@ -1555,19 +1452,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, FOO);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, Object) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, FOO),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, Object) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, FOO);
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, Object) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, FOO),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, Object) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, (Object) null);
|
sb.insert(0, (Object) null);
|
||||||
assertEquals("nullbarbaz", sb.toString());
|
assertEquals("nullbarbaz", sb.toString());
|
||||||
|
@ -1579,19 +1472,15 @@ public class StrBuilderAppendInsertTest {
|
||||||
sb.append("barbaz");
|
sb.append("barbaz");
|
||||||
assertEquals("barbaz", sb.toString());
|
assertEquals("barbaz", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(-1, "foo");
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(-1, String) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(-1, "foo"),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(-1, String) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.insert(7, "foo");
|
IndexOutOfBoundsException.class,
|
||||||
fail("insert(7, String) expected StringIndexOutOfBoundsException");
|
() -> sb.insert(7, "foo"),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"insert(7, String) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.insert(0, (String) null);
|
sb.insert(0, (String) null);
|
||||||
assertEquals("nullbarbaz", sb.toString());
|
assertEquals("nullbarbaz", sb.toString());
|
||||||
|
|
|
@ -25,8 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
@ -267,12 +267,10 @@ public class StrBuilderTest {
|
||||||
assertEquals(33, sb.size());
|
assertEquals(33, sb.size());
|
||||||
assertTrue(sb.isEmpty() == false);
|
assertTrue(sb.isEmpty() == false);
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.setLength(-1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("setLength(-1) expected StringIndexOutOfBoundsException");
|
() -> sb.setLength(-1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"setLength(-1) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.setLength(33);
|
sb.setLength(33);
|
||||||
assertEquals(33, sb.capacity());
|
assertEquals(33, sb.capacity());
|
||||||
|
@ -322,12 +320,10 @@ public class StrBuilderTest {
|
||||||
sb.setLength(3); // lengthen
|
sb.setLength(3); // lengthen
|
||||||
assertEquals("He\0", sb.toString());
|
assertEquals("He\0", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.setLength(-1);
|
IndexOutOfBoundsException.class,
|
||||||
fail("setLength(-1) expected StringIndexOutOfBoundsException");
|
() -> sb.setLength(-1),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"setLength(-1) expected StringIndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -400,62 +396,40 @@ public class StrBuilderTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCharAt() {
|
public void testCharAt() {
|
||||||
final StrBuilder sb = new StrBuilder();
|
final StrBuilder sb = new StrBuilder();
|
||||||
try {
|
assertThrows(
|
||||||
sb.charAt(0);
|
IndexOutOfBoundsException.class, () -> sb.charAt(0), "charAt(0) expected IndexOutOfBoundsException");
|
||||||
fail("charAt(0) expected IndexOutOfBoundsException");
|
assertThrows(
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
IndexOutOfBoundsException.class, () -> sb.charAt(-1), "charAt(-1) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
sb.charAt(-1);
|
|
||||||
fail("charAt(-1) expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
sb.append("foo");
|
sb.append("foo");
|
||||||
assertEquals('f', sb.charAt(0));
|
assertEquals('f', sb.charAt(0));
|
||||||
assertEquals('o', sb.charAt(1));
|
assertEquals('o', sb.charAt(1));
|
||||||
assertEquals('o', sb.charAt(2));
|
assertEquals('o', sb.charAt(2));
|
||||||
try {
|
assertThrows(
|
||||||
sb.charAt(-1);
|
IndexOutOfBoundsException.class, () -> sb.charAt(-1), "charAt(-1) expected IndexOutOfBoundsException");
|
||||||
fail("charAt(-1) expected IndexOutOfBoundsException");
|
assertThrows(
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
IndexOutOfBoundsException.class, () -> sb.charAt(3), "charAt(3) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
sb.charAt(3);
|
|
||||||
fail("charAt(3) expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@Test
|
@Test
|
||||||
public void testSetCharAt() {
|
public void testSetCharAt() {
|
||||||
final StrBuilder sb = new StrBuilder();
|
final StrBuilder sb = new StrBuilder();
|
||||||
try {
|
assertThrows(
|
||||||
sb.setCharAt(0, 'f');
|
IndexOutOfBoundsException.class,
|
||||||
fail("setCharAt(0,) expected IndexOutOfBoundsException");
|
() -> sb.setCharAt(0, 'f'),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"setCharAt(0,) expected IndexOutOfBoundsException");
|
||||||
// expected
|
assertThrows(
|
||||||
}
|
IndexOutOfBoundsException.class,
|
||||||
try {
|
() -> sb.setCharAt(-1, 'f'),
|
||||||
sb.setCharAt(-1, 'f');
|
"setCharAt(-1,) expected IndexOutOfBoundsException");
|
||||||
fail("setCharAt(-1,) expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
sb.append("foo");
|
sb.append("foo");
|
||||||
sb.setCharAt(0, 'b');
|
sb.setCharAt(0, 'b');
|
||||||
sb.setCharAt(1, 'a');
|
sb.setCharAt(1, 'a');
|
||||||
sb.setCharAt(2, 'r');
|
sb.setCharAt(2, 'r');
|
||||||
try {
|
assertThrows(
|
||||||
sb.setCharAt(3, '!');
|
IndexOutOfBoundsException.class,
|
||||||
fail("setCharAt(3,) expected IndexOutOfBoundsException");
|
() -> sb.setCharAt(3, '!'),
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
"setCharAt(3,) expected IndexOutOfBoundsException");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertEquals("bar", sb.toString());
|
assertEquals("bar", sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,10 +440,7 @@ public class StrBuilderTest {
|
||||||
sb.deleteCharAt(0);
|
sb.deleteCharAt(0);
|
||||||
assertEquals("bc", sb.toString());
|
assertEquals("bc", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.deleteCharAt(1000));
|
||||||
sb.deleteCharAt(1000);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -509,17 +480,11 @@ public class StrBuilderTest {
|
||||||
a = sb.toCharArray(0, 1);
|
a = sb.toCharArray(0, 1);
|
||||||
assertNotNull(a, "toCharArray(int,int) result is null");
|
assertNotNull(a, "toCharArray(int,int) result is null");
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.toCharArray(-1, 5);
|
IndexOutOfBoundsException.class, () -> sb.toCharArray(-1, 5), "no string index out of bound on -1");
|
||||||
fail("no string index out of bound on -1");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
sb.toCharArray(6, 5);
|
IndexOutOfBoundsException.class, () -> sb.toCharArray(6, 5), "no string index out of bound on -1");
|
||||||
fail("no string index out of bound on -1");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -559,33 +524,14 @@ public class StrBuilderTest {
|
||||||
sb.getChars(0,5,a,0);
|
sb.getChars(0,5,a,0);
|
||||||
assertTrue(Arrays.equals(new char[] {'j','u','n','i','t'},a));
|
assertTrue(Arrays.equals(new char[] {'j','u','n','i','t'},a));
|
||||||
|
|
||||||
a = new char[5];
|
final char[] b = new char[5];
|
||||||
sb.getChars(0,2,a,3);
|
sb.getChars(0,2,b,3);
|
||||||
assertTrue(Arrays.equals(new char[] {0,0,0,'j','u'},a));
|
assertTrue(Arrays.equals(new char[] {0,0,0,'j','u'},b));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.getChars(-1,0,b,0));
|
||||||
sb.getChars(-1,0,a,0);
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.getChars(0,-1,b,0));
|
||||||
fail("no exception");
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.getChars(0,20,b,0));
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.getChars(4,2,b,0));
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
sb.getChars(0,-1,a,0);
|
|
||||||
fail("no exception");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
sb.getChars(0,20,a,0);
|
|
||||||
fail("no exception");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
sb.getChars(4,2,a,0);
|
|
||||||
fail("no exception");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -601,20 +547,9 @@ public class StrBuilderTest {
|
||||||
sb.delete(0, 1000);
|
sb.delete(0, 1000);
|
||||||
assertEquals("", sb.toString());
|
assertEquals("", sb.toString());
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.delete(1, 2));
|
||||||
sb.delete(1, 2);
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.delete(-1, 1));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
assertThrows(IndexOutOfBoundsException.class, () -> new StrBuilder("anything").delete(2, 1));
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
sb.delete(-1, 1);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
sb = new StrBuilder("anything");
|
|
||||||
try {
|
|
||||||
sb.delete(2, 1);
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -757,23 +692,14 @@ public class StrBuilderTest {
|
||||||
sb.replace(0, 1000, "text");
|
sb.replace(0, 1000, "text");
|
||||||
assertEquals("text", sb.toString());
|
assertEquals("text", sb.toString());
|
||||||
|
|
||||||
sb = new StrBuilder("atext");
|
StrBuilder sb1 = new StrBuilder("atext");
|
||||||
sb.replace(1, 1, "ny");
|
sb1.replace(1, 1, "ny");
|
||||||
assertEquals("anytext", sb.toString());
|
assertEquals("anytext", sb1.toString());
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb1.replace(2, 1, "anything"));
|
||||||
sb.replace(2, 1, "anything");
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
sb = new StrBuilder();
|
StrBuilder sb2 = new StrBuilder();
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb2.replace(1, 2, "anything"));
|
||||||
sb.replace(1, 2, "anything");
|
assertThrows(IndexOutOfBoundsException.class, () -> sb2.replace(-1, 1, "anything"));
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
try {
|
|
||||||
sb.replace(-1, 1, "anything");
|
|
||||||
fail("Expected IndexOutOfBoundsException");
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -1033,19 +959,17 @@ public class StrBuilderTest {
|
||||||
sb.replace(StrMatcher.stringMatcher("aa"), "-", 10, sb.length(), -1);
|
sb.replace(StrMatcher.stringMatcher("aa"), "-", 10, sb.length(), -1);
|
||||||
assertEquals("aaxaaaayaa", sb.toString());
|
assertEquals("aaxaaaayaa", sb.toString());
|
||||||
|
|
||||||
sb = new StrBuilder("aaxaaaayaa");
|
StrBuilder sb1 = new StrBuilder("aaxaaaayaa");
|
||||||
try {
|
assertThrows(
|
||||||
sb.replace(StrMatcher.stringMatcher("aa"), "-", 11, sb.length(), -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail();
|
() -> sb1.replace(StrMatcher.stringMatcher("aa"), "-", 11, sb1.length(), -1));
|
||||||
} catch (final IndexOutOfBoundsException ex) {}
|
assertEquals("aaxaaaayaa", sb1.toString());
|
||||||
assertEquals("aaxaaaayaa", sb.toString());
|
|
||||||
|
|
||||||
sb = new StrBuilder("aaxaaaayaa");
|
StrBuilder sb2 = new StrBuilder("aaxaaaayaa");
|
||||||
try {
|
assertThrows(
|
||||||
sb.replace(StrMatcher.stringMatcher("aa"), "-", -1, sb.length(), -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail();
|
() -> sb2.replace(StrMatcher.stringMatcher("aa"), "-", -1, sb2.length(), -1));
|
||||||
} catch (final IndexOutOfBoundsException ex) {}
|
assertEquals("aaxaaaayaa", sb2.toString());
|
||||||
assertEquals("aaxaaaayaa", sb.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1094,12 +1018,11 @@ public class StrBuilderTest {
|
||||||
sb.replace(StrMatcher.stringMatcher("aa"), "-", 0, 1000, -1);
|
sb.replace(StrMatcher.stringMatcher("aa"), "-", 0, 1000, -1);
|
||||||
assertEquals("-x--y-", sb.toString());
|
assertEquals("-x--y-", sb.toString());
|
||||||
|
|
||||||
sb = new StrBuilder("aaxaaaayaa");
|
StrBuilder sb1 = new StrBuilder("aaxaaaayaa");
|
||||||
try {
|
assertThrows(
|
||||||
sb.replace(StrMatcher.stringMatcher("aa"), "-", 2, 1, -1);
|
IndexOutOfBoundsException.class,
|
||||||
fail();
|
() -> sb1.replace(StrMatcher.stringMatcher("aa"), "-", 2, 1, -1));
|
||||||
} catch (final IndexOutOfBoundsException ex) {}
|
assertEquals("aaxaaaayaa", sb1.toString());
|
||||||
assertEquals("aaxaaaayaa", sb.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1202,28 +1125,16 @@ public class StrBuilderTest {
|
||||||
public void testSubSequenceIntInt() {
|
public void testSubSequenceIntInt() {
|
||||||
final StrBuilder sb = new StrBuilder ("hello goodbye");
|
final StrBuilder sb = new StrBuilder ("hello goodbye");
|
||||||
// Start index is negative
|
// Start index is negative
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.subSequence(-1, 5));
|
||||||
sb.subSequence(-1, 5);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
// End index is negative
|
// End index is negative
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.subSequence(2, -1));
|
||||||
sb.subSequence(2, -1);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
// End index greater than length()
|
// End index greater than length()
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.subSequence(2, sb.length() + 1));
|
||||||
sb.subSequence(2, sb.length() + 1);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
// Start index greater then end index
|
// Start index greater then end index
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.subSequence(3, 2));
|
||||||
sb.subSequence(3, 2);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
// Normal cases
|
// Normal cases
|
||||||
assertEquals ("hello", sb.subSequence(0, 5));
|
assertEquals ("hello", sb.subSequence(0, 5));
|
||||||
|
@ -1239,16 +1150,9 @@ public class StrBuilderTest {
|
||||||
assertEquals ("hello goodbye".substring(6), sb.substring(6));
|
assertEquals ("hello goodbye".substring(6), sb.substring(6));
|
||||||
assertEquals ("hello goodbye", sb.substring(0));
|
assertEquals ("hello goodbye", sb.substring(0));
|
||||||
assertEquals ("hello goodbye".substring(0), sb.substring(0));
|
assertEquals ("hello goodbye".substring(0), sb.substring(0));
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.substring(-1));
|
||||||
sb.substring(-1);
|
|
||||||
fail ();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
sb.substring(15);
|
|
||||||
fail ();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.substring(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1262,15 +1166,8 @@ public class StrBuilderTest {
|
||||||
|
|
||||||
assertEquals ("goodbye", sb.substring(6, 20));
|
assertEquals ("goodbye", sb.substring(6, 20));
|
||||||
|
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.substring(-1, 5));
|
||||||
sb.substring(-1, 5);
|
assertThrows(IndexOutOfBoundsException.class, () -> sb.substring(15, 20));
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
sb.substring(15, 20);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException e) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@ -1736,40 +1633,25 @@ public class StrBuilderTest {
|
||||||
reader.close();
|
reader.close();
|
||||||
assertTrue(reader.ready());
|
assertTrue(reader.ready());
|
||||||
|
|
||||||
reader = sb.asReader();
|
final Reader r = sb.asReader();
|
||||||
array = new char[3];
|
final char[] arr = new char[3];
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> r.read(arr, -1, 0));
|
||||||
reader.read(array, -1, 0);
|
assertThrows(IndexOutOfBoundsException.class, () -> r.read(arr, 0, -1));
|
||||||
fail();
|
assertThrows(IndexOutOfBoundsException.class, () -> r.read(arr, 100, 1));
|
||||||
} catch (final IndexOutOfBoundsException ex) {}
|
assertThrows(IndexOutOfBoundsException.class, () -> r.read(arr, 0, 100));
|
||||||
try {
|
assertThrows(IndexOutOfBoundsException.class, () -> r.read(arr, Integer.MAX_VALUE, Integer.MAX_VALUE));
|
||||||
reader.read(array, 0, -1);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException ex) {}
|
|
||||||
try {
|
|
||||||
reader.read(array, 100, 1);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException ex) {}
|
|
||||||
try {
|
|
||||||
reader.read(array, 0, 100);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException ex) {}
|
|
||||||
try {
|
|
||||||
reader.read(array, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
|
||||||
fail();
|
|
||||||
} catch (final IndexOutOfBoundsException ex) {}
|
|
||||||
|
|
||||||
assertEquals(0, reader.read(array, 0, 0));
|
assertEquals(0, r.read(arr, 0, 0));
|
||||||
assertEquals(0, array[0]);
|
assertEquals(0, arr[0]);
|
||||||
assertEquals(0, array[1]);
|
assertEquals(0, arr[1]);
|
||||||
assertEquals(0, array[2]);
|
assertEquals(0, arr[2]);
|
||||||
|
|
||||||
reader.skip(9);
|
r.skip(9);
|
||||||
assertEquals(-1, reader.read(array, 0, 1));
|
assertEquals(-1, r.read(arr, 0, 1));
|
||||||
|
|
||||||
reader.reset();
|
r.reset();
|
||||||
array = new char[30];
|
array = new char[30];
|
||||||
assertEquals(9, reader.read(array, 0, 30));
|
assertEquals(9, r.read(array, 0, 30));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.commons.lang3.text;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -46,12 +46,7 @@ public class StrLookupTest {
|
||||||
assertEquals(System.getProperty("os.name"), StrLookup.systemPropertiesLookup().lookup("os.name"));
|
assertEquals(System.getProperty("os.name"), StrLookup.systemPropertiesLookup().lookup("os.name"));
|
||||||
assertNull(StrLookup.systemPropertiesLookup().lookup(""));
|
assertNull(StrLookup.systemPropertiesLookup().lookup(""));
|
||||||
assertNull(StrLookup.systemPropertiesLookup().lookup("other"));
|
assertNull(StrLookup.systemPropertiesLookup().lookup("other"));
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> StrLookup.systemPropertiesLookup().lookup(null));
|
||||||
StrLookup.systemPropertiesLookup().lookup(null);
|
|
||||||
fail();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,8 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -246,22 +246,18 @@ public class StrSubstitutorTest {
|
||||||
map.put("critterColor", "brown");
|
map.put("critterColor", "brown");
|
||||||
map.put("critterType", "${animal}");
|
map.put("critterType", "${animal}");
|
||||||
StrSubstitutor sub = new StrSubstitutor(map);
|
StrSubstitutor sub = new StrSubstitutor(map);
|
||||||
try {
|
assertThrows(
|
||||||
sub.replace("The ${animal} jumps over the ${target}.");
|
IllegalStateException.class,
|
||||||
fail("Cyclic replacement was not detected!");
|
() -> sub.replace("The ${animal} jumps over the ${target}."),
|
||||||
} catch (final IllegalStateException ex) {
|
"Cyclic replacement was not detected!");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
// also check even when default value is set.
|
// also check even when default value is set.
|
||||||
map.put("critterType", "${animal:-fox}");
|
map.put("critterType", "${animal:-fox}");
|
||||||
sub = new StrSubstitutor(map);
|
StrSubstitutor sub2 = new StrSubstitutor(map);
|
||||||
try {
|
assertThrows(
|
||||||
sub.replace("The ${animal} jumps over the ${target}.");
|
IllegalStateException.class,
|
||||||
fail("Cyclic replacement was not detected!");
|
() -> sub2.replace("The ${animal} jumps over the ${target}."),
|
||||||
} catch (final IllegalStateException ex) {
|
"Cyclic replacement was not detected!");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -477,23 +473,13 @@ public class StrSubstitutorTest {
|
||||||
|
|
||||||
sub.setVariablePrefix("<<");
|
sub.setVariablePrefix("<<");
|
||||||
assertTrue(sub.getVariablePrefixMatcher() instanceof StrMatcher.StringMatcher);
|
assertTrue(sub.getVariablePrefixMatcher() instanceof StrMatcher.StringMatcher);
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> sub.setVariablePrefix(null));
|
||||||
sub.setVariablePrefix(null);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertTrue(sub.getVariablePrefixMatcher() instanceof StrMatcher.StringMatcher);
|
assertTrue(sub.getVariablePrefixMatcher() instanceof StrMatcher.StringMatcher);
|
||||||
|
|
||||||
final StrMatcher matcher = StrMatcher.commaMatcher();
|
final StrMatcher matcher = StrMatcher.commaMatcher();
|
||||||
sub.setVariablePrefixMatcher(matcher);
|
sub.setVariablePrefixMatcher(matcher);
|
||||||
assertSame(matcher, sub.getVariablePrefixMatcher());
|
assertSame(matcher, sub.getVariablePrefixMatcher());
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> sub.setVariablePrefixMatcher(null));
|
||||||
sub.setVariablePrefixMatcher(null);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertSame(matcher, sub.getVariablePrefixMatcher());
|
assertSame(matcher, sub.getVariablePrefixMatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,23 +495,13 @@ public class StrSubstitutorTest {
|
||||||
|
|
||||||
sub.setVariableSuffix("<<");
|
sub.setVariableSuffix("<<");
|
||||||
assertTrue(sub.getVariableSuffixMatcher() instanceof StrMatcher.StringMatcher);
|
assertTrue(sub.getVariableSuffixMatcher() instanceof StrMatcher.StringMatcher);
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> sub.setVariableSuffix(null));
|
||||||
sub.setVariableSuffix(null);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertTrue(sub.getVariableSuffixMatcher() instanceof StrMatcher.StringMatcher);
|
assertTrue(sub.getVariableSuffixMatcher() instanceof StrMatcher.StringMatcher);
|
||||||
|
|
||||||
final StrMatcher matcher = StrMatcher.commaMatcher();
|
final StrMatcher matcher = StrMatcher.commaMatcher();
|
||||||
sub.setVariableSuffixMatcher(matcher);
|
sub.setVariableSuffixMatcher(matcher);
|
||||||
assertSame(matcher, sub.getVariableSuffixMatcher());
|
assertSame(matcher, sub.getVariableSuffixMatcher());
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> sub.setVariableSuffixMatcher(null));
|
||||||
sub.setVariableSuffixMatcher(null);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertSame(matcher, sub.getVariableSuffixMatcher());
|
assertSame(matcher, sub.getVariableSuffixMatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -541,10 +541,7 @@ public class StrTokenizerTest {
|
||||||
assertFalse(tokenizer.hasPrevious());
|
assertFalse(tokenizer.hasPrevious());
|
||||||
assertNull(tokenizer.nextToken());
|
assertNull(tokenizer.nextToken());
|
||||||
assertEquals(0, tokenizer.size());
|
assertEquals(0, tokenizer.size());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, tokenizer::next);
|
||||||
tokenizer.next();
|
|
||||||
fail();
|
|
||||||
} catch (final NoSuchElementException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -805,25 +802,13 @@ public class StrTokenizerTest {
|
||||||
public void testIteration() {
|
public void testIteration() {
|
||||||
final StrTokenizer tkn = new StrTokenizer("a b c");
|
final StrTokenizer tkn = new StrTokenizer("a b c");
|
||||||
assertFalse(tkn.hasPrevious());
|
assertFalse(tkn.hasPrevious());
|
||||||
try {
|
assertThrows(NoSuchElementException.class, tkn::previous);
|
||||||
tkn.previous();
|
|
||||||
fail();
|
|
||||||
} catch (final NoSuchElementException ex) {}
|
|
||||||
assertTrue(tkn.hasNext());
|
assertTrue(tkn.hasNext());
|
||||||
|
|
||||||
assertEquals("a", tkn.next());
|
assertEquals("a", tkn.next());
|
||||||
try {
|
assertThrows(UnsupportedOperationException.class, tkn::remove);
|
||||||
tkn.remove();
|
assertThrows(UnsupportedOperationException.class, () -> tkn.set("x"));
|
||||||
fail();
|
assertThrows(UnsupportedOperationException.class, () -> tkn.add("y"));
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
try {
|
|
||||||
tkn.set("x");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
try {
|
|
||||||
tkn.add("y");
|
|
||||||
fail();
|
|
||||||
} catch (final UnsupportedOperationException ex) {}
|
|
||||||
assertTrue(tkn.hasPrevious());
|
assertTrue(tkn.hasPrevious());
|
||||||
assertTrue(tkn.hasNext());
|
assertTrue(tkn.hasNext());
|
||||||
|
|
||||||
|
@ -835,10 +820,7 @@ public class StrTokenizerTest {
|
||||||
assertTrue(tkn.hasPrevious());
|
assertTrue(tkn.hasPrevious());
|
||||||
assertFalse(tkn.hasNext());
|
assertFalse(tkn.hasNext());
|
||||||
|
|
||||||
try {
|
assertThrows(NoSuchElementException.class, tkn::next);
|
||||||
tkn.next();
|
|
||||||
fail();
|
|
||||||
} catch (final NoSuchElementException ex) {}
|
|
||||||
assertTrue(tkn.hasPrevious());
|
assertTrue(tkn.hasPrevious());
|
||||||
assertFalse(tkn.hasNext());
|
assertFalse(tkn.hasNext());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
package org.apache.commons.lang3.text.translate;
|
package org.apache.commons.lang3.text.translate;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -67,15 +67,10 @@ public class NumericEntityUnescaperTest {
|
||||||
assertEquals(expected, result, "Failed to ignore unfinished entities (i.e. missing semi-colon)");
|
assertEquals(expected, result, "Failed to ignore unfinished entities (i.e. missing semi-colon)");
|
||||||
|
|
||||||
// fail it
|
// fail it
|
||||||
neu = new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.errorIfNoSemiColon);
|
final NumericEntityUnescaper failingNeu =
|
||||||
input = "Test 0 not test";
|
new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.errorIfNoSemiColon);
|
||||||
|
final String failingInput = "Test 0 not test";
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> failingNeu.translate(failingInput));
|
||||||
result = neu.translate(input);
|
|
||||||
fail("IllegalArgumentException expected");
|
|
||||||
} catch(final IllegalArgumentException iae) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
package org.apache.commons.lang3.text.translate;
|
package org.apache.commons.lang3.text.translate;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -51,11 +51,9 @@ public class UnicodeUnescaperTest {
|
||||||
final UnicodeUnescaper uu = new UnicodeUnescaper();
|
final UnicodeUnescaper uu = new UnicodeUnescaper();
|
||||||
|
|
||||||
final String input = "\\0047\\u006";
|
final String input = "\\0047\\u006";
|
||||||
try {
|
assertThrows(
|
||||||
uu.translate(input);
|
IllegalArgumentException.class,
|
||||||
fail("A lack of digits in a Unicode escape sequence failed to throw an exception");
|
() -> uu.translate(input),
|
||||||
} catch(final IllegalArgumentException iae) {
|
"A lack of digits in a Unicode escape sequence failed to throw an exception");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -47,114 +48,66 @@ public class DateUtilsFragmentTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullDate() {
|
public void testNullDate() {
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInSeconds((Date) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInSeconds((Date) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInMinutes((Date) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInMinutes((Date) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInHours((Date) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInHours((Date) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInDays((Date) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInDays((Date) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullCalendar() {
|
public void testNullCalendar() {
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInSeconds((Calendar) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInSeconds((Calendar) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInMinutes((Calendar) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInMinutes((Calendar) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInHours((Calendar) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInHours((Calendar) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.getFragmentInDays((Calendar) null, Calendar.MILLISECOND);
|
IllegalArgumentException.class,
|
||||||
fail();
|
() -> DateUtils.getFragmentInDays((Calendar) null, Calendar.MILLISECOND));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidFragmentWithDate() {
|
public void testInvalidFragmentWithDate() {
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInMilliseconds(aDate, 0));
|
||||||
DateUtils.getFragmentInMilliseconds(aDate, 0);
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInSeconds(aDate, 0));
|
||||||
fail();
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInMinutes(aDate, 0));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInHours(aDate, 0));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInDays(aDate, 0));
|
||||||
try {
|
|
||||||
DateUtils.getFragmentInSeconds(aDate, 0);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DateUtils.getFragmentInMinutes(aDate, 0);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DateUtils.getFragmentInHours(aDate, 0);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DateUtils.getFragmentInDays(aDate, 0);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidFragmentWithCalendar() {
|
public void testInvalidFragmentWithCalendar() {
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInMilliseconds(aCalendar, 0));
|
||||||
DateUtils.getFragmentInMilliseconds(aCalendar, 0);
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInSeconds(aCalendar, 0));
|
||||||
fail();
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInMinutes(aCalendar, 0));
|
||||||
} catch(final IllegalArgumentException iae) {}
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInHours(aCalendar, 0));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.getFragmentInDays(aCalendar, 0));
|
||||||
try {
|
|
||||||
DateUtils.getFragmentInSeconds(aCalendar, 0);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DateUtils.getFragmentInMinutes(aCalendar, 0);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DateUtils.getFragmentInHours(aCalendar, 0);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DateUtils.getFragmentInDays(aCalendar, 0);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException iae) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
@ -366,10 +365,7 @@ public class DateUtilsTest {
|
||||||
final Date date = DateUtils.parseDate(dateStr, parsers);
|
final Date date = DateUtils.parseDate(dateStr, parsers);
|
||||||
assertEquals(cal.getTime(), date);
|
assertEquals(cal.getTime(), date);
|
||||||
|
|
||||||
try {
|
assertThrows(ParseException.class, () -> DateUtils.parseDateStrictly(dateStr, parsers));
|
||||||
DateUtils.parseDateStrictly(dateStr, parsers);
|
|
||||||
fail();
|
|
||||||
} catch (final ParseException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -556,12 +552,10 @@ public class DateUtilsTest {
|
||||||
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
||||||
assertDate(result, 2000, 1, 5, 4, 3, 2, 1);
|
assertDate(result, 2000, 1, 5, 4, 3, 2, 1);
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.setMonths(BASE_DATE, 12);
|
IllegalArgumentException.class,
|
||||||
fail("DateUtils.setMonths did not throw an expected IllegalArgumentException.");
|
() -> DateUtils.setMonths(BASE_DATE, 12),
|
||||||
} catch (final IllegalArgumentException e) {
|
"DateUtils.setMonths did not throw an expected IllegalArgumentException.");
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@ -577,12 +571,10 @@ public class DateUtilsTest {
|
||||||
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
||||||
assertDate(result, 2000, 6, 29, 4, 3, 2, 1);
|
assertDate(result, 2000, 6, 29, 4, 3, 2, 1);
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.setDays(BASE_DATE, 32);
|
IllegalArgumentException.class,
|
||||||
fail("DateUtils.setDays did not throw an expected IllegalArgumentException.");
|
() -> DateUtils.setDays(BASE_DATE, 32),
|
||||||
} catch (final IllegalArgumentException e) {
|
"DateUtils.setDays did not throw an expected IllegalArgumentException.");
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@ -598,12 +590,10 @@ public class DateUtilsTest {
|
||||||
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
||||||
assertDate(result, 2000, 6, 5, 23, 3, 2, 1);
|
assertDate(result, 2000, 6, 5, 23, 3, 2, 1);
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.setHours(BASE_DATE, 24);
|
IllegalArgumentException.class,
|
||||||
fail("DateUtils.setHours did not throw an expected IllegalArgumentException.");
|
() -> DateUtils.setHours(BASE_DATE, 24),
|
||||||
} catch (final IllegalArgumentException e) {
|
"DateUtils.setHours did not throw an expected IllegalArgumentException.");
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@ -619,12 +609,10 @@ public class DateUtilsTest {
|
||||||
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
||||||
assertDate(result, 2000, 6, 5, 4, 59, 2, 1);
|
assertDate(result, 2000, 6, 5, 4, 59, 2, 1);
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.setMinutes(BASE_DATE, 60);
|
IllegalArgumentException.class,
|
||||||
fail("DateUtils.setMinutes did not throw an expected IllegalArgumentException.");
|
() -> DateUtils.setMinutes(BASE_DATE, 60),
|
||||||
} catch (final IllegalArgumentException e) {
|
"DateUtils.setMinutes did not throw an expected IllegalArgumentException.");
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@ -640,12 +628,10 @@ public class DateUtilsTest {
|
||||||
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
||||||
assertDate(result, 2000, 6, 5, 4, 3, 59, 1);
|
assertDate(result, 2000, 6, 5, 4, 3, 59, 1);
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.setSeconds(BASE_DATE, 60);
|
IllegalArgumentException.class,
|
||||||
fail("DateUtils.setSeconds did not throw an expected IllegalArgumentException.");
|
() -> DateUtils.setSeconds(BASE_DATE, 60),
|
||||||
} catch (final IllegalArgumentException e) {
|
"DateUtils.setSeconds did not throw an expected IllegalArgumentException.");
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@ -661,12 +647,10 @@ public class DateUtilsTest {
|
||||||
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1);
|
||||||
assertDate(result, 2000, 6, 5, 4, 3, 2, 999);
|
assertDate(result, 2000, 6, 5, 4, 3, 2, 999);
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
DateUtils.setMilliseconds(BASE_DATE, 1000);
|
IllegalArgumentException.class,
|
||||||
fail("DateUtils.setMilliseconds did not throw an expected IllegalArgumentException.");
|
() -> DateUtils.setMilliseconds(BASE_DATE, 1000),
|
||||||
} catch (final IllegalArgumentException e) {
|
"DateUtils.setMilliseconds did not throw an expected IllegalArgumentException.");
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -686,12 +670,7 @@ public class DateUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testToCalendar() {
|
public void testToCalendar() {
|
||||||
assertEquals(date1, DateUtils.toCalendar(date1).getTime(), "Failed to convert to a Calendar and back");
|
assertEquals(date1, DateUtils.toCalendar(date1).getTime(), "Failed to convert to a Calendar and back");
|
||||||
try {
|
assertThrows(NullPointerException.class, () -> DateUtils.toCalendar(null));
|
||||||
DateUtils.toCalendar(null);
|
|
||||||
fail("Expected NullPointerException to be thrown");
|
|
||||||
} catch(final NullPointerException npe) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -851,26 +830,11 @@ public class DateUtilsTest {
|
||||||
DateUtils.round((Object) dateAmPm4, Calendar.AM_PM),
|
DateUtils.round((Object) dateAmPm4, Calendar.AM_PM),
|
||||||
"round ampm-4 failed");
|
"round ampm-4 failed");
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.round((Date) null, Calendar.SECOND));
|
||||||
DateUtils.round((Date) null, Calendar.SECOND);
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.round((Calendar) null, Calendar.SECOND));
|
||||||
fail();
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.round((Object) null, Calendar.SECOND));
|
||||||
} catch (final IllegalArgumentException ex) {}
|
assertThrows(ClassCastException.class, () -> DateUtils.round("", Calendar.SECOND));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.round(date1, -9999));
|
||||||
DateUtils.round((Calendar) null, Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.round((Object) null, Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.round("", Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final ClassCastException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.round(date1, -9999);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException ex) {}
|
|
||||||
|
|
||||||
assertEquals(dateTimeParser.parse("February 3, 2002 00:00:00.000"),
|
assertEquals(dateTimeParser.parse("February 3, 2002 00:00:00.000"),
|
||||||
DateUtils.round((Object) calAmPm1, Calendar.AM_PM),
|
DateUtils.round((Object) calAmPm1, Calendar.AM_PM),
|
||||||
|
@ -1147,22 +1111,10 @@ public class DateUtilsTest {
|
||||||
DateUtils.truncate((Object) calAmPm4, Calendar.AM_PM),
|
DateUtils.truncate((Object) calAmPm4, Calendar.AM_PM),
|
||||||
"truncate ampm-4 failed");
|
"truncate ampm-4 failed");
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.truncate((Date) null, Calendar.SECOND));
|
||||||
DateUtils.truncate((Date) null, Calendar.SECOND);
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.truncate((Calendar) null, Calendar.SECOND));
|
||||||
fail();
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.truncate((Object) null, Calendar.SECOND));
|
||||||
} catch (final IllegalArgumentException ex) {}
|
assertThrows(ClassCastException.class, () -> DateUtils.truncate("", Calendar.SECOND));
|
||||||
try {
|
|
||||||
DateUtils.truncate((Calendar) null, Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.truncate((Object) null, Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.truncate("", Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final ClassCastException ex) {}
|
|
||||||
|
|
||||||
// Fix for http://issues.apache.org/bugzilla/show_bug.cgi?id=25560
|
// Fix for http://issues.apache.org/bugzilla/show_bug.cgi?id=25560
|
||||||
// Test truncate across beginning of daylight saving time
|
// Test truncate across beginning of daylight saving time
|
||||||
|
@ -1191,15 +1143,9 @@ public class DateUtilsTest {
|
||||||
final Date endOfTime = new Date(Long.MAX_VALUE); // fyi: Sun Aug 17 07:12:55 CET 292278994 -- 807 millis
|
final Date endOfTime = new Date(Long.MAX_VALUE); // fyi: Sun Aug 17 07:12:55 CET 292278994 -- 807 millis
|
||||||
final GregorianCalendar endCal = new GregorianCalendar();
|
final GregorianCalendar endCal = new GregorianCalendar();
|
||||||
endCal.setTime(endOfTime);
|
endCal.setTime(endOfTime);
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> DateUtils.truncate(endCal, Calendar.DATE));
|
||||||
DateUtils.truncate(endCal, Calendar.DATE);
|
|
||||||
fail();
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
endCal.set(Calendar.YEAR, 280000001);
|
endCal.set(Calendar.YEAR, 280000001);
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> DateUtils.truncate(endCal, Calendar.DATE));
|
||||||
DateUtils.truncate(endCal, Calendar.DATE);
|
|
||||||
fail();
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
endCal.set(Calendar.YEAR, 280000000);
|
endCal.set(Calendar.YEAR, 280000000);
|
||||||
final Calendar cal = DateUtils.truncate(endCal, Calendar.DATE);
|
final Calendar cal = DateUtils.truncate(endCal, Calendar.DATE);
|
||||||
assertEquals(0, cal.get(Calendar.HOUR));
|
assertEquals(0, cal.get(Calendar.HOUR));
|
||||||
|
@ -1445,27 +1391,11 @@ public class DateUtilsTest {
|
||||||
DateUtils.ceiling((Object) calAmPm4, Calendar.AM_PM),
|
DateUtils.ceiling((Object) calAmPm4, Calendar.AM_PM),
|
||||||
"ceiling ampm-4 failed");
|
"ceiling ampm-4 failed");
|
||||||
|
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.ceiling((Date) null, Calendar.SECOND));
|
||||||
DateUtils.ceiling((Date) null, Calendar.SECOND);
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.ceiling((Calendar) null, Calendar.SECOND));
|
||||||
fail();
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.ceiling((Object) null, Calendar.SECOND));
|
||||||
} catch (final IllegalArgumentException ex) {}
|
assertThrows(ClassCastException.class, () -> DateUtils.ceiling("", Calendar.SECOND));
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.ceiling(date1, -9999));
|
||||||
DateUtils.ceiling((Calendar) null, Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.ceiling((Object) null, Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.ceiling("", Calendar.SECOND);
|
|
||||||
fail();
|
|
||||||
} catch (final ClassCastException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.ceiling(date1, -9999);
|
|
||||||
fail();
|
|
||||||
} catch(final IllegalArgumentException ex) {}
|
|
||||||
|
|
||||||
|
|
||||||
// Fix for http://issues.apache.org/bugzilla/show_bug.cgi?id=25560
|
// Fix for http://issues.apache.org/bugzilla/show_bug.cgi?id=25560
|
||||||
// Test ceiling across the beginning of daylight saving time
|
// Test ceiling across the beginning of daylight saving time
|
||||||
|
@ -1532,15 +1462,9 @@ public class DateUtilsTest {
|
||||||
final Date endOfTime = new Date(Long.MAX_VALUE); // fyi: Sun Aug 17 07:12:55 CET 292278994 -- 807 millis
|
final Date endOfTime = new Date(Long.MAX_VALUE); // fyi: Sun Aug 17 07:12:55 CET 292278994 -- 807 millis
|
||||||
final GregorianCalendar endCal = new GregorianCalendar();
|
final GregorianCalendar endCal = new GregorianCalendar();
|
||||||
endCal.setTime(endOfTime);
|
endCal.setTime(endOfTime);
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> DateUtils.ceiling(endCal, Calendar.DATE));
|
||||||
DateUtils.ceiling(endCal, Calendar.DATE);
|
|
||||||
fail();
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
endCal.set(Calendar.YEAR, 280000001);
|
endCal.set(Calendar.YEAR, 280000001);
|
||||||
try {
|
assertThrows(ArithmeticException.class, () -> DateUtils.ceiling(endCal, Calendar.DATE));
|
||||||
DateUtils.ceiling(endCal, Calendar.DATE);
|
|
||||||
fail();
|
|
||||||
} catch (final ArithmeticException ex) {}
|
|
||||||
endCal.set(Calendar.YEAR, 280000000);
|
endCal.set(Calendar.YEAR, 280000000);
|
||||||
final Calendar cal = DateUtils.ceiling(endCal, Calendar.DATE);
|
final Calendar cal = DateUtils.ceiling(endCal, Calendar.DATE);
|
||||||
assertEquals(0, cal.get(Calendar.HOUR));
|
assertEquals(0, cal.get(Calendar.HOUR));
|
||||||
|
@ -1553,25 +1477,14 @@ public class DateUtilsTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIteratorEx() throws Exception {
|
public void testIteratorEx() throws Exception {
|
||||||
try {
|
assertThrows(IllegalArgumentException.class, () -> DateUtils.iterator(Calendar.getInstance(), -9999));
|
||||||
DateUtils.iterator(Calendar.getInstance(), -9999);
|
assertThrows
|
||||||
} catch (final IllegalArgumentException ex) {}
|
(IllegalArgumentException.class, () -> DateUtils.iterator((Date) null, DateUtils.RANGE_WEEK_CENTER));
|
||||||
try {
|
assertThrows
|
||||||
DateUtils.iterator((Date) null, DateUtils.RANGE_WEEK_CENTER);
|
(IllegalArgumentException.class, () -> DateUtils.iterator((Calendar) null, DateUtils.RANGE_WEEK_CENTER));
|
||||||
fail();
|
assertThrows
|
||||||
} catch (final IllegalArgumentException ex) {}
|
(IllegalArgumentException.class, () -> DateUtils.iterator((Object) null, DateUtils.RANGE_WEEK_CENTER));
|
||||||
try {
|
assertThrows(ClassCastException.class, () -> DateUtils.iterator("", DateUtils.RANGE_WEEK_CENTER));
|
||||||
DateUtils.iterator((Calendar) null, DateUtils.RANGE_WEEK_CENTER);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.iterator((Object) null, DateUtils.RANGE_WEEK_CENTER);
|
|
||||||
fail();
|
|
||||||
} catch (final IllegalArgumentException ex) {}
|
|
||||||
try {
|
|
||||||
DateUtils.iterator("", DateUtils.RANGE_WEEK_CENTER);
|
|
||||||
fail();
|
|
||||||
} catch (final ClassCastException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1607,17 +1520,12 @@ public class DateUtilsTest {
|
||||||
|
|
||||||
it = DateUtils.iterator((Object) now, DateUtils.RANGE_WEEK_CENTER);
|
it = DateUtils.iterator((Object) now, DateUtils.RANGE_WEEK_CENTER);
|
||||||
assertWeekIterator(it, centered);
|
assertWeekIterator(it, centered);
|
||||||
it = DateUtils.iterator((Object) now.getTime(), DateUtils.RANGE_WEEK_CENTER);
|
Iterator<?> it2 = DateUtils.iterator((Object) now.getTime(), DateUtils.RANGE_WEEK_CENTER);
|
||||||
assertWeekIterator(it, centered);
|
assertWeekIterator(it2, centered);
|
||||||
try {
|
assertThrows(NoSuchElementException.class, it2::next);
|
||||||
it.next();
|
Iterator<?> it3 = DateUtils.iterator(now, DateUtils.RANGE_WEEK_CENTER);
|
||||||
fail();
|
it3.next();
|
||||||
} catch (final NoSuchElementException ex) {}
|
assertThrows(UnsupportedOperationException.class, it3::remove);
|
||||||
it = DateUtils.iterator(now, DateUtils.RANGE_WEEK_CENTER);
|
|
||||||
it.next();
|
|
||||||
try {
|
|
||||||
it.remove();
|
|
||||||
} catch( final UnsupportedOperationException ex) {}
|
|
||||||
|
|
||||||
now.add(Calendar.DATE,1);
|
now.add(Calendar.DATE,1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,34 +335,27 @@ public class FastDateParserTest {
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
|
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
|
||||||
final DateParser fdf = getInstance(format, locale);
|
final DateParser fdf = getInstance(format, locale);
|
||||||
|
|
||||||
try {
|
// If parsing fails, a ParseException will be thrown and the test will fail
|
||||||
checkParse(locale, cal, sdf, fdf);
|
checkParse(locale, cal, sdf, fdf);
|
||||||
} catch(final ParseException ex) {
|
|
||||||
fail("Locale "+locale+ " failed with "+format+" era "+(eraBC?"BC":"AD")+"\n" + trimMessage(ex.toString()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJpLocales() {
|
public void testJpLocales() throws ParseException {
|
||||||
|
|
||||||
final Calendar cal= Calendar.getInstance(GMT);
|
final Calendar cal= Calendar.getInstance(GMT);
|
||||||
cal.clear();
|
cal.clear();
|
||||||
cal.set(2003, Calendar.FEBRUARY, 10);
|
cal.set(2003, Calendar.FEBRUARY, 10);
|
||||||
cal.set(Calendar.ERA, GregorianCalendar.BC);
|
cal.set(Calendar.ERA, GregorianCalendar.BC);
|
||||||
|
|
||||||
final Locale locale = LocaleUtils.toLocale("zh"); {
|
final Locale locale = LocaleUtils.toLocale("zh");
|
||||||
// ja_JP_JP cannot handle dates before 1868 properly
|
// ja_JP_JP cannot handle dates before 1868 properly
|
||||||
|
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat(LONG_FORMAT, locale);
|
final SimpleDateFormat sdf = new SimpleDateFormat(LONG_FORMAT, locale);
|
||||||
final DateParser fdf = getInstance(LONG_FORMAT, locale);
|
final DateParser fdf = getInstance(LONG_FORMAT, locale);
|
||||||
|
|
||||||
try {
|
// If parsing fails, a ParseException will be thrown and the test will fail
|
||||||
checkParse(locale, cal, sdf, fdf);
|
checkParse(locale, cal, sdf, fdf);
|
||||||
} catch(final ParseException ex) {
|
|
||||||
fail("Locale "+locale+ " failed with "+LONG_FORMAT+"\n" + trimMessage(ex.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String trimMessage(final String msg) {
|
private String trimMessage(final String msg) {
|
||||||
|
@ -668,12 +661,7 @@ public class FastDateParserTest {
|
||||||
final TimeZone kst = TimeZone.getTimeZone("KST");
|
final TimeZone kst = TimeZone.getTimeZone("KST");
|
||||||
final DateParser fdp = getInstance("yyyyMMdd", kst, Locale.KOREA);
|
final DateParser fdp = getInstance("yyyyMMdd", kst, Locale.KOREA);
|
||||||
|
|
||||||
try {
|
assertThrows(ParseException.class, () -> fdp.parse("2015"));
|
||||||
fdp.parse("2015");
|
|
||||||
fail("expected parse exception");
|
|
||||||
} catch (final ParseException pe) {
|
|
||||||
// expected parse exception
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wed Apr 29 00:00:00 KST 2015
|
// Wed Apr 29 00:00:00 KST 2015
|
||||||
Date actual = fdp.parse("20150429");
|
Date actual = fdp.parse("20150429");
|
||||||
|
|
|
@ -27,13 +27,12 @@ import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
class FastDateParser_TimeZoneStrategyTest {
|
class FastDateParser_TimeZoneStrategyTest {
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("java.util.Locale#getAvailableLocales")
|
@MethodSource("java.util.Locale#getAvailableLocales")
|
||||||
void testTimeZoneStrategyPattern(final Locale locale) {
|
void testTimeZoneStrategyPattern(final Locale locale) throws ParseException {
|
||||||
final FastDateParser parser = new FastDateParser("z", TimeZone.getDefault(), locale);
|
final FastDateParser parser = new FastDateParser("z", TimeZone.getDefault(), locale);
|
||||||
final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
|
final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
|
||||||
for (final String[] zone : zones) {
|
for (final String[] zone : zones) {
|
||||||
|
@ -42,17 +41,8 @@ class FastDateParser_TimeZoneStrategyTest {
|
||||||
if (tzDisplay == null) {
|
if (tzDisplay == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try {
|
// An exception will be thrown and the test will fail if parsing isn't successful
|
||||||
parser.parse(tzDisplay);
|
parser.parse(tzDisplay);
|
||||||
} catch (final Exception ex) {
|
|
||||||
fail("'" + tzDisplay + "'"
|
|
||||||
+ " Locale: '" + locale.getDisplayName() + "'"
|
|
||||||
+ " TimeZone: " + zone[0]
|
|
||||||
+ " offset: " + t
|
|
||||||
+ " defaultLocale: " + Locale.getDefault()
|
|
||||||
+ " defaultTimeZone: " + TimeZone.getDefault().getDisplayName()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -167,105 +167,79 @@ public class StopWatchTest {
|
||||||
@Test
|
@Test
|
||||||
public void testBadStates() {
|
public void testBadStates() {
|
||||||
final StopWatch watch = new StopWatch();
|
final StopWatch watch = new StopWatch();
|
||||||
try {
|
assertThrows(
|
||||||
watch.stop();
|
IllegalStateException.class,
|
||||||
fail("Calling stop on an unstarted StopWatch should throw an exception. ");
|
watch::stop,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling stop on an unstarted StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.suspend();
|
IllegalStateException.class,
|
||||||
fail("Calling suspend on an unstarted StopWatch should throw an exception. ");
|
watch::suspend,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling suspend on an unstarted StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.split();
|
IllegalStateException.class,
|
||||||
fail("Calling split on a non-running StopWatch should throw an exception. ");
|
watch::split,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling split on a non-running StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.unsplit();
|
IllegalStateException.class,
|
||||||
fail("Calling unsplit on an unsplit StopWatch should throw an exception. ");
|
watch::unsplit,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling unsplit on an unsplit StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.resume();
|
IllegalStateException.class,
|
||||||
fail("Calling resume on an unsuspended StopWatch should throw an exception. ");
|
watch::resume,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling resume on an unsuspended StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
watch.start();
|
watch.start();
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.start();
|
IllegalStateException.class,
|
||||||
fail("Calling start on a started StopWatch should throw an exception. ");
|
watch::start,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling start on a started StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.unsplit();
|
IllegalStateException.class,
|
||||||
fail("Calling unsplit on an unsplit StopWatch should throw an exception. ");
|
watch::unsplit,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling unsplit on an unsplit StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.getSplitTime();
|
IllegalStateException.class,
|
||||||
fail("Calling getSplitTime on an unsplit StopWatch should throw an exception. ");
|
watch::getSplitTime,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling getSplitTime on an unsplit StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.resume();
|
IllegalStateException.class,
|
||||||
fail("Calling resume on an unsuspended StopWatch should throw an exception. ");
|
watch::resume,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling resume on an unsuspended StopWatch should throw an exception. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
watch.stop();
|
watch.stop();
|
||||||
|
|
||||||
try {
|
assertThrows(
|
||||||
watch.start();
|
IllegalStateException.class,
|
||||||
fail("Calling start on a stopped StopWatch should throw an exception as it needs to be reset. ");
|
watch::start,
|
||||||
} catch (final IllegalStateException ise) {
|
"Calling start on a stopped StopWatch should throw an exception as it needs to be reset. ");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetStartTime() {
|
public void testGetStartTime() {
|
||||||
final long beforeStopWatch = System.currentTimeMillis();
|
final long beforeStopWatch = System.currentTimeMillis();
|
||||||
final StopWatch watch = new StopWatch();
|
final StopWatch watch = new StopWatch();
|
||||||
try {
|
assertThrows(
|
||||||
watch.getStartTime();
|
IllegalStateException.class,
|
||||||
fail("Calling getStartTime on an unstarted StopWatch should throw an exception");
|
watch::getStartTime,
|
||||||
} catch (final IllegalStateException expected) {
|
"Calling getStartTime on an unstarted StopWatch should throw an exception");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
watch.start();
|
watch.start();
|
||||||
try {
|
|
||||||
watch.getStartTime();
|
watch.getStartTime();
|
||||||
assertTrue(watch.getStartTime() >= beforeStopWatch);
|
assertTrue(watch.getStartTime() >= beforeStopWatch);
|
||||||
} catch (final IllegalStateException ex) {
|
|
||||||
fail("Start time should be available: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
watch.reset();
|
watch.reset();
|
||||||
try {
|
assertThrows(
|
||||||
watch.getStartTime();
|
IllegalStateException.class,
|
||||||
fail("Calling getStartTime on a reset, but unstarted StopWatch should throw an exception");
|
watch::getStartTime,
|
||||||
} catch (final IllegalStateException expected) {
|
"Calling getStartTime on a reset, but unstarted StopWatch should throw an exception");
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue