|
25 | 25 | import static org.junit.jupiter.api.Assertions.assertTrue; |
26 | 26 |
|
27 | 27 | import java.io.ByteArrayOutputStream; |
| 28 | +import java.io.FileOutputStream; |
28 | 29 | import java.io.OutputStream; |
| 30 | +import java.nio.file.Files; |
| 31 | +import java.nio.file.Path; |
29 | 32 |
|
30 | 33 | import org.apache.commons.codec.CodecPolicy; |
31 | 34 | import org.junit.jupiter.api.Test; |
| 35 | +import org.junit.jupiter.api.io.TempDir; |
32 | 36 |
|
33 | 37 | /** |
34 | 38 | * Tests {@link Base64OutputStream}. |
@@ -275,6 +279,32 @@ private void testByteByByte(final byte[] encoded, final byte[] decoded, final in |
275 | 279 | assertArrayEquals(decoded, output, "Streaming byte-by-byte base64 wrap-wrap-wrap!"); |
276 | 280 | } |
277 | 281 |
|
| 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 | + |
278 | 308 | /** |
279 | 309 | * Test the Base64OutputStream implementation against the special NPE inducing input |
280 | 310 | * identified in the CODEC-98 bug. |
|
0 commit comments