aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/java/jopt-simple/src/test/java/joptsimple/util/PathPropertiesTest.java
blob: 1c6bf59718662e0fcdc0c7b405fb62198351c849 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package joptsimple.util;

import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.Test;

import static org.junit.Assert.*;

import static joptsimple.util.PathProperties.*;

public class PathPropertiesTest {
    @Test
    public void readableFile() throws Exception {
        Path path = Files.createTempFile("prefix", null);

        path.toFile().deleteOnExit();

        assertTrue( READABLE.accept( path ) );
        assertFalse( DIRECTORY_EXISTING.accept( path ) );
        assertTrue( FILE_EXISTING.accept( path ) );
        assertTrue( FILE_OVERWRITABLE.accept( path ) );
        assertTrue( WRITABLE.accept( path ) );
        assertFalse( NOT_EXISTING.accept( path ) );
    }

    @Test
    public void nonExisting() throws Exception {
        Path path = Files.createTempFile( "prefix", null );

        Files.deleteIfExists( path );

        assertFalse( READABLE.accept( path ) );
        assertFalse( DIRECTORY_EXISTING.accept( path ) );
        assertFalse( FILE_EXISTING.accept( path ) );
        assertFalse( FILE_OVERWRITABLE.accept( path ) );
        assertTrue( NOT_EXISTING.accept( path ) );
        assertFalse( WRITABLE.accept( path ) );
    }

    @Test
    public void directory() throws Exception {
        Path path = Files.createTempDirectory( "prefix" );

        path.toFile().deleteOnExit();

        assertTrue( READABLE.accept( path ) );
        assertTrue( DIRECTORY_EXISTING.accept( path ) );
        assertFalse( FILE_EXISTING.accept( path ) );
        assertFalse( FILE_OVERWRITABLE.accept( path ) );
        assertFalse( NOT_EXISTING.accept( path ) );
        assertTrue( WRITABLE.accept( path ) );
    }
}