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  package org.apache.commons.configuration2.io;
18  
19  import static org.junit.jupiter.api.Assertions.assertSame;
20  import static org.mockito.Mockito.mock;
21  import static org.mockito.Mockito.verify;
22  import static org.mockito.Mockito.verifyNoMoreInteractions;
23  import static org.mockito.Mockito.when;
24  
25  import java.net.URL;
26  
27  import org.apache.commons.configuration2.ConfigurationAssert;
28  import org.junit.jupiter.api.BeforeEach;
29  import org.junit.jupiter.api.Test;
30  
31  /**
32   * Test class for {@code FileSystemLocationStrategy}.
33   */
34  public class TestFileSystemLocationStrategy {
35      /** The strategy to be tested. */
36      private FileSystemLocationStrategy strategy;
37  
38      @BeforeEach
39      public void setUp() throws Exception {
40          strategy = new FileSystemLocationStrategy();
41      }
42  
43      /**
44       * Tests a locate() operation.
45       */
46      @Test
47      public void testLocate() {
48          final FileSystem fs = mock(FileSystem.class);
49          final URL url = ConfigurationAssert.getTestURL("test.xml");
50          final String basePath = "testBasePath";
51          final String fileName = "testFileName.txt";
52  
53          when(fs.locateFromURL(basePath, fileName)).thenReturn(url);
54  
55          final FileLocator locator = FileLocatorUtils.fileLocator().basePath(basePath).fileName(fileName).fileSystem(FileLocatorUtils.DEFAULT_FILE_SYSTEM)
56              .sourceURL(ConfigurationAssert.getTestURL("test.properties")).create();
57  
58          assertSame(url, strategy.locate(fs, locator));
59  
60          verify(fs).locateFromURL(basePath, fileName);
61          verifyNoMoreInteractions(fs);
62      }
63  }