Rename test class.
RENAME
src/test/java/org/apache/commons/io/serialization/ClosingBase.java
src/test/java/org/apache/commons/io/serialization/AbstractCloseableListTest.java
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
-/** Test base class that keeps track of Closeable objects
- * and cleans them up.
+/**
+ * Test base class that keeps track of Closeable objects and cleans them up.
*/
-public class ClosingBase {
- private final List<Closeable> toClose = new ArrayList<>();
+public abstract class AbstractCloseableListTest {
+ private final List<Closeable> closeableList = new ArrayList<>();
- protected <T extends Closeable> T willClose(final T t) {
- toClose.add(t);
+ /**
+ * Adds a Closeable to close after each test.
+ *
+ * @param <T> The Closeable type
+ * @param t The Closeable.
+ * @return The Closeable.
+ */
+ protected <T extends Closeable> T closeAfterEachTest(final T t) {
+ closeableList.add(t);
return t;
}
@BeforeEach
public void setup() {
- toClose.clear();
+ closeableList.clear();
}
@AfterEach
public void cleanup() {
- for (final Closeable c : toClose) {
+ for (final Closeable c : closeableList) {
try {
c.close();
} catch (final IOException ignored) {

MODIFY
src/test/java/org/apache/commons/io/serialization/MoreComplexObjectTest.java
src/test/java/org/apache/commons/io/serialization/MoreComplexObjectTest.java
* to verify which settings it requires, as the object uses a number of primitive
* and java.* member objects.
*/
-public class MoreComplexObjectTest extends ClosingBase {
+public class MoreComplexObjectTest extends AbstractCloseableListTest {
private InputStream inputStream;
private MoreComplexObject original;
@BeforeEach
public void setupMoreComplexObject() throws IOException {
original = new MoreComplexObject();
- final ByteArrayOutputStream bos = willClose(new ByteArrayOutputStream());
- final ObjectOutputStream oos = willClose(new ObjectOutputStream(bos));
+ final ByteArrayOutputStream bos = closeAfterEachTest(new ByteArrayOutputStream());
+ final ObjectOutputStream oos = closeAfterEachTest(new ObjectOutputStream(bos));
oos.writeObject(original);
- inputStream = willClose(new ByteArrayInputStream(bos.toByteArray()));
+ inputStream = closeAfterEachTest(new ByteArrayInputStream(bos.toByteArray()));
}
private void assertSerialization(final ObjectInputStream ois) throws ClassNotFoundException, IOException {
@@ -61,7 +61,7 @@ private void assertSerialization(final ObjectInputStream ois) throws ClassNotFou
*/
@Test
public void trustJavaLang() throws IOException, ClassNotFoundException {
- assertSerialization(willClose(
+ assertSerialization(closeAfterEachTest(
new ValidatingObjectInputStream(inputStream)
.accept(MoreComplexObject.class, ArrayList.class, Random.class)
.accept("java.lang.*","[Ljava.lang.*")
@@ -73,7 +73,7 @@ public void trustJavaLang() throws IOException, ClassNotFoundException {
*/
@Test
public void trustJavaIncludingArrays() throws IOException, ClassNotFoundException {
- assertSerialization(willClose(
+ assertSerialization(closeAfterEachTest(
new ValidatingObjectInputStream(inputStream)
.accept(MoreComplexObject.class)
.accept("java.*","[Ljava.*")
@@ -94,7 +94,7 @@ public void useBlacklist() throws IOException, ClassNotFoundException {
"org.codehaus.groovy.runtime.MethodClosure",
"org.springframework.beans.factory.ObjectFactory"
};
- assertSerialization(willClose(
+ assertSerialization(closeAfterEachTest(
new ValidatingObjectInputStream(inputStream)
.accept("*")
.reject(blacklist)

MODIFY
src/test/java/org/apache/commons/io/serialization/ValidatingObjectInputStreamTest.java
src/test/java/org/apache/commons/io/serialization/ValidatingObjectInputStreamTest.java
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public class ValidatingObjectInputStreamTest extends ClosingBase {
+public class ValidatingObjectInputStreamTest extends AbstractCloseableListTest {
private MockSerializedClass testObject;
private InputStream testStream;
@BeforeEach
public void setupMockSerializedClass() throws IOException {
testObject = new MockSerializedClass(UUID.randomUUID().toString());
- final ByteArrayOutputStream bos = willClose(new ByteArrayOutputStream());
- final ObjectOutputStream oos = willClose(new ObjectOutputStream(bos));
+ final ByteArrayOutputStream bos = closeAfterEachTest(new ByteArrayOutputStream());
+ final ObjectOutputStream oos = closeAfterEachTest(new ObjectOutputStream(bos));
oos.writeObject(testObject);
- testStream = willClose(new ByteArrayInputStream(bos.toByteArray()));
+ testStream = closeAfterEachTest(new ByteArrayInputStream(bos.toByteArray()));
}
private void assertSerialization(final ObjectInputStream ois) throws ClassNotFoundException, IOException {
@@ -59,14 +59,14 @@ private void assertSerialization(final ObjectInputStream ois) throws ClassNotFou
@Test
public void noAccept() {
assertThrows(InvalidClassException.class, () -> assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))));
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))));
}
@Test
public void exceptionIncludesClassName() throws Exception {
try {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream)));
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream)));
fail("Expected an InvalidClassException");
} catch(final InvalidClassException ice) {
final String name = MockSerializedClass.class.getName();
@@ -77,7 +77,7 @@ public void exceptionIncludesClassName() throws Exception {
@Test
public void acceptCustomMatcher() throws Exception {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(ALWAYS_TRUE)
);
}
@@ -86,7 +86,7 @@ public void acceptCustomMatcher() throws Exception {
public void rejectCustomMatcher() {
assertThrows(InvalidClassException.class,
() -> assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(MockSerializedClass.class)
.reject(ALWAYS_TRUE)
));
@@ -95,7 +95,7 @@ public void rejectCustomMatcher() {
@Test
public void acceptPattern() throws Exception {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(Pattern.compile(".*MockSerializedClass.*"))
);
}
@@ -104,7 +104,7 @@ public void acceptPattern() throws Exception {
public void rejectPattern() {
assertThrows(InvalidClassException.class,
() -> assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(MockSerializedClass.class)
.reject(Pattern.compile("org.*"))
));
@@ -113,7 +113,7 @@ public void rejectPattern() {
@Test
public void acceptWildcard() throws Exception {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept("org.apache.commons.io.*")
);
}
@@ -122,7 +122,7 @@ public void acceptWildcard() throws Exception {
public void rejectWildcard() {
assertThrows(InvalidClassException.class,
() -> assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(MockSerializedClass.class)
.reject("org.*")
));
@@ -132,7 +132,7 @@ public void rejectWildcard() {
public void ourTestClassNotAccepted() {
assertThrows(InvalidClassException.class,
() -> assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(Integer.class)
));
}
@@ -140,7 +140,7 @@ public void ourTestClassNotAccepted() {
@Test
public void ourTestClassOnlyAccepted() throws Exception {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(MockSerializedClass.class)
);
}
@@ -148,7 +148,7 @@ public void ourTestClassOnlyAccepted() throws Exception {
@Test
public void ourTestClassAcceptedFirst() throws Exception {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(MockSerializedClass.class, Integer.class)
);
}
@@ -156,7 +156,7 @@ public void ourTestClassAcceptedFirst() throws Exception {
@Test
public void ourTestClassAcceptedSecond() throws Exception {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(Integer.class, MockSerializedClass.class)
);
}
@@ -164,7 +164,7 @@ public void ourTestClassAcceptedSecond() throws Exception {
@Test
public void ourTestClassAcceptedFirstWildcard() throws Exception {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept("*MockSerializedClass","*Integer")
);
}
@@ -172,7 +172,7 @@ public void ourTestClassAcceptedFirstWildcard() throws Exception {
@Test
public void ourTestClassAcceptedSecondWildcard() throws Exception {
assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept("*Integer","*MockSerializedClass")
);
}
@@ -181,7 +181,7 @@ public void ourTestClassAcceptedSecondWildcard() throws Exception {
public void reject() {
assertThrows(InvalidClassException.class,
() -> assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(Long.class)
.reject(MockSerializedClass.class, Integer.class)
));
@@ -191,7 +191,7 @@ public void reject() {
public void rejectPrecedence() {
assertThrows(InvalidClassException.class,
() -> assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.accept(MockSerializedClass.class)
.reject(MockSerializedClass.class, Integer.class)
));
@@ -201,7 +201,7 @@ public void rejectPrecedence() {
public void rejectOnly() {
assertThrows(InvalidClassException.class,
() -> assertSerialization(
- willClose(new ValidatingObjectInputStream(testStream))
+ closeAfterEachTest(new ValidatingObjectInputStream(testStream))
.reject(Integer.class)
));
}
@@ -221,7 +221,7 @@ protected void invalidClassNameFound(final String className) throws InvalidClass
assertThrows(RuntimeException.class,
() -> assertSerialization(
- willClose(new CustomVOIS(testStream))
+ closeAfterEachTest(new CustomVOIS(testStream))
.reject(Integer.class)
));
}

Rename test class.