1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.io.file;
19
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Paths;
26
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 public class TempFileTest {
33
34 @SuppressWarnings("resource")
35 @Test
36 public void testCreatePath() throws IOException {
37 final TempFile ref;
38 try (TempFile tempDir = TempFile.create(Paths.get("target"), "prefix", ".suffix")) {
39 ref = tempDir;
40 assertTrue(Files.exists(ref.get()));
41 }
42 assertFalse(Files.exists(ref.get()));
43
44
45
46
47 }
48
49 @SuppressWarnings("resource")
50 @Test
51 public void testCreateString() throws IOException {
52 final TempFile ref;
53 try (TempFile tempDir = TempFile.create(getClass().getCanonicalName(), ".suffix")) {
54 ref = tempDir;
55 assertTrue(Files.exists(ref.get()));
56 }
57 assertFalse(Files.exists(ref.get()));
58 }
59
60 }