All tests should leave the ToStringStyle registry empty.

This commit is contained in:
Gary Gregory 2022-07-05 12:46:01 -04:00
parent ae65d3b255
commit 1bf7d7ec12
30 changed files with 98 additions and 47 deletions

View File

@ -186,7 +186,7 @@ public abstract class ToStringStyle implements Serializable {
*
* @return Set the registry of objects being traversed
*/
static Map<Object, Object> getRegistry() {
public static Map<Object, Object> getRegistry() {
return REGISTRY.get();
}

View File

@ -0,0 +1,41 @@
/*
* 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;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Map;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.junit.jupiter.api.AfterEach;
public class AbstractLangTest {
/**
* All tests should leave the {@link ToStringStyle} registry empty.
*/
@AfterEach
public void after() {
validateNullToStringStyleRegistry();
}
void validateNullToStringStyleRegistry() {
final Map<Object, Object> registry = ToStringStyle.getRegistry();
assertNull(registry, "Expected null, actual: " + registry);
}
}

View File

@ -22,12 +22,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigInteger;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.CompareToBuilder}.
*/
public class CompareToBuilderTest {
public class CompareToBuilderTest extends AbstractLangTest {
static class TestObject implements Comparable<TestObject> {

View File

@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.Collections;
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;
@ -29,7 +30,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.DefaultToStringStyleTest}.
*/
public class DefaultToStringStyleTest {
public class DefaultToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);
private final String baseStr = base.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(base));

View File

@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.ArrayUtils;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
@ -33,7 +34,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link DiffBuilder}.
*/
public class DiffBuilderTest {
public class DiffBuilderTest extends AbstractLangTest {
private static class TypeTestClass implements Diffable<TypeTestClass> {
private ToStringStyle style = SHORT_STYLE;

View File

@ -23,12 +23,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Unit tests {@link DiffResult}.
*/
public class DiffResultTest {
public class DiffResultTest extends AbstractLangTest {
private static final SimpleClass SIMPLE_FALSE = new SimpleClass(false);
private static final SimpleClass SIMPLE_TRUE = new SimpleClass(true);

View File

@ -19,13 +19,14 @@ package org.apache.commons.lang3.builder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Unit tests {@link Diff}.
*/
public class DiffTest {
public class DiffTest extends AbstractLangTest {
private static final String FIELD_NAME = "field";
private static final Diff<Boolean> booleanDiff = new BooleanDiff(FIELD_NAME);

View File

@ -25,13 +25,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Method;
import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.EqualsBuilder}.
*/
public class EqualsBuilderTest {
public class EqualsBuilderTest extends AbstractLangTest {
static class TestObject {

View File

@ -18,6 +18,7 @@ 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;
/**
@ -25,7 +26,7 @@ import org.junit.jupiter.api.Test;
* {@link org.apache.commons.lang3.builder.EqualsBuilderTest} to insure that equal
* objects must have equal hash codes.
*/
public class HashCodeBuilderAndEqualsBuilderTest {
public class HashCodeBuilderAndEqualsBuilderTest extends AbstractLangTest {
private void testInteger(final boolean testTransients) {

View File

@ -21,12 +21,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.HashCodeBuilder}.
*/
public class HashCodeBuilderTest {
public class HashCodeBuilderTest extends AbstractLangTest {
/**
* A reflection test fixture.

View File

@ -28,6 +28,7 @@ import java.util.LinkedHashMap;
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;
@ -36,7 +37,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.JsonToStringStyleTest}.
*/
public class JsonToStringStyleTest {
public class JsonToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);

View File

@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.Collections;
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;
@ -29,7 +30,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.MultiLineToStringStyleTest}.
*/
public class MultiLineToStringStyleTest {
public class MultiLineToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);
private final String baseStr = base.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(base));

View File

@ -22,11 +22,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
*/
public class MultilineRecursiveToStringStyleTest {
public class MultilineRecursiveToStringStyleTest extends AbstractLangTest {
private static final String LS = System.lineSeparator();
private static final String BASE_WITH_ARRAYS_TO_STRING = "[" + LS

View File

@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.Collections;
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;
@ -29,7 +30,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link ToStringStyle#NO_CLASS_NAME_STYLE}.
*/
public class NoClassNameToStringStyleTest {
public class NoClassNameToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);

View File

@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.Collections;
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;
@ -29,7 +30,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.NoFieldNamesToStringStyleTest}.
*/
public class NoFieldNamesToStringStyleTest {
public class NoFieldNamesToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);
private final String baseStr = base.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(base));

View File

@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
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;
@ -28,7 +29,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.RecursiveToStringStyleTest}.
*/
public class RecursiveToStringStyleTest {
public class RecursiveToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);
private final String baseStr = base.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(base));

View File

@ -18,10 +18,10 @@ 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;
public class ReflectionDiffBuilderTest {
public class ReflectionDiffBuilderTest extends AbstractLangTest {
private static final ToStringStyle SHORT_STYLE = ToStringStyle.SHORT_PREFIX_STYLE;

View File

@ -31,6 +31,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.concurrent.UncheckedFuture;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -49,7 +50,7 @@ import org.junit.jupiter.api.Test;
* and ToStringBuilder for collections that are not thread safe</a>
* @since 3.1
*/
public class ReflectionToStringBuilderConcurrencyTest {
public class ReflectionToStringBuilderConcurrencyTest extends AbstractLangTest {
static class CollectionHolder<T extends Collection<?>> {
T collection;

View File

@ -20,9 +20,10 @@ package org.apache.commons.lang3.builder;
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;
public class ReflectionToStringBuilderExcludeNullValuesTest {
public class ReflectionToStringBuilderExcludeNullValuesTest extends AbstractLangTest {
static class TestFixture {
@SuppressWarnings("unused")

View File

@ -24,12 +24,13 @@ import java.util.ArrayList;
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;
/**
*/
public class ReflectionToStringBuilderExcludeTest {
public class ReflectionToStringBuilderExcludeTest extends AbstractLangTest {
class TestFixture {
@SuppressWarnings("unused")

View File

@ -21,12 +21,13 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Test class for ToStringExclude annotation
*/
public class ReflectionToStringBuilderExcludeWithAnnotationTest {
public class ReflectionToStringBuilderExcludeWithAnnotationTest extends AbstractLangTest {
class TestFixture {
@ToStringExclude

View File

@ -20,6 +20,7 @@ package org.apache.commons.lang3.builder;
import java.util.LinkedList;
import java.util.Random;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -34,7 +35,7 @@ import org.junit.jupiter.api.Test;
* and ToStringBuilder for collections that are not thread safe</a>
* @since 3.1
*/
public class ReflectionToStringBuilderMutateInspectConcurrencyTest {
public class ReflectionToStringBuilderMutateInspectConcurrencyTest extends AbstractLangTest {
class TestFixture {
private final LinkedList<Integer> listField = new LinkedList<>();

View File

@ -18,9 +18,10 @@ 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;
public class ReflectionToStringBuilderSummaryTest {
public class ReflectionToStringBuilderSummaryTest extends AbstractLangTest {
@SuppressWarnings("unused")
private final String stringField = "string";

View File

@ -18,9 +18,10 @@ package org.apache.commons.lang3.builder;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
public class ReflectionToStringBuilderTest {
public class ReflectionToStringBuilderTest extends AbstractLangTest {
@Test
public void testConstructorWithNullObject() {

View File

@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.Collections;
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;
@ -29,7 +30,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.ToStringStyle#SHORT_PREFIX_STYLE}.
*/
public class ShortPrefixToStringStyleTest {
public class ShortPrefixToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);
private final String baseStr = "Integer";

View File

@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.Collections;
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;
@ -29,7 +30,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.SimpleToStringStyleTest}.
*/
public class SimpleToStringStyleTest {
public class SimpleToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);

View File

@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.Collections;
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;
@ -31,7 +32,7 @@ import org.junit.jupiter.api.Test;
/**
* Unit tests {@link org.apache.commons.lang3.builder.ToStringStyle}.
*/
public class StandardToStringStyleTest {
public class StandardToStringStyleTest extends AbstractLangTest {
private final Integer base = Integer.valueOf(5);
private final String baseStr = "Integer";

View File

@ -18,36 +18,26 @@ package org.apache.commons.lang3.builder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.builder.ToStringBuilder}.
*/
public class ToStringBuilderTest {
public class ToStringBuilderTest extends AbstractLangTest {
// See LANG-1337 for more.
private static final int ARRAYLIST_INITIAL_CAPACITY = 10;
private final Integer base = Integer.valueOf(5);
private final String baseStr = base.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(base));
/**
* All tests should leave the registry empty.
*/
@AfterEach
public void after() {
validateNullToStringStyleRegistry();
}
@Test
public void testConstructorEx1() {
assertEquals("<null>", new ToStringBuilder(null).toString());
@ -585,12 +575,6 @@ public class ToStringBuilderTest {
ToStringBuilder.reflectionToString(simple));
}
void validateNullToStringStyleRegistry() {
final Map<Object, Object> registry = ToStringStyle.getRegistry();
assertNull(registry, "Expected null, actual: " + registry);
}
// End: Reflection cycle tests
@Test
public void testAppendSuper() {
assertEquals(baseStr + "[]", new ToStringBuilder(base).appendSuper("Integer@8888[]").toString());

View File

@ -28,6 +28,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.AbstractLangTest;
import org.apache.commons.lang3.concurrent.UncheckedFuture;
import org.junit.jupiter.api.Test;
@ -45,7 +46,7 @@ import org.junit.jupiter.api.Test;
* and ToStringBuilder for collections that are not thread safe</a>
* @since 3.1
*/
public class ToStringStyleConcurrencyTest {
public class ToStringStyleConcurrencyTest extends AbstractLangTest {
static class CollectionHolder<T extends Collection<?>> {
T collection;

View File

@ -18,12 +18,13 @@ 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;
/**
* Test case for ToStringStyle.
*/
public class ToStringStyleTest {
public class ToStringStyleTest extends AbstractLangTest {
private static class ToStringStyleImpl extends ToStringStyle {
private static final long serialVersionUID = 1L;