View Javadoc
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.spi;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  import static org.junit.jupiter.api.Assertions.assertNotNull;
22  
23  import java.net.MalformedURLException;
24  import java.net.URI;
25  import java.net.URISyntaxException;
26  import java.net.URL;
27  import java.nio.file.Paths;
28  import java.nio.file.spi.FileSystemProvider;
29  
30  import org.junit.jupiter.api.Test;
31  
32  public class FileSystemProvidersTest {
33  
34      private static final String FILE_PATH = "file:///foo.txt";
35  
36      @Test
37      public void testGetFileSystemProvider_all() throws URISyntaxException {
38          for (final FileSystemProvider fileSystemProvider : FileSystemProvider.installedProviders()) {
39              final String scheme = fileSystemProvider.getScheme();
40              final URI uri = new URI(scheme, "ssp", "fragment");
41              assertEquals(scheme, FileSystemProviders.installed().getFileSystemProvider(uri).getScheme());
42          }
43      }
44  
45      @Test
46      public void testGetFileSystemProvider_filePath() {
47          assertNotNull(FileSystemProviders.getFileSystemProvider(Paths.get(URI.create(FILE_PATH))));
48      }
49  
50      @Test
51      public void testGetFileSystemProvider_fileScheme() {
52          assertNotNull(FileSystemProviders.installed().getFileSystemProvider("file"));
53      }
54  
55      @Test
56      public void testGetFileSystemProvider_fileURI() {
57          assertNotNull(FileSystemProviders.installed().getFileSystemProvider(URI.create(FILE_PATH)));
58      }
59  
60      @Test
61      public void testGetFileSystemProvider_fileURL() throws MalformedURLException {
62          assertNotNull(FileSystemProviders.installed().getFileSystemProvider(new URL(FILE_PATH)));
63      }
64  
65  }