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.vfs2.cache;
18  
19  import org.apache.commons.vfs2.FileName;
20  import org.apache.commons.vfs2.FileObject;
21  import org.apache.commons.vfs2.FileSystem;
22  import org.apache.commons.vfs2.FilesCache;
23  import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
24  import org.junit.Test;
25  import org.junit.jupiter.api.Assertions;
26  
27  /**
28   * Tests for {@link NullFilesCache} used by {@link NullFilesCacheTestCase}.
29   */
30  public class NullFilesCacheTests extends AbstractFilesCacheTestsBase {
31  
32      @Override
33      @Test
34      public void testBasicCacheOps() throws Exception {
35          final DefaultFileSystemManager manager = getManager();
36          Assertions.assertNotNull(manager, "This test should not have a null DefaultFileSystemManager");
37          // the basic test looks different for a null cache:
38          final FilesCache cache = manager.getFilesCache();
39          final FileObject fo = getWriteFolder().resolveFile("dir1");
40          final FileName fn = fo.getName();
41          final FileSystem fs = fo.getFileSystem();
42  
43          cache.clear(fs);
44          assertNull(cache.getFile(fs, fn));
45  
46          cache.putFile(fo);
47          assertNull(null, cache.getFile(fs, fn));
48  
49          assertFalse(cache.putFileIfAbsent(fo)); // hmmm?
50          assertNull(null, cache.getFile(fs, fn));
51  
52          cache.removeFile(fs, fn);
53          assertNull(cache.getFile(fs, fn));
54      }
55  
56      @Test
57      public void testClass() {
58          final DefaultFileSystemManager manager = getManager();
59          Assertions.assertNotNull(manager, "This test should not have a null DefaultFileSystemManager");
60          assertTrue(manager.getFilesCache() instanceof NullFilesCache);
61      }
62  
63      @Test
64      public void testFilesCache() throws Exception {
65          final FileObject scratchFolder = getWriteFolder();
66          Assertions.assertNotNull(scratchFolder, "This test should not have a null FileObject scratch folder");
67  
68          final FileObject dir1 = scratchFolder.resolveFile("dir1");
69          final FileObject dir1_2 = scratchFolder.resolveFile("dir1");
70  
71          assertNotSame("Should always be new instance with NullCache", dir1, dir1_2);
72      }
73  
74  }