Revert "Use JUnit TempDir instead of custom code."
This reverts commit ebf06ea477399a778564d2bc60422f652b89989f.
diff --git a/src/main/java/org/apache/commons/io/file/CloseablePath.java b/src/main/java/org/apache/commons/io/file/CloseablePath.java
deleted file mode 100644
index 62a6f22..0000000
--- a/src/main/java/org/apache/commons/io/file/CloseablePath.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.io.file;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.nio.file.Path;
-
-public class CloseablePath extends PathWrapper implements Closeable {
-
- private DeleteOption[] deleteOptions;
-
- public CloseablePath(Path path) {
- super(path);
- }
-
- @Override
- public void close() throws IOException {
- PathUtils.delete(unwrap(), deleteOptions);
- }
-
-
-}
diff --git a/src/main/java/org/apache/commons/io/file/PathWrapper.java b/src/main/java/org/apache/commons/io/file/PathWrapper.java
deleted file mode 100644
index bd6f8bb..0000000
--- a/src/main/java/org/apache/commons/io/file/PathWrapper.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.io.file;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.nio.file.FileSystem;
-import java.nio.file.LinkOption;
-import java.nio.file.Path;
-import java.nio.file.WatchEvent.Kind;
-import java.nio.file.WatchEvent.Modifier;
-import java.nio.file.WatchKey;
-import java.nio.file.WatchService;
-import java.util.Iterator;
-import java.util.Objects;
-import java.util.Spliterator;
-import java.util.function.Consumer;
-
-/**
- * Wraps a path for subclasses.
- *
- * @since 2.12.0
- */
-public abstract class PathWrapper implements Path {
-
- /**
- * Unwraps a PathWrapper if it is one.
- *
- * @param path a Path or PathWrapper.
- * @param <P> The Path type.
- * @return The unwrapped path or the given path.
- */
- public static <P extends Path> P unwrap(final P path) {
- return path instanceof PathWrapper ? (P) unwrap((PathWrapper) path) : path;
- }
-
- static Path unwrap(final PathWrapper path) {
- return path.unwrap();
- }
-
- /**
- * The path delegate.
- */
- private final Path path;
-
- /**
- * Constructs a new instance.
- *
- * @param path The path to wrap.
- */
- protected PathWrapper(final Path path) {
- this.path = Objects.requireNonNull(path, "path");
- }
-
- @Override
- public int compareTo(final Path other) {
- return path.compareTo(other);
- }
-
- @Override
- public boolean endsWith(final Path other) {
- return path.endsWith(other);
- }
-
- @Override
- public boolean endsWith(final String other) {
- return path.endsWith(other);
- }
-
- @Override
- public boolean equals(final Object other) {
- return path.equals(other);
- }
-
- @Override
- public void forEach(final Consumer<? super Path> action) {
- path.forEach(action);
- }
-
- @Override
- public Path getFileName() {
- return path.getFileName();
- }
-
- @Override
- public FileSystem getFileSystem() {
- return path.getFileSystem();
- }
-
- @Override
- public Path getName(final int index) {
- return path.getName(index);
- }
-
- @Override
- public int getNameCount() {
- return path.getNameCount();
- }
-
- @Override
- public Path getParent() {
- return path.getParent();
- }
-
- @Override
- public Path getRoot() {
- return path.getRoot();
- }
-
- @Override
- public int hashCode() {
- return path.hashCode();
- }
-
- @Override
- public boolean isAbsolute() {
- return path.isAbsolute();
- }
-
- @Override
- public Iterator<Path> iterator() {
- return path.iterator();
- }
-
- @Override
- public Path normalize() {
- return path.normalize();
- }
-
- @Override
- public WatchKey register(final WatchService watcher, final Kind<?>... events) throws IOException {
- return path.register(watcher, events);
- }
-
- @Override
- public WatchKey register(final WatchService watcher, final Kind<?>[] events, final Modifier... modifiers) throws IOException {
- return path.register(watcher, events, modifiers);
- }
-
- @Override
- public Path relativize(final Path other) {
- return path.relativize(other);
- }
-
- @Override
- public Path resolve(final Path other) {
- return path.resolve(other);
- }
-
- @Override
- public Path resolve(final String other) {
- return path.resolve(other);
- }
-
- @Override
- public Path resolveSibling(final Path other) {
- return path.resolveSibling(other);
- }
-
- @Override
- public Path resolveSibling(final String other) {
- return path.resolveSibling(other);
- }
-
- @Override
- public Spliterator<Path> spliterator() {
- return path.spliterator();
- }
-
- @Override
- public boolean startsWith(final Path other) {
- return path.startsWith(other);
- }
-
- @Override
- public boolean startsWith(final String other) {
- return path.startsWith(other);
- }
-
- @Override
- public Path subpath(final int beginIndex, final int endIndex) {
- return path.subpath(beginIndex, endIndex);
- }
-
- @Override
- public Path toAbsolutePath() {
- return path.toAbsolutePath();
- }
-
- @Override
- public File toFile() {
- return path.toFile();
- }
-
- @Override
- public Path toRealPath(final LinkOption... options) throws IOException {
- return path.toRealPath(options);
- }
-
- @Override
- public String toString() {
- return path.toString();
- }
-
- @Override
- public URI toUri() {
- return path.toUri();
- }
-
- /**
- * Unwraps the Path.
- *
- * @return the Path.
- */
- public Path unwrap() {
- return path;
- }
-
-}
diff --git a/src/main/java/org/apache/commons/io/file/TempDirectory.java b/src/main/java/org/apache/commons/io/file/TempDirectory.java
deleted file mode 100644
index a31d977..0000000
--- a/src/main/java/org/apache/commons/io/file/TempDirectory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.io.file;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.attribute.FileAttribute;
-
-public class TempDirectory extends CloseablePath {
-
- public static TempDirectory create(final Path dir, final String prefix, final FileAttribute<?>... attrs) throws IOException {
- return new TempDirectory(Files.createTempDirectory(dir, prefix, attrs));
- }
-
- public static TempDirectory create(final String prefix, final FileAttribute<?>... attrs) throws IOException {
- return new TempDirectory(Files.createTempDirectory(prefix, attrs));
- }
-
- protected TempDirectory(final Path path) {
- super(path);
- }
-
-}
diff --git a/src/main/java/org/apache/commons/io/file/TempFile.java b/src/main/java/org/apache/commons/io/file/TempFile.java
deleted file mode 100644
index 8d9531d..0000000
--- a/src/main/java/org/apache/commons/io/file/TempFile.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.io.file;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.attribute.FileAttribute;
-
-public class TempFile extends CloseablePath {
-
- public static TempFile create(final Path dir, final String prefix, final String suffix, final FileAttribute<?>... attrs) throws IOException {
- return new TempFile(Files.createTempFile(dir, prefix, suffix, attrs));
- }
-
- public static TempFile create(final String prefix, final String suffix, final FileAttribute<?>... attrs) throws IOException {
- return new TempFile(Files.createTempFile(prefix, suffix, attrs));
- }
-
- protected TempFile(final Path path) {
- super(path);
- }
-
-}
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index 0d2789d..addea66 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -66,7 +66,6 @@
import org.apache.commons.io.file.AbstractTempDirTest;
import org.apache.commons.io.file.PathUtils;
import org.apache.commons.io.file.PathUtilsIsEmptyTest;
-import org.apache.commons.io.file.TempDirectory;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.NameFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
@@ -1622,19 +1621,21 @@ public void testIsDirectory() throws IOException {
assertTrue(FileUtils.isDirectory(tempDirFile));
assertFalse(FileUtils.isDirectory(testFile1));
- final File tempDirAsFile;
- try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
- tempDirAsFile = tempDir.toFile();
- assertTrue(FileUtils.isDirectory(tempDirAsFile));
- }
+ final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ final File tempDirAsFile = tempDir.toFile();
+ assertTrue(FileUtils.isDirectory(tempDirAsFile));
+ Files.delete(tempDir);
assertFalse(FileUtils.isDirectory(tempDirAsFile));
}
@Test
public void testIsEmptyDirectory() throws IOException {
- try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
- final File tempDirAsFile = tempDir.toFile();
+ final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ final File tempDirAsFile = tempDir.toFile();
+ try {
Assertions.assertTrue(FileUtils.isEmptyDirectory(tempDirAsFile));
+ } finally {
+ Files.delete(tempDir);
}
Assertions.assertFalse(FileUtils.isEmptyDirectory(PathUtilsIsEmptyTest.DIR_SIZE_1.toFile()));
}
diff --git a/src/test/java/org/apache/commons/io/file/CleaningPathVisitorTest.java b/src/test/java/org/apache/commons/io/file/CleaningPathVisitorTest.java
index 11ebefc..a033fa0 100644
--- a/src/test/java/org/apache/commons/io/file/CleaningPathVisitorTest.java
+++ b/src/test/java/org/apache/commons/io/file/CleaningPathVisitorTest.java
@@ -18,6 +18,7 @@
package org.apache.commons.io.file;
import static org.apache.commons.io.file.CounterAssertions.assertCounts;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
@@ -25,8 +26,9 @@
import java.nio.file.Paths;
import org.apache.commons.io.file.Counters.PathCounters;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@@ -35,14 +37,28 @@
*/
public class CleaningPathVisitorTest extends TestArguments {
- @TempDir
private Path tempDir;
+ @AfterEach
+ public void afterEach() throws IOException {
+ // temp dir should still exist since we are cleaning and not deleting.
+ assertTrue(Files.exists(tempDir));
+ // backstop
+ if (Files.exists(tempDir) && PathUtils.isEmptyDirectory(tempDir)) {
+ Files.deleteIfExists(tempDir);
+ }
+ }
+
private void applyCleanEmptyDirectory(final CleaningPathVisitor visitor) throws IOException {
Files.walkFileTree(tempDir, visitor);
assertCounts(1, 0, 0, visitor);
}
+ @BeforeEach
+ public void beforeEach() throws IOException {
+ tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ }
+
/**
* Tests an empty folder.
*/
diff --git a/src/test/java/org/apache/commons/io/file/CopyDirectoryVisitorTest.java b/src/test/java/org/apache/commons/io/file/CopyDirectoryVisitorTest.java
index 9ae599b..9ecc900 100644
--- a/src/test/java/org/apache/commons/io/file/CopyDirectoryVisitorTest.java
+++ b/src/test/java/org/apache/commons/io/file/CopyDirectoryVisitorTest.java
@@ -28,7 +28,6 @@
import org.apache.commons.io.file.Counters.PathCounters;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@@ -37,18 +36,30 @@
*/
public class CopyDirectoryVisitorTest extends TestArguments {
- @TempDir
private Path targetDir;
+ @AfterEach
+ public void afterEach() throws IOException {
+ PathUtils.deleteDirectory(targetDir);
+ }
+
+ @BeforeEach
+ public void beforeEach() throws IOException {
+ targetDir = Files.createTempDirectory(getClass().getCanonicalName() + "-target");
+ }
+
/**
* Tests an empty folder.
*/
@ParameterizedTest
@MethodSource("pathCounters")
public void testCopyDirectoryEmptyFolder(final PathCounters pathCounters) throws IOException {
- try (final TempDirectory sourceDir = TempDirectory.create(getClass().getSimpleName())) {
- assertCounts(1, 0, 0, PathUtils
- .visitFileTree(new CopyDirectoryVisitor(pathCounters, sourceDir, targetDir, StandardCopyOption.REPLACE_EXISTING), sourceDir.unwrap()));
+ final Path sourceDir = Files.createTempDirectory(getClass().getSimpleName());
+ try {
+ assertCounts(1, 0, 0,
+ PathUtils.visitFileTree(new CopyDirectoryVisitor(pathCounters, sourceDir, targetDir, StandardCopyOption.REPLACE_EXISTING), sourceDir));
+ } finally {
+ Files.deleteIfExists(sourceDir);
}
}
diff --git a/src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java b/src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java
index e015fe9..4aa719e 100644
--- a/src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java
+++ b/src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java
@@ -20,6 +20,8 @@
import static org.apache.commons.io.file.CounterAssertions.assertCounts;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
@@ -42,8 +44,11 @@ private void checkZeroCounts(final CountingPathVisitor visitor) {
@MethodSource("countingPathVisitors")
public void testCountEmptyFolder(final CountingPathVisitor visitor) throws IOException {
checkZeroCounts(visitor);
- try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
- assertCounts(1, 0, 0, PathUtils.visitFileTree(visitor, tempDir.unwrap()));
+ final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ try {
+ assertCounts(1, 0, 0, PathUtils.visitFileTree(visitor, tempDir));
+ } finally {
+ Files.deleteIfExists(tempDir);
}
}
diff --git a/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java b/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java
index 800c272..c821165 100644
--- a/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java
+++ b/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java
@@ -25,8 +25,9 @@
import java.nio.file.Paths;
import org.apache.commons.io.file.Counters.PathCounters;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@@ -35,14 +36,26 @@
*/
public class DeletingPathVisitorTest extends TestArguments {
- @TempDir
private Path tempDir;
+ @AfterEach
+ public void afterEach() throws IOException {
+ // backstop
+ if (Files.exists(tempDir) && PathUtils.isEmptyDirectory(tempDir)) {
+ Files.deleteIfExists(tempDir);
+ }
+ }
+
private void applyDeleteEmptyDirectory(final DeletingPathVisitor visitor) throws IOException {
Files.walkFileTree(tempDir, visitor);
assertCounts(1, 0, 0, visitor);
}
+ @BeforeEach
+ public void beforeEach() throws IOException {
+ tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ }
+
/**
* Tests an empty folder.
*/
diff --git a/src/test/java/org/apache/commons/io/file/PathUtilsCountingTest.java b/src/test/java/org/apache/commons/io/file/PathUtilsCountingTest.java
index cdd35fd..c0829c5 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsCountingTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsCountingTest.java
@@ -20,6 +20,8 @@
import static org.apache.commons.io.file.CounterAssertions.assertCounts;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.io.file.Counters.PathCounters;
@@ -35,9 +37,12 @@ public class PathUtilsCountingTest {
*/
@Test
public void testCountEmptyFolder() throws IOException {
- try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
- final PathCounters pathCounts = PathUtils.countDirectory(tempDir.unwrap());
+ final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ try {
+ final PathCounters pathCounts = PathUtils.countDirectory(tempDir);
assertCounts(1, 0, 0, pathCounts);
+ } finally {
+ Files.deleteIfExists(tempDir);
}
}
diff --git a/src/test/java/org/apache/commons/io/file/PathUtilsIsEmptyTest.java b/src/test/java/org/apache/commons/io/file/PathUtilsIsEmptyTest.java
index 2cf9112..3cb31cd 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsIsEmptyTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsIsEmptyTest.java
@@ -18,6 +18,7 @@
package org.apache.commons.io.file;
import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -41,16 +42,22 @@ public class PathUtilsIsEmptyTest {
public void testIsEmpty() throws IOException {
Assertions.assertTrue(PathUtils.isEmpty(FILE_SIZE_0));
Assertions.assertFalse(PathUtils.isEmpty(FILE_SIZE_1));
- try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
- Assertions.assertTrue(PathUtils.isEmpty(tempDir.unwrap()));
+ final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ try {
+ Assertions.assertTrue(PathUtils.isEmpty(tempDir));
+ } finally {
+ Files.delete(tempDir);
}
Assertions.assertFalse(PathUtils.isEmpty(DIR_SIZE_1));
}
@Test
public void testIsEmptyDirectory() throws IOException {
- try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
- Assertions.assertTrue(PathUtils.isEmptyDirectory(tempDir.unwrap()));
+ final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ try {
+ Assertions.assertTrue(PathUtils.isEmptyDirectory(tempDir));
+ } finally {
+ Files.delete(tempDir);
}
Assertions.assertFalse(PathUtils.isEmptyDirectory(DIR_SIZE_1));
}
diff --git a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
index f7ea8c3..5cd0c78 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
@@ -220,7 +220,6 @@ public void testGetTempDirectory() {
assertEquals(tempDirectory, PathUtils.getTempDirectory());
}
- @SuppressWarnings("resource")
@Test
public void testIsDirectory() throws IOException {
assertFalse(PathUtils.isDirectory(null));
@@ -229,12 +228,10 @@ public void testIsDirectory() throws IOException {
final Path testFile1 = Files.createTempFile(tempDirPath, "prefix", null);
assertFalse(PathUtils.isDirectory(testFile1));
- Path ref = null;
- try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
- ref = tempDir.unwrap();
- assertTrue(PathUtils.isDirectory(tempDir.unwrap()));
- }
- assertFalse(PathUtils.isDirectory(ref));
+ final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
+ assertTrue(PathUtils.isDirectory(tempDir));
+ Files.delete(tempDir);
+ assertFalse(PathUtils.isDirectory(tempDir));
}
@Test
diff --git a/src/test/java/org/apache/commons/io/file/TempDirectoryTest.java b/src/test/java/org/apache/commons/io/file/TempDirectoryTest.java
deleted file mode 100644
index de4406e..0000000
--- a/src/test/java/org/apache/commons/io/file/TempDirectoryTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.io.file;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.jupiter.api.Test;
-
-public class TempDirectoryTest {
-
- @SuppressWarnings("resource")
- @Test
- public void testCreatePath() throws IOException {
- final TempDirectory ref;
- try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
- ref = tempDir;
- assertTrue(FileUtils.isEmptyDirectory(tempDir.toFile()));
- }
- assertFalse(Files.exists(ref.unwrap()));
- // Fails with a ProviderMismatchException
- // assertFalse(Files.exists(ref));
- //
- // Not quite right since we cannot pretend to be a package private interface instead of a class.
-// final Path proxy = (Path) Proxy.newProxyInstance(TempDirectory.class.getClassLoader(), new Class[] {Path.class}, new InvocationHandler() {
-// @Override
-// public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
-// return method.invoke(ref.unwrap(), args);
-// }
-// });
-
- }
-
- @SuppressWarnings("resource")
- @Test
- public void testCreateString() throws IOException {
- final TempDirectory ref;
- try (final TempDirectory tempDir = TempDirectory.create(Paths.get("target"), getClass().getCanonicalName())) {
- ref = tempDir;
- assertTrue(FileUtils.isEmptyDirectory(tempDir.toFile()));
- }
- assertFalse(Files.exists(ref.unwrap()));
- // Fails with a ProviderMismatchException
- // assertFalse(Files.exists(ref));
- }
-
-}