hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/SearchPathTest.java
changeset 43464 f38fde4a6b52
child 44081 5dbc6c93f9bf
equal deleted inserted replaced
43462:cde11973a86a 43464:f38fde4a6b52
       
     1 /*
       
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 package jdk.tools.jaotc.test.collect;
       
    24 
       
    25 import org.junit.Before;
       
    26 import org.junit.Test;
       
    27 
       
    28 import java.nio.file.FileSystem;
       
    29 import java.nio.file.FileSystems;
       
    30 import java.nio.file.Path;
       
    31 import java.nio.file.Paths;
       
    32 
       
    33 import static jdk.tools.jaotc.test.collect.Utils.set;
       
    34 import static org.junit.Assert.*;
       
    35 
       
    36 public class SearchPathTest {
       
    37     private FakeFileSupport fileSupport;
       
    38     private FileSystem fs;
       
    39 
       
    40     @Before
       
    41     public void setUp() throws Exception {
       
    42         fs = FileSystems.getDefault();
       
    43     }
       
    44 
       
    45     @Test
       
    46     public void itShouldUsePathIfPathIsAbsoluteAndExisting() {
       
    47         fileSupport = new FakeFileSupport(set("/foo"), set());
       
    48         SearchPath target = new SearchPath(fileSupport);
       
    49         Path foo = Paths.get("/foo");
       
    50         Path result = target.find(fs, foo);
       
    51         assertSame(result, foo);
       
    52     }
       
    53 
       
    54     @Test
       
    55     public void itShouldReturnNullIfPathIsAbsoluteAndNonExisting() {
       
    56         fileSupport = new FakeFileSupport(set(), set());
       
    57         SearchPath target = new SearchPath(fileSupport);
       
    58         Path result = target.find(fs, Paths.get("/bar"));
       
    59         assertNull(result);
       
    60     }
       
    61 
       
    62     @Test
       
    63     public void itShouldUseRelativeExisting() {
       
    64         fileSupport = new FakeFileSupport(set("hello", "tmp/hello", "search/hello"), set());
       
    65         SearchPath target = new SearchPath(fileSupport);
       
    66         target.add("search");
       
    67         Path hello = Paths.get("hello");
       
    68         Path result = target.find(fs, hello, "tmp");
       
    69         assertSame(result, hello);
       
    70     }
       
    71 
       
    72     @Test
       
    73     public void itShouldSearchDefaultsBeforeSearchPaths() {
       
    74         fileSupport = new FakeFileSupport(set("bar/foobar"), set());
       
    75         SearchPath target = new SearchPath(fileSupport);
       
    76         Path result = target.find(fs, Paths.get("foobar"), "default1", "bar");
       
    77         assertEquals("bar/foobar", result.toString());
       
    78         assertEquals(set("foobar", "default1/foobar", "bar/foobar"), fileSupport.getCheckedExists());
       
    79     }
       
    80 
       
    81     @Test
       
    82     public void itShouldUseSearchPathsIfNotInDefaults() {
       
    83         fileSupport = new FakeFileSupport(set("bar/tmp/foobar"), set());
       
    84         SearchPath target = new SearchPath(fileSupport);
       
    85         target.add("foo/tmp", "bar/tmp");
       
    86 
       
    87         Path result = target.find(fs, Paths.get("foobar"), "foo", "bar");
       
    88         assertEquals("bar/tmp/foobar", result.toString());
       
    89         assertEquals(set("foobar", "foo/foobar", "bar/foobar", "bar/tmp/foobar", "foo/tmp/foobar"), fileSupport.getCheckedExists());
       
    90     }
       
    91 
       
    92     @Test
       
    93     public void itShouldReturnNullIfNoExistingPathIsFound() {
       
    94         fileSupport = new FakeFileSupport(set(), set());
       
    95         SearchPath target = new SearchPath(fileSupport);
       
    96         target.add("dir1", "dir2");
       
    97 
       
    98         Path result = target.find(fs, Paths.get("entry"), "dir3", "dir4");
       
    99         assertNull(result);
       
   100         assertEquals(set("entry", "dir1/entry", "dir2/entry", "dir3/entry", "dir4/entry"), fileSupport.getCheckedExists());
       
   101     }
       
   102 }