This commit is contained in:
Gary Gregory 2022-05-26 16:57:50 -04:00
commit 385df6f9f8
4 changed files with 262 additions and 77 deletions

View File

@ -81,6 +81,8 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Arturo Bernal">Remove unnecessary variable creations #882.</action>
<action type="fix" dev="ggregory" due-to="Arturo Bernal">Minor changes #769.</action>
<action issue="LANG-1680" type="fix" dev="ggregory" due-to="Michael Krause, Steve Bosman, Gary Gregory">FastDateFormat does not support the 'L'-Pattern from SimpleDateFormat.</action>
<action type="fix" dev="ggregory" due-to="Steve Bosman, Gary Gregory">Increase test coverage of ComparableUtils from 71% to 100% #898.</action>
<action type="fix" dev="ggregory" due-to="Steve Bosman">Increase method test coverage of MultilineRecursiveToStringStyle #899.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add EnumUtils.getEnumSystemProperty(...).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add TriConsumer.</action>

View File

@ -88,7 +88,6 @@ public class CalendarUtils {
/**
* Gets month names in the requested style.
* @param locale Locale
* @param style Must be a valid {@link Calendar#getDisplayNames(int, int, Locale)} month style.
* @return Styled names of months
*/

View File

@ -28,7 +28,18 @@ import org.junit.jupiter.api.Test;
*/
public class MultilineRecursiveToStringStyleTest {
private final String BR = System.lineSeparator();
private static final String BR = System.lineSeparator();
private static final String BASE_WITH_ARRAYS_TO_STRING = "[" + BR
+ " boolArray=#BOOLEAN#," + BR
+ " byteArray=#BYTE#," + BR
+ " charArray=#CHAR#," + BR
+ " doubleArray=#DOUBLE#," + BR
+ " floatArray=#FLOAT#," + BR
+ " intArray=#INT#," + BR
+ " longArray=#LONG#," + BR
+ " shortArray=#SHORT#," + BR
+ " stringArray=#STRING#" + BR
+ "]";
@Test
public void simpleObject() {
@ -81,14 +92,7 @@ public class MultilineRecursiveToStringStyleTest {
@Test
public void noArray() {
final WithArrays wa = new WithArrays();
final String exp = getClassPrefix(wa) + "[" + BR
+ " boolArray=<null>," + BR
+ " charArray=<null>," + BR
+ " doubleArray=<null>," + BR
+ " intArray=<null>," + BR
+ " longArray=<null>," + BR
+ " stringArray=<null>" + BR
+ "]";
final String exp = getExpectedToString(wa, WithArraysTestType.NONE, "");
assertEquals(exp, toString(wa));
}
@ -96,18 +100,26 @@ public class MultilineRecursiveToStringStyleTest {
public void boolArray() {
final WithArrays wa = new WithArrays();
wa.boolArray = new boolean[] { true, false, true };
final String exp = getClassPrefix(wa) + "[" + BR
+ " boolArray={" + BR
+ " true," + BR
+ " false," + BR
+ " true" + BR
+ " }," + BR
+ " charArray=<null>," + BR
+ " doubleArray=<null>," + BR
+ " intArray=<null>," + BR
+ " longArray=<null>," + BR
+ " stringArray=<null>" + BR
+ "]";
final String exp = getExpectedToString(
wa, WithArraysTestType.BOOLEAN,
"{" + BR
+ " true," + BR
+ " false," + BR
+ " true" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@Test
public void byteArray() {
final WithArrays wa = new WithArrays();
wa.byteArray = new byte[] { 1, 2 };
final String exp = getExpectedToString(
wa, WithArraysTestType.BYTE,
"{" + BR
+ " 1," + BR
+ " 2" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@ -115,17 +127,12 @@ public class MultilineRecursiveToStringStyleTest {
public void charArray() {
final WithArrays wa = new WithArrays();
wa.charArray = new char[] { 'a', 'A' };
final String exp = getClassPrefix(wa) + "[" + BR
+ " boolArray=<null>," + BR
+ " charArray={" + BR
+ " a," + BR
+ " A" + BR
+ " }," + BR
+ " doubleArray=<null>," + BR
+ " intArray=<null>," + BR
+ " longArray=<null>," + BR
+ " stringArray=<null>" + BR
+ "]";
final String exp = getExpectedToString(
wa, WithArraysTestType.CHAR,
"{" + BR
+ " a," + BR
+ " A" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@ -133,17 +140,12 @@ public class MultilineRecursiveToStringStyleTest {
public void intArray() {
final WithArrays wa = new WithArrays();
wa.intArray = new int[] { 1, 2 };
final String exp = getClassPrefix(wa) + "[" + BR
+ " boolArray=<null>," + BR
+ " charArray=<null>," + BR
+ " doubleArray=<null>," + BR
+ " intArray={" + BR
+ " 1," + BR
+ " 2" + BR
+ " }," + BR
+ " longArray=<null>," + BR
+ " stringArray=<null>" + BR
+ "]";
final String exp = getExpectedToString(
wa, WithArraysTestType.INT,
"{" + BR
+ " 1," + BR
+ " 2" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@ -151,17 +153,25 @@ public class MultilineRecursiveToStringStyleTest {
public void doubleArray() {
final WithArrays wa = new WithArrays();
wa.doubleArray = new double[] { 1, 2 };
final String exp = getClassPrefix(wa) + "[" + BR
+ " boolArray=<null>," + BR
+ " charArray=<null>," + BR
+ " doubleArray={" + BR
+ " 1.0," + BR
+ " 2.0" + BR
+ " }," + BR
+ " intArray=<null>," + BR
+ " longArray=<null>," + BR
+ " stringArray=<null>" + BR
+ "]";
final String exp = getExpectedToString(
wa, WithArraysTestType.DOUBLE,
"{" + BR
+ " 1.0," + BR
+ " 2.0" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@Test
public void floatArray() {
final WithArrays wa = new WithArrays();
wa.floatArray = new float[] { 1f, 2f };
final String exp = getExpectedToString(
wa, WithArraysTestType.FLOAT,
"{" + BR
+ " 1.0," + BR
+ " 2.0" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@ -169,17 +179,12 @@ public class MultilineRecursiveToStringStyleTest {
public void longArray() {
final WithArrays wa = new WithArrays();
wa.longArray = new long[] { 1L, 2L };
final String exp = getClassPrefix(wa) + "[" + BR
+ " boolArray=<null>," + BR
+ " charArray=<null>," + BR
+ " doubleArray=<null>," + BR
+ " intArray=<null>," + BR
+ " longArray={" + BR
+ " 1," + BR
+ " 2" + BR
+ " }," + BR
+ " stringArray=<null>" + BR
+ "]";
final String exp = getExpectedToString(
wa, WithArraysTestType.LONG,
"{" + BR
+ " 1," + BR
+ " 2" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@ -187,20 +192,27 @@ public class MultilineRecursiveToStringStyleTest {
public void stringArray() {
final WithArrays wa = new WithArrays();
wa.stringArray = new String[] { "a", "A" };
final String exp = getClassPrefix(wa) + "[" + BR
+ " boolArray=<null>," + BR
+ " charArray=<null>," + BR
+ " doubleArray=<null>," + BR
+ " intArray=<null>," + BR
+ " longArray=<null>," + BR
+ " stringArray={" + BR
+ " a," + BR
+ " A" + BR
+ " }" + BR
+ "]";
final String exp = getExpectedToString(
wa, WithArraysTestType.STRING,
"{" + BR
+ " a," + BR
+ " A" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@Test
public void shortArray() {
final WithArrays wa = new WithArrays();
wa.shortArray = new short[] { 1, 2 };
final String exp = getExpectedToString(
wa, WithArraysTestType.SHORT,
"{" + BR
+ " 1," + BR
+ " 2" + BR
+ " }");
assertEquals(exp, toString(wa));
}
@Test
public void testLANG1319() {
@ -225,13 +237,34 @@ public class MultilineRecursiveToStringStyleTest {
static class WithArrays {
boolean[] boolArray;
byte[] byteArray;
char[] charArray;
double[] doubleArray;
float[] floatArray;
int[] intArray;
long[] longArray;
short[] shortArray;
String[] stringArray;
}
/**
* Create an expected to String for the given WithArraysInstance
* @param wa Instance
* @param arrayType Type - empty used to indicate expect all nulls
* @param expectedArrayValue Expected value for the array type
* @return expected toString
*/
private String getExpectedToString(final WithArrays wa, final WithArraysTestType arrayType, final String expectedArrayValue) {
return getClassPrefix(wa)
+ BASE_WITH_ARRAYS_TO_STRING
.replace("#" + arrayType + "#", expectedArrayValue)
.replaceAll("#[A-Z]+#", "<null>");
}
private enum WithArraysTestType {
NONE, BOOLEAN, BYTE, CHAR, DOUBLE, FLOAT, INT, LONG, SHORT, STRING
}
static class Bank {
String name;

View File

@ -55,6 +55,17 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_false() {
assertFalse(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_false() {
assertFalse(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_false() {
assertFalse(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
@DisplayName("C is 1 (B < A = C)")
@ -72,6 +83,16 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_false() {
assertFalse(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_true() {
assertTrue(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_false() {
assertFalse(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
@DisplayName("C is 10 (B < A < C)")
@ -89,6 +110,16 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_true() {
assertTrue(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_true() {
assertTrue(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_true() {
assertTrue(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
BigDecimal b = BigDecimal.ZERO;
@ -117,6 +148,26 @@ public class ComparableUtilsTest {
void lessThanOrEqualTo_returns_false() {
assertFalse(is(a).lessThanOrEqualTo(b));
}
@Test
void static_gt_returns_true() {
assertTrue(ComparableUtils.gt(b).test(a));
}
@Test
void static_ge_returns_true() {
assertTrue(ComparableUtils.ge(b).test(a));
}
@Test
void static_lt_returns_false() {
assertFalse(ComparableUtils.lt(b).test(a));
}
@Test
void static_le_returns_false() {
assertFalse(ComparableUtils.le(b).test(a));
}
}
@DisplayName("B is 1 (B = A)")
@ -138,6 +189,16 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_false() {
assertFalse(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_true() {
assertTrue(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_false() {
assertFalse(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
@DisplayName("C is 1 (B = A = C)")
@ -155,6 +216,16 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_false() {
assertFalse(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_true() {
assertTrue(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_false() {
assertFalse(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
@DisplayName("C is 10 (B = A < C)")
@ -172,6 +243,16 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_false() {
assertFalse(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_true() {
assertTrue(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_false() {
assertFalse(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
BigDecimal b = BigDecimal.ONE;
@ -200,6 +281,26 @@ public class ComparableUtilsTest {
void lessThanOrEqualTo_returns_true() {
assertTrue(is(a).lessThanOrEqualTo(b));
}
@Test
void static_gt_returns_false() {
assertFalse(ComparableUtils.gt(b).test(a));
}
@Test
void static_ge_returns_true() {
assertTrue(ComparableUtils.ge(b).test(a));
}
@Test
void static_lt_returns_false() {
assertFalse(ComparableUtils.lt(b).test(a));
}
@Test
void static_le_returns_true() {
assertTrue(ComparableUtils.le(b).test(a));
}
}
@DisplayName("B is 10 (B > A)")
@ -221,6 +322,16 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_true() {
assertTrue(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_true() {
assertTrue(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_true() {
assertTrue(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
@DisplayName("C is 1 (B > A = C)")
@ -238,6 +349,16 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_false() {
assertFalse(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_true() {
assertTrue(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_false() {
assertFalse(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
@DisplayName("C is 10 ([B,C] > A)")
@ -255,6 +376,16 @@ public class ComparableUtilsTest {
void betweenExclusive_returns_false() {
assertFalse(is(a).betweenExclusive(b, c));
}
@Test
void static_between_returns_false() {
assertFalse(ComparableUtils.between(b, c).test(a));
}
@Test
void static_betweenExclusive_returns_false() {
assertFalse(ComparableUtils.betweenExclusive(b, c).test(a));
}
}
BigDecimal b = BigDecimal.TEN;
@ -283,6 +414,26 @@ public class ComparableUtilsTest {
void lessThanOrEqualTo_returns_true() {
assertTrue(is(a).lessThanOrEqualTo(b));
}
@Test
void static_gt_returns_false() {
assertFalse(ComparableUtils.gt(b).test(a));
}
@Test
void static_ge_returns_false() {
assertFalse(ComparableUtils.ge(b).test(a));
}
@Test
void static_lt_returns_true() {
assertTrue(ComparableUtils.lt(b).test(a));
}
@Test
void static_le_returns_true() {
assertTrue(ComparableUtils.le(b).test(a));
}
}
BigDecimal a = BigDecimal.ONE;