This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new bae40a5 Rename test class. bae40a5 is described below commit bae40a557de13b3f0924a13a24715ee78b65de1b Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Thu May 13 09:40:58 2021 -0400 Rename test class. --- ...ingBase.java => AbstractCloseableListTest.java} | 23 +++++++---- .../io/serialization/MoreComplexObjectTest.java | 14 +++---- .../ValidatingObjectInputStreamTest.java | 44 +++++++++++----------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/test/java/org/apache/commons/io/serialization/ClosingBase.java b/src/test/java/org/apache/commons/io/serialization/AbstractCloseableListTest.java similarity index 70% rename from src/test/java/org/apache/commons/io/serialization/ClosingBase.java rename to src/test/java/org/apache/commons/io/serialization/AbstractCloseableListTest.java index fcc3ac7..ba49c73 100644 --- a/src/test/java/org/apache/commons/io/serialization/ClosingBase.java +++ b/src/test/java/org/apache/commons/io/serialization/AbstractCloseableListTest.java @@ -26,25 +26,32 @@ import java.util.List; 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) { diff --git a/src/test/java/org/apache/commons/io/serialization/MoreComplexObjectTest.java b/src/test/java/org/apache/commons/io/serialization/MoreComplexObjectTest.java index b63bf83..69187d4 100644 --- a/src/test/java/org/apache/commons/io/serialization/MoreComplexObjectTest.java +++ b/src/test/java/org/apache/commons/io/serialization/MoreComplexObjectTest.java @@ -36,7 +36,7 @@ import org.junit.jupiter.api.Test; * 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; @@ -44,10 +44,10 @@ public class MoreComplexObjectTest extends ClosingBase { @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 @@ public class MoreComplexObjectTest extends ClosingBase { */ @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 class MoreComplexObjectTest extends ClosingBase { */ @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 class MoreComplexObjectTest extends ClosingBase { "org.codehaus.groovy.runtime.MethodClosure", "org.springframework.beans.factory.ObjectFactory" }; - assertSerialization(willClose( + assertSerialization(closeAfterEachTest( new ValidatingObjectInputStream(inputStream) .accept("*") .reject(blacklist) diff --git a/src/test/java/org/apache/commons/io/serialization/ValidatingObjectInputStreamTest.java b/src/test/java/org/apache/commons/io/serialization/ValidatingObjectInputStreamTest.java index 6d1bede..dcc8a29 100644 --- a/src/test/java/org/apache/commons/io/serialization/ValidatingObjectInputStreamTest.java +++ b/src/test/java/org/apache/commons/io/serialization/ValidatingObjectInputStreamTest.java @@ -36,7 +36,7 @@ import java.util.regex.Pattern; 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; @@ -45,10 +45,10 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { @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 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { @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 class ValidatingObjectInputStreamTest extends ClosingBase { @Test public void acceptCustomMatcher() throws Exception { assertSerialization( - willClose(new ValidatingObjectInputStream(testStream)) + closeAfterEachTest(new ValidatingObjectInputStream(testStream)) .accept(ALWAYS_TRUE) ); } @@ -86,7 +86,7 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { 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 class ValidatingObjectInputStreamTest extends ClosingBase { @Test public void acceptPattern() throws Exception { assertSerialization( - willClose(new ValidatingObjectInputStream(testStream)) + closeAfterEachTest(new ValidatingObjectInputStream(testStream)) .accept(Pattern.compile(".*MockSerializedClass.*")) ); } @@ -104,7 +104,7 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { 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 class ValidatingObjectInputStreamTest extends ClosingBase { @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 class ValidatingObjectInputStreamTest extends ClosingBase { 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 class ValidatingObjectInputStreamTest extends ClosingBase { public void ourTestClassNotAccepted() { assertThrows(InvalidClassException.class, () -> assertSerialization( - willClose(new ValidatingObjectInputStream(testStream)) + closeAfterEachTest(new ValidatingObjectInputStream(testStream)) .accept(Integer.class) )); } @@ -140,7 +140,7 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { @Test public void ourTestClassOnlyAccepted() throws Exception { assertSerialization( - willClose(new ValidatingObjectInputStream(testStream)) + closeAfterEachTest(new ValidatingObjectInputStream(testStream)) .accept(MockSerializedClass.class) ); } @@ -148,7 +148,7 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { @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 class ValidatingObjectInputStreamTest extends ClosingBase { @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 class ValidatingObjectInputStreamTest extends ClosingBase { @Test public void ourTestClassAcceptedFirstWildcard() throws Exception { assertSerialization( - willClose(new ValidatingObjectInputStream(testStream)) + closeAfterEachTest(new ValidatingObjectInputStream(testStream)) .accept("*MockSerializedClass","*Integer") ); } @@ -172,7 +172,7 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { @Test public void ourTestClassAcceptedSecondWildcard() throws Exception { assertSerialization( - willClose(new ValidatingObjectInputStream(testStream)) + closeAfterEachTest(new ValidatingObjectInputStream(testStream)) .accept("*Integer","*MockSerializedClass") ); } @@ -181,7 +181,7 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { 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 class ValidatingObjectInputStreamTest extends ClosingBase { 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 class ValidatingObjectInputStreamTest extends ClosingBase { public void rejectOnly() { assertThrows(InvalidClassException.class, () -> assertSerialization( - willClose(new ValidatingObjectInputStream(testStream)) + closeAfterEachTest(new ValidatingObjectInputStream(testStream)) .reject(Integer.class) )); } @@ -221,7 +221,7 @@ public class ValidatingObjectInputStreamTest extends ClosingBase { assertThrows(RuntimeException.class, () -> assertSerialization( - willClose(new CustomVOIS(testStream)) + closeAfterEachTest(new CustomVOIS(testStream)) .reject(Integer.class) )); }