diff --git a/src/main/java/org/apache/commons/lang3/builder/AbstractReflection.java b/src/main/java/org/apache/commons/lang3/builder/AbstractReflection.java
new file mode 100644
index 00000000000..f3b8cebb1cf
--- /dev/null
+++ b/src/main/java/org/apache/commons/lang3/builder/AbstractReflection.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.util.function.Supplier;
+
+import org.apache.commons.lang3.SystemProperties;
+
+/**
+ * Abstracts reflection access for reflection classes in this package.
+ *
+ * @since 3.21.0
+ */
+public abstract class AbstractReflection {
+
+ /**
+ * Builds a subclass.
+ *
+ * @param This Builder type.
+ */
+ public abstract static class AbstractBuilder> implements Supplier {
+
+ /**
+ * Whether to set the the {@code accessible} flag.
+ */
+ private boolean accessibleFlag = accessibleFlag();
+
+ AbstractBuilder() {
+ // Empty.
+ }
+
+ /**
+ * Returns {@code this} instance typed as a subclass.
+ *
+ * @return {@code this} instance typed as a subclass.
+ */
+ @SuppressWarnings("unchecked")
+ protected B asThis() {
+ return (B) this;
+ }
+
+ /**
+ * Sets the forceAccessible flag, defaults to {@code forceAccessible()} which defaults to true.
+ *
+ * In general, controls whether the instances built by this builder will force the accessible flag for reflection.
+ *
+ *
+ * See subclassses for specific behavior.
+ *
+ *
+ * @param forceAccessible Whether to force accessibility by calling {@link AccessibleObject#setAccessible(boolean)}.
+ * @return {@code this} instance.
+ */
+ public B setForceAccessible(final boolean forceAccessible) {
+ this.accessibleFlag = forceAccessible;
+ return asThis();
+ }
+ }
+
+ /**
+ * Tests whether the system property {@code "AbstractReflection.forceAccessible"} is set to true.
+ *
+ *
+ * If the property is not set, return true.
+ *
+ *
+ * @return whether the system property {@code "AbstractReflection.forceAccessible"} is set to true with true as the default.
+ */
+ static boolean accessibleFlag() {
+ return SystemProperties.getBoolean(AbstractReflection.class, "forceAccessible", () -> true);
+ }
+
+ /**
+ * If {@code forceAccessible} flag is true, each field in the given array is made accessible via {@link AccessibleObject#setAccessible(boolean)} only if a
+ * field is not already accessible.
+ *
+ * @param accessibleFlag Whether to call {@link AccessibleObject#setAccessible(boolean)} if a field is not already accessible.
+ * @param fields The fields to set.
+ * @throws SecurityException Thrown if {@code forceAccessible} flag is true and the request is denied.
+ * @see SecurityManager#checkPermission
+ * @see RuntimePermission
+ */
+ static void setAccessible(final boolean accessibleFlag, final Field[] fields) {
+ if (accessibleFlag) {
+ for (final Field field : fields) {
+ // Test to avoid the permission check if there is a security manager.
+ if (!field.isAccessible()) {
+ field.setAccessible(true);
+ }
+ }
+ }
+ }
+
+ /**
+ * Whether to set the the {@code accessible} flag.
+ */
+ private final boolean accessibleFlag;
+
+
+ /**
+ * Constructs a new instance.
+ *
+ * @param The type to build.
+ * @param builder The builder.
+ */
+ > AbstractReflection(final AbstractBuilder builder) {
+ this.accessibleFlag = builder.accessibleFlag;
+ }
+
+ /**
+ * Tests whether fields should be made accessible.
+ *
+ * @return whether fields should be made accessible.
+ */
+ protected boolean isAccessible() {
+ return accessibleFlag;
+ }
+
+ void setAccessible(final Field[] fields) {
+ setAccessible(accessibleFlag, fields);
+ }
+}
diff --git a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
index 9a3b419ab0f..f932b70d61e 100644
--- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
@@ -16,7 +16,6 @@
*/
package org.apache.commons.lang3.builder;
-import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
@@ -94,7 +93,35 @@
* @see HashCodeBuilder
* @since 1.0
*/
-public class CompareToBuilder implements Builder {
+public class CompareToBuilder extends AbstractReflection implements Builder {
+
+ /**
+ * Builds instances of CompareToBuilder.
+ */
+ public static class Builder extends AbstractBuilder {
+
+ /**
+ * Constructs a new Builder instance.
+ */
+ private Builder() {
+ // empty
+ }
+
+ @Override
+ public CompareToBuilder get() {
+ return new CompareToBuilder(this);
+ }
+
+ }
+
+ /**
+ * Constructs a new Builder.
+ *
+ * @return a new Builder.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
/**
* Appends to {@code builder} the comparison of {@code lhs}
@@ -106,6 +133,7 @@ public class CompareToBuilder implements Builder {
* @param builder {@link CompareToBuilder} to append to
* @param useTransients whether to compare transient fields
* @param excludeFields fields to exclude
+ * @param forceAccessible Whether to set fields' accessible flags
*/
private static void reflectionAppend(
final Object lhs,
@@ -113,16 +141,19 @@ private static void reflectionAppend(
final Class> clazz,
final CompareToBuilder builder,
final boolean useTransients,
- final String[] excludeFields) {
+ final String[] excludeFields,
+ final boolean forceAccessible) {
final Field[] fields = clazz.getDeclaredFields();
- AccessibleObject.setAccessible(fields, true);
+ setAccessible(forceAccessible, fields);
for (int i = 0; i < fields.length && builder.comparison == 0; i++) {
final Field field = fields[i];
- if (!ArrayUtils.contains(excludeFields, field.getName())
- && !field.getName().contains("$")
+ final String name = field.getName();
+ if (!ArrayUtils.contains(excludeFields, name)
+ && !name.contains("$")
&& (useTransients || !Modifier.isTransient(field.getModifiers()))
- && !Modifier.isStatic(field.getModifiers())) {
+ && !Modifier.isStatic(field.getModifiers())
+ && field.isAccessible()) {
// IllegalAccessException can't happen. Would get a Security exception instead.
// Throw a runtime exception in case the impossible happens.
builder.append(Reflection.getUnchecked(field, lhs), Reflection.getUnchecked(field, rhs));
@@ -230,22 +261,20 @@ public static int reflectionCompare(
final boolean compareTransients,
final Class> reflectUpToClass,
final String... excludeFields) {
-
if (lhs == rhs) {
return 0;
}
Objects.requireNonNull(lhs, "lhs");
Objects.requireNonNull(rhs, "rhs");
-
Class> lhsClazz = lhs.getClass();
if (!lhsClazz.isInstance(rhs)) {
throw new ClassCastException();
}
final CompareToBuilder compareToBuilder = new CompareToBuilder();
- reflectionAppend(lhs, rhs, lhsClazz, compareToBuilder, compareTransients, excludeFields);
+ reflectionAppend(lhs, rhs, lhsClazz, compareToBuilder, compareTransients, excludeFields, AbstractReflection.accessibleFlag());
while (lhsClazz.getSuperclass() != null && lhsClazz != reflectUpToClass) {
lhsClazz = lhsClazz.getSuperclass();
- reflectionAppend(lhs, rhs, lhsClazz, compareToBuilder, compareTransients, excludeFields);
+ reflectionAppend(lhs, rhs, lhsClazz, compareToBuilder, compareTransients, excludeFields, AbstractReflection.accessibleFlag());
}
return compareToBuilder.toComparison();
}
@@ -329,9 +358,14 @@ public static int reflectionCompare(final Object lhs, final Object rhs, final St
* {@link #toComparison} to get the result.
*/
public CompareToBuilder() {
+ super(builder());
comparison = 0;
}
+ private CompareToBuilder(final Builder builder) {
+ super(builder);
+ }
+
/**
* Appends to the {@code builder} the comparison of
* two {@code booleans}s.
diff --git a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
index d4bbdf55804..399f499c8aa 100644
--- a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
@@ -16,7 +16,6 @@
*/
package org.apache.commons.lang3.builder;
-import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
@@ -86,7 +85,35 @@
*
* @since 1.0
*/
-public class EqualsBuilder implements Builder {
+public class EqualsBuilder extends AbstractReflection implements org.apache.commons.lang3.builder.Builder {
+
+ /**
+ * Builds instances of CompareToBuilder.
+ */
+ public static class Builder extends AbstractBuilder {
+
+ /**
+ * Constructs a new Builder instance.
+ */
+ private Builder() {
+ // empty
+ }
+
+ @Override
+ public EqualsBuilder get() {
+ return new EqualsBuilder(this);
+ }
+
+ }
+
+ /**
+ * Constructs a new Builder.
+ *
+ * @return a new Builder.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
/**
* A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
@@ -371,11 +398,16 @@ private static void unregister(final Object lhs, final Object rhs) {
* @see Object#equals(Object)
*/
public EqualsBuilder() {
+ super(builder());
// set up default classes to bypass reflection for
bypassReflectionClasses = new ArrayList<>(1);
bypassReflectionClasses.add(String.class); //hashCode field being lazy but not transient
}
+ private EqualsBuilder(Builder builder) {
+ super(builder);
+ }
+
/**
* Test if two {@code booleans}s are equal.
*
@@ -1003,7 +1035,7 @@ private void reflectionAppend(
try {
register(lhs, rhs);
final Field[] fields = clazz.getDeclaredFields();
- AccessibleObject.setAccessible(fields, true);
+ setAccessible(fields);
for (int i = 0; i < fields.length && isEquals; i++) {
final Field field = fields[i];
if (!ArrayUtils.contains(excludeFields, field.getName())
diff --git a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
index 8e0007da6fb..46d845f931c 100644
--- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
@@ -17,7 +17,6 @@
package org.apache.commons.lang3.builder;
-import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
@@ -102,7 +101,53 @@
*
* @since 1.0
*/
-public class HashCodeBuilder implements Builder {
+public class HashCodeBuilder extends AbstractReflection implements org.apache.commons.lang3.builder.Builder {
+
+ /**
+ * Builds instances of CompareToBuilder.
+ */
+ public static class Builder extends AbstractBuilder {
+
+ private int initialOddNumber;
+
+ private int multiplierOddNumber;
+
+ /**
+ * Constructs a new Builder instance.
+ */
+ private Builder() {
+ // empty
+ }
+
+ @Override
+ public HashCodeBuilder get() {
+ return new HashCodeBuilder(this);
+ }
+
+
+ /**
+ * Sets an odd number used as the initial value.
+ *
+ * @param initialOddNumber an odd number used as the initial value.
+ * @return {@code this} instance.
+ */
+ public Builder setInitialOddNumber(final int initialOddNumber) {
+ this.initialOddNumber = initialOddNumber;
+ return asThis();
+ }
+
+ /**
+ * Sets an odd number used as the multiplier.
+ *
+ * @param multiplierOddNumber an odd number used as the multiplier.
+ * @return {@code this} instance.
+ */
+ public Builder setMultiplierOddNumber(final int multiplierOddNumber) {
+ this.multiplierOddNumber = multiplierOddNumber;
+ return asThis();
+ }
+
+ }
/**
* The default initial value to use in reflection hash code building.
@@ -121,6 +166,15 @@ public class HashCodeBuilder implements Builder {
*/
private static final ThreadLocal> REGISTRY = ThreadLocal.withInitial(HashSet::new);
+ /**
+ * Constructs a new Builder.
+ *
+ * @return a new Builder.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
/*
* NOTE: we cannot store the actual objects in a HashSet, as that would use the very hashCode()
* we are in the process of calculating.
@@ -175,9 +229,10 @@ static boolean isRegistered(final Object value) {
* whether to use transient fields
* @param excludeFields
* Collection of String field names to exclude from use in calculation of hash code
+ * @param setAccessible Whether to set fields' accessible flags
*/
private static void reflectionAppend(final Object object, final Class> clazz, final HashCodeBuilder builder, final boolean useTransients,
- final String[] excludeFields) {
+ final String[] excludeFields, final boolean setAccessible) {
if (isRegistered(object)) {
return;
}
@@ -185,7 +240,7 @@ private static void reflectionAppend(final Object object, final Class> clazz,
register(object);
// The elements in the returned array are not sorted and are not in any particular order.
final Field[] fields = ArraySorter.sort(clazz.getDeclaredFields(), Comparator.comparing(Field::getName));
- AccessibleObject.setAccessible(fields, true);
+ setAccessible(setAccessible, fields);
for (final Field field : fields) {
if (!ArrayUtils.contains(excludeFields, field.getName())
&& !field.getName().contains("$")
@@ -340,10 +395,10 @@ public static int reflectionHashCode(final int initialNonZeroOddNumber, fina
Objects.requireNonNull(object, "object");
final HashCodeBuilder builder = new HashCodeBuilder(initialNonZeroOddNumber, multiplierNonZeroOddNumber);
Class> clazz = object.getClass();
- reflectionAppend(object, clazz, builder, testTransients, excludeFields);
+ reflectionAppend(object, clazz, builder, testTransients, excludeFields, true);
while (clazz.getSuperclass() != null && clazz != reflectUpToClass) {
clazz = clazz.getSuperclass();
- reflectionAppend(object, clazz, builder, testTransients, excludeFields);
+ reflectionAppend(object, clazz, builder, testTransients, excludeFields, true);
}
return builder.toHashCode();
}
@@ -504,8 +559,15 @@ private static void unregister(final Object value) {
* Uses two hard coded choices for the constants needed to build a {@code hashCode}.
*/
public HashCodeBuilder() {
- iConstant = 37;
- iTotal = 17;
+ this(builder().setInitialOddNumber(17).setMultiplierOddNumber(37));
+ }
+
+ private HashCodeBuilder(final Builder builder) {
+ super(builder);
+ Validate.isTrue(builder.initialOddNumber % 2 != 0, "HashCodeBuilder requires an odd initial value");
+ Validate.isTrue(builder.multiplierOddNumber % 2 != 0, "HashCodeBuilder requires an odd multiplier");
+ iConstant = builder.multiplierOddNumber;
+ iTotal = builder.initialOddNumber;
}
/**
@@ -524,10 +586,7 @@ public HashCodeBuilder() {
* if the number is even
*/
public HashCodeBuilder(final int initialOddNumber, final int multiplierOddNumber) {
- Validate.isTrue(initialOddNumber % 2 != 0, "HashCodeBuilder requires an odd initial value");
- Validate.isTrue(multiplierOddNumber % 2 != 0, "HashCodeBuilder requires an odd multiplier");
- iConstant = multiplierOddNumber;
- iTotal = initialOddNumber;
+ this(builder().setInitialOddNumber(initialOddNumber).setMultiplierOddNumber(multiplierOddNumber));
}
/**
diff --git a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
index 418e96fd1fd..68a0a7ff7e3 100644
--- a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
@@ -17,7 +17,6 @@
package org.apache.commons.lang3.builder;
-import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
@@ -471,6 +470,8 @@ public static String toStringInclude(final Object object, final String... includ
*/
protected String[] includeFieldNames;
+ private boolean accessibleFlag = AbstractReflection.accessibleFlag();
+
/**
* The last super class to stop appending fields for.
*/
@@ -646,14 +647,14 @@ protected void appendFieldsIn(final Class> clazz) {
}
// The elements in the returned array are not sorted and are not in any particular order.
final Field[] fields = ArraySorter.sort(clazz.getDeclaredFields(), Comparator.comparing(Field::getName));
- AccessibleObject.setAccessible(fields, true);
+ AbstractReflection.setAccessible(accessibleFlag, fields);
for (final Field field : fields) {
final String fieldName = field.getName();
if (accept(field)) {
try {
// Warning: Field.get(Object) creates wrappers objects
// for primitive types.
- final Object fieldValue = getValue(field);
+ final Object fieldValue = field.isAccessible() ? getValue(field) : null;
if (!excludeNullValues || fieldValue != null) {
this.append(fieldName, fieldValue, !field.isAnnotationPresent(ToStringSummary.class));
}
diff --git a/src/test/java/org/apache/commons/lang3/AbstractLangTest.java b/src/test/java/org/apache/commons/lang3/AbstractLangTest.java
index 8be8f69dd02..84373105b9a 100644
--- a/src/test/java/org/apache/commons/lang3/AbstractLangTest.java
+++ b/src/test/java/org/apache/commons/lang3/AbstractLangTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.lang3;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -34,5 +35,4 @@ public void after() {
assertTrue(ToStringStyle.getRegistry().isEmpty(), "Expected null, actual: " + ToStringStyle.getRegistry());
// TODO Do more to make sure memory is not retained, maybe like Log4j checks for it.
}
-
}
diff --git a/src/test/java/org/apache/commons/lang3/builder/AbstractBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/AbstractBuilderTest.java
new file mode 100644
index 00000000000..e679e5cc0af
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/AbstractBuilderTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Objects;
+import java.util.function.Supplier;
+
+import org.apache.commons.lang3.AbstractLangTest;
+
+/**
+ * Helps test this package.
+ */
+class AbstractBuilderTest extends AbstractLangTest {
+
+ /**
+ * Delegates to {@link AbstractReflection#accessibleFlag()}.
+ *
+ * @return {@link AbstractReflection#accessibleFlag()}.
+ */
+ protected static boolean accessibleFlag() {
+ return AbstractReflection.accessibleFlag();
+ }
+
+ /**
+ * Helps test reflection classes.
+ *
+ * @param string An input string.
+ * @return The given string or "".
+ */
+ protected static String accessibleString(final String string) {
+ return accessibleFlag() ? string : "";
+ }
+
+ protected static void assertEqualsIfAccessible(final Object expected, final Object actual) {
+ assertEquals(accessibleFlag(), Objects.equals(expected, actual));
+ }
+
+ protected static void assertTrueIfAccessible(final boolean test) {
+ assertEquals(accessibleFlag(), test);
+ }
+
+ protected static void assertTrueIfAccessible(final boolean test, final Supplier messageSupplier) {
+ assertEquals(accessibleFlag(), test, messageSupplier);
+ }
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/AbstractReflectionTest.java b/src/test/java/org/apache/commons/lang3/builder/AbstractReflectionTest.java
new file mode 100644
index 00000000000..e0428310d0d
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/AbstractReflectionTest.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+/**
+ * Helps test no forced access.
+ */
+public class AbstractReflectionTest {
+
+ static final String FORCE_ACCESSIBLE = "AbstractReflection.forceAccessible";
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderNoForceTest.java
new file mode 100644
index 00000000000..ad10f70fe31
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link CompareToBuilderTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class CompareToBuilderNoForceTest extends CompareToBuilderTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java
index d00a98706b2..43540c4860e 100644
--- a/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java
@@ -24,13 +24,12 @@
import java.math.BigInteger;
import java.util.Objects;
-import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Tests {@link CompareToBuilder}.
*/
-class CompareToBuilderTest extends AbstractLangTest {
+class CompareToBuilderTest extends AbstractBuilderTest {
static class TestObject implements Comparable {
private int a;
@@ -114,9 +113,10 @@ static class TestTransientSubObject extends TestObject {
* @param z an object to compare
* @param testTransients Whether to include transients in the comparison
* @param excludeFields fields to exclude
+ * @param expectAccessibleFactor Whether accessibility is expected.
*/
- private void assertReflectionCompareContract(final Object x, final Object y, final Object z, final boolean testTransients, final String[] excludeFields) {
-
+ private void assertReflectionCompareContract(final Object x, final Object y, final Object z, final boolean testTransients, final String[] excludeFields,
+ final boolean expectAccessibleFactor) {
// signum
assertEquals(reflectionCompareSignum(x, y, testTransients, excludeFields), -reflectionCompareSignum(y, x, testTransients, excludeFields));
@@ -132,7 +132,14 @@ private void assertReflectionCompareContract(final Object x, final Object y, fin
}
// strongly recommended but not strictly required
- assertTrue(CompareToBuilder.reflectionCompare(x, y, testTransients) == 0 == EqualsBuilder.reflectionEquals(x, y, testTransients));
+ // assertTrue(CompareToBuilder.reflectionCompare(x, y, testTransients) == 0 == EqualsBuilder.reflectionEquals(x, y, testTransients));
+ //assertTrueIfAccessible(CompareToBuilder.reflectionCompare(x, y, testTransients) == 0 == EqualsBuilder.reflectionEquals(x, y, testTransients));
+ final boolean actual = CompareToBuilder.reflectionCompare(x, y, testTransients) == 0 == EqualsBuilder.reflectionEquals(x, y, testTransients);
+ if (accessibleFlag()) {
+ assertEqualsIfAccessible(expectAccessibleFactor, actual);
+ } else {
+ assertEqualsIfAccessible(accessibleFlag() || expectAccessibleFactor, actual);
+ }
}
private void assertXYZCompareOrder(final Object x, final Object y, final Object z, final boolean testTransients, final String[] excludeFields) {
@@ -140,13 +147,13 @@ private void assertXYZCompareOrder(final Object x, final Object y, final Object
assertEquals(0, CompareToBuilder.reflectionCompare(y, y, testTransients, null, excludeFields));
assertEquals(0, CompareToBuilder.reflectionCompare(z, z, testTransients, null, excludeFields));
- assertTrue(0 > CompareToBuilder.reflectionCompare(x, y, testTransients, null, excludeFields));
- assertTrue(0 > CompareToBuilder.reflectionCompare(x, z, testTransients, null, excludeFields));
- assertTrue(0 > CompareToBuilder.reflectionCompare(y, z, testTransients, null, excludeFields));
+ assertTrueIfAccessible(0 > CompareToBuilder.reflectionCompare(x, y, testTransients, null, excludeFields));
+ assertTrueIfAccessible(0 > CompareToBuilder.reflectionCompare(x, z, testTransients, null, excludeFields));
+ assertTrueIfAccessible(0 > CompareToBuilder.reflectionCompare(y, z, testTransients, null, excludeFields));
- assertTrue(0 < CompareToBuilder.reflectionCompare(y, x, testTransients, null, excludeFields));
- assertTrue(0 < CompareToBuilder.reflectionCompare(z, x, testTransients, null, excludeFields));
- assertTrue(0 < CompareToBuilder.reflectionCompare(z, y, testTransients, null, excludeFields));
+ assertTrueIfAccessible(0 < CompareToBuilder.reflectionCompare(y, x, testTransients, null, excludeFields));
+ assertTrueIfAccessible(0 < CompareToBuilder.reflectionCompare(z, x, testTransients, null, excludeFields));
+ assertTrueIfAccessible(0 < CompareToBuilder.reflectionCompare(z, y, testTransients, null, excludeFields));
}
/**
@@ -1022,8 +1029,8 @@ void testReflectionCompare() {
assertEquals(0, CompareToBuilder.reflectionCompare(o1, o1));
assertEquals(0, CompareToBuilder.reflectionCompare(o1, o2));
o2.setA(5);
- assertTrue(CompareToBuilder.reflectionCompare(o1, o2) < 0);
- assertTrue(CompareToBuilder.reflectionCompare(o2, o1) > 0);
+ assertTrueIfAccessible(CompareToBuilder.reflectionCompare(o1, o2) < 0);
+ assertTrueIfAccessible(CompareToBuilder.reflectionCompare(o2, o1) > 0);
}
@Test
@@ -1052,14 +1059,14 @@ private void testReflectionHierarchyCompare(final boolean testTransients, final
final TestSubObject tso2 = new TestSubObject(2, 2);
final TestSubObject tso3 = new TestSubObject(3, 3);
- assertReflectionCompareContract(to1, to1, to1, false, excludeFields);
- assertReflectionCompareContract(to1, to2, to3, false, excludeFields);
- assertReflectionCompareContract(tso1, tso1, tso1, false, excludeFields);
- assertReflectionCompareContract(tso1, tso2, tso3, false, excludeFields);
- assertReflectionCompareContract("1", "2", "3", false, excludeFields);
+ assertReflectionCompareContract(to1, to1, to1, false, excludeFields, accessibleFlag());
+ assertReflectionCompareContract(to1, to2, to3, false, excludeFields, true);
+ assertReflectionCompareContract(tso1, tso1, tso1, false, excludeFields, accessibleFlag());
+ assertReflectionCompareContract(tso1, tso2, tso3, false, excludeFields, true);
+ assertReflectionCompareContract("1", "2", "3", false, excludeFields, true);
- assertTrue(0 != CompareToBuilder.reflectionCompare(tso1, new TestSubObject(1, 0), testTransients));
- assertTrue(0 != CompareToBuilder.reflectionCompare(tso1, new TestSubObject(0, 1), testTransients));
+ assertTrueIfAccessible(0 != CompareToBuilder.reflectionCompare(tso1, new TestSubObject(1, 0), testTransients));
+ assertTrueIfAccessible(0 != CompareToBuilder.reflectionCompare(tso1, new TestSubObject(0, 1), testTransients));
// root class
assertXYZCompareOrder(to1, to2, to3, true, null);
diff --git a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderNoForceTest.java
new file mode 100644
index 00000000000..c0c219dd410
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link DiffBuilderTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class DiffBuilderNoForceTest extends DiffBuilderTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
index 5a879713364..ba81a6b3af4 100644
--- a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
@@ -26,14 +26,13 @@
import java.util.List;
-import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Test;
/**
* Tests {@link DiffBuilder}.
*/
-class DiffBuilderTest extends AbstractLangTest {
+class DiffBuilderTest extends AbstractBuilderTest {
/**
* Test fixture.
@@ -549,7 +548,7 @@ void testSimilarObjectIgnoresAppends() {
final TypeTestClass testClass1 = new TypeTestClass();
final TypeTestClass testClass2 = new TypeTestClass();
final DiffResult list = new DiffBuilder<>(testClass1, testClass2, SHORT_STYLE).append("ignored", false, true).build();
- assertEquals(0, list.getNumberOfDiffs());
+ assertEquals(accessibleFlag() ? 0 : 1, list.getNumberOfDiffs());
}
@Test
diff --git a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderNoForceTest.java
new file mode 100644
index 00000000000..2ba0863bba0
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link EqualsBuilderTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class EqualsBuilderNoForceTest extends EqualsBuilderTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderReflectJreImplementationNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderReflectJreImplementationNoForceTest.java
new file mode 100644
index 00000000000..a5cecf88244
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderReflectJreImplementationNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link EqualsBuilderReflectJreImplementationTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class EqualsBuilderReflectJreImplementationNoForceTest extends EqualsBuilderReflectJreImplementationTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderReflectJreImplementationTest.java b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderReflectJreImplementationTest.java
index 7877356289e..929ea2af465 100644
--- a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderReflectJreImplementationTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderReflectJreImplementationTest.java
@@ -47,14 +47,13 @@
import java.util.List;
import java.util.function.Supplier;
-import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.stream.IntStreams;
import org.junit.jupiter.api.Test;
/**
* Tests that {@link EqualsBuilder} works using reflection when types that implement JRE interfaces like TemporalAccessor, TemporalAmout, and CharSequence work.
*/
-class EqualsBuilderReflectJreImplementationTest extends AbstractLangTest {
+class EqualsBuilderReflectJreImplementationTest extends AbstractBuilderTest {
static class MyCharSequence implements CharSequence {
@@ -268,16 +267,16 @@ void testRecursive() {
final MyClass o2 = new MyClass(new MyCharSequence("5"), new MyTemporal("6"), new MyTemporalAccessor("7"), new MyTemporalAmount("8"));
final MyClass o2Bis = new MyClass(new MyCharSequence("5"), new MyTemporal("6"), new MyTemporalAccessor("7"), new MyTemporalAmount("8"));
// MyTemporal
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(new MyTemporal("1"), new MyTemporal("1")).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(new MyTemporal("1"), new MyTemporal("1")).isEquals());
// MyTemporalAccessor
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(new MyTemporalAccessor("1"), new MyTemporalAccessor("1")).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(new MyTemporalAccessor("1"), new MyTemporalAccessor("1")).isEquals());
// MyCharSequence
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(new MyCharSequence("1"), new MyCharSequence("1")).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(new MyCharSequence("1"), new MyCharSequence("1")).isEquals());
// MyClass
assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1, o1).isEquals(), o1::toString);
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1, o1Bis).isEquals(), o1::toString);
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o1, o1Bis).isEquals(), o1::toString);
assertTrue(new EqualsBuilder().setTestRecursive(true).append(o2, o2).isEquals(), o2::toString);
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o2, o2Bis).isEquals(), o2::toString);
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o2, o2Bis).isEquals(), o2::toString);
assertFalse(new EqualsBuilder().setTestRecursive(true).append(o1, o2).isEquals());
assertFalse(new EqualsBuilder().setTestRecursive(true).append(o2, o1).isEquals());
}
diff --git a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java
index 874aff3ab41..e390fdd1dd7 100644
--- a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java
@@ -29,14 +29,13 @@
import java.util.Arrays;
import java.util.List;
-import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.junit.jupiter.api.Test;
/**
* Tests {@link org.apache.commons.lang3.builder.EqualsBuilder}.
*/
-class EqualsBuilderTest extends AbstractLangTest {
+class EqualsBuilderTest extends AbstractBuilderTest {
public static class TestACanEqualB {
private final int a;
@@ -579,7 +578,7 @@ void testCyclicalObjectReferences() {
x3.setObjectReference(refX3);
refX3.setObjectReference(x3);
- assertEquals(x1, x2);
+ assertTrueIfAccessible(x1.equals(x2));
assertNotEquals(x1, x3);
assertNotEquals(x2, x3);
}
@@ -1069,7 +1068,7 @@ void testObjectRecursive() {
final TestRecursiveObject oNull = new TestRecursiveObject(null, null, 2);
assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1A, o1A).isEquals());
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
assertFalse(new EqualsBuilder().setTestRecursive(true).append(o1A, o2).isEquals());
@@ -1092,10 +1091,10 @@ void testObjectRecursiveCycle() {
o2.setCycle(i2);
assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1A, o1A).isEquals());
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
assertFalse(new EqualsBuilder().setTestRecursive(true).append(o1A, o2).isEquals());
- assertTrue(EqualsBuilder.reflectionEquals(o1A, o1B, false, null, true));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(o1A, o1B, false, null, true));
assertFalse(EqualsBuilder.reflectionEquals(o1A, o2, false, null, true));
}
@@ -1106,7 +1105,7 @@ void testObjectRecursiveCycleSelfreference() {
final TestRecursiveCycleObject o2 = new TestRecursiveCycleObject(2);
assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1A, o1A).isEquals());
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
assertFalse(new EqualsBuilder().setTestRecursive(true).append(o1A, o2).isEquals());
}
@@ -1116,8 +1115,8 @@ void testObjectRecursiveGenericInteger() {
final TestRecursiveGenericObject o1B = new TestRecursiveGenericObject<>(1);
final TestRecursiveGenericObject o2 = new TestRecursiveGenericObject<>(2);
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1B, o1A).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o1B, o1A).isEquals());
assertFalse(new EqualsBuilder().setTestRecursive(true).append(o1B, o2).isEquals());
}
@@ -1133,8 +1132,8 @@ void testObjectRecursiveGenericString() {
// To trigger bug reported in LANG-1356, call hashCode only on string in instance o1_a
s1A.hashCode();
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
- assertTrue(new EqualsBuilder().setTestRecursive(true).append(o1B, o1A).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o1A, o1B).isEquals());
+ assertTrueIfAccessible(new EqualsBuilder().setTestRecursive(true).append(o1B, o1A).isEquals());
assertFalse(new EqualsBuilder().setTestRecursive(true).append(o1B, o2).isEquals());
}
@@ -1176,7 +1175,7 @@ void testReflectionAppend() {
assertFalse(new EqualsBuilder().reflectionAppend(o1, o2).reflectionAppend(o1, o1).build());
o2.setA(4);
- assertTrue(new EqualsBuilder().reflectionAppend(o1, o2).build());
+ assertTrueIfAccessible(new EqualsBuilder().reflectionAppend(o1, o2).build());
assertFalse(new EqualsBuilder().reflectionAppend(o1, this).build());
@@ -1214,7 +1213,7 @@ void testReflectionEquals() {
assertTrue(EqualsBuilder.reflectionEquals(o1, o1));
assertFalse(EqualsBuilder.reflectionEquals(o1, o2));
o2.setA(4);
- assertTrue(EqualsBuilder.reflectionEquals(o1, o2));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(o1, o2));
assertFalse(EqualsBuilder.reflectionEquals(o1, this));
@@ -1251,12 +1250,10 @@ private void testReflectionEqualsEquivalenceRelationship(
// reflection test
assertTrue(EqualsBuilder.reflectionEquals(to, to, testTransients));
assertTrue(EqualsBuilder.reflectionEquals(to2, to2, testTransients));
-
// symmetry test
- assertTrue(EqualsBuilder.reflectionEquals(to, toBis, testTransients) && EqualsBuilder.reflectionEquals(toBis, to, testTransients));
-
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(to, toBis, testTransients) && EqualsBuilder.reflectionEquals(toBis, to, testTransients));
// transitive test
- assertTrue(
+ assertEquals(accessibleFlag(),
EqualsBuilder.reflectionEquals(to, toBis, testTransients)
&& EqualsBuilder.reflectionEquals(toBis, toTer, testTransients)
&& EqualsBuilder.reflectionEquals(to, toTer, testTransients));
@@ -1266,8 +1263,8 @@ private void testReflectionEqualsEquivalenceRelationship(
if (oToChange instanceof TestSubObject) {
((TestSubObject) oToChange).setB(((TestSubObject) to).getB());
}
- assertTrue(EqualsBuilder.reflectionEquals(oToChange, to, testTransients));
- assertTrue(EqualsBuilder.reflectionEquals(oToChange, to, testTransients));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(oToChange, to, testTransients));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(oToChange, to, testTransients));
oToChange.setA(to.getA() + 1);
if (oToChange instanceof TestSubObject) {
((TestSubObject) oToChange).setB(((TestSubObject) to).getB() + 1);
@@ -1301,7 +1298,7 @@ void testReflectionEqualsExcludeFields() {
assertFalse(EqualsBuilder.reflectionEquals(x1, x2, "three"));
// equal if both differing fields excluded
- assertTrue(EqualsBuilder.reflectionEquals(x1, x2, "two", "three"));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(x1, x2, "two", "three"));
// still equal as long as both differing fields are among excluded
assertTrue(EqualsBuilder.reflectionEquals(x1, x2, "one", "two", "three"));
@@ -1318,8 +1315,8 @@ void testReflectionHierarchyEquals() {
testReflectionHierarchyEquals(false);
testReflectionHierarchyEquals(true);
// Transients
- assertTrue(EqualsBuilder.reflectionEquals(new TestTTLeafObject(1, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 4), true));
- assertTrue(EqualsBuilder.reflectionEquals(new TestTTLeafObject(1, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 4), false));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(new TestTTLeafObject(1, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 4), true));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(new TestTTLeafObject(1, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 4), false));
assertFalse(EqualsBuilder.reflectionEquals(new TestTTLeafObject(1, 0, 0, 4), new TestTTLeafObject(1, 2, 3, 4), true));
assertFalse(EqualsBuilder.reflectionEquals(new TestTTLeafObject(1, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 0), true));
assertFalse(EqualsBuilder.reflectionEquals(new TestTTLeafObject(0, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 4), true));
@@ -1346,7 +1343,7 @@ private void testReflectionHierarchyEquals(final boolean testTransients) {
// same values
assertTrue(EqualsBuilder.reflectionEquals(ttlo, ttlo, testTransients));
- assertTrue(EqualsBuilder.reflectionEquals(new TestSubObject(1, 10), new TestSubObject(1, 10), testTransients));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(new TestSubObject(1, 10), new TestSubObject(1, 10), testTransients));
// same super values, diff sub values
assertFalse(EqualsBuilder.reflectionEquals(new TestSubObject(1, 10), new TestSubObject(1, 11), testTransients));
assertFalse(EqualsBuilder.reflectionEquals(new TestSubObject(1, 11), new TestSubObject(1, 10), testTransients));
@@ -1355,17 +1352,17 @@ private void testReflectionHierarchyEquals(final boolean testTransients) {
assertFalse(EqualsBuilder.reflectionEquals(new TestSubObject(1, 10), new TestSubObject(0, 10), testTransients));
// mix super and sub types: equals
- assertTrue(EqualsBuilder.reflectionEquals(to1, teso, testTransients));
- assertTrue(EqualsBuilder.reflectionEquals(teso, to1, testTransients));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(to1, teso, testTransients));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(teso, to1, testTransients));
- assertTrue(EqualsBuilder.reflectionEquals(to1, ttso, false)); // Force testTransients = false for this assert
- assertTrue(EqualsBuilder.reflectionEquals(ttso, to1, false)); // Force testTransients = false for this assert
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(to1, ttso, false)); // Force testTransients = false for this assert
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(ttso, to1, false)); // Force testTransients = false for this assert
- assertTrue(EqualsBuilder.reflectionEquals(to1, tttso, false)); // Force testTransients = false for this assert
- assertTrue(EqualsBuilder.reflectionEquals(tttso, to1, false)); // Force testTransients = false for this assert
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(to1, tttso, false)); // Force testTransients = false for this assert
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(tttso, to1, false)); // Force testTransients = false for this assert
- assertTrue(EqualsBuilder.reflectionEquals(ttso, tttso, false)); // Force testTransients = false for this assert
- assertTrue(EqualsBuilder.reflectionEquals(tttso, ttso, false)); // Force testTransients = false for this assert
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(ttso, tttso, false)); // Force testTransients = false for this assert
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(tttso, ttso, false)); // Force testTransients = false for this assert
// mix super and sub types: NOT equals
assertFalse(EqualsBuilder.reflectionEquals(new TestObject(0), new TestEmptySubObject(1), testTransients));
@@ -1462,7 +1459,7 @@ void testToEqualsExclude() {
one = new TestObjectEqualsExclude(1, 2);
two = new TestObjectEqualsExclude(2, 2);
- assertTrue(EqualsBuilder.reflectionEquals(one, two));
+ assertTrueIfAccessible(EqualsBuilder.reflectionEquals(one, two));
}
/**
diff --git a/src/test/java/org/apache/commons/lang3/builder/JsonToStringStyleNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/JsonToStringStyleNoForceTest.java
new file mode 100644
index 00000000000..b3d3033b0a0
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/JsonToStringStyleNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link JsonToStringStyleTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class JsonToStringStyleNoForceTest extends JsonToStringStyleTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/JsonToStringStyleTest.java b/src/test/java/org/apache/commons/lang3/builder/JsonToStringStyleTest.java
index dbdb92e179b..0f5ac273156 100644
--- a/src/test/java/org/apache/commons/lang3/builder/JsonToStringStyleTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/JsonToStringStyleTest.java
@@ -28,7 +28,6 @@
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -37,7 +36,7 @@
/**
* Tests {@link org.apache.commons.lang3.builder.JsonToStringStyleTest}.
*/
-class JsonToStringStyleTest extends AbstractLangTest {
+class JsonToStringStyleTest extends AbstractBuilderTest {
static class AcademyClass {
Teacher teacher;
@@ -214,9 +213,9 @@ void testArrayEnum() {
teacher.setHobbies(hobbies);
- assertEquals(teacher.toString(), "{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}");
+ assertEqualsIfAccessible(teacher.toString(), "{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}");
teacher.setHobbies(new Hobby[0]);
- assertEquals(teacher.toString(), "{\"hobbies\":[]}");
+ assertEqualsIfAccessible(teacher.toString(), "{\"hobbies\":[]}");
teacher.setHobbies(null);
assertEquals(teacher.toString(), "{\"hobbies\":null}");
}
@@ -295,7 +294,8 @@ void testCombineListAndEnum() {
academyClass.setStudents(students);
academyClass.setTeacher(teacher);
- assertEquals(academyClass.toString(), "{\"students\":[{\"hobbies\":[\"BOOK\",\"MUSIC\"]},{\"hobbies\":[]},{\"hobbies\":[\"BOOK\"]}],\"teacher\":{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}}");
+ assertEqualsIfAccessible(academyClass.toString(),
+ "{\"students\":[{\"hobbies\":[\"BOOK\",\"MUSIC\"]},{\"hobbies\":[]},{\"hobbies\":[\"BOOK\"]}],\"teacher\":{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}}");
}
@Test
@@ -368,9 +368,9 @@ void testList() {
student.setHobbies(objects);
- assertEquals(student.toString(), "{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}");
+ assertEqualsIfAccessible(student.toString(), "{\"hobbies\":[\"BOOK\",\"SPORT\",\"MUSIC\"]}");
student.setHobbies(new ArrayList<>());
- assertEquals(student.toString(), "{\"hobbies\":[]}");
+ assertEqualsIfAccessible(student.toString(), "{\"hobbies\":[]}");
student.setHobbies(null);
assertEquals(student.toString(), "{\"hobbies\":null}");
}
diff --git a/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleNoForceTest.java
new file mode 100644
index 00000000000..d03c2d57404
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link MultilineRecursiveToStringStyleTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class MultilineRecursiveToStringStyleNoForceTest extends MultilineRecursiveToStringStyleTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java b/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java
index 4d4d7f57aaf..a0bb2ece2fa 100644
--- a/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/MultilineRecursiveToStringStyleTest.java
@@ -22,12 +22,11 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
*/
-class MultilineRecursiveToStringStyleTest extends AbstractLangTest {
+class MultilineRecursiveToStringStyleTest extends AbstractBuilderTest {
static class Account {
Customer owner;
@@ -110,7 +109,7 @@ public void boolArray() {
+ " false," + LS
+ " true" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
@Test
@@ -123,7 +122,7 @@ public void byteArray() {
+ " 1," + LS
+ " 2" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
@Test
@@ -136,7 +135,7 @@ public void charArray() {
+ " a," + LS
+ " A" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
@Test
@@ -149,7 +148,7 @@ public void doubleArray() {
+ " 1.0," + LS
+ " 2.0" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
@Test
@@ -162,7 +161,7 @@ public void floatArray() {
+ " 1.0," + LS
+ " 2.0" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
private String getClassPrefix(final Object object) {
@@ -193,7 +192,7 @@ public void intArray() {
+ " 1," + LS
+ " 2" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
@Test
@@ -206,7 +205,7 @@ public void longArray() {
+ " 1," + LS
+ " 2" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
@Test
@@ -229,7 +228,7 @@ public void nestedAndArray() {
+ " ]" + LS
+ " }" + LS
+ "]";
- assertEquals(expected, toString(acc));
+ assertEqualsIfAccessible(expected, toString(acc));
}
@Test
@@ -244,7 +243,7 @@ public void nestedElements() {
+ " ]," + LS
+ " name=Douglas Adams" + LS
+ "]";
- assertEquals(exp, toString(customer));
+ assertEqualsIfAccessible(exp, toString(customer));
}
@Test
@@ -264,7 +263,7 @@ public void shortArray() {
+ " 1," + LS
+ " 2" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
@Test
@@ -274,7 +273,7 @@ public void simpleObject() {
+ " amount=100.0," + LS
+ " date=2014.10.15" + LS
+ "]";
- assertEquals(expected, toString(tx));
+ assertEqualsIfAccessible(expected, toString(tx));
}
@Test
@@ -287,7 +286,7 @@ public void stringArray() {
+ " a," + LS
+ " A" + LS
+ " }");
- assertEquals(exp, toString(wa));
+ assertEqualsIfAccessible(exp, toString(wa));
}
@Test
diff --git a/src/test/java/org/apache/commons/lang3/builder/RecursiveToStringStyleNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/RecursiveToStringStyleNoForceTest.java
new file mode 100644
index 00000000000..5900ef6a5a5
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/RecursiveToStringStyleNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link RecursiveToStringStyleTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class RecursiveToStringStyleNoForceTest extends RecursiveToStringStyleTest {
+ // Empty.
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/RecursiveToStringStyleTest.java b/src/test/java/org/apache/commons/lang3/builder/RecursiveToStringStyleTest.java
index 3267d8fc5b0..b88fec4b214 100644
--- a/src/test/java/org/apache/commons/lang3/builder/RecursiveToStringStyleTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/RecursiveToStringStyleTest.java
@@ -21,7 +21,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -29,7 +28,7 @@
/**
* Tests {@link org.apache.commons.lang3.builder.RecursiveToStringStyleTest}.
*/
-class RecursiveToStringStyleTest extends AbstractLangTest {
+class RecursiveToStringStyleTest extends AbstractBuilderTest {
static class Job {
@@ -158,8 +157,13 @@ void testPerson() {
p.job.title = "Manager";
final String baseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
final String jobStr = p.job.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p.job));
- assertEquals(baseStr + "[age=33,job=" + jobStr + "[title=Manager],name=John Doe,smoker=false]",
- new ReflectionToStringBuilder(p, new RecursiveToStringStyle()).toString());
+ testPersonAssert(p, baseStr, jobStr);
+ }
+
+ protected void testPersonAssert(final Person p, final String baseStr, final String jobStr) {
+ assertEquals(baseStr + "[age=" + accessibleString("33") + ",job=" + accessibleString(jobStr + "[title=Manager]") + ",name="
+ + accessibleString("John Doe") + ",smoker=" + accessibleString("false") + "]",
+ new ReflectionToStringBuilder(p, new RecursiveToStringStyle()).toString());
}
}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderCustomImplementationNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderCustomImplementationNoForceTest.java
new file mode 100644
index 00000000000..f592ce482c6
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderCustomImplementationNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link ReflectionToStringBuilderCustomImplementationTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class ReflectionToStringBuilderCustomImplementationNoForceTest extends ReflectionToStringBuilderCustomImplementationTest {
+ // Empty
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderCustomImplementationTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderCustomImplementationTest.java
index 4bddf0223a9..28003746e1a 100644
--- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderCustomImplementationTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderCustomImplementationTest.java
@@ -14,20 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.lang3.builder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.lang.reflect.Field;
-import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link ReflectionToStringBuilder} always uses {@link ReflectionToStringBuilder#getValue(Field)} to get the
- * value of every field in the class.
+ * Tests {@link ReflectionToStringBuilder} always uses {@link ReflectionToStringBuilder#getValue(Field)} to get the value of every field in the class.
*/
-class ReflectionToStringBuilderCustomImplementationTest extends AbstractLangTest {
+class ReflectionToStringBuilderCustomImplementationTest extends AbstractBuilderTest {
public static class CustomReflectionToStringBuilder extends ReflectionToStringBuilder {
@@ -48,8 +47,7 @@ protected Object getValue(final Field field) throws IllegalAccessException {
@Test
void testBuild() {
- assertEquals("[stringField=prefix:string]",
+ assertEquals("[stringField=" + accessibleString("prefix:string") + "]",
new CustomReflectionToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE).build());
}
-
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNoForceTest.java
new file mode 100644
index 00000000000..52aad0f4622
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link ReflectionToStringBuilderExcludeTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class ReflectionToStringBuilderExcludeNoForceTest extends ReflectionToStringBuilderExcludeTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNullValuesNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNullValuesNoForceTest.java
new file mode 100644
index 00000000000..20b92782225
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNullValuesNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link ReflectionToStringBuilderExcludeNullValuesTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class ReflectionToStringBuilderExcludeNullValuesNoForceTest extends ReflectionToStringBuilderExcludeNullValuesTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNullValuesTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNullValuesTest.java
index f40049a8c7a..8e161f76af5 100644
--- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNullValuesTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeNullValuesTest.java
@@ -20,10 +20,9 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
-class ReflectionToStringBuilderExcludeNullValuesTest extends AbstractLangTest {
+class ReflectionToStringBuilderExcludeNullValuesTest extends AbstractBuilderTest {
static class TestFixture {
@SuppressWarnings("unused")
@@ -49,17 +48,17 @@ void test_ConstructorOption() {
ReflectionToStringBuilder builder = new ReflectionToStringBuilder(BOTH_NON_NULL, null, null, null, false, false, true);
assertTrue(builder.isExcludeNullValues());
String toString = builder.toString();
- assertTrue(toString.contains(INTEGER_FIELD_NAME));
- assertTrue(toString.contains(STRING_FIELD_NAME));
+ assertTrueIfAccessible(toString.contains(INTEGER_FIELD_NAME));
+ assertTrueIfAccessible(toString.contains(STRING_FIELD_NAME));
builder = new ReflectionToStringBuilder(FIRST_NULL, null, null, null, false, false, true);
toString = builder.toString();
assertFalse(toString.contains(INTEGER_FIELD_NAME));
- assertTrue(toString.contains(STRING_FIELD_NAME));
+ assertTrueIfAccessible(toString.contains(STRING_FIELD_NAME));
builder = new ReflectionToStringBuilder(SECOND_NULL, null, null, null, false, false, true);
toString = builder.toString();
- assertTrue(toString.contains(INTEGER_FIELD_NAME));
+ assertTrueIfAccessible(toString.contains(INTEGER_FIELD_NAME));
assertFalse(toString.contains(STRING_FIELD_NAME));
builder = new ReflectionToStringBuilder(BOTH_NULL, null, null, null, false, false, true);
@@ -120,17 +119,17 @@ void test_excludeNull() {
//test normal case
String toString = ReflectionToStringBuilder.toString(BOTH_NON_NULL, null, false, false, true, null);
- assertTrue(toString.contains(INTEGER_FIELD_NAME));
- assertTrue(toString.contains(STRING_FIELD_NAME));
+ assertTrueIfAccessible(toString.contains(INTEGER_FIELD_NAME));
+ assertTrueIfAccessible(toString.contains(STRING_FIELD_NAME));
//make one null
toString = ReflectionToStringBuilder.toString(FIRST_NULL, null, false, false, true, null);
assertFalse(toString.contains(INTEGER_FIELD_NAME));
- assertTrue(toString.contains(STRING_FIELD_NAME));
+ assertTrueIfAccessible(toString.contains(STRING_FIELD_NAME));
//other one null
toString = ReflectionToStringBuilder.toString(SECOND_NULL, null, false, false, true, null);
- assertTrue(toString.contains(INTEGER_FIELD_NAME));
+ assertTrueIfAccessible(toString.contains(INTEGER_FIELD_NAME));
assertFalse(toString.contains(STRING_FIELD_NAME));
//both null
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeTest.java
index a4d684b3f8d..3e85c74ab62 100644
--- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeTest.java
@@ -24,13 +24,12 @@
import java.util.Collection;
import java.util.List;
-import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Test;
/**
*/
-class ReflectionToStringBuilderExcludeTest extends AbstractLangTest {
+class ReflectionToStringBuilderExcludeTest extends AbstractBuilderTest {
final class TestFixture {
@SuppressWarnings("unused")
@@ -123,7 +122,7 @@ void test_toStringExcludeNullCollection() {
private void validateNonSecretField(final String toString) {
assertTrue(toString.contains(NOT_SECRET_FIELD));
- assertTrue(toString.contains(NOT_SECRET_VALUE));
+ assertTrueIfAccessible(toString.contains(NOT_SECRET_VALUE));
}
private void validateSecretFieldAbsent(final String toString) {
@@ -132,7 +131,7 @@ private void validateSecretFieldAbsent(final String toString) {
}
private void validateSecretFieldPresent(final String toString) {
- assertTrue(toString.indexOf(SECRET_VALUE) > 0);
+ assertTrueIfAccessible(toString.indexOf(SECRET_VALUE) > 0);
validateNonSecretField(toString);
}
}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationNoForceTest.java
new file mode 100644
index 00000000000..8cf66e31dad
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link ReflectionToStringBuilderExcludeWithAnnotationTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class ReflectionToStringBuilderExcludeWithAnnotationNoForceTest extends ReflectionToStringBuilderExcludeWithAnnotationTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationTest.java
index 55f9f48ceaf..acb811af0bf 100644
--- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderExcludeWithAnnotationTest.java
@@ -20,13 +20,12 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Test class for ToStringExclude annotation
*/
-class ReflectionToStringBuilderExcludeWithAnnotationTest extends AbstractLangTest {
+class ReflectionToStringBuilderExcludeWithAnnotationTest extends AbstractBuilderTest {
final class TestFixture {
@ToStringExclude
@@ -50,7 +49,7 @@ void test_toStringExclude() {
assertFalse(toString.contains(EXCLUDED_FIELD_NAME));
assertFalse(toString.contains(EXCLUDED_FIELD_VALUE));
assertTrue(toString.contains(INCLUDED_FIELD_NAME));
- assertTrue(toString.contains(INCLUDED_FIELD_VALUE));
+ assertTrueIfAccessible(toString.contains(INCLUDED_FIELD_VALUE));
}
}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderIncludeNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderIncludeNoForceTest.java
new file mode 100644
index 00000000000..25a7ec0bd05
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderIncludeNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link ReflectionToStringBuilderIncludeTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class ReflectionToStringBuilderIncludeNoForceTest extends ReflectionToStringBuilderIncludeTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderIncludeTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderIncludeTest.java
index 04107fd1d18..0e051bd6aa1 100644
--- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderIncludeTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderIncludeTest.java
@@ -24,12 +24,11 @@
import java.util.Collection;
import java.util.List;
-import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
+class ReflectionToStringBuilderIncludeTest extends AbstractBuilderTest {
final class TestFeature {
@SuppressWarnings("unused")
@@ -214,7 +213,7 @@ private void validateIncludeFieldsPresent(final String toString, final String[]
}
for (final String includeValue : valuesToShow) {
- assertTrue(toString.indexOf(includeValue) > 0);
+ assertTrueIfAccessible(toString.indexOf(includeValue) > 0);
}
validateNonIncludeFieldsAbsent(toString, fieldsToShow, valuesToShow);
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryNoForceTest.java
new file mode 100644
index 00000000000..e9605f92091
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link ReflectionToStringBuilderSummaryTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class ReflectionToStringBuilderSummaryNoForceTest extends ReflectionToStringBuilderSummaryTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java
index be0f5227c34..78ced90f178 100644
--- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderSummaryTest.java
@@ -16,12 +16,9 @@
*/
package org.apache.commons.lang3.builder;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
-class ReflectionToStringBuilderSummaryTest extends AbstractLangTest {
+class ReflectionToStringBuilderSummaryTest extends AbstractBuilderTest {
@SuppressWarnings("unused")
private final String stringField = "string";
@@ -31,8 +28,7 @@ class ReflectionToStringBuilderSummaryTest extends AbstractLangTest {
@Test
void testSummary() {
- assertEquals("[stringField=string,summaryString=]",
- new ReflectionToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE).build());
+ assertEqualsIfAccessible("[stringField=string,summaryString=]", new ReflectionToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE).build());
}
}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderNoForceTest.java b/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderNoForceTest.java
new file mode 100644
index 00000000000..2b65c47f399
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderNoForceTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.builder;
+
+import org.junitpioneer.jupiter.SetSystemProperty;
+
+/**
+ * Like {@link ToStringBuilderTest} with force accessible disabled.
+ */
+@SetSystemProperty(key = AbstractReflectionTest.FORCE_ACCESSIBLE, value = "false")
+public class ToStringBuilderNoForceTest extends ToStringBuilderTest {
+ // TODO Override failing methods with new assertions
+}
diff --git a/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
index befd4ae8bf2..fc79105affe 100644
--- a/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java
@@ -26,13 +26,12 @@
import java.util.HashMap;
import java.util.List;
-import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link org.apache.commons.lang3.builder.ToStringBuilder}.
*/
-class ToStringBuilderTest extends AbstractLangTest {
+class ToStringBuilderTest extends AbstractBuilderTest {
/**
* Test fixture for ReflectionToStringBuilder.toString() for statics.
@@ -655,20 +654,20 @@ void testGetSetDefault() {
@Test
void testInheritedReflectionStatics() {
final InheritedReflectionStaticFieldsFixture instance1 = new InheritedReflectionStaticFieldsFixture();
- assertEquals(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2]",
+ assertEqualsIfAccessible(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2]",
ReflectionToStringBuilder.toString(instance1, null, false, true, InheritedReflectionStaticFieldsFixture.class));
- assertEquals(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
+ assertEqualsIfAccessible(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
ReflectionToStringBuilder.toString(instance1, null, false, true, SimpleReflectionStaticFieldsFixture.class));
- assertEquals(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
+ assertEqualsIfAccessible(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class));
- assertEquals(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
+ assertEqualsIfAccessible(toBaseString(instance1) + "[staticInt2=67890,staticString2=staticString2,staticInt=12345,staticString=staticString]",
this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class));
}
@Test
void testInnerClassReflection() {
final Outer outer = new Outer();
- assertEquals(toBaseString(outer) + "[inner=" + toBaseString(outer.inner) + "[]]", outer.toString());
+ assertEqualsIfAccessible(toBaseString(outer) + "[inner=" + toBaseString(outer.inner) + "[]]", outer.toString());
}
@Test
@@ -790,9 +789,9 @@ void testReflectionArrayAndObjectCycle() {
final Object[] objects = new Object[1];
final SimpleReflectionTestFixture simple = new SimpleReflectionTestFixture(objects);
objects[0] = simple;
- assertEquals(toBaseString(objects) + "[{" + toBaseString(simple) + "[o=" + toBaseString(objects) + "]}]",
+ assertEqualsIfAccessible(toBaseString(objects) + "[{" + toBaseString(simple) + "[o=" + toBaseString(objects) + "]}]",
ToStringBuilder.reflectionToString(objects));
- assertEquals(toBaseString(simple) + "[o={" + toBaseString(simple) + "}]", ToStringBuilder.reflectionToString(simple));
+ assertEqualsIfAccessible(toBaseString(simple) + "[o={" + toBaseString(simple) + "}]", ToStringBuilder.reflectionToString(simple));
}
@Test
@@ -837,9 +836,9 @@ void testReflectionArrayCycleLevel2() {
void testReflectionBoolean() {
Boolean b;
b = Boolean.TRUE;
- assertEquals(toBaseString(b) + "[value=true]", ToStringBuilder.reflectionToString(b));
+ assertEqualsIfAccessible(toBaseString(b) + "[value=true]", ToStringBuilder.reflectionToString(b));
b = Boolean.FALSE;
- assertEquals(toBaseString(b) + "[value=false]", ToStringBuilder.reflectionToString(b));
+ assertEqualsIfAccessible(toBaseString(b) + "[value=false]", ToStringBuilder.reflectionToString(b));
}
@Test
@@ -885,7 +884,7 @@ void testReflectionByteArrayArray() {
@Test
void testReflectionCharacter() {
final Character c = 'A';
- assertEquals(toBaseString(c) + "[value=A]", ToStringBuilder.reflectionToString(c));
+ assertEqualsIfAccessible(toBaseString(c) + "[value=A]", ToStringBuilder.reflectionToString(c));
}
@Test
@@ -946,25 +945,24 @@ void testReflectionFloatArrayArray() {
void testReflectionHierarchy() {
final ReflectionTestFixtureA baseA = new ReflectionTestFixtureA();
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));
- assertEquals(baseString + "[a=a,transientA=t]", ToStringBuilder.reflectionToString(baseA, null, true));
- assertEquals(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, null));
- assertEquals(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, Object.class));
- assertEquals(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, ReflectionTestFixtureA.class));
-
+ assertEqualsIfAccessible(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA));
+ assertEqualsIfAccessible(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null));
+ assertEqualsIfAccessible(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false));
+ assertEqualsIfAccessible(baseString + "[a=a,transientA=t]", ToStringBuilder.reflectionToString(baseA, null, true));
+ assertEqualsIfAccessible(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, null));
+ assertEqualsIfAccessible(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, Object.class));
+ assertEqualsIfAccessible(baseString + "[a=a]", ToStringBuilder.reflectionToString(baseA, null, false, ReflectionTestFixtureA.class));
final ReflectionTestFixtureB baseB = new ReflectionTestFixtureB();
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));
- assertEquals(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false));
- assertEquals(baseString + "[b=b,transientB=t,a=a,transientA=t]", ToStringBuilder.reflectionToString(baseB, null, true));
- assertEquals(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, null));
- assertEquals(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, Object.class));
- assertEquals(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureA.class));
- assertEquals(baseString + "[b=b]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureB.class));
+ assertEqualsIfAccessible(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB));
+ assertEqualsIfAccessible(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB));
+ assertEqualsIfAccessible(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null));
+ assertEqualsIfAccessible(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false));
+ assertEqualsIfAccessible(baseString + "[b=b,transientB=t,a=a,transientA=t]", ToStringBuilder.reflectionToString(baseB, null, true));
+ assertEqualsIfAccessible(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, null));
+ assertEqualsIfAccessible(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, Object.class));
+ assertEqualsIfAccessible(baseString + "[b=b,a=a]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureA.class));
+ assertEqualsIfAccessible(baseString + "[b=b]", ToStringBuilder.reflectionToString(baseB, null, false, ReflectionTestFixtureB.class));
}
// Reflection hierarchy tests
@@ -973,13 +971,14 @@ void testReflectionHierarchyArrayList() {
// LANG-1337 without this, the generated string can differ depending on the JVM version/vendor
final List