Simplify assertions with equivalent but more simple. (#792)
This commit is contained in:
parent
5afd54ce67
commit
0a73261eef
|
@ -402,9 +402,9 @@ public class ArrayUtilsTest {
|
||||||
assertNull(ArrayUtils.get(array0, 0));
|
assertNull(ArrayUtils.get(array0, 0));
|
||||||
assertNull(ArrayUtils.get(array0, 1));
|
assertNull(ArrayUtils.get(array0, 1));
|
||||||
final String[] array1 = { StringUtils.EMPTY };
|
final String[] array1 = { StringUtils.EMPTY };
|
||||||
assertEquals(null, ArrayUtils.get(array1, -1));
|
assertNull(ArrayUtils.get(array1, -1));
|
||||||
assertEquals(StringUtils.EMPTY, ArrayUtils.get(array1, 0));
|
assertEquals(StringUtils.EMPTY, ArrayUtils.get(array1, 0));
|
||||||
assertEquals(null, ArrayUtils.get(array1, 1));
|
assertNull(ArrayUtils.get(array1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -428,9 +428,9 @@ public class ArrayUtilsTest {
|
||||||
assertNull(ArrayUtils.get(array0, 0, null));
|
assertNull(ArrayUtils.get(array0, 0, null));
|
||||||
assertNull(ArrayUtils.get(array0, 1, null));
|
assertNull(ArrayUtils.get(array0, 1, null));
|
||||||
final String[] array1 = { StringUtils.EMPTY };
|
final String[] array1 = { StringUtils.EMPTY };
|
||||||
assertEquals(null, ArrayUtils.get(array1, -1, null));
|
assertNull(ArrayUtils.get(array1, -1, null));
|
||||||
assertEquals(StringUtils.EMPTY, ArrayUtils.get(array1, 0, null));
|
assertEquals(StringUtils.EMPTY, ArrayUtils.get(array1, 0, null));
|
||||||
assertEquals(null, ArrayUtils.get(array1, 1, null));
|
assertNull(ArrayUtils.get(array1, 1, null));
|
||||||
}
|
}
|
||||||
// non-null default
|
// non-null default
|
||||||
{
|
{
|
||||||
|
|
|
@ -452,20 +452,20 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"False result for (true, true)");
|
"False result for (true, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils
|
BooleanUtils
|
||||||
.and(new Boolean[] { Boolean.FALSE, Boolean.FALSE })
|
.and(new Boolean[] { Boolean.FALSE, Boolean.FALSE })
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (false, false)");
|
"True result for (false, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils
|
BooleanUtils
|
||||||
.and(new Boolean[] { Boolean.TRUE, Boolean.FALSE })
|
.and(new Boolean[] { Boolean.TRUE, Boolean.FALSE })
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (true, false)");
|
"True result for (true, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils
|
BooleanUtils
|
||||||
.and(new Boolean[] { Boolean.FALSE, Boolean.TRUE })
|
.and(new Boolean[] { Boolean.FALSE, Boolean.TRUE })
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (false, true)");
|
"True result for (false, true)");
|
||||||
|
@ -473,8 +473,8 @@ public class BooleanUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnd_object_validInput_3items() {
|
public void testAnd_object_validInput_3items() {
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils
|
BooleanUtils
|
||||||
.and(
|
.and(
|
||||||
new Boolean[] {
|
new Boolean[] {
|
||||||
Boolean.FALSE,
|
Boolean.FALSE,
|
||||||
|
@ -483,8 +483,8 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (false, false, true)");
|
"True result for (false, false, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils
|
BooleanUtils
|
||||||
.and(
|
.and(
|
||||||
new Boolean[] {
|
new Boolean[] {
|
||||||
Boolean.FALSE,
|
Boolean.FALSE,
|
||||||
|
@ -493,8 +493,8 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (false, true, false)");
|
"True result for (false, true, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils
|
BooleanUtils
|
||||||
.and(
|
.and(
|
||||||
new Boolean[] {
|
new Boolean[] {
|
||||||
Boolean.TRUE,
|
Boolean.TRUE,
|
||||||
|
@ -509,8 +509,8 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"False result for (true, true, true)");
|
"False result for (true, true, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(
|
BooleanUtils.and(
|
||||||
new Boolean[] {
|
new Boolean[] {
|
||||||
Boolean.FALSE,
|
Boolean.FALSE,
|
||||||
Boolean.FALSE,
|
Boolean.FALSE,
|
||||||
|
@ -518,8 +518,8 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (false, false)");
|
"True result for (false, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(
|
BooleanUtils.and(
|
||||||
new Boolean[] {
|
new Boolean[] {
|
||||||
Boolean.TRUE,
|
Boolean.TRUE,
|
||||||
Boolean.TRUE,
|
Boolean.TRUE,
|
||||||
|
@ -527,8 +527,8 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (true, true, false)");
|
"True result for (true, true, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(
|
BooleanUtils.and(
|
||||||
new Boolean[] {
|
new Boolean[] {
|
||||||
Boolean.TRUE,
|
Boolean.TRUE,
|
||||||
Boolean.FALSE,
|
Boolean.FALSE,
|
||||||
|
@ -536,8 +536,8 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (true, false, true)");
|
"True result for (true, false, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(
|
BooleanUtils.and(
|
||||||
new Boolean[] {
|
new Boolean[] {
|
||||||
Boolean.FALSE,
|
Boolean.FALSE,
|
||||||
Boolean.TRUE,
|
Boolean.TRUE,
|
||||||
|
@ -562,51 +562,51 @@ public class BooleanUtilsTest {
|
||||||
BooleanUtils.and(new boolean[] { true, true }),
|
BooleanUtils.and(new boolean[] { true, true }),
|
||||||
"False result for (true, true)");
|
"False result for (true, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { false, false }),
|
BooleanUtils.and(new boolean[] { false, false }),
|
||||||
"True result for (false, false)");
|
"True result for (false, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { true, false }),
|
BooleanUtils.and(new boolean[] { true, false }),
|
||||||
"True result for (true, false)");
|
"True result for (true, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { false, true }),
|
BooleanUtils.and(new boolean[] { false, true }),
|
||||||
"True result for (false, true)");
|
"True result for (false, true)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnd_primitive_validInput_3items() {
|
public void testAnd_primitive_validInput_3items() {
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { false, false, true }),
|
BooleanUtils.and(new boolean[] { false, false, true }),
|
||||||
"True result for (false, false, true)");
|
"True result for (false, false, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { false, true, false }),
|
BooleanUtils.and(new boolean[] { false, true, false }),
|
||||||
"True result for (false, true, false)");
|
"True result for (false, true, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { true, false, false }),
|
BooleanUtils.and(new boolean[] { true, false, false }),
|
||||||
"True result for (true, false, false)");
|
"True result for (true, false, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
BooleanUtils.and(new boolean[] { true, true, true }),
|
BooleanUtils.and(new boolean[] { true, true, true }),
|
||||||
"False result for (true, true, true)");
|
"False result for (true, true, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { false, false, false }),
|
BooleanUtils.and(new boolean[] { false, false, false }),
|
||||||
"True result for (false, false)");
|
"True result for (false, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { true, true, false }),
|
BooleanUtils.and(new boolean[] { true, true, false }),
|
||||||
"True result for (true, true, false)");
|
"True result for (true, true, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { true, false, true }),
|
BooleanUtils.and(new boolean[] { true, false, true }),
|
||||||
"True result for (true, false, true)");
|
"True result for (true, false, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.and(new boolean[] { false, true, true }),
|
BooleanUtils.and(new boolean[] { false, true, true }),
|
||||||
"True result for (false, true, true)");
|
"True result for (false, true, true)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,8 +651,8 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"False result for (true, true)");
|
"False result for (true, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils
|
BooleanUtils
|
||||||
.or(new Boolean[] { Boolean.FALSE, Boolean.FALSE })
|
.or(new Boolean[] { Boolean.FALSE, Boolean.FALSE })
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"True result for (false, false)");
|
"True result for (false, false)");
|
||||||
|
@ -708,8 +708,8 @@ public class BooleanUtilsTest {
|
||||||
.booleanValue(),
|
.booleanValue(),
|
||||||
"False result for (true, true, true)");
|
"False result for (true, true, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.or(
|
BooleanUtils.or(
|
||||||
new Boolean[] {
|
new Boolean[] {
|
||||||
Boolean.FALSE,
|
Boolean.FALSE,
|
||||||
Boolean.FALSE,
|
Boolean.FALSE,
|
||||||
|
@ -761,8 +761,8 @@ public class BooleanUtilsTest {
|
||||||
BooleanUtils.or(new boolean[] { true, true }),
|
BooleanUtils.or(new boolean[] { true, true }),
|
||||||
"False result for (true, true)");
|
"False result for (true, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.or(new boolean[] { false, false }),
|
BooleanUtils.or(new boolean[] { false, false }),
|
||||||
"True result for (false, false)");
|
"True result for (false, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
|
@ -792,8 +792,8 @@ public class BooleanUtilsTest {
|
||||||
BooleanUtils.or(new boolean[] { true, true, true }),
|
BooleanUtils.or(new boolean[] { true, true, true }),
|
||||||
"False result for (true, true, true)");
|
"False result for (true, true, true)");
|
||||||
|
|
||||||
assertTrue(
|
assertFalse(
|
||||||
! BooleanUtils.or(new boolean[] { false, false, false }),
|
BooleanUtils.or(new boolean[] { false, false, false }),
|
||||||
"True result for (false, false)");
|
"True result for (false, false)");
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
|
|
|
@ -397,9 +397,9 @@ public class ObjectUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
assertTrue(ObjectUtils.equals(null, null), "ObjectUtils.equals(null, null) returned false");
|
assertTrue(ObjectUtils.equals(null, null), "ObjectUtils.equals(null, null) returned false");
|
||||||
assertTrue(!ObjectUtils.equals(FOO, null), "ObjectUtils.equals(\"foo\", null) returned true");
|
assertFalse(ObjectUtils.equals(FOO, null), "ObjectUtils.equals(\"foo\", null) returned true");
|
||||||
assertTrue(!ObjectUtils.equals(null, BAR), "ObjectUtils.equals(null, \"bar\") returned true");
|
assertFalse(ObjectUtils.equals(null, BAR), "ObjectUtils.equals(null, \"bar\") returned true");
|
||||||
assertTrue(!ObjectUtils.equals(FOO, BAR), "ObjectUtils.equals(\"foo\", \"bar\") returned true");
|
assertFalse(ObjectUtils.equals(FOO, BAR), "ObjectUtils.equals(\"foo\", \"bar\") returned true");
|
||||||
assertTrue(ObjectUtils.equals(FOO, FOO), "ObjectUtils.equals(\"foo\", \"foo\") returned false");
|
assertTrue(ObjectUtils.equals(FOO, FOO), "ObjectUtils.equals(\"foo\", \"foo\") returned false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,8 +776,8 @@ public class ObjectUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString_SupplierString() {
|
public void testToString_SupplierString() {
|
||||||
assertEquals(null, ObjectUtils.toString(null, (Supplier<String>) null));
|
assertNull(ObjectUtils.toString(null, (Supplier<String>) null));
|
||||||
assertEquals(null, ObjectUtils.toString(null, () -> null));
|
assertNull(ObjectUtils.toString(null, () -> null));
|
||||||
// Pretend computing BAR is expensive.
|
// Pretend computing BAR is expensive.
|
||||||
assertEquals(BAR, ObjectUtils.toString(null, () -> BAR));
|
assertEquals(BAR, ObjectUtils.toString(null, () -> BAR));
|
||||||
assertEquals(Boolean.TRUE.toString(), ObjectUtils.toString(Boolean.TRUE, () -> BAR));
|
assertEquals(Boolean.TRUE.toString(), ObjectUtils.toString(Boolean.TRUE, () -> BAR));
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class RandomStringUtilsTest {
|
||||||
assertEquals(50, r1.length(), "random(50) length");
|
assertEquals(50, r1.length(), "random(50) length");
|
||||||
String r2 = RandomStringUtils.random(50);
|
String r2 = RandomStringUtils.random(50);
|
||||||
assertEquals(50, r2.length(), "random(50) length");
|
assertEquals(50, r2.length(), "random(50) length");
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomAscii(50);
|
r1 = RandomStringUtils.randomAscii(50);
|
||||||
assertEquals(50, r1.length(), "randomAscii(50) length");
|
assertEquals(50, r1.length(), "randomAscii(50) length");
|
||||||
|
@ -68,7 +68,7 @@ public class RandomStringUtilsTest {
|
||||||
assertTrue(r1.charAt(i) >= 32 && r1.charAt(i) <= 127, "char between 32 and 127");
|
assertTrue(r1.charAt(i) >= 32 && r1.charAt(i) <= 127, "char between 32 and 127");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomAscii(50);
|
r2 = RandomStringUtils.randomAscii(50);
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomAlphabetic(50);
|
r1 = RandomStringUtils.randomAlphabetic(50);
|
||||||
assertEquals(50, r1.length(), "randomAlphabetic(50)");
|
assertEquals(50, r1.length(), "randomAlphabetic(50)");
|
||||||
|
@ -76,7 +76,7 @@ public class RandomStringUtilsTest {
|
||||||
assertTrue(Character.isLetter(r1.charAt(i)) && !Character.isDigit(r1.charAt(i)), "r1 contains alphabetic");
|
assertTrue(Character.isLetter(r1.charAt(i)) && !Character.isDigit(r1.charAt(i)), "r1 contains alphabetic");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomAlphabetic(50);
|
r2 = RandomStringUtils.randomAlphabetic(50);
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomAlphanumeric(50);
|
r1 = RandomStringUtils.randomAlphanumeric(50);
|
||||||
assertEquals(50, r1.length(), "randomAlphanumeric(50)");
|
assertEquals(50, r1.length(), "randomAlphanumeric(50)");
|
||||||
|
@ -84,7 +84,7 @@ public class RandomStringUtilsTest {
|
||||||
assertTrue(Character.isLetterOrDigit(r1.charAt(i)), "r1 contains alphanumeric");
|
assertTrue(Character.isLetterOrDigit(r1.charAt(i)), "r1 contains alphanumeric");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomAlphabetic(50);
|
r2 = RandomStringUtils.randomAlphabetic(50);
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomGraph(50);
|
r1 = RandomStringUtils.randomGraph(50);
|
||||||
assertEquals(50, r1.length(), "randomGraph(50) length");
|
assertEquals(50, r1.length(), "randomGraph(50) length");
|
||||||
|
@ -92,7 +92,7 @@ public class RandomStringUtilsTest {
|
||||||
assertTrue(r1.charAt(i) >= 33 && r1.charAt(i) <= 126, "char between 33 and 126");
|
assertTrue(r1.charAt(i) >= 33 && r1.charAt(i) <= 126, "char between 33 and 126");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomGraph(50);
|
r2 = RandomStringUtils.randomGraph(50);
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomNumeric(50);
|
r1 = RandomStringUtils.randomNumeric(50);
|
||||||
assertEquals(50, r1.length(), "randomNumeric(50)");
|
assertEquals(50, r1.length(), "randomNumeric(50)");
|
||||||
|
@ -100,7 +100,7 @@ public class RandomStringUtilsTest {
|
||||||
assertTrue(Character.isDigit(r1.charAt(i)) && !Character.isLetter(r1.charAt(i)), "r1 contains numeric");
|
assertTrue(Character.isDigit(r1.charAt(i)) && !Character.isLetter(r1.charAt(i)), "r1 contains numeric");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomNumeric(50);
|
r2 = RandomStringUtils.randomNumeric(50);
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.randomPrint(50);
|
r1 = RandomStringUtils.randomPrint(50);
|
||||||
assertEquals(50, r1.length(), "randomPrint(50) length");
|
assertEquals(50, r1.length(), "randomPrint(50) length");
|
||||||
|
@ -108,7 +108,7 @@ public class RandomStringUtilsTest {
|
||||||
assertTrue(r1.charAt(i) >= 32 && r1.charAt(i) <= 126, "char between 32 and 126");
|
assertTrue(r1.charAt(i) >= 32 && r1.charAt(i) <= 126, "char between 32 and 126");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.randomPrint(50);
|
r2 = RandomStringUtils.randomPrint(50);
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
String set = "abcdefg";
|
String set = "abcdefg";
|
||||||
r1 = RandomStringUtils.random(50, set);
|
r1 = RandomStringUtils.random(50, set);
|
||||||
|
@ -117,13 +117,13 @@ public class RandomStringUtilsTest {
|
||||||
assertTrue(set.indexOf(r1.charAt(i)) > -1, "random char in set");
|
assertTrue(set.indexOf(r1.charAt(i)) > -1, "random char in set");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.random(50, set);
|
r2 = RandomStringUtils.random(50, set);
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.random(50, (String) null);
|
r1 = RandomStringUtils.random(50, (String) null);
|
||||||
assertEquals(50, r1.length(), "random(50) length");
|
assertEquals(50, r1.length(), "random(50) length");
|
||||||
r2 = RandomStringUtils.random(50, (String) null);
|
r2 = RandomStringUtils.random(50, (String) null);
|
||||||
assertEquals(50, r2.length(), "random(50) length");
|
assertEquals(50, r2.length(), "random(50) length");
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
set = "stuvwxyz";
|
set = "stuvwxyz";
|
||||||
r1 = RandomStringUtils.random(50, set.toCharArray());
|
r1 = RandomStringUtils.random(50, set.toCharArray());
|
||||||
|
@ -132,13 +132,13 @@ public class RandomStringUtilsTest {
|
||||||
assertTrue(set.indexOf(r1.charAt(i)) > -1, "random char in set");
|
assertTrue(set.indexOf(r1.charAt(i)) > -1, "random char in set");
|
||||||
}
|
}
|
||||||
r2 = RandomStringUtils.random(50, set);
|
r2 = RandomStringUtils.random(50, set);
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
r1 = RandomStringUtils.random(50, (char[]) null);
|
r1 = RandomStringUtils.random(50, (char[]) null);
|
||||||
assertEquals(50, r1.length(), "random(50) length");
|
assertEquals(50, r1.length(), "random(50) length");
|
||||||
r2 = RandomStringUtils.random(50, (char[]) null);
|
r2 = RandomStringUtils.random(50, (char[]) null);
|
||||||
assertEquals(50, r2.length(), "random(50) length");
|
assertEquals(50, r2.length(), "random(50) length");
|
||||||
assertTrue(!r1.equals(r2), "!r1.equals(r2)");
|
assertFalse(r1.equals(r2), "!r1.equals(r2)");
|
||||||
|
|
||||||
final long seedMillis = System.currentTimeMillis();
|
final long seedMillis = System.currentTimeMillis();
|
||||||
r1 = RandomStringUtils.random(50, 0, 0, true, true, null, new Random(seedMillis));
|
r1 = RandomStringUtils.random(50, 0, 0, true, true, null, new Random(seedMillis));
|
||||||
|
|
|
@ -2910,8 +2910,7 @@ public class StringUtilsTest {
|
||||||
// don't actively test for that.
|
// don't actively test for that.
|
||||||
final Class<?>[] params = m.getParameterTypes();
|
final Class<?>[] params = m.getParameterTypes();
|
||||||
if (params.length > 0 && (params[0] == CharSequence.class || params[0] == CharSequence[].class)) {
|
if (params.length > 0 && (params[0] == CharSequence.class || params[0] == CharSequence[].class)) {
|
||||||
assertTrue(!ArrayUtils.contains(excludeMethods, methodStr),
|
assertFalse(ArrayUtils.contains(excludeMethods, methodStr), "The method \"" + methodStr + "\" appears to be mutable in spirit and therefore must not accept a CharSequence");
|
||||||
"The method \"" + methodStr + "\" appears to be mutable in spirit and therefore must not accept a CharSequence");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Assume this is immutable in spirit and ensure the first parameter is not String.
|
// Assume this is immutable in spirit and ensure the first parameter is not String.
|
||||||
|
@ -3288,7 +3287,7 @@ public class StringUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToRootLowerCase() {
|
public void testToRootLowerCase() {
|
||||||
assertEquals(null, StringUtils.toRootLowerCase(null));
|
assertNull(StringUtils.toRootLowerCase(null));
|
||||||
assertEquals("a", StringUtils.toRootLowerCase("A"));
|
assertEquals("a", StringUtils.toRootLowerCase("A"));
|
||||||
assertEquals("a", StringUtils.toRootLowerCase("a"));
|
assertEquals("a", StringUtils.toRootLowerCase("a"));
|
||||||
final Locale TURKISH = Locale.forLanguageTag("tr");
|
final Locale TURKISH = Locale.forLanguageTag("tr");
|
||||||
|
@ -3308,7 +3307,7 @@ public class StringUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToRootUpperCase() {
|
public void testToRootUpperCase() {
|
||||||
assertEquals(null, StringUtils.toRootUpperCase(null));
|
assertNull(StringUtils.toRootUpperCase(null));
|
||||||
assertEquals("A", StringUtils.toRootUpperCase("a"));
|
assertEquals("A", StringUtils.toRootUpperCase("a"));
|
||||||
assertEquals("A", StringUtils.toRootUpperCase("A"));
|
assertEquals("A", StringUtils.toRootUpperCase("A"));
|
||||||
final Locale TURKISH = Locale.forLanguageTag("tr");
|
final Locale TURKISH = Locale.forLanguageTag("tr");
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.commons.lang3.compare;
|
package org.apache.commons.lang3.compare;
|
||||||
|
|
||||||
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 java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -48,8 +49,8 @@ public class ObjectToStringComparatorTest {
|
||||||
final List<Thing> things = Arrays.asList(null, new Thing("y"), null);
|
final List<Thing> things = Arrays.asList(null, new Thing("y"), null);
|
||||||
things.sort(ObjectToStringComparator.INSTANCE);
|
things.sort(ObjectToStringComparator.INSTANCE);
|
||||||
assertEquals("y", things.get(0).string);
|
assertEquals("y", things.get(0).string);
|
||||||
assertEquals(null, things.get(1));
|
assertNull(things.get(1));
|
||||||
assertEquals(null, things.get(2));
|
assertNull(things.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -57,8 +58,8 @@ public class ObjectToStringComparatorTest {
|
||||||
final List<Thing> things = Arrays.asList(new Thing(null), new Thing("y"), new Thing(null));
|
final List<Thing> things = Arrays.asList(new Thing(null), new Thing("y"), new Thing(null));
|
||||||
things.sort(ObjectToStringComparator.INSTANCE);
|
things.sort(ObjectToStringComparator.INSTANCE);
|
||||||
assertEquals("y", things.get(0).string);
|
assertEquals("y", things.get(0).string);
|
||||||
assertEquals(null, things.get(1).string);
|
assertNull(things.get(1).string);
|
||||||
assertEquals(null, things.get(2).string);
|
assertNull(things.get(2).string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -20,6 +20,7 @@ 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.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.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;
|
||||||
|
@ -562,73 +563,73 @@ public class ExceptionUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThrowableOf_ThrowableClass() {
|
public void testThrowableOf_ThrowableClass() {
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(null, null));
|
assertNull(ExceptionUtils.throwableOfThrowable(null, null));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(null, NestableException.class));
|
assertNull(ExceptionUtils.throwableOfThrowable(null, NestableException.class));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withoutCause, null));
|
assertNull(ExceptionUtils.throwableOfThrowable(withoutCause, null));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withoutCause, ExceptionWithCause.class));
|
assertNull(ExceptionUtils.throwableOfThrowable(withoutCause, ExceptionWithCause.class));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withoutCause, NestableException.class));
|
assertNull(ExceptionUtils.throwableOfThrowable(withoutCause, NestableException.class));
|
||||||
assertEquals(withoutCause, ExceptionUtils.throwableOfThrowable(withoutCause, ExceptionWithoutCause.class));
|
assertEquals(withoutCause, ExceptionUtils.throwableOfThrowable(withoutCause, ExceptionWithoutCause.class));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(nested, null));
|
assertNull(ExceptionUtils.throwableOfThrowable(nested, null));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(nested, ExceptionWithCause.class));
|
assertNull(ExceptionUtils.throwableOfThrowable(nested, ExceptionWithCause.class));
|
||||||
assertEquals(nested, ExceptionUtils.throwableOfThrowable(nested, NestableException.class));
|
assertEquals(nested, ExceptionUtils.throwableOfThrowable(nested, NestableException.class));
|
||||||
assertEquals(nested.getCause(), ExceptionUtils.throwableOfThrowable(nested, ExceptionWithoutCause.class));
|
assertEquals(nested.getCause(), ExceptionUtils.throwableOfThrowable(nested, ExceptionWithoutCause.class));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withCause, null));
|
assertNull(ExceptionUtils.throwableOfThrowable(withCause, null));
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class));
|
assertEquals(withCause, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class));
|
||||||
assertEquals(withCause.getCause(), ExceptionUtils.throwableOfThrowable(withCause, NestableException.class));
|
assertEquals(withCause.getCause(), ExceptionUtils.throwableOfThrowable(withCause, NestableException.class));
|
||||||
assertEquals(withCause.getCause().getCause(), ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithoutCause.class));
|
assertEquals(withCause.getCause().getCause(), ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithoutCause.class));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withCause, Exception.class));
|
assertNull(ExceptionUtils.throwableOfThrowable(withCause, Exception.class));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withCause, Throwable.class));
|
assertNull(ExceptionUtils.throwableOfThrowable(withCause, Throwable.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThrowableOf_ThrowableClassInt() {
|
public void testThrowableOf_ThrowableClassInt() {
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(null, null, 0));
|
assertNull(ExceptionUtils.throwableOfThrowable(null, null, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(null, NestableException.class, 0));
|
assertNull(ExceptionUtils.throwableOfThrowable(null, NestableException.class, 0));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withoutCause, null));
|
assertNull(ExceptionUtils.throwableOfThrowable(withoutCause, null));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withoutCause, ExceptionWithCause.class, 0));
|
assertNull(ExceptionUtils.throwableOfThrowable(withoutCause, ExceptionWithCause.class, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withoutCause, NestableException.class, 0));
|
assertNull(ExceptionUtils.throwableOfThrowable(withoutCause, NestableException.class, 0));
|
||||||
assertEquals(withoutCause, ExceptionUtils.throwableOfThrowable(withoutCause, ExceptionWithoutCause.class, 0));
|
assertEquals(withoutCause, ExceptionUtils.throwableOfThrowable(withoutCause, ExceptionWithoutCause.class, 0));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(nested, null, 0));
|
assertNull(ExceptionUtils.throwableOfThrowable(nested, null, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(nested, ExceptionWithCause.class, 0));
|
assertNull(ExceptionUtils.throwableOfThrowable(nested, ExceptionWithCause.class, 0));
|
||||||
assertEquals(nested, ExceptionUtils.throwableOfThrowable(nested, NestableException.class, 0));
|
assertEquals(nested, ExceptionUtils.throwableOfThrowable(nested, NestableException.class, 0));
|
||||||
assertEquals(nested.getCause(), ExceptionUtils.throwableOfThrowable(nested, ExceptionWithoutCause.class, 0));
|
assertEquals(nested.getCause(), ExceptionUtils.throwableOfThrowable(nested, ExceptionWithoutCause.class, 0));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withCause, null));
|
assertNull(ExceptionUtils.throwableOfThrowable(withCause, null));
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, 0));
|
assertEquals(withCause, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, 0));
|
||||||
assertEquals(withCause.getCause(), ExceptionUtils.throwableOfThrowable(withCause, NestableException.class, 0));
|
assertEquals(withCause.getCause(), ExceptionUtils.throwableOfThrowable(withCause, NestableException.class, 0));
|
||||||
assertEquals(withCause.getCause().getCause(), ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithoutCause.class, 0));
|
assertEquals(withCause.getCause().getCause(), ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithoutCause.class, 0));
|
||||||
|
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, -1));
|
assertEquals(withCause, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, -1));
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, 0));
|
assertEquals(withCause, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, 1));
|
assertNull(ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, 1));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, 9));
|
assertNull(ExceptionUtils.throwableOfThrowable(withCause, ExceptionWithCause.class, 9));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withCause, Exception.class, 0));
|
assertNull(ExceptionUtils.throwableOfThrowable(withCause, Exception.class, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfThrowable(withCause, Throwable.class, 0));
|
assertNull(ExceptionUtils.throwableOfThrowable(withCause, Throwable.class, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThrowableOfType_ThrowableClass() {
|
public void testThrowableOfType_ThrowableClass() {
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(null, null));
|
assertNull(ExceptionUtils.throwableOfType(null, null));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(null, NestableException.class));
|
assertNull(ExceptionUtils.throwableOfType(null, NestableException.class));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withoutCause, null));
|
assertNull(ExceptionUtils.throwableOfType(withoutCause, null));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withoutCause, ExceptionWithCause.class));
|
assertNull(ExceptionUtils.throwableOfType(withoutCause, ExceptionWithCause.class));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withoutCause, NestableException.class));
|
assertNull(ExceptionUtils.throwableOfType(withoutCause, NestableException.class));
|
||||||
assertEquals(withoutCause, ExceptionUtils.throwableOfType(withoutCause, ExceptionWithoutCause.class));
|
assertEquals(withoutCause, ExceptionUtils.throwableOfType(withoutCause, ExceptionWithoutCause.class));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(nested, null));
|
assertNull(ExceptionUtils.throwableOfType(nested, null));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(nested, ExceptionWithCause.class));
|
assertNull(ExceptionUtils.throwableOfType(nested, ExceptionWithCause.class));
|
||||||
assertEquals(nested, ExceptionUtils.throwableOfType(nested, NestableException.class));
|
assertEquals(nested, ExceptionUtils.throwableOfType(nested, NestableException.class));
|
||||||
assertEquals(nested.getCause(), ExceptionUtils.throwableOfType(nested, ExceptionWithoutCause.class));
|
assertEquals(nested.getCause(), ExceptionUtils.throwableOfType(nested, ExceptionWithoutCause.class));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withCause, null));
|
assertNull(ExceptionUtils.throwableOfType(withCause, null));
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class));
|
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class));
|
||||||
assertEquals(withCause.getCause(), ExceptionUtils.throwableOfType(withCause, NestableException.class));
|
assertEquals(withCause.getCause(), ExceptionUtils.throwableOfType(withCause, NestableException.class));
|
||||||
assertEquals(withCause.getCause().getCause(), ExceptionUtils.throwableOfType(withCause, ExceptionWithoutCause.class));
|
assertEquals(withCause.getCause().getCause(), ExceptionUtils.throwableOfType(withCause, ExceptionWithoutCause.class));
|
||||||
|
@ -639,28 +640,28 @@ public class ExceptionUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testThrowableOfType_ThrowableClassInt() {
|
public void testThrowableOfType_ThrowableClassInt() {
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(null, null, 0));
|
assertNull(ExceptionUtils.throwableOfType(null, null, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(null, NestableException.class, 0));
|
assertNull(ExceptionUtils.throwableOfType(null, NestableException.class, 0));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withoutCause, null));
|
assertNull(ExceptionUtils.throwableOfType(withoutCause, null));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withoutCause, ExceptionWithCause.class, 0));
|
assertNull(ExceptionUtils.throwableOfType(withoutCause, ExceptionWithCause.class, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withoutCause, NestableException.class, 0));
|
assertNull(ExceptionUtils.throwableOfType(withoutCause, NestableException.class, 0));
|
||||||
assertEquals(withoutCause, ExceptionUtils.throwableOfType(withoutCause, ExceptionWithoutCause.class, 0));
|
assertEquals(withoutCause, ExceptionUtils.throwableOfType(withoutCause, ExceptionWithoutCause.class, 0));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(nested, null, 0));
|
assertNull(ExceptionUtils.throwableOfType(nested, null, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(nested, ExceptionWithCause.class, 0));
|
assertNull(ExceptionUtils.throwableOfType(nested, ExceptionWithCause.class, 0));
|
||||||
assertEquals(nested, ExceptionUtils.throwableOfType(nested, NestableException.class, 0));
|
assertEquals(nested, ExceptionUtils.throwableOfType(nested, NestableException.class, 0));
|
||||||
assertEquals(nested.getCause(), ExceptionUtils.throwableOfType(nested, ExceptionWithoutCause.class, 0));
|
assertEquals(nested.getCause(), ExceptionUtils.throwableOfType(nested, ExceptionWithoutCause.class, 0));
|
||||||
|
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withCause, null));
|
assertNull(ExceptionUtils.throwableOfType(withCause, null));
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, 0));
|
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, 0));
|
||||||
assertEquals(withCause.getCause(), ExceptionUtils.throwableOfType(withCause, NestableException.class, 0));
|
assertEquals(withCause.getCause(), ExceptionUtils.throwableOfType(withCause, NestableException.class, 0));
|
||||||
assertEquals(withCause.getCause().getCause(), ExceptionUtils.throwableOfType(withCause, ExceptionWithoutCause.class, 0));
|
assertEquals(withCause.getCause().getCause(), ExceptionUtils.throwableOfType(withCause, ExceptionWithoutCause.class, 0));
|
||||||
|
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, -1));
|
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, -1));
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, 0));
|
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, 0));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, 1));
|
assertNull(ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, 1));
|
||||||
assertEquals(null, ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, 9));
|
assertNull(ExceptionUtils.throwableOfType(withCause, ExceptionWithCause.class, 9));
|
||||||
|
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, Exception.class, 0));
|
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, Exception.class, 0));
|
||||||
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, Throwable.class, 0));
|
assertEquals(withCause, ExceptionUtils.throwableOfType(withCause, Throwable.class, 0));
|
||||||
|
|
Loading…
Reference in New Issue