Skip to content

Commit f550561

Browse files
committed
[CODEC-334] Add tests in Base64OutputStreamTest
1 parent 19b3c4c commit f550561

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
import static org.junit.jupiter.api.Assertions.assertTrue;
2626

2727
import java.io.ByteArrayOutputStream;
28+
import java.io.FileOutputStream;
2829
import java.io.OutputStream;
30+
import java.nio.file.Files;
31+
import java.nio.file.Path;
2932

3033
import org.apache.commons.codec.CodecPolicy;
3134
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.api.io.TempDir;
3236

3337
/**
3438
* Tests {@link Base64OutputStream}.
@@ -275,6 +279,32 @@ private void testByteByByte(final byte[] encoded, final byte[] decoded, final in
275279
assertArrayEquals(decoded, output, "Streaming byte-by-byte base64 wrap-wrap-wrap!");
276280
}
277281

282+
/**
283+
* Tests https://issues.apache.org/jira/browse/CODEC-334
284+
*/
285+
@Test
286+
void testCloseIdempotentCreateTempFile() throws Exception {
287+
final Path tmp = Files.createTempFile("codec-test", ".bin");
288+
try {
289+
final OutputStream out = new Base64OutputStream(new FileOutputStream(tmp.toFile()));
290+
out.close();
291+
out.close();
292+
} finally {
293+
Files.deleteIfExists(tmp);
294+
}
295+
}
296+
297+
/**
298+
* Tests https://issues.apache.org/jira/browse/CODEC-334
299+
*/
300+
@Test
301+
void testCloseIdempotentFileOutputStream(@TempDir final Path tempDir) throws Exception {
302+
final Path tmp = Files.createFile(tempDir.resolve(getClass().getSimpleName() + ".tmp"));
303+
try (OutputStream out = new Base64OutputStream(new FileOutputStream(tmp.toFile()))) {
304+
out.close();
305+
}
306+
}
307+
278308
/**
279309
* Test the Base64OutputStream implementation against the special NPE inducing input
280310
* identified in the CODEC-98 bug.

0 commit comments

Comments
 (0)