aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/apache
diff options
context:
space:
mode:
authorGary Gregory <garydgregory@gmail.com>2022-05-30 09:02:29 -0400
committerGary Gregory <garydgregory@gmail.com>2022-05-30 09:02:29 -0400
commitbb43de8a5e93da97cb024b97c650ae884aecd341 (patch)
tree60dca755ce045438290aecc3dc0639f92e8aa643 /src/test/java/org/apache
parent1fed20b5312bf8cc495d7f8ebbd214f0ff1f953d (diff)
downloadapache-commons-lang-bb43de8a5e93da97cb024b97c650ae884aecd341.tar.gz
Use try-with-resources
Diffstat (limited to 'src/test/java/org/apache')
-rw-r--r--src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java75
1 files changed, 37 insertions, 38 deletions
diff --git a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java
index 1c84ec68d..47682e718 100644
--- a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java
@@ -102,10 +102,10 @@ public class SerializationUtilsTest {
SerializationUtils.serialize(iMap, streamTest);
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(iMap);
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(iMap);
+ oos.flush();
+ }
final byte[] testBytes = streamTest.toByteArray();
final byte[] realBytes = streamReal.toByteArray();
@@ -126,10 +126,10 @@ public class SerializationUtilsTest {
SerializationUtils.serialize(null, streamTest);
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(null);
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(null);
+ oos.flush();
+ }
final byte[] testBytes = streamTest.toByteArray();
final byte[] realBytes = streamReal.toByteArray();
@@ -166,10 +166,10 @@ public class SerializationUtilsTest {
@Test
public void testDeserializeStream() throws Exception {
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(iMap);
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(iMap);
+ oos.flush();
+ }
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
final Object test = SerializationUtils.deserialize(inTest);
@@ -199,10 +199,10 @@ public class SerializationUtilsTest {
@Test
public void testDeserializeStreamOfNull() throws Exception {
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(null);
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(null);
+ oos.flush();
+ }
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
final Object test = SerializationUtils.deserialize(inTest);
@@ -223,14 +223,13 @@ public class SerializationUtilsTest {
@Test
public void testDeserializeStreamClassNotFound() throws Exception {
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(new ClassNotFoundSerialization());
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(new ClassNotFoundSerialization());
+ oos.flush();
+ }
final ByteArrayInputStream inTest = new ByteArrayInputStream(streamReal.toByteArray());
- final SerializationException se =
- assertThrows(SerializationException.class, () -> SerializationUtils.deserialize(inTest));
+ final SerializationException se = assertThrows(SerializationException.class, () -> SerializationUtils.deserialize(inTest));
assertEquals("java.lang.ClassNotFoundException: " + CLASS_NOT_FOUND_MESSAGE, se.getMessage());
}
@@ -246,10 +245,10 @@ public class SerializationUtilsTest {
final byte[] testBytes = SerializationUtils.serialize(iMap);
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(iMap);
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(iMap);
+ oos.flush();
+ }
final byte[] realBytes = streamReal.toByteArray();
assertEquals(testBytes.length, realBytes.length);
@@ -267,10 +266,10 @@ public class SerializationUtilsTest {
final byte[] testBytes = SerializationUtils.serialize(null);
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(null);
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(null);
+ oos.flush();
+ }
final byte[] realBytes = streamReal.toByteArray();
assertEquals(testBytes.length, realBytes.length);
@@ -281,10 +280,10 @@ public class SerializationUtilsTest {
@Test
public void testDeserializeBytes() throws Exception {
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(iMap);
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(iMap);
+ oos.flush();
+ }
final Object test = SerializationUtils.deserialize(streamReal.toByteArray());
assertNotNull(test);
@@ -301,10 +300,10 @@ public class SerializationUtilsTest {
@Test
public void testDeserializeBytesOfNull() throws Exception {
final ByteArrayOutputStream streamReal = new ByteArrayOutputStream();
- final ObjectOutputStream oos = new ObjectOutputStream(streamReal);
- oos.writeObject(null);
- oos.flush();
- oos.close();
+ try (final ObjectOutputStream oos = new ObjectOutputStream(streamReal)) {
+ oos.writeObject(null);
+ oos.flush();
+ }
final Object test = SerializationUtils.deserialize(streamReal.toByteArray());
assertNull(test);