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