Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-lang.git
This commit is contained in:
commit
4b621c8c03
|
@ -57,7 +57,7 @@ jobs:
|
|||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6
|
||||
uses: github/codeql-action/init@8214744c546c1e5c8f03dde8fab3a7353211988d # 3.26.7
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
|
@ -68,7 +68,7 @@ jobs:
|
|||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6
|
||||
uses: github/codeql-action/autobuild@8214744c546c1e5c8f03dde8fab3a7353211988d # 3.26.7
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
@ -82,4 +82,4 @@ jobs:
|
|||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6
|
||||
uses: github/codeql-action/analyze@8214744c546c1e5c8f03dde8fab3a7353211988d # 3.26.7
|
||||
|
|
|
@ -49,7 +49,7 @@ jobs:
|
|||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
- name: Set up JDK ${{ matrix.java }}
|
||||
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2
|
||||
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4.3.0
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ matrix.java }}
|
||||
|
|
|
@ -57,13 +57,13 @@ jobs:
|
|||
publish_results: true
|
||||
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # 4.3.6
|
||||
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # 4.4.0
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
retention-days: 5
|
||||
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6
|
||||
uses: github/codeql-action/upload-sarif@8214744c546c1e5c8f03dde8fab3a7353211988d # 3.26.7
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
|
|
@ -49,6 +49,8 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<!-- FIX -->
|
||||
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix flaky FileUtilsWaitForTest.testWaitForNegativeDuration().</action>
|
||||
<action type="fix" dev="ggregory" due-to="Gary Gregory">Pick up exec-maven-plugin version from parent POM.</action>
|
||||
<action type="fix" dev="ggregory" due-to="Gary Gregory">Speed up and sanitize StopWatchTest.</action>
|
||||
<action type="fix" dev="ggregory" due-to="Fabrice Benhamouda">Fix handling of non-ASCII letters & numbers in RandomStringUtils #1273.</action>
|
||||
<!-- ADD -->
|
||||
<!-- UPDATE -->
|
||||
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 73 to 74 #1267.</action>
|
||||
|
|
|
@ -4214,7 +4214,7 @@ public class ArrayUtils {
|
|||
return INDEX_NOT_FOUND;
|
||||
}
|
||||
|
||||
private static int max0(int other) {
|
||||
private static int max0(final int other) {
|
||||
return Math.max(0, other);
|
||||
}
|
||||
|
||||
|
|
|
@ -90,9 +90,9 @@ final class CachedRandomBits {
|
|||
}
|
||||
// generatedBitsInIteration is the number of bits that we will generate
|
||||
// in this iteration of the while loop
|
||||
int generatedBitsInIteration = Math.min(8 - (bitIndex & 0x7), bits - generatedBits);
|
||||
final int generatedBitsInIteration = Math.min(8 - (bitIndex & 0x7), bits - generatedBits);
|
||||
result = result << generatedBitsInIteration;
|
||||
result |= (cache[bitIndex >> 3] >> (bitIndex & 0x7)) & ((1 << generatedBitsInIteration) - 1);
|
||||
result |= cache[bitIndex >> 3] >> (bitIndex & 0x7) & (1 << generatedBitsInIteration) - 1;
|
||||
generatedBits += generatedBitsInIteration;
|
||||
bitIndex += generatedBitsInIteration;
|
||||
}
|
||||
|
|
|
@ -93,6 +93,11 @@ public class RandomStringUtils {
|
|||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1',
|
||||
'2', '3', '4', '5', '6', '7', '8', '9' };
|
||||
|
||||
private static final int ASCII_0 = '0';
|
||||
private static final int ASCII_9 = '9';
|
||||
private static final int ASCII_A = 'A';
|
||||
private static final int ASCII_z = 'z';
|
||||
|
||||
/**
|
||||
* Gets the singleton instance based on {@link ThreadLocalRandom#current()}; <b>which is not cryptographically
|
||||
* secure</b>; use {@link #secure()} to use an algorithms/providers specified in the
|
||||
|
@ -277,45 +282,45 @@ public class RandomStringUtils {
|
|||
end = Character.MAX_CODE_POINT;
|
||||
}
|
||||
|
||||
// Optimize generation of full alphanumerical characters
|
||||
// Normally, we would need to pick a 7-bit integer, since gap = 'z' - '0' + 1 = 75 > 64
|
||||
// In turn, this would make us reject the sampling with probability 1 - 62 / 2^7 > 1 / 2
|
||||
// Instead we can pick directly from the right set of 62 characters, which requires
|
||||
// picking a 6-bit integer and only rejecting with probability 2 / 64 = 1 / 32
|
||||
if (chars == null && letters && numbers && start <= '0' && end >= 'z' + 1) {
|
||||
return random(count, 0, 0, false, false, ALPHANUMERICAL_CHARS, random);
|
||||
}
|
||||
// Optimizations and tests when chars == null and using ASCII characters (end <= 0x7f)
|
||||
if (chars == null && end <= 0x7f) {
|
||||
// Optimize generation of full alphanumerical characters
|
||||
// Normally, we would need to pick a 7-bit integer, since gap = 'z' - '0' + 1 = 75 > 64
|
||||
// In turn, this would make us reject the sampling with probability 1 - 62 / 2^7 > 1 / 2
|
||||
// Instead we can pick directly from the right set of 62 characters, which requires
|
||||
// picking a 6-bit integer and only rejecting with probability 2 / 64 = 1 / 32
|
||||
if (letters && numbers && start <= ASCII_0 && end >= ASCII_z + 1) {
|
||||
return random(count, 0, 0, false, false, ALPHANUMERICAL_CHARS, random);
|
||||
}
|
||||
|
||||
// Optimize start and end when filtering by letters and/or numbers:
|
||||
// The range provided may be too large since we filter anyway afterward.
|
||||
// Note the use of Math.min/max (as opposed to setting start to '0' for example),
|
||||
// since it is possible the range start/end excludes some of the letters/numbers,
|
||||
// e.g., it is possible that start already is '1' when numbers = true, and start
|
||||
// needs to stay equal to '1' in that case.
|
||||
if (chars == null) {
|
||||
if (numbers && end <= ASCII_0 || letters && end <= ASCII_A) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter end (" + end + ") must be greater then (" + ASCII_0 + ") for generating digits "
|
||||
+ "or greater then (" + ASCII_A + ") for generating letters.");
|
||||
}
|
||||
|
||||
// Optimize start and end when filtering by letters and/or numbers:
|
||||
// The range provided may be too large since we filter anyway afterward.
|
||||
// Note the use of Math.min/max (as opposed to setting start to '0' for example),
|
||||
// since it is possible the range start/end excludes some of the letters/numbers,
|
||||
// e.g., it is possible that start already is '1' when numbers = true, and start
|
||||
// needs to stay equal to '1' in that case.
|
||||
// Note that because of the above test, we will always have start < end
|
||||
// even after this optimization.
|
||||
if (letters && numbers) {
|
||||
start = Math.max('0', start);
|
||||
end = Math.min('z' + 1, end);
|
||||
start = Math.max(ASCII_0, start);
|
||||
end = Math.min(ASCII_z + 1, end);
|
||||
} else if (numbers) {
|
||||
// just numbers, no letters
|
||||
start = Math.max('0', start);
|
||||
end = Math.min('9' + 1, end);
|
||||
start = Math.max(ASCII_0, start);
|
||||
end = Math.min(ASCII_9 + 1, end);
|
||||
} else if (letters) {
|
||||
// just letters, no numbers
|
||||
start = Math.max('A', start);
|
||||
end = Math.min('z' + 1, end);
|
||||
start = Math.max(ASCII_A, start);
|
||||
end = Math.min(ASCII_z + 1, end);
|
||||
}
|
||||
}
|
||||
|
||||
final int zeroDigitAscii = 48;
|
||||
final int firstLetterAscii = 65;
|
||||
|
||||
if (chars == null && (numbers && end <= zeroDigitAscii || letters && end <= firstLetterAscii)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Parameter end (" + end + ") must be greater then (" + zeroDigitAscii + ") for generating digits "
|
||||
+ "or greater then (" + firstLetterAscii + ") for generating letters.");
|
||||
}
|
||||
|
||||
final StringBuilder builder = new StringBuilder(count);
|
||||
final int gap = end - start;
|
||||
final int gapBits = Integer.SIZE - Integer.numberOfLeadingZeros(gap);
|
||||
|
|
|
@ -412,11 +412,11 @@ public class EqualsBuilder implements Builder<Boolean> {
|
|||
return this;
|
||||
}
|
||||
if (lhs == null || rhs == null) {
|
||||
this.setEquals(false);
|
||||
setEquals(false);
|
||||
return this;
|
||||
}
|
||||
if (lhs.length != rhs.length) {
|
||||
this.setEquals(false);
|
||||
setEquals(false);
|
||||
return this;
|
||||
}
|
||||
for (int i = 0; i < lhs.length && isEquals; ++i) {
|
||||
|
|
|
@ -551,9 +551,9 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
final T object, final ToStringStyle style, final StringBuffer buffer,
|
||||
final Class<? super T> reflectUpToClass, final boolean outputTransients, final boolean outputStatics) {
|
||||
super(object, style, buffer);
|
||||
this.setUpToClass(reflectUpToClass);
|
||||
this.setAppendTransients(outputTransients);
|
||||
this.setAppendStatics(outputStatics);
|
||||
setUpToClass(reflectUpToClass);
|
||||
setAppendTransients(outputTransients);
|
||||
setAppendStatics(outputStatics);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -582,10 +582,10 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
final Class<? super T> reflectUpToClass, final boolean outputTransients, final boolean outputStatics,
|
||||
final boolean excludeNullValues) {
|
||||
super(object, style, buffer);
|
||||
this.setUpToClass(reflectUpToClass);
|
||||
this.setAppendTransients(outputTransients);
|
||||
this.setAppendStatics(outputStatics);
|
||||
this.setExcludeNullValues(excludeNullValues);
|
||||
setUpToClass(reflectUpToClass);
|
||||
setAppendTransients(outputTransients);
|
||||
setAppendStatics(outputStatics);
|
||||
setExcludeNullValues(excludeNullValues);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -605,11 +605,11 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
// Reject field from inner class.
|
||||
return false;
|
||||
}
|
||||
if (Modifier.isTransient(field.getModifiers()) && !this.isAppendTransients()) {
|
||||
if (Modifier.isTransient(field.getModifiers()) && !isAppendTransients()) {
|
||||
// Reject transient fields.
|
||||
return false;
|
||||
}
|
||||
if (Modifier.isStatic(field.getModifiers()) && !this.isAppendStatics()) {
|
||||
if (Modifier.isStatic(field.getModifiers()) && !isAppendStatics()) {
|
||||
// Reject static fields.
|
||||
return false;
|
||||
}
|
||||
|
@ -641,7 +641,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
*/
|
||||
protected void appendFieldsIn(final Class<?> clazz) {
|
||||
if (clazz.isArray()) {
|
||||
this.reflectionAppendArray(this.getObject());
|
||||
reflectionAppendArray(getObject());
|
||||
return;
|
||||
}
|
||||
// The elements in the returned array are not sorted and are not in any particular order.
|
||||
|
@ -649,11 +649,11 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
AccessibleObject.setAccessible(fields, true);
|
||||
for (final Field field : fields) {
|
||||
final String fieldName = field.getName();
|
||||
if (this.accept(field)) {
|
||||
if (accept(field)) {
|
||||
try {
|
||||
// Warning: Field.get(Object) creates wrappers objects
|
||||
// for primitive types.
|
||||
final Object fieldValue = this.getValue(field);
|
||||
final Object fieldValue = getValue(field);
|
||||
if (!excludeNullValues || fieldValue != null) {
|
||||
this.append(fieldName, fieldValue, !field.isAnnotationPresent(ToStringSummary.class));
|
||||
}
|
||||
|
@ -709,7 +709,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
* @see java.lang.reflect.Field#get(Object)
|
||||
*/
|
||||
protected Object getValue(final Field field) throws IllegalAccessException {
|
||||
return field.get(this.getObject());
|
||||
return field.get(getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -749,7 +749,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
* @return {@code this} instance.
|
||||
*/
|
||||
public ReflectionToStringBuilder reflectionAppendArray(final Object array) {
|
||||
this.getStyle().reflectionAppendArrayDetail(this.getStringBuffer(), null, array);
|
||||
getStyle().reflectionAppendArrayDetail(getStringBuffer(), null, array);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -843,17 +843,17 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.getObject() == null) {
|
||||
return this.getStyle().getNullText();
|
||||
if (getObject() == null) {
|
||||
return getStyle().getNullText();
|
||||
}
|
||||
|
||||
validate();
|
||||
|
||||
Class<?> clazz = this.getObject().getClass();
|
||||
this.appendFieldsIn(clazz);
|
||||
while (clazz.getSuperclass() != null && clazz != this.getUpToClass()) {
|
||||
Class<?> clazz = getObject().getClass();
|
||||
appendFieldsIn(clazz);
|
||||
while (clazz.getSuperclass() != null && clazz != getUpToClass()) {
|
||||
clazz = clazz.getSuperclass();
|
||||
this.appendFieldsIn(clazz);
|
||||
appendFieldsIn(clazz);
|
||||
}
|
||||
return super.toString();
|
||||
}
|
||||
|
@ -863,7 +863,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
*/
|
||||
private void validate() {
|
||||
if (ArrayUtils.containsAny(this.excludeFieldNames, (Object[]) this.includeFieldNames)) {
|
||||
ToStringStyle.unregister(this.getObject());
|
||||
ToStringStyle.unregister(getObject());
|
||||
throw new IllegalStateException("includeFieldNames and excludeFieldNames must not intersect");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -911,7 +911,7 @@ public class ToStringBuilder implements Builder<String> {
|
|||
* @since 2.0
|
||||
*/
|
||||
public ToStringBuilder appendAsObjectToString(final Object srcObject) {
|
||||
ObjectUtils.identityToString(this.getStringBuffer(), srcObject);
|
||||
ObjectUtils.identityToString(getStringBuffer(), srcObject);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -1024,11 +1024,11 @@ public class ToStringBuilder implements Builder<String> {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.getObject() == null) {
|
||||
this.getStringBuffer().append(this.getStyle().getNullText());
|
||||
if (getObject() == null) {
|
||||
getStringBuffer().append(getStyle().getNullText());
|
||||
} else {
|
||||
style.appendEnd(this.getStringBuffer(), this.getObject());
|
||||
style.appendEnd(getStringBuffer(), getObject());
|
||||
}
|
||||
return this.getStringBuffer().toString();
|
||||
return getStringBuffer().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,25 +127,25 @@ public abstract class ToStringStyle implements Serializable {
|
|||
* </p>
|
||||
*/
|
||||
JsonToStringStyle() {
|
||||
this.setUseClassName(false);
|
||||
this.setUseIdentityHashCode(false);
|
||||
setUseClassName(false);
|
||||
setUseIdentityHashCode(false);
|
||||
|
||||
this.setContentStart("{");
|
||||
this.setContentEnd("}");
|
||||
setContentStart("{");
|
||||
setContentEnd("}");
|
||||
|
||||
this.setArrayStart("[");
|
||||
this.setArrayEnd("]");
|
||||
setArrayStart("[");
|
||||
setArrayEnd("]");
|
||||
|
||||
this.setFieldSeparator(",");
|
||||
this.setFieldNameValueSeparator(":");
|
||||
setFieldSeparator(",");
|
||||
setFieldNameValueSeparator(":");
|
||||
|
||||
this.setNullText("null");
|
||||
setNullText("null");
|
||||
|
||||
this.setSummaryObjectStartText("\"<");
|
||||
this.setSummaryObjectEndText(">\"");
|
||||
setSummaryObjectStartText("\"<");
|
||||
setSummaryObjectEndText(">\"");
|
||||
|
||||
this.setSizeStartText("\"<size=");
|
||||
this.setSizeEndText(">\"");
|
||||
setSizeStartText("\"<size=");
|
||||
setSizeEndText(">\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -445,10 +445,10 @@ public abstract class ToStringStyle implements Serializable {
|
|||
* <p>Use the static constant rather than instantiating.</p>
|
||||
*/
|
||||
MultiLineToStringStyle() {
|
||||
this.setContentStart("[");
|
||||
this.setFieldSeparator(System.lineSeparator() + " ");
|
||||
this.setFieldSeparatorAtStart(true);
|
||||
this.setContentEnd(System.lineSeparator() + "]");
|
||||
setContentStart("[");
|
||||
setFieldSeparator(System.lineSeparator() + " ");
|
||||
setFieldSeparatorAtStart(true);
|
||||
setContentEnd(System.lineSeparator() + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -479,8 +479,8 @@ public abstract class ToStringStyle implements Serializable {
|
|||
* <p>Use the static constant rather than instantiating.</p>
|
||||
*/
|
||||
NoClassNameToStringStyle() {
|
||||
this.setUseClassName(false);
|
||||
this.setUseIdentityHashCode(false);
|
||||
setUseClassName(false);
|
||||
setUseIdentityHashCode(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -511,7 +511,7 @@ public abstract class ToStringStyle implements Serializable {
|
|||
* <p>Use the static constant rather than instantiating.</p>
|
||||
*/
|
||||
NoFieldNameToStringStyle() {
|
||||
this.setUseFieldNames(false);
|
||||
setUseFieldNames(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -542,8 +542,8 @@ public abstract class ToStringStyle implements Serializable {
|
|||
* <p>Use the static constant rather than instantiating.</p>
|
||||
*/
|
||||
ShortPrefixToStringStyle() {
|
||||
this.setUseShortClassName(true);
|
||||
this.setUseIdentityHashCode(false);
|
||||
setUseShortClassName(true);
|
||||
setUseIdentityHashCode(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -573,11 +573,11 @@ public abstract class ToStringStyle implements Serializable {
|
|||
* <p>Use the static constant rather than instantiating.</p>
|
||||
*/
|
||||
SimpleToStringStyle() {
|
||||
this.setUseClassName(false);
|
||||
this.setUseIdentityHashCode(false);
|
||||
this.setUseFieldNames(false);
|
||||
this.setContentStart(StringUtils.EMPTY);
|
||||
this.setContentEnd(StringUtils.EMPTY);
|
||||
setUseClassName(false);
|
||||
setUseIdentityHashCode(false);
|
||||
setUseFieldNames(false);
|
||||
setContentStart(StringUtils.EMPTY);
|
||||
setContentEnd(StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1667,7 +1667,7 @@ public abstract class ToStringStyle implements Serializable {
|
|||
* @param object the {@link Object} whose id to output
|
||||
*/
|
||||
protected void appendIdentityHashCode(final StringBuffer buffer, final Object object) {
|
||||
if (this.isUseIdentityHashCode() && object != null) {
|
||||
if (isUseIdentityHashCode() && object != null) {
|
||||
register(object);
|
||||
buffer.append('@');
|
||||
buffer.append(ObjectUtils.identityHashCodeHex(object));
|
||||
|
|
|
@ -248,7 +248,7 @@ public class ExceptionUtils {
|
|||
// TODO: Remove in Lang 4
|
||||
private static Throwable getCauseUsingMethodName(final Throwable throwable, final String methodName) {
|
||||
if (methodName != null) {
|
||||
Method method = MethodUtils.getMethodObject(throwable.getClass(), methodName);
|
||||
final Method method = MethodUtils.getMethodObject(throwable.getClass(), methodName);
|
||||
if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
|
||||
try {
|
||||
return (Throwable) method.invoke(throwable);
|
||||
|
|
|
@ -809,11 +809,11 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
|||
}
|
||||
if (power < 0) {
|
||||
if (power == Integer.MIN_VALUE) { // MIN_VALUE can't be negated.
|
||||
return this.invert().pow(2).pow(-(power / 2));
|
||||
return invert().pow(2).pow(-(power / 2));
|
||||
}
|
||||
return this.invert().pow(-power);
|
||||
return invert().pow(-power);
|
||||
}
|
||||
final Fraction f = this.multiplyBy(this);
|
||||
final Fraction f = multiplyBy(this);
|
||||
if (power % 2 == 0) { // if even...
|
||||
return f.pow(power / 2);
|
||||
}
|
||||
|
|
|
@ -233,12 +233,10 @@ public class MethodUtils {
|
|||
while (interfaceIndex < allInterfaces.size() ||
|
||||
superClassIndex < allSuperclasses.size()) {
|
||||
final Class<?> acls;
|
||||
if (interfaceIndex >= allInterfaces.size()) {
|
||||
if (interfaceIndex >= allInterfaces.size() || superClassIndex < allSuperclasses.size() && superClassIndex < interfaceIndex) {
|
||||
acls = allSuperclasses.get(superClassIndex++);
|
||||
} else if (superClassIndex >= allSuperclasses.size() || !(superClassIndex < interfaceIndex)) {
|
||||
acls = allInterfaces.get(interfaceIndex++);
|
||||
} else {
|
||||
acls = allSuperclasses.get(superClassIndex++);
|
||||
acls = allInterfaces.get(interfaceIndex++);
|
||||
}
|
||||
allSuperClassesAndInterfaces.add(acls);
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
|
|||
if (!ready()) {
|
||||
return -1;
|
||||
}
|
||||
return StrBuilder.this.charAt(pos++);
|
||||
return charAt(pos++);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -135,11 +135,11 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
|
|||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (pos >= StrBuilder.this.size()) {
|
||||
if (pos >= size()) {
|
||||
return -1;
|
||||
}
|
||||
if (pos + len > size()) {
|
||||
len = StrBuilder.this.size() - pos;
|
||||
len = size() - pos;
|
||||
}
|
||||
StrBuilder.this.getChars(pos, pos + len, b, off);
|
||||
pos += len;
|
||||
|
@ -149,7 +149,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean ready() {
|
||||
return pos < StrBuilder.this.size();
|
||||
return pos < size();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -161,8 +161,8 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public long skip(long n) {
|
||||
if (pos + n > StrBuilder.this.size()) {
|
||||
n = StrBuilder.this.size() - pos;
|
||||
if (pos + n > size()) {
|
||||
n = size() - pos;
|
||||
}
|
||||
if (n < 0) {
|
||||
return 0;
|
||||
|
|
|
@ -170,7 +170,7 @@ public class StopWatch {
|
|||
abstract boolean isSuspended();
|
||||
}
|
||||
|
||||
private static final long NANO_2_MILLIS = 1000000L;
|
||||
private static final long NANO_2_MILLIS = 1_000_000L;
|
||||
|
||||
/**
|
||||
* Creates a StopWatch.
|
||||
|
|
|
@ -236,7 +236,7 @@ public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L,
|
|||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// see Map.Entry API specification
|
||||
// See Map.Entry API specification
|
||||
return Objects.hashCode(getKey()) ^ Objects.hashCode(getValue());
|
||||
}
|
||||
|
||||
|
@ -253,13 +253,14 @@ public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L,
|
|||
/**
|
||||
* Formats the receiver using the given format.
|
||||
*
|
||||
* <p>This uses {@link java.util.Formattable} to perform the formatting. Two variables may
|
||||
* be used to embed the left and right elements. Use {@code %1$s} for the left
|
||||
* element (key) and {@code %2$s} for the right element (value).
|
||||
* The default format used by {@code toString()} is {@code (%1$s,%2$s)}.</p>
|
||||
* <p>
|
||||
* This uses {@link String#format(String, Object...)} to the format. Two variables may be used to embed the left and right elements. Use {@code %1$s} for
|
||||
* the left element (key) and {@code %2$s} for the right element (value).
|
||||
* </p>
|
||||
*
|
||||
* @param format the format string, optionally containing {@code %1$s} and {@code %2$s}, not null
|
||||
* @param format the format string, optionally containing {@code %1$s} and {@code %2$s}, not null.
|
||||
* @return the formatted string, not null
|
||||
* @see String#format(String, Object...)
|
||||
*/
|
||||
public String toString(final String format) {
|
||||
return String.format(format, getLeft(), getRight());
|
||||
|
|
|
@ -75,7 +75,7 @@ public class ArrayUtilsTest extends AbstractLangTest {
|
|||
|
||||
@Test
|
||||
public void testArraycopyFunction() {
|
||||
String[] arr = { "a", "b" };
|
||||
final String[] arr = { "a", "b" };
|
||||
assertThrows(NullPointerException.class, () -> ArrayUtils.arraycopy(null, 0, 0, 1, i -> new String[3]));
|
||||
assertThrows(NullPointerException.class, () -> ArrayUtils.arraycopy(arr, 0, 0, 1, i -> null));
|
||||
assertThrows(NullPointerException.class, () -> ArrayUtils.arraycopy(arr, 0, 0, 1, (Function<Integer, String[]>) null));
|
||||
|
@ -83,7 +83,7 @@ public class ArrayUtilsTest extends AbstractLangTest {
|
|||
|
||||
@Test
|
||||
public void testArraycopySupplier() {
|
||||
String[] arr = { "a", "b" };
|
||||
final String[] arr = { "a", "b" };
|
||||
assertThrows(NullPointerException.class, () -> ArrayUtils.arraycopy(null, 0, 0, 1, () -> new String[3]));
|
||||
assertThrows(NullPointerException.class, () -> ArrayUtils.arraycopy(arr, 0, 0, 1, Suppliers.nul()));
|
||||
assertThrows(NullPointerException.class, () -> ArrayUtils.arraycopy(arr, 0, 0, 1, (Supplier<String[]>) null));
|
||||
|
@ -1397,42 +1397,42 @@ public class ArrayUtilsTest extends AbstractLangTest {
|
|||
final long[][] larray1 = {{2, 5}, {4, 5}};
|
||||
final long[][] larray2 = {{2, 5}, {4, 6}};
|
||||
final long[] larray3 = {2, 5};
|
||||
this.assertIsEquals(larray1, larray2, larray3);
|
||||
assertIsEquals(larray1, larray2, larray3);
|
||||
|
||||
final int[][] iarray1 = {{2, 5}, {4, 5}};
|
||||
final int[][] iarray2 = {{2, 5}, {4, 6}};
|
||||
final int[] iarray3 = {2, 5};
|
||||
this.assertIsEquals(iarray1, iarray2, iarray3);
|
||||
assertIsEquals(iarray1, iarray2, iarray3);
|
||||
|
||||
final short[][] sarray1 = {{2, 5}, {4, 5}};
|
||||
final short[][] sarray2 = {{2, 5}, {4, 6}};
|
||||
final short[] sarray3 = {2, 5};
|
||||
this.assertIsEquals(sarray1, sarray2, sarray3);
|
||||
assertIsEquals(sarray1, sarray2, sarray3);
|
||||
|
||||
final float[][] farray1 = {{2, 5}, {4, 5}};
|
||||
final float[][] farray2 = {{2, 5}, {4, 6}};
|
||||
final float[] farray3 = {2, 5};
|
||||
this.assertIsEquals(farray1, farray2, farray3);
|
||||
assertIsEquals(farray1, farray2, farray3);
|
||||
|
||||
final double[][] darray1 = {{2, 5}, {4, 5}};
|
||||
final double[][] darray2 = {{2, 5}, {4, 6}};
|
||||
final double[] darray3 = {2, 5};
|
||||
this.assertIsEquals(darray1, darray2, darray3);
|
||||
assertIsEquals(darray1, darray2, darray3);
|
||||
|
||||
final byte[][] byteArray1 = {{2, 5}, {4, 5}};
|
||||
final byte[][] byteArray2 = {{2, 5}, {4, 6}};
|
||||
final byte[] byteArray3 = {2, 5};
|
||||
this.assertIsEquals(byteArray1, byteArray2, byteArray3);
|
||||
assertIsEquals(byteArray1, byteArray2, byteArray3);
|
||||
|
||||
final char[][] charArray1 = {{2, 5}, {4, 5}};
|
||||
final char[][] charArray2 = {{2, 5}, {4, 6}};
|
||||
final char[] charArray3 = {2, 5};
|
||||
this.assertIsEquals(charArray1, charArray2, charArray3);
|
||||
assertIsEquals(charArray1, charArray2, charArray3);
|
||||
|
||||
final boolean[][] barray1 = {{true, false}, {true, true}};
|
||||
final boolean[][] barray2 = {{true, false}, {true, false}};
|
||||
final boolean[] barray3 = {false, true};
|
||||
this.assertIsEquals(barray1, barray2, barray3);
|
||||
assertIsEquals(barray1, barray2, barray3);
|
||||
|
||||
final Object[] array3 = {new String(new char[]{'A', 'B'})};
|
||||
final Object[] array4 = {"AB"};
|
||||
|
|
|
@ -38,13 +38,12 @@ public class CachedRandomBitsTest {
|
|||
private int index;
|
||||
|
||||
MockRandom(final byte[] outputs) {
|
||||
super();
|
||||
this.outputs = outputs.clone();
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextBytes(byte[] bytes) {
|
||||
public void nextBytes(final byte[] bytes) {
|
||||
Objects.requireNonNull(bytes, "bytes");
|
||||
if (index + bytes.length > outputs.length) {
|
||||
throw new IllegalStateException("Not enough outputs given in MockRandom");
|
||||
|
@ -56,8 +55,8 @@ public class CachedRandomBitsTest {
|
|||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 32})
|
||||
public void testNext(int cacheSize) {
|
||||
MockRandom random = new MockRandom(new byte[]{
|
||||
public void testNext(final int cacheSize) {
|
||||
final MockRandom random = new MockRandom(new byte[]{
|
||||
0x11, 0x12, 0x13, 0x25,
|
||||
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0xff,
|
||||
0x55, 0x44, 0x12, 0x34,
|
||||
|
@ -68,7 +67,7 @@ public class CachedRandomBitsTest {
|
|||
0x00, 0x00, 0x00, 0x00,
|
||||
});
|
||||
|
||||
CachedRandomBits arb = new CachedRandomBits(cacheSize, random);
|
||||
final CachedRandomBits arb = new CachedRandomBits(cacheSize, random);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> arb.nextBits(0));
|
||||
assertThrows(IllegalArgumentException.class, () -> arb.nextBits(33));
|
||||
|
@ -86,7 +85,7 @@ public class CachedRandomBitsTest {
|
|||
|
||||
assertEquals(0x4, arb.nextBits(6));
|
||||
|
||||
assertEquals(0x40000000 | (0x12345600 >> 2) | 0x38, arb.nextBits(32));
|
||||
assertEquals(0x40000000 | 0x12345600 >> 2 | 0x38, arb.nextBits(32));
|
||||
|
||||
assertEquals(1, arb.nextBits(1));
|
||||
assertEquals(0, arb.nextBits(1));
|
||||
|
|
|
@ -47,12 +47,12 @@ public class CharEncodingTest extends AbstractLangTest {
|
|||
|
||||
@Test
|
||||
public void testMustBeSupportedJava1_3_1_and_above() {
|
||||
this.assertSupportedEncoding(CharEncoding.ISO_8859_1);
|
||||
this.assertSupportedEncoding(CharEncoding.US_ASCII);
|
||||
this.assertSupportedEncoding(CharEncoding.UTF_16);
|
||||
this.assertSupportedEncoding(CharEncoding.UTF_16BE);
|
||||
this.assertSupportedEncoding(CharEncoding.UTF_16LE);
|
||||
this.assertSupportedEncoding(CharEncoding.UTF_8);
|
||||
assertSupportedEncoding(CharEncoding.ISO_8859_1);
|
||||
assertSupportedEncoding(CharEncoding.US_ASCII);
|
||||
assertSupportedEncoding(CharEncoding.UTF_16);
|
||||
assertSupportedEncoding(CharEncoding.UTF_16BE);
|
||||
assertSupportedEncoding(CharEncoding.UTF_16LE);
|
||||
assertSupportedEncoding(CharEncoding.UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -99,22 +99,22 @@ public class CharUtilsPerfRun {
|
|||
}
|
||||
|
||||
private void run() {
|
||||
this.printSysInfo();
|
||||
printSysInfo();
|
||||
long startMillis;
|
||||
startMillis = System.currentTimeMillis();
|
||||
this.printlnTotal("Do nothing", startMillis);
|
||||
printlnTotal("Do nothing", startMillis);
|
||||
run_CharUtils_isAsciiNumeric(WARM_UP);
|
||||
startMillis = System.currentTimeMillis();
|
||||
run_CharUtils_isAsciiNumeric(COUNT);
|
||||
this.printlnTotal("run_CharUtils_isAsciiNumeric", startMillis);
|
||||
printlnTotal("run_CharUtils_isAsciiNumeric", startMillis);
|
||||
run_inlined_CharUtils_isAsciiNumeric(WARM_UP);
|
||||
startMillis = System.currentTimeMillis();
|
||||
run_inlined_CharUtils_isAsciiNumeric(COUNT);
|
||||
this.printlnTotal("run_inlined_CharUtils_isAsciiNumeric", startMillis);
|
||||
printlnTotal("run_inlined_CharUtils_isAsciiNumeric", startMillis);
|
||||
run_CharSet(WARM_UP);
|
||||
startMillis = System.currentTimeMillis();
|
||||
run_CharSet(COUNT);
|
||||
this.printlnTotal("run_CharSet", startMillis);
|
||||
printlnTotal("run_CharSet", startMillis);
|
||||
}
|
||||
|
||||
private int run_CharSet(final int loopCount) {
|
||||
|
|
|
@ -72,7 +72,7 @@ public class LocaleUtilsTest extends AbstractLangTest {
|
|||
for (final String country : countries) {
|
||||
boolean found = false;
|
||||
// see if it was returned by the set
|
||||
for (Locale locale : list) {
|
||||
for (final Locale locale : list) {
|
||||
// should have an en empty variant
|
||||
assertTrue(StringUtils.isEmpty(locale.getVariant()));
|
||||
assertEquals(language, locale.getLanguage());
|
||||
|
@ -104,7 +104,7 @@ public class LocaleUtilsTest extends AbstractLangTest {
|
|||
for (final String language : languages) {
|
||||
boolean found = false;
|
||||
// see if it was returned by the set
|
||||
for (Locale locale : list) {
|
||||
for (final Locale locale : list) {
|
||||
// should have an en empty variant
|
||||
assertTrue(StringUtils.isEmpty(locale.getVariant()));
|
||||
assertEquals(country, locale.getCountry());
|
||||
|
|
|
@ -732,4 +732,74 @@ public class RandomStringUtilsTest extends AbstractLangTest {
|
|||
assertNotEquals(r1, r3);
|
||||
assertNotEquals(r2, r3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@code RandomStringUtils.random} works appropriately when letters=true
|
||||
* and the range does not only include ASCII letters.
|
||||
* Fails with probability less than 2^-40 (in practice this never happens).
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("randomProvider")
|
||||
void testNonASCIILetters(final RandomStringUtils rsu) {
|
||||
// Check that the following create a string with 10 characters 0x4e00 (a non-ASCII letter)
|
||||
String r1 = rsu.next(10, 0x4e00, 0x4e01, true, false);
|
||||
assertEquals(10, r1.length(), "wrong length");
|
||||
for (int i = 0; i < r1.length(); i++) {
|
||||
assertEquals(0x4e00, r1.charAt(i), "characters not all equal to 0x4e00");
|
||||
}
|
||||
|
||||
// Same with both letters=true and numbers=true
|
||||
r1 = rsu.next(10, 0x4e00, 0x4e01, true, true);
|
||||
assertEquals(10, r1.length(), "wrong length");
|
||||
for (int i = 0; i < r1.length(); i++) {
|
||||
assertEquals(0x4e00, r1.charAt(i), "characters not all equal to 0x4e00");
|
||||
}
|
||||
|
||||
// Check that at least one letter is not ASCII
|
||||
boolean found = false;
|
||||
r1 = rsu.next(40, 'F', 0x3000, true, false);
|
||||
assertEquals(40, r1.length(), "wrong length");
|
||||
for (int i = 0; i < r1.length(); i++) {
|
||||
assertTrue(Character.isLetter(r1.charAt(i)), "characters not all letters");
|
||||
if (r1.charAt(i) > 0x7f) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue(found, "no non-ASCII letter generated");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@code RandomStringUtils.random} works appropriately when numbers=true
|
||||
* and the range does not only include ASCII numbers/digits.
|
||||
* Fails with probability less than 2^-40 (in practice this never happens).
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("randomProvider")
|
||||
void testNonASCIINumbers(final RandomStringUtils rsu) {
|
||||
// Check that the following create a string with 10 characters 0x0660 (a non-ASCII digit)
|
||||
String r1 = rsu.next(10, 0x0660, 0x0661, false, true);
|
||||
assertEquals(10, r1.length(), "wrong length");
|
||||
for (int i = 0; i < r1.length(); i++) {
|
||||
assertEquals(0x0660, r1.charAt(i), "characters not all equal to 0x0660");
|
||||
}
|
||||
|
||||
// Same with both letters=true and numbers=true
|
||||
r1 = rsu.next(10, 0x0660, 0x0661, true, true);
|
||||
assertEquals(10, r1.length(), "wrong length");
|
||||
for (int i = 0; i < r1.length(); i++) {
|
||||
assertEquals(0x0660, r1.charAt(i), "characters not all equal to 0x0660");
|
||||
}
|
||||
|
||||
// Check that at least one letter is not ASCII
|
||||
boolean found = false;
|
||||
r1 = rsu.next(40, 'F', 0x3000, false, true);
|
||||
assertEquals(40, r1.length(), "wrong length");
|
||||
for (int i = 0; i < r1.length(); i++) {
|
||||
assertTrue(Character.isDigit(r1.charAt(i)), "characters not all numbers");
|
||||
if (r1.charAt(i) > 0x7f) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue(found, "no non-ASCII number generated");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class ReflectionToStringBuilderConcurrencyTest extends AbstractLangTest {
|
|||
@Test
|
||||
@Disabled
|
||||
public void testArrayList() throws InterruptedException {
|
||||
this.testConcurrency(new CollectionHolder<>(new ArrayList<>()));
|
||||
testConcurrency(new CollectionHolder<>(new ArrayList<>()));
|
||||
}
|
||||
|
||||
private void testConcurrency(final CollectionHolder<List<Integer>> holder) throws InterruptedException {
|
||||
|
@ -106,12 +106,12 @@ public class ReflectionToStringBuilderConcurrencyTest extends AbstractLangTest {
|
|||
@Test
|
||||
@Disabled
|
||||
public void testCopyOnWriteArrayList() throws InterruptedException {
|
||||
this.testConcurrency(new CollectionHolder<>(new CopyOnWriteArrayList<>()));
|
||||
testConcurrency(new CollectionHolder<>(new CopyOnWriteArrayList<>()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testLinkedList() throws InterruptedException {
|
||||
this.testConcurrency(new CollectionHolder<>(new LinkedList<>()));
|
||||
testConcurrency(new CollectionHolder<>(new LinkedList<>()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,25 +51,25 @@ public class ReflectionToStringBuilderExcludeTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void test_toStringExclude() {
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), SECRET_FIELD);
|
||||
this.validateSecretFieldAbsent(toString);
|
||||
validateSecretFieldAbsent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringExcludeArray() {
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), SECRET_FIELD);
|
||||
this.validateSecretFieldAbsent(toString);
|
||||
validateSecretFieldAbsent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringExcludeArrayWithNull() {
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), new String[]{null});
|
||||
this.validateSecretFieldPresent(toString);
|
||||
validateSecretFieldPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringExcludeArrayWithNulls() {
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), null, null);
|
||||
this.validateSecretFieldPresent(toString);
|
||||
validateSecretFieldPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,7 +77,7 @@ public class ReflectionToStringBuilderExcludeTest extends AbstractLangTest {
|
|||
final List<String> excludeList = new ArrayList<>();
|
||||
excludeList.add(SECRET_FIELD);
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), excludeList);
|
||||
this.validateSecretFieldAbsent(toString);
|
||||
validateSecretFieldAbsent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,7 +85,7 @@ public class ReflectionToStringBuilderExcludeTest extends AbstractLangTest {
|
|||
final List<String> excludeList = new ArrayList<>();
|
||||
excludeList.add(null);
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), excludeList);
|
||||
this.validateSecretFieldPresent(toString);
|
||||
validateSecretFieldPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -94,31 +94,31 @@ public class ReflectionToStringBuilderExcludeTest extends AbstractLangTest {
|
|||
excludeList.add(null);
|
||||
excludeList.add(null);
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), excludeList);
|
||||
this.validateSecretFieldPresent(toString);
|
||||
validateSecretFieldPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringExcludeEmptyArray() {
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
this.validateSecretFieldPresent(toString);
|
||||
validateSecretFieldPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringExcludeEmptyCollection() {
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), new ArrayList<>());
|
||||
this.validateSecretFieldPresent(toString);
|
||||
validateSecretFieldPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringExcludeNullArray() {
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), (String[]) null);
|
||||
this.validateSecretFieldPresent(toString);
|
||||
validateSecretFieldPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringExcludeNullCollection() {
|
||||
final String toString = ReflectionToStringBuilder.toStringExclude(new TestFixture(), (Collection<String>) null);
|
||||
this.validateSecretFieldPresent(toString);
|
||||
validateSecretFieldPresent(toString);
|
||||
}
|
||||
|
||||
private void validateNonSecretField(final String toString) {
|
||||
|
@ -128,11 +128,11 @@ public class ReflectionToStringBuilderExcludeTest extends AbstractLangTest {
|
|||
|
||||
private void validateSecretFieldAbsent(final String toString) {
|
||||
assertEquals(ArrayUtils.INDEX_NOT_FOUND, toString.indexOf(SECRET_VALUE));
|
||||
this.validateNonSecretField(toString);
|
||||
validateNonSecretField(toString);
|
||||
}
|
||||
|
||||
private void validateSecretFieldPresent(final String toString) {
|
||||
assertTrue(toString.indexOf(SECRET_VALUE) > 0);
|
||||
this.validateNonSecretField(toString);
|
||||
validateNonSecretField(toString);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,31 +64,31 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
public void test_toStringDefaultBehavior() {
|
||||
final ReflectionToStringBuilder builder = new ReflectionToStringBuilder(new TestFeature());
|
||||
final String toString = builder.toString();
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringInclude() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), SINGLE_FIELD_TO_SHOW);
|
||||
this.validateIncludeFieldsPresent(toString, new String[]{ SINGLE_FIELD_TO_SHOW }, new String[]{ SINGLE_FIELD_VALUE_TO_SHOW });
|
||||
validateIncludeFieldsPresent(toString, new String[]{ SINGLE_FIELD_TO_SHOW }, new String[]{ SINGLE_FIELD_VALUE_TO_SHOW });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeArray() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), FIELDS_TO_SHOW);
|
||||
this.validateIncludeFieldsPresent(toString, FIELDS_TO_SHOW, FIELDS_VALUES_TO_SHOW);
|
||||
validateIncludeFieldsPresent(toString, FIELDS_TO_SHOW, FIELDS_VALUES_TO_SHOW);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeArrayWithNull() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), new String[]{null});
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeArrayWithNulls() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), null, null);
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -96,7 +96,7 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
final List<String> includeList = new ArrayList<>();
|
||||
includeList.add(SINGLE_FIELD_TO_SHOW);
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), includeList);
|
||||
this.validateIncludeFieldsPresent(toString, new String[]{ SINGLE_FIELD_TO_SHOW }, new String[]{ SINGLE_FIELD_VALUE_TO_SHOW });
|
||||
validateIncludeFieldsPresent(toString, new String[]{ SINGLE_FIELD_TO_SHOW }, new String[]{ SINGLE_FIELD_VALUE_TO_SHOW });
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -104,7 +104,7 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
final List<String> includeList = new ArrayList<>();
|
||||
includeList.add(null);
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), includeList);
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -113,43 +113,43 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
includeList.add(null);
|
||||
includeList.add(null);
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), includeList);
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeEmptyArray() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeEmptyCollection() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), new ArrayList<>());
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeNullArray() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), (String[]) null);
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeNullArrayMultiplesValues() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), null, null, null, null);
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeNullCollection() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), (Collection<String>) null);
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toStringIncludeWithoutInformingFields() {
|
||||
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature());
|
||||
this.validateAllFieldsPresent(toString);
|
||||
validateAllFieldsPresent(toString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -168,7 +168,7 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
builder.setExcludeFieldNames(FIELDS[1], FIELDS[4]);
|
||||
builder.setIncludeFieldNames(FIELDS_TO_SHOW);
|
||||
final String toString = builder.toString();
|
||||
this.validateIncludeFieldsPresent(toString, FIELDS_TO_SHOW, FIELDS_VALUES_TO_SHOW);
|
||||
validateIncludeFieldsPresent(toString, FIELDS_TO_SHOW, FIELDS_VALUES_TO_SHOW);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -187,7 +187,7 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
builder.setExcludeFieldNames(FIELDS[1], "random1");
|
||||
builder.setIncludeFieldNames("random2", FIELDS[2]);
|
||||
final String toString = builder.toString();
|
||||
this.validateIncludeFieldsPresent(toString, new String[]{FIELDS[2]}, new String[]{VALUES[2]});
|
||||
validateIncludeFieldsPresent(toString, new String[]{FIELDS[2]}, new String[]{VALUES[2]});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -196,7 +196,7 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
builder.setExcludeFieldNames(FIELDS[1], FIELDS[4]);
|
||||
builder.setIncludeFieldNames(null, null, null);
|
||||
final String toString = builder.toString();
|
||||
this.validateIncludeFieldsPresent(toString, new String[]{FIELDS[0], FIELDS[2], FIELDS[3]}, new String[]{VALUES[0], VALUES[2], VALUES[3]});
|
||||
validateIncludeFieldsPresent(toString, new String[]{FIELDS[0], FIELDS[2], FIELDS[3]}, new String[]{VALUES[0], VALUES[2], VALUES[3]});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -205,7 +205,7 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
builder.setExcludeFieldNames(FIELDS[1], FIELDS[4]);
|
||||
builder.setIncludeFieldNames(null, null, null);
|
||||
final String toString = builder.toString();
|
||||
this.validateIncludeFieldsPresent(toString, new String[]{FIELDS[0], FIELDS[2], FIELDS[3]}, new String[]{VALUES[0], VALUES[2], VALUES[3]});
|
||||
validateIncludeFieldsPresent(toString, new String[]{FIELDS[0], FIELDS[2], FIELDS[3]}, new String[]{VALUES[0], VALUES[2], VALUES[3]});
|
||||
}
|
||||
|
||||
private void validateAllFieldsPresent(final String toString) {
|
||||
|
@ -221,7 +221,7 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
|
|||
assertTrue(toString.indexOf(includeValue) > 0);
|
||||
}
|
||||
|
||||
this.validateNonIncludeFieldsAbsent(toString, fieldsToShow, valuesToShow);
|
||||
validateNonIncludeFieldsAbsent(toString, fieldsToShow, valuesToShow);
|
||||
}
|
||||
|
||||
private void validateNonIncludeFieldsAbsent(final String toString, final String[] IncludeFields, final String[] IncludeFieldsValues) {
|
||||
|
|
|
@ -654,13 +654,13 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testInheritedReflectionStatics() {
|
||||
final InheritedReflectionStaticFieldsFixture instance1 = new InheritedReflectionStaticFieldsFixture();
|
||||
assertEquals(this.toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2]",
|
||||
assertEquals(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2]",
|
||||
ReflectionToStringBuilder.toString(instance1, null, false, true, InheritedReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
|
||||
ReflectionToStringBuilder.toString(instance1, null, false, true, SimpleReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
|
||||
this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
|
||||
this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class));
|
||||
}
|
||||
|
||||
|
@ -789,9 +789,9 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
final Object[] objects = new Object[1];
|
||||
final SimpleReflectionTestFixture simple = new SimpleReflectionTestFixture(objects);
|
||||
objects[0] = simple;
|
||||
assertEquals(this.toBaseString(objects) + "[{" + this.toBaseString(simple) + "[o=" + this.toBaseString(objects) + "]" + "}]",
|
||||
assertEquals(toBaseString(objects) + "[{" + toBaseString(simple) + "[o=" + toBaseString(objects) + "]" + "}]",
|
||||
ToStringBuilder.reflectionToString(objects));
|
||||
assertEquals(this.toBaseString(simple) + "[o={" + this.toBaseString(simple) + "}]", ToStringBuilder.reflectionToString(simple));
|
||||
assertEquals(toBaseString(simple) + "[o={" + toBaseString(simple) + "}]", ToStringBuilder.reflectionToString(simple));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -801,7 +801,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
objects[0][1] = objects;
|
||||
objects[1][0] = objects;
|
||||
objects[1][1] = objects;
|
||||
final String basicToString = this.toBaseString(objects);
|
||||
final String basicToString = toBaseString(objects);
|
||||
assertEquals(basicToString + "[{{" + basicToString + "," + basicToString + "},{" + basicToString + "," + basicToString + "}}]",
|
||||
ToStringBuilder.reflectionToString(objects));
|
||||
}
|
||||
|
@ -813,7 +813,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
public void testReflectionArrayCycle() {
|
||||
final Object[] objects = new Object[1];
|
||||
objects[0] = objects;
|
||||
assertEquals(this.toBaseString(objects) + "[{" + this.toBaseString(objects) + "}]", ToStringBuilder.reflectionToString(objects));
|
||||
assertEquals(toBaseString(objects) + "[{" + toBaseString(objects) + "}]", ToStringBuilder.reflectionToString(objects));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -825,8 +825,8 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
final Object[] objectsLevel2 = new Object[1];
|
||||
objects[0] = objectsLevel2;
|
||||
objectsLevel2[0] = objects;
|
||||
assertEquals(this.toBaseString(objects) + "[{{" + this.toBaseString(objects) + "}}]", ToStringBuilder.reflectionToString(objects));
|
||||
assertEquals(this.toBaseString(objectsLevel2) + "[{{" + this.toBaseString(objectsLevel2) + "}}]", ToStringBuilder.reflectionToString(objectsLevel2));
|
||||
assertEquals(toBaseString(objects) + "[{{" + toBaseString(objects) + "}}]", ToStringBuilder.reflectionToString(objects));
|
||||
assertEquals(toBaseString(objectsLevel2) + "[{{" + toBaseString(objectsLevel2) + "}}]", ToStringBuilder.reflectionToString(objectsLevel2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -836,15 +836,15 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
public void testReflectionBoolean() {
|
||||
Boolean b;
|
||||
b = Boolean.TRUE;
|
||||
assertEquals(this.toBaseString(b) + "[value=true]", ToStringBuilder.reflectionToString(b));
|
||||
assertEquals(toBaseString(b) + "[value=true]", ToStringBuilder.reflectionToString(b));
|
||||
b = Boolean.FALSE;
|
||||
assertEquals(this.toBaseString(b) + "[value=false]", ToStringBuilder.reflectionToString(b));
|
||||
assertEquals(toBaseString(b) + "[value=false]", ToStringBuilder.reflectionToString(b));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReflectionBooleanArray() {
|
||||
boolean[] array = { true, false, false };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{true,false,false}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -853,7 +853,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionBooleanArrayArray() {
|
||||
boolean[][] array = { { true, false }, null, { false } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{{true,false},<null>,{false}}]", ToStringBuilder.reflectionToString(array));
|
||||
assertEquals(baseString + "[{{true,false},<null>,{false}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
|
@ -863,7 +863,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionByteArray() {
|
||||
byte[] array = { 1, 2, -3, 4 };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{1,2,-3,4}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -872,7 +872,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionByteArrayArray() {
|
||||
byte[][] array = { { 1, 2 }, null, { 5 } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{{1,2},<null>,{5}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -884,13 +884,13 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionCharacter() {
|
||||
final Character c = 'A';
|
||||
assertEquals(this.toBaseString(c) + "[value=A]", ToStringBuilder.reflectionToString(c));
|
||||
assertEquals(toBaseString(c) + "[value=A]", ToStringBuilder.reflectionToString(c));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReflectionCharArray() {
|
||||
char[] array = { 'A', '2', '_', 'D' };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{A,2,_,D}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -899,7 +899,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionCharArrayArray() {
|
||||
char[][] array = { { 'A', 'B' }, null, { 'p' } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{{A,B},<null>,{p}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -908,7 +908,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionDoubleArray() {
|
||||
double[] array = { 1.0, 2.9876, -3.00001, 4.3 };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{1.0,2.9876,-3.00001,4.3}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -917,7 +917,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionDoubleArrayArray() {
|
||||
double[][] array = { { 1.0, 2.29686 }, null, { Double.NaN } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{{1.0,2.29686},<null>,{NaN}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -926,7 +926,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionFloatArray() {
|
||||
float[] array = { 1.0f, 2.9876f, -3.00001f, 4.3f };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{1.0,2.9876,-3.00001,4.3}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -935,7 +935,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionFloatArrayArray() {
|
||||
float[][] array = { { 1.0f, 2.29686f }, null, { Float.NaN } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{{1.0,2.29686},<null>,{NaN}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -944,7 +944,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionHierarchy() {
|
||||
final ReflectionTestFixtureA baseA = new ReflectionTestFixtureA();
|
||||
String baseString = this.toBaseString(baseA);
|
||||
String baseString = toBaseString(baseA);
|
||||
assertEquals(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA));
|
||||
assertEquals(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null));
|
||||
assertEquals(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false));
|
||||
|
@ -954,7 +954,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
assertEquals(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, ReflectionTestFixtureA.class));
|
||||
|
||||
final ReflectionTestFixtureB baseB = new ReflectionTestFixtureB();
|
||||
baseString = this.toBaseString(baseB);
|
||||
baseString = toBaseString(baseB);
|
||||
assertEquals(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB));
|
||||
assertEquals(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB));
|
||||
assertEquals(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null));
|
||||
|
@ -971,7 +971,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
public void testReflectionHierarchyArrayList() {
|
||||
// LANG-1337 without this, the generated string can differ depending on the JVM version/vendor
|
||||
final List<Object> list = new ArrayList<>(ARRAYLIST_INITIAL_CAPACITY);
|
||||
final String baseString = this.toBaseString(list);
|
||||
final String baseString = toBaseString(list);
|
||||
final String expectedWithTransients = baseString
|
||||
+ "[elementData={<null>,<null>,<null>,<null>,<null>,<null>,<null>,<null>,<null>,<null>},size=0,modCount=0]";
|
||||
final String toStringWithTransients = ToStringBuilder.reflectionToString(list, null, true);
|
||||
|
@ -988,7 +988,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionIntArray() {
|
||||
int[] array = { 1, 2, -3, 4 };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{1,2,-3,4}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -997,7 +997,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionIntArrayArray() {
|
||||
int[][] array = { { 1, 2 }, null, { 5 } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{{1,2},<null>,{5}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -1014,7 +1014,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionLongArray() {
|
||||
long[] array = { 1, 2, -3, 4 };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{1,2,-3,4}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -1023,7 +1023,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionLongArrayArray() {
|
||||
long[][] array = { { 1, 2 }, null, { 5 } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{{1,2},<null>,{5}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -1037,7 +1037,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionObjectArray() {
|
||||
Object[] array = { null, base, new int[] { 3, 6 } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{<null>,5,{3,6}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -1052,13 +1052,13 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
final ReflectionTestCycleB b = new ReflectionTestCycleB();
|
||||
a.b = b;
|
||||
b.a = a;
|
||||
assertEquals(this.toBaseString(a) + "[b=" + this.toBaseString(b) + "[a=" + this.toBaseString(a) + "]]", a.toString());
|
||||
assertEquals(toBaseString(a) + "[b=" + toBaseString(b) + "[a=" + toBaseString(a) + "]]", a.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReflectionShort2DArray() {
|
||||
short[][] array = { { 1, 2 }, null, { 5 } };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{{1,2},<null>,{5}}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -1067,7 +1067,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionShortArray() {
|
||||
short[] array = { 1, 2, -3, 4 };
|
||||
final String baseString = this.toBaseString(array);
|
||||
final String baseString = toBaseString(array);
|
||||
assertEquals(baseString + "[{1,2,-3,4}]", ToStringBuilder.reflectionToString(array));
|
||||
array = null;
|
||||
assertReflectionArray("<null>", array);
|
||||
|
@ -1079,14 +1079,14 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testReflectionStatics() {
|
||||
final ReflectionStaticFieldsFixture instance1 = new ReflectionStaticFieldsFixture();
|
||||
assertEquals(this.toBaseString(instance1) + "[instanceInt=67890,instanceString=instanceString,staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[instanceInt=67890,instanceString=instanceString,staticInt=12345,staticString=staticString]",
|
||||
ReflectionToStringBuilder.toString(instance1, null, false, true, ReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1)
|
||||
assertEquals(toBaseString(instance1)
|
||||
+ "[instanceInt=67890,instanceString=instanceString,staticInt=12345,staticString=staticString,staticTransientInt=54321,staticTransientString=staticTransientString,transientInt=98765,transientString=transientString]",
|
||||
ReflectionToStringBuilder.toString(instance1, null, true, true, ReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1) + "[instanceInt=67890,instanceString=instanceString,staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[instanceInt=67890,instanceString=instanceString,staticInt=12345,staticString=staticString]",
|
||||
this.toStringWithStatics(instance1, null, ReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1) + "[instanceInt=67890,instanceString=instanceString,staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[instanceInt=67890,instanceString=instanceString,staticInt=12345,staticString=staticString]",
|
||||
this.toStringWithStatics(instance1, null, ReflectionStaticFieldsFixture.class));
|
||||
}
|
||||
|
||||
|
@ -1097,7 +1097,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testSelfInstanceTwoVarsReflectionObjectCycle() {
|
||||
final SelfInstanceTwoVarsReflectionTestFixture test = new SelfInstanceTwoVarsReflectionTestFixture();
|
||||
assertEquals(this.toBaseString(test) + "[otherType=" + test.getOtherType().toString() + ",typeIsSelf=" + this.toBaseString(test) + "]",
|
||||
assertEquals(toBaseString(test) + "[otherType=" + test.getOtherType().toString() + ",typeIsSelf=" + toBaseString(test) + "]",
|
||||
test.toString());
|
||||
}
|
||||
|
||||
|
@ -1107,7 +1107,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testSelfInstanceVarReflectionObjectCycle() {
|
||||
final SelfInstanceVarReflectionTestFixture test = new SelfInstanceVarReflectionTestFixture();
|
||||
assertEquals(this.toBaseString(test) + "[typeIsSelf=" + this.toBaseString(test) + "]", test.toString());
|
||||
assertEquals(toBaseString(test) + "[typeIsSelf=" + toBaseString(test) + "]", test.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1149,19 +1149,19 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
public void testSimpleReflectionObjectCycle() {
|
||||
final SimpleReflectionTestFixture simple = new SimpleReflectionTestFixture();
|
||||
simple.o = simple;
|
||||
assertEquals(this.toBaseString(simple) + "[o=" + this.toBaseString(simple) + "]", simple.toString());
|
||||
assertEquals(toBaseString(simple) + "[o=" + toBaseString(simple) + "]", simple.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleReflectionStatics() {
|
||||
final SimpleReflectionStaticFieldsFixture instance1 = new SimpleReflectionStaticFieldsFixture();
|
||||
assertEquals(this.toBaseString(instance1) + "[staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[staticInt=12345,staticString=staticString]",
|
||||
ReflectionToStringBuilder.toString(instance1, null, false, true, SimpleReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1) + "[staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[staticInt=12345,staticString=staticString]",
|
||||
ReflectionToStringBuilder.toString(instance1, null, true, true, SimpleReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1) + "[staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[staticInt=12345,staticString=staticString]",
|
||||
this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class));
|
||||
assertEquals(this.toBaseString(instance1) + "[staticInt=12345,staticString=staticString]",
|
||||
assertEquals(toBaseString(instance1) + "[staticInt=12345,staticString=staticString]",
|
||||
this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class));
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public class ToStringStyleConcurrencyTest extends AbstractLangTest {
|
|||
|
||||
@Test
|
||||
public void testArrayList() throws InterruptedException {
|
||||
this.testConcurrency(new CollectionHolder<>(new ArrayList<>()));
|
||||
testConcurrency(new CollectionHolder<>(new ArrayList<>()));
|
||||
}
|
||||
|
||||
private void testConcurrency(final CollectionHolder<List<Integer>> holder) throws InterruptedException {
|
||||
|
@ -99,11 +99,11 @@ public class ToStringStyleConcurrencyTest extends AbstractLangTest {
|
|||
|
||||
@Test
|
||||
public void testCopyOnWriteArrayList() throws InterruptedException {
|
||||
this.testConcurrency(new CollectionHolder<>(new CopyOnWriteArrayList<>()));
|
||||
testConcurrency(new CollectionHolder<>(new CopyOnWriteArrayList<>()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkedList() throws InterruptedException {
|
||||
this.testConcurrency(new CollectionHolder<>(new LinkedList<>()));
|
||||
testConcurrency(new CollectionHolder<>(new LinkedList<>()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -443,21 +443,21 @@ public class NumberUtilsTest extends AbstractLangTest {
|
|||
assertEquals(new BigDecimal("1234.5"), NumberUtils.createBigDecimal("1234.5"),
|
||||
"createBigDecimal(String) failed");
|
||||
assertNull(NumberUtils.createBigDecimal(null), "createBigDecimal(null) failed");
|
||||
this.testCreateBigDecimalFailure("");
|
||||
this.testCreateBigDecimalFailure(" ");
|
||||
this.testCreateBigDecimalFailure("\b\t\n\f\r");
|
||||
testCreateBigDecimalFailure("");
|
||||
testCreateBigDecimalFailure(" ");
|
||||
testCreateBigDecimalFailure("\b\t\n\f\r");
|
||||
// Funky whitespaces
|
||||
this.testCreateBigDecimalFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
testCreateBigDecimalFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
// sign alone not valid
|
||||
this.testCreateBigDecimalFailure("-");
|
||||
testCreateBigDecimalFailure("-");
|
||||
// comment in NumberUtils suggests some implementations may incorrectly allow this
|
||||
this.testCreateBigDecimalFailure("--");
|
||||
this.testCreateBigDecimalFailure("--0");
|
||||
testCreateBigDecimalFailure("--");
|
||||
testCreateBigDecimalFailure("--0");
|
||||
// sign alone not valid
|
||||
this.testCreateBigDecimalFailure("+");
|
||||
testCreateBigDecimalFailure("+");
|
||||
// in case this was also allowed by some JVMs
|
||||
this.testCreateBigDecimalFailure("++");
|
||||
this.testCreateBigDecimalFailure("++0");
|
||||
testCreateBigDecimalFailure("++");
|
||||
testCreateBigDecimalFailure("++0");
|
||||
}
|
||||
|
||||
protected void testCreateBigDecimalFailure(final String str) {
|
||||
|
@ -469,11 +469,11 @@ public class NumberUtilsTest extends AbstractLangTest {
|
|||
public void testCreateBigInteger() {
|
||||
assertEquals(new BigInteger("12345"), NumberUtils.createBigInteger("12345"), "createBigInteger(String) failed");
|
||||
assertNull(NumberUtils.createBigInteger(null), "createBigInteger(null) failed");
|
||||
this.testCreateBigIntegerFailure("");
|
||||
this.testCreateBigIntegerFailure(" ");
|
||||
this.testCreateBigIntegerFailure("\b\t\n\f\r");
|
||||
testCreateBigIntegerFailure("");
|
||||
testCreateBigIntegerFailure(" ");
|
||||
testCreateBigIntegerFailure("\b\t\n\f\r");
|
||||
// Funky whitespaces
|
||||
this.testCreateBigIntegerFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
testCreateBigIntegerFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
assertEquals(new BigInteger("255"), NumberUtils.createBigInteger("0xff"), "createBigInteger(String) failed");
|
||||
assertEquals(new BigInteger("255"), NumberUtils.createBigInteger("0Xff"), "createBigInteger(String) failed");
|
||||
assertEquals(new BigInteger("255"), NumberUtils.createBigInteger("#ff"), "createBigInteger(String) failed");
|
||||
|
@ -502,11 +502,11 @@ public class NumberUtilsTest extends AbstractLangTest {
|
|||
public void testCreateDouble() {
|
||||
assertEquals(Double.valueOf("1234.5"), NumberUtils.createDouble("1234.5"), "createDouble(String) failed");
|
||||
assertNull(NumberUtils.createDouble(null), "createDouble(null) failed");
|
||||
this.testCreateDoubleFailure("");
|
||||
this.testCreateDoubleFailure(" ");
|
||||
this.testCreateDoubleFailure("\b\t\n\f\r");
|
||||
testCreateDoubleFailure("");
|
||||
testCreateDoubleFailure(" ");
|
||||
testCreateDoubleFailure("\b\t\n\f\r");
|
||||
// Funky whitespaces
|
||||
this.testCreateDoubleFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
testCreateDoubleFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
}
|
||||
|
||||
protected void testCreateDoubleFailure(final String str) {
|
||||
|
@ -518,11 +518,11 @@ public class NumberUtilsTest extends AbstractLangTest {
|
|||
public void testCreateFloat() {
|
||||
assertEquals(Float.valueOf("1234.5"), NumberUtils.createFloat("1234.5"), "createFloat(String) failed");
|
||||
assertNull(NumberUtils.createFloat(null), "createFloat(null) failed");
|
||||
this.testCreateFloatFailure("");
|
||||
this.testCreateFloatFailure(" ");
|
||||
this.testCreateFloatFailure("\b\t\n\f\r");
|
||||
testCreateFloatFailure("");
|
||||
testCreateFloatFailure(" ");
|
||||
testCreateFloatFailure("\b\t\n\f\r");
|
||||
// Funky whitespaces
|
||||
this.testCreateFloatFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
testCreateFloatFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
}
|
||||
|
||||
protected void testCreateFloatFailure(final String str) {
|
||||
|
@ -534,11 +534,11 @@ public class NumberUtilsTest extends AbstractLangTest {
|
|||
public void testCreateInteger() {
|
||||
assertEquals(Integer.valueOf("12345"), NumberUtils.createInteger("12345"), "createInteger(String) failed");
|
||||
assertNull(NumberUtils.createInteger(null), "createInteger(null) failed");
|
||||
this.testCreateIntegerFailure("");
|
||||
this.testCreateIntegerFailure(" ");
|
||||
this.testCreateIntegerFailure("\b\t\n\f\r");
|
||||
testCreateIntegerFailure("");
|
||||
testCreateIntegerFailure(" ");
|
||||
testCreateIntegerFailure("\b\t\n\f\r");
|
||||
// Funky whitespaces
|
||||
this.testCreateIntegerFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
testCreateIntegerFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
// LANG-1645
|
||||
assertEquals(Integer.decode("+0xF"), NumberUtils.createInteger("+0xF"));
|
||||
}
|
||||
|
@ -552,11 +552,11 @@ public class NumberUtilsTest extends AbstractLangTest {
|
|||
public void testCreateLong() {
|
||||
assertEquals(Long.valueOf("12345"), NumberUtils.createLong("12345"), "createLong(String) failed");
|
||||
assertNull(NumberUtils.createLong(null), "createLong(null) failed");
|
||||
this.testCreateLongFailure("");
|
||||
this.testCreateLongFailure(" ");
|
||||
this.testCreateLongFailure("\b\t\n\f\r");
|
||||
testCreateLongFailure("");
|
||||
testCreateLongFailure(" ");
|
||||
testCreateLongFailure("\b\t\n\f\r");
|
||||
// Funky whitespaces
|
||||
this.testCreateLongFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
testCreateLongFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
|
||||
// LANG-1645
|
||||
assertEquals(Long.decode("+0xFFFFFFFF"), NumberUtils.createLong("+0xFFFFFFFF"));
|
||||
}
|
||||
|
|
|
@ -651,30 +651,30 @@ public class StrTokenizerTest extends AbstractLangTest {
|
|||
}
|
||||
|
||||
private void testCSV(final String data) {
|
||||
this.testXSVAbc(StrTokenizer.getCSVInstance(data));
|
||||
this.testXSVAbc(StrTokenizer.getCSVInstance(data.toCharArray()));
|
||||
testXSVAbc(StrTokenizer.getCSVInstance(data));
|
||||
testXSVAbc(StrTokenizer.getCSVInstance(data.toCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCSVEmpty() {
|
||||
this.testEmpty(StrTokenizer.getCSVInstance());
|
||||
this.testEmpty(StrTokenizer.getCSVInstance(""));
|
||||
testEmpty(StrTokenizer.getCSVInstance());
|
||||
testEmpty(StrTokenizer.getCSVInstance(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCSVSimple() {
|
||||
this.testCSV(CSV_SIMPLE_FIXTURE);
|
||||
testCSV(CSV_SIMPLE_FIXTURE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCSVSimpleNeedsTrim() {
|
||||
this.testCSV(" " + CSV_SIMPLE_FIXTURE);
|
||||
this.testCSV(" \n\t " + CSV_SIMPLE_FIXTURE);
|
||||
this.testCSV(" \n " + CSV_SIMPLE_FIXTURE + "\n\n\r");
|
||||
testCSV(" " + CSV_SIMPLE_FIXTURE);
|
||||
testCSV(" \n\t " + CSV_SIMPLE_FIXTURE);
|
||||
testCSV(" \n " + CSV_SIMPLE_FIXTURE + "\n\n\r");
|
||||
}
|
||||
|
||||
void testEmpty(final StrTokenizer tokenizer) {
|
||||
this.checkClone(tokenizer);
|
||||
checkClone(tokenizer);
|
||||
assertFalse(tokenizer.hasNext());
|
||||
assertFalse(tokenizer.hasPrevious());
|
||||
assertNull(tokenizer.nextToken());
|
||||
|
@ -810,18 +810,18 @@ public class StrTokenizerTest extends AbstractLangTest {
|
|||
|
||||
@Test
|
||||
public void testTSV() {
|
||||
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE));
|
||||
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE.toCharArray()));
|
||||
testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE));
|
||||
testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE.toCharArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTSVEmpty() {
|
||||
this.testEmpty(StrTokenizer.getTSVInstance());
|
||||
this.testEmpty(StrTokenizer.getTSVInstance(""));
|
||||
testEmpty(StrTokenizer.getTSVInstance());
|
||||
testEmpty(StrTokenizer.getTSVInstance(""));
|
||||
}
|
||||
|
||||
void testXSVAbc(final StrTokenizer tokenizer) {
|
||||
this.checkClone(tokenizer);
|
||||
checkClone(tokenizer);
|
||||
assertEquals(-1, tokenizer.previousIndex());
|
||||
assertEquals(0, tokenizer.nextIndex());
|
||||
assertNull(tokenizer.previousToken());
|
||||
|
|
|
@ -526,7 +526,7 @@ public class DurationFormatUtilsTest extends AbstractLangTest {
|
|||
*/
|
||||
@Test
|
||||
public void testFourYears() {
|
||||
Calendar c = Calendar.getInstance();
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.set(2004, 0, 1, 0, 0, 0);
|
||||
for (int i = 0; i < FOUR_YEARS; i++) {
|
||||
bruteForce(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), "d", Calendar.DAY_OF_MONTH);
|
||||
|
|
|
@ -17,10 +17,7 @@
|
|||
package org.apache.commons.lang3.time;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
@ -37,6 +34,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.apache.commons.lang3.AbstractLangTest;
|
||||
import org.apache.commons.lang3.ThreadUtils;
|
||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||
import org.junit.jupiter.api.RepeatedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
|
@ -44,10 +42,9 @@ import org.junit.jupiter.api.Test;
|
|||
*/
|
||||
public class StopWatchTest extends AbstractLangTest {
|
||||
|
||||
private static final Duration MILLIS_200 = Duration.ofMillis(200);
|
||||
private static final Duration MILLIS_550 = Duration.ofMillis(550);
|
||||
private static final int SPLIT_CLOCK_STR_LEN = 12;
|
||||
private static final Duration MIN_DURATION = Duration.ofMillis(20);
|
||||
private static final String MESSAGE = "Baking cookies";
|
||||
private static final Duration MIN_SLEEP = Duration.ofMillis(20);
|
||||
private static final String ZERO_HOURS_PREFIX = "00:";
|
||||
private static final String ZERO_TIME_ELAPSED = "00:00:00.000";
|
||||
|
||||
|
@ -87,8 +84,14 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
return watch;
|
||||
}
|
||||
|
||||
private void sleep(final Duration duration) throws InterruptedException {
|
||||
ThreadUtils.sleep(duration);
|
||||
/**
|
||||
* Sleeps the requested duration plus one millisecond. On Java 8, sleeping for 2 or 20 millis can sleep for a tiny bit less.
|
||||
*
|
||||
* @param duration How long to sleep.
|
||||
* @throws InterruptedException if any thread has interrupted the current thread.
|
||||
*/
|
||||
private void sleepPlus1(final Duration duration) throws InterruptedException {
|
||||
ThreadUtils.sleep(duration.plusMillis(1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,7 +164,7 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testFormatSplitTime() {
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
ThreadUtils.sleepQuietly(MIN_SLEEP);
|
||||
ThreadUtils.sleepQuietly(MIN_DURATION);
|
||||
watch.split();
|
||||
final String formatSplitTime = watch.formatSplitTime();
|
||||
assertNotEquals(ZERO_TIME_ELAPSED, formatSplitTime);
|
||||
|
@ -172,7 +175,7 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
public void testFormatSplitTimeWithMessage() {
|
||||
final StopWatch watch = new StopWatch(MESSAGE);
|
||||
watch.start();
|
||||
ThreadUtils.sleepQuietly(MIN_SLEEP);
|
||||
ThreadUtils.sleepQuietly(MIN_DURATION);
|
||||
watch.split();
|
||||
final String formatSplitTime = watch.formatSplitTime();
|
||||
assertThat("formatSplitTime", formatSplitTime, not(startsWith(MESSAGE)));
|
||||
|
@ -200,18 +203,18 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
assertEquals(Duration.ZERO, watch.getDuration());
|
||||
assertEquals(ZERO_TIME_ELAPSED, watch.toString());
|
||||
watch.start();
|
||||
sleep(MILLIS_550);
|
||||
assertThat("watch.getDuration()", watch.getDuration().toMillis(), lessThan(2000L));
|
||||
sleepPlus1(MIN_DURATION);
|
||||
final long nanos = watch.getNanoTime();
|
||||
assertTrue(nanos > 0, () -> "getNanoTime(): " + nanos);
|
||||
assertTrue(DurationUtils.isPositive(watch.getDuration()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSplitDuration() {
|
||||
// Create a mock StopWatch with a time of 2:59:01.999
|
||||
// @formatter:off
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
watch.split();
|
||||
set(watch, 123456);
|
||||
// @formatter:on
|
||||
assertEquals(Duration.ofNanos(123456), watch.getSplitDuration());
|
||||
}
|
||||
|
||||
|
@ -244,14 +247,16 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
assertThrows(IllegalStateException.class, watch::getStartTime, "Calling getStartTime on a reset, but unstarted StopWatch should throw an exception");
|
||||
}
|
||||
|
||||
@Test
|
||||
@RepeatedTest(10)
|
||||
public void testGetTime() throws InterruptedException {
|
||||
final StopWatch watch = new StopWatch();
|
||||
assertEquals(0, watch.getTime());
|
||||
assertEquals(ZERO_TIME_ELAPSED, watch.toString());
|
||||
watch.start();
|
||||
sleep(MILLIS_550);
|
||||
assertThat("watch.getTime()", watch.getTime(), lessThan(2000L));
|
||||
sleepPlus1(MIN_DURATION);
|
||||
final long time = watch.getTime();
|
||||
assertTrue(time > 0, () -> "getTime() millis: " + time);
|
||||
assertTrue(time < 2000, () -> "getTime() millis: " + time);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -273,11 +278,11 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testLang315() throws InterruptedException {
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
sleep(MILLIS_200);
|
||||
sleepPlus1(MIN_DURATION);
|
||||
watch.suspend();
|
||||
final long suspendTime = watch.getTime();
|
||||
final Duration suspendDuration = watch.getDuration();
|
||||
sleep(MILLIS_200);
|
||||
sleepPlus1(MIN_DURATION);
|
||||
watch.stop();
|
||||
final long totalTime = watch.getTime();
|
||||
final Duration totalDuration = watch.getDuration();
|
||||
|
@ -299,14 +304,14 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testSimple() throws InterruptedException {
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
sleep(MILLIS_550);
|
||||
final Duration sleepDuration = MIN_DURATION;
|
||||
sleepPlus1(sleepDuration);
|
||||
watch.stop();
|
||||
final long time = watch.getTime();
|
||||
final Duration duration = watch.getDuration();
|
||||
assertEquals(time, watch.getTime());
|
||||
assertEquals(duration, watch.getDuration());
|
||||
assertThat("time", time, allOf(greaterThanOrEqualTo(500L), lessThan(2000L)));
|
||||
assertThat("duration", duration.toMillis(), allOf(greaterThanOrEqualTo(500L), lessThan(2000L)));
|
||||
assertTrue(duration.compareTo(sleepDuration) >= 0, () -> "duration: " + duration);
|
||||
watch.reset();
|
||||
assertEquals(0, watch.getTime());
|
||||
assertEquals(Duration.ZERO, watch.getDuration());
|
||||
|
@ -315,25 +320,26 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
@Test
|
||||
public void testSplit() throws InterruptedException {
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
sleep(MILLIS_550);
|
||||
// slept ~550 millis
|
||||
final Duration sleepDuration = MIN_DURATION;
|
||||
final long sleepMillis = sleepDuration.toMillis();
|
||||
assertTrue(sleepMillis > 0);
|
||||
sleepPlus1(sleepDuration);
|
||||
watch.split();
|
||||
final long splitTime = watch.getSplitTime();
|
||||
final Duration splitDuration = watch.getSplitDuration();
|
||||
assertEquals(splitTime, watch.getSplitDuration().toMillis());
|
||||
assertEquals(12, watch.toSplitString().length(), "Formatted split string not the correct length");
|
||||
sleep(MILLIS_550);
|
||||
// slept ~1100 millis
|
||||
assertEquals(SPLIT_CLOCK_STR_LEN, watch.toSplitString().length(), "Formatted split string not the correct length");
|
||||
sleepPlus1(sleepDuration);
|
||||
watch.unsplit();
|
||||
sleep(MILLIS_550);
|
||||
// slept ~1650 millis
|
||||
sleepPlus1(sleepDuration);
|
||||
watch.stop();
|
||||
final long totalTime = watch.getTime();
|
||||
final Duration totalDuration = watch.getDuration();
|
||||
assertThat("splitTime", splitTime, allOf(greaterThanOrEqualTo(500L), lessThan(1000L)));
|
||||
assertThat("splitDuration", splitDuration.toMillis(), allOf(greaterThanOrEqualTo(500L), lessThan(1000L)));
|
||||
assertThat("totalTime", totalTime, allOf(greaterThanOrEqualTo(1500L), lessThan(2100L)));
|
||||
assertThat("totalDuration", totalDuration.toMillis(), allOf(greaterThanOrEqualTo(1500L), lessThan(2100L)));
|
||||
assertTrue(splitTime >= sleepMillis, () -> "splitTime: " + splitTime);
|
||||
assertTrue(splitDuration.toMillis() >= sleepMillis, () -> "splitDuration: " + splitDuration);
|
||||
final long sleepMillisX3 = sleepMillis * 3;
|
||||
assertTrue(totalTime >= sleepMillisX3 && splitTime < 21000);
|
||||
assertTrue(totalDuration.toMillis() >= sleepMillisX3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -346,25 +352,27 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
public void testStopInstantSimple() throws InterruptedException {
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
final long testStartMillis = System.currentTimeMillis();
|
||||
sleep(MILLIS_550);
|
||||
sleepPlus1(MIN_DURATION);
|
||||
watch.stop();
|
||||
final long testEndMillis = System.currentTimeMillis();
|
||||
final Instant stopTime = watch.getStopInstant();
|
||||
assertEquals(stopTime, watch.getStopInstant());
|
||||
assertThat("stopTime", stopTime,
|
||||
allOf(greaterThanOrEqualTo(Instant.ofEpochMilli(testStartMillis)), lessThanOrEqualTo(Instant.ofEpochMilli(testEndMillis))));
|
||||
// Only less than, not equal
|
||||
assertTrue(testStartMillis < testEndMillis);
|
||||
assertTrue(Instant.ofEpochMilli(testStartMillis).isBefore(Instant.ofEpochMilli(testEndMillis)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopTimeSimple() throws InterruptedException {
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
final long testStartMillis = System.currentTimeMillis();
|
||||
sleep(MILLIS_550);
|
||||
sleepPlus1(MIN_DURATION);
|
||||
watch.stop();
|
||||
final long testEndMillis = System.currentTimeMillis();
|
||||
final long stopTime = watch.getStopTime();
|
||||
assertEquals(stopTime, watch.getStopTime());
|
||||
assertThat("stopTime", stopTime, allOf(greaterThanOrEqualTo(testStartMillis), lessThanOrEqualTo(testEndMillis)));
|
||||
// Only less than, not equal
|
||||
assertTrue(testStartMillis < testEndMillis);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -374,67 +382,82 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
final long testStartMillis = System.currentTimeMillis();
|
||||
final long testStartNanos = System.nanoTime();
|
||||
final Instant testStartInstant = Instant.ofEpochMilli(testStartMillis);
|
||||
sleep(MILLIS_550);
|
||||
final Duration sleepDuration = MIN_DURATION;
|
||||
final long sleepMillis = sleepDuration.toMillis();
|
||||
sleepPlus1(sleepDuration);
|
||||
watch.suspend();
|
||||
final long testSuspendMillis = System.currentTimeMillis();
|
||||
final long testSuspendNanos = System.nanoTime();
|
||||
final long testSuspendTimeNanos = testSuspendNanos - testStartNanos;
|
||||
final Duration testSuspendDuration = Duration.ofNanos(testSuspendTimeNanos);
|
||||
// See sleepPlus1
|
||||
final Duration testSuspendDuration = Duration.ofNanos(testSuspendTimeNanos).plusMillis(1);
|
||||
final long suspendTimeFromNanos = watch.getTime();
|
||||
final Duration suspendDuration = watch.getDuration();
|
||||
final long stopTimeMillis = watch.getStopTime();
|
||||
final Instant stopInstant = watch.getStopInstant();
|
||||
|
||||
assertThat("testStartMillis <= stopTimeMillis", testStartMillis, lessThanOrEqualTo(stopTimeMillis));
|
||||
assertThat("testStartInstant <= stopInstant", testStartInstant, lessThanOrEqualTo(stopInstant));
|
||||
assertThat("testSuspendMillis <= stopTimeMillis", testSuspendMillis, lessThanOrEqualTo(stopTimeMillis));
|
||||
assertThat("testSuspendMillis <= stopInstant", testSuspendMillis, lessThanOrEqualTo(stopInstant.toEpochMilli()));
|
||||
assertTrue(testStartMillis <= stopTimeMillis, () -> String.format("testStartMillis %s <= stopTimeMillis %s", testStartMillis, stopTimeMillis));
|
||||
assertTrue(testStartInstant.isBefore(stopInstant), () -> String.format("testStartInstant %s < stopInstant %s", testStartInstant, stopInstant));
|
||||
assertTrue(testSuspendMillis <= stopTimeMillis, () -> String.format("testSuspendMillis %s <= stopTimeMillis %s", testSuspendMillis, stopTimeMillis));
|
||||
assertTrue(testSuspendMillis <= stopInstant.toEpochMilli(),
|
||||
() -> String.format("testSuspendMillis %s <= stopInstant %s", testSuspendMillis, stopInstant));
|
||||
|
||||
sleep(MILLIS_550);
|
||||
sleepPlus1(sleepDuration);
|
||||
watch.resume();
|
||||
sleep(MILLIS_550);
|
||||
sleepPlus1(sleepDuration);
|
||||
watch.stop();
|
||||
final long totalTimeFromNanos = watch.getTime();
|
||||
final Duration totalDuration = watch.getDuration();
|
||||
|
||||
assertThat("suspendTimeFromNanos", suspendTimeFromNanos, greaterThanOrEqualTo(500L));
|
||||
assertThat("suspendDuration", suspendDuration, greaterThanOrEqualTo(Duration.ofMillis(500L)));
|
||||
assertThat("suspendTimeFromNanos <= testSuspendTimeNanos", suspendTimeFromNanos, lessThanOrEqualTo(testSuspendTimeNanos));
|
||||
assertThat("suspendDuration <= testSuspendDuration", suspendDuration, lessThanOrEqualTo(testSuspendDuration));
|
||||
assertThat("totalTimeFromNanos", totalTimeFromNanos, greaterThanOrEqualTo(1000L));
|
||||
assertThat("totalDuration", totalDuration, greaterThanOrEqualTo(Duration.ofMillis(1000L)));
|
||||
assertTrue(suspendTimeFromNanos >= sleepMillis, () -> String.format("suspendTimeFromNanos %s >= sleepMillis %s", suspendTimeFromNanos, sleepMillis));
|
||||
assertTrue(suspendDuration.compareTo(Duration.ofMillis(sleepMillis)) >= 0,
|
||||
() -> String.format("suspendDuration %s >= sleepMillis %s", suspendDuration, sleepMillis));
|
||||
assertTrue(suspendTimeFromNanos <= testSuspendTimeNanos,
|
||||
() -> String.format("suspendTimeFromNanos %s <= testSuspendTimeNanos %s", suspendTimeFromNanos, testSuspendTimeNanos));
|
||||
assertTrue(suspendDuration.compareTo(testSuspendDuration) <= 0,
|
||||
() -> String.format("suspendDuration %s <= testSuspendDuration %s", suspendDuration, testSuspendDuration));
|
||||
|
||||
final long sleepMillisX2 = sleepMillis + sleepMillis;
|
||||
assertTrue(totalTimeFromNanos >= sleepMillisX2, () -> String.format("totalTimeFromNanos %s >= sleepMillisX2 %s", totalTimeFromNanos, sleepMillisX2));
|
||||
assertTrue(totalDuration.compareTo(Duration.ofMillis(sleepMillisX2)) >= 0,
|
||||
() -> String.format("totalDuration >= sleepMillisX2", totalDuration, sleepMillisX2));
|
||||
;
|
||||
// Be lenient for slow running builds
|
||||
assertThat("totalTimeFromNanos", totalTimeFromNanos, lessThan(2500L));
|
||||
assertThat("totalDuration", totalDuration, lessThan(Duration.ofMillis(2500L)));
|
||||
final long testTooLongMillis = sleepMillis * 100;
|
||||
assertTrue(totalTimeFromNanos < testTooLongMillis,
|
||||
() -> String.format("totalTimeFromNanos %s < testTooLongMillis %s", totalTimeFromNanos, testTooLongMillis));
|
||||
assertTrue(totalDuration.compareTo(Duration.ofMillis(testTooLongMillis)) < 0,
|
||||
() -> String.format("totalDuration %s < testTooLongMillis %s", totalDuration, testTooLongMillis));
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToSplitString() throws InterruptedException {
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
sleep(MILLIS_550);
|
||||
sleepPlus1(MIN_DURATION);
|
||||
watch.split();
|
||||
final String splitStr = watch.toSplitString();
|
||||
assertEquals(12, splitStr.length(), "Formatted split string not the correct length");
|
||||
assertEquals(SPLIT_CLOCK_STR_LEN, splitStr.length(), "Formatted split string not the correct length");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToSplitStringWithMessage() throws InterruptedException {
|
||||
final StopWatch watch = new StopWatch(MESSAGE);
|
||||
watch.start();
|
||||
sleep(MILLIS_550);
|
||||
sleepPlus1(MIN_DURATION);
|
||||
watch.split();
|
||||
final String splitStr = watch.toSplitString();
|
||||
assertEquals(12 + MESSAGE.length() + 1, splitStr.length(), "Formatted split string not the correct length");
|
||||
assertEquals(SPLIT_CLOCK_STR_LEN + MESSAGE.length() + 1, splitStr.length(), "Formatted split string not the correct length");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() throws InterruptedException {
|
||||
//
|
||||
final StopWatch watch = StopWatch.createStarted();
|
||||
sleep(MILLIS_550);
|
||||
sleepPlus1(MIN_DURATION);
|
||||
watch.split();
|
||||
final String splitStr = watch.toString();
|
||||
assertEquals(12, splitStr.length(), "Formatted split string not the correct length");
|
||||
assertEquals(SPLIT_CLOCK_STR_LEN, splitStr.length(), "Formatted split string not the correct length");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -443,9 +466,9 @@ public class StopWatchTest extends AbstractLangTest {
|
|||
//
|
||||
final StopWatch watch = new StopWatch(MESSAGE);
|
||||
watch.start();
|
||||
sleep(MILLIS_550);
|
||||
sleepPlus1(MIN_DURATION);
|
||||
watch.split();
|
||||
final String splitStr = watch.toString();
|
||||
assertEquals(12 + MESSAGE.length() + 1, splitStr.length(), "Formatted split string not the correct length");
|
||||
assertEquals(SPLIT_CLOCK_STR_LEN + MESSAGE.length() + 1, splitStr.length(), "Formatted split string not the correct length");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue