xref: /aosp_15_r20/external/apache-commons-io/src/test/java/org/apache/commons/io/file/AbstractTempDirTest.java (revision 0c4d7b72e49a04598d65c566f44504b95342d75a)
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package org.apache.commons.io.file;
19 
20 import java.io.File;
21 import java.io.IOException;
22 import java.nio.file.FileSystems;
23 import java.nio.file.Files;
24 import java.nio.file.Path;
25 
26 import org.junit.jupiter.api.BeforeEach;
27 import org.junit.jupiter.api.io.TempDir;
28 
29 /**
30  * Provides services for test subclasses.
31  */
32 public abstract class AbstractTempDirTest {
33 
34     /**
35      * A temporary directory managed by JUnit.
36      */
37     @TempDir
38     public Path managedTempDirPath;
39 
40     /**
41      * A temporary directory managed by each test so we can optionally fiddle with its permissions independently.
42      */
43     public Path tempDirPath;
44 
45     /**
46      * A File version of this test's Path object.
47      */
48     public File tempDirFile;
49 
50     @BeforeEach
beforeEachCreateTempDirs()51     public void beforeEachCreateTempDirs() throws IOException {
52         tempDirPath = Files.createTempDirectory(managedTempDirPath, getClass().getSimpleName());
53         tempDirFile = tempDirPath.toFile();
54     }
55 
56 
isPosixFilePermissionsSupported()57     protected final boolean isPosixFilePermissionsSupported() {
58         return FileSystems.getDefault().supportedFileAttributeViews().contains("posix");
59     }
60 }
61