Home | History | Annotate | Download | only in file
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package libcore.java.nio.file;
     18 
     19 
     20 import org.junit.Test;
     21 
     22 import java.net.URI;
     23 import java.net.URISyntaxException;
     24 import java.nio.file.Paths;
     25 import java.util.List;
     26 
     27 import static libcore.java.nio.file.LinuxFileSystemTestData.*;
     28 import static libcore.java.nio.file.LinuxFileSystemTestData.getPathInputOutputTestData;
     29 import static org.junit.Assert.assertEquals;
     30 import static org.junit.Assert.fail;
     31 
     32 
     33 public class PathsTest {
     34 
     35     @Test
     36     public void test_get_String() {
     37         List<TestData> inputOutputTestCases = getPathInputOutputTestData();
     38         for (TestData inputOutputTestCase : inputOutputTestCases) {
     39             assertEquals(inputOutputTestCase.output, Paths.get(inputOutputTestCase.input,
     40                     inputOutputTestCase.inputArray).toString());
     41         }
     42 
     43         List<TestData> exceptionTestCases = getPathExceptionTestData();
     44         for (TestData exceptionTestCase : exceptionTestCases) {
     45             try {
     46                 Paths.get(exceptionTestCase.input, exceptionTestCase.inputArray);
     47                 fail();
     48             } catch (Exception expected) {
     49                 assertEquals(exceptionTestCase.exceptionClass, expected.getClass());
     50             }
     51         }
     52     }
     53 
     54     @Test
     55     public void test_get_URI() throws URISyntaxException {
     56         List<TestData> inputOutputTestCases = getPath_URI_InputOutputTestData();
     57         for (TestData inputOutputTestCase : inputOutputTestCases) {
     58             assertEquals(inputOutputTestCase.output, Paths.get(new URI(inputOutputTestCase.input)).
     59                     toString());
     60         }
     61 
     62         List<TestData> exceptionTestCases = getPath_URI_ExceptionTestData();
     63         for (TestData exceptionTestCase : exceptionTestCases) {
     64             try {
     65                 System.out.println(exceptionTestCase.input);
     66                 Paths.get(new URI(exceptionTestCase.input));
     67                 fail();
     68             } catch (Exception expected) {
     69                 assertEquals(exceptionTestCase.exceptionClass, expected.getClass());
     70             }
     71         }
     72     }
     73 }