Fix transcript in transfer window.
[cyberduck.git] / test / ch / cyberduck / core / PathCacheTest.java
blob26d9807f42775642ba8031438669ea85f797b1fd
1 package ch.cyberduck.core;
3 import org.junit.Test;
5 import java.util.Arrays;
6 import java.util.EnumSet;
8 import static org.junit.Assert.*;
10 /**
11 * @version $Id$
13 public class PathCacheTest extends AbstractTestCase {
15 @Test
16 public void testLookup() throws Exception {
17 final PathCache cache = new PathCache(1);
18 assertNull(cache.lookup(new DefaultPathReference(new Path("/", EnumSet.of(Path.Type.directory)))));
19 final AttributedList<Path> list = new AttributedList<Path>();
20 final Path file = new Path("name", EnumSet.of(Path.Type.file));
21 list.add(file);
22 cache.put(new Path("p", EnumSet.of(Path.Type.directory)), list);
23 assertNotNull(cache.lookup(new DefaultPathReference(file)));
26 @Test
27 public void testIsEmpty() throws Exception {
28 final PathCache cache = new PathCache(1);
29 assertTrue(cache.isEmpty());
30 cache.put(new Path("/", EnumSet.of(Path.Type.directory)), new AttributedList<Path>());
31 assertFalse(cache.isEmpty());
34 @Test
35 public void testContainsKey() throws Exception {
36 final PathCache cache = new PathCache(1);
37 final Path f = new Path("/", EnumSet.of(Path.Type.directory));
38 assertFalse(cache.containsKey(f));
39 cache.put(f, new AttributedList<Path>());
40 final CacheReference reference = new DefaultPathReference(new Path("/", EnumSet.of(Path.Type.directory)));
41 assertTrue(cache.containsKey(f));
42 assertTrue(cache.isCached(f));
45 @Test
46 public void testInvalidate() throws Exception {
47 final PathCache cache = new PathCache(1);
48 final AttributedList<Path> list = new AttributedList<Path>();
49 final Path f = new Path("/t", EnumSet.of(Path.Type.directory));
50 cache.put(f, list);
51 assertFalse(cache.get(f).attributes().isInvalid());
52 cache.invalidate(f);
53 assertTrue(cache.get(f).attributes().isInvalid());
54 assertTrue(cache.containsKey(f));
55 assertTrue(cache.isCached(f));
56 assertFalse(cache.isValid(f));
59 @Test
60 public void testGet() throws Exception {
61 final PathCache cache = new PathCache(1);
62 final Path file = new Path("name", EnumSet.of(Path.Type.file));
63 assertEquals(AttributedList.<Path>emptyList(), cache.get(file));
66 @Test
67 public void testDisabledCache() throws Exception {
68 Cache<Path> cache = PathCache.empty();
69 final Path file = new Path("name", EnumSet.of(Path.Type.file));
70 cache.put(file, AttributedList.<Path>emptyList());
71 assertFalse(cache.containsKey(file));
72 assertEquals(0, cache.keySet().size());
75 @Test
76 public void testCacheIsHidden() throws Exception {
77 final PathCache cache = new PathCache(1);
78 final Path parent = new Path("/", EnumSet.of(Path.Type.directory));
79 final AttributedList<Path> list = new AttributedList<Path>(
80 Arrays.asList(new Path(parent, "a", EnumSet.of(Path.Type.file)), new Path(parent, "b", EnumSet.of(Path.Type.file))));
81 list.filter(new Filter<Path>() {
82 @Override
83 public boolean accept(final Path file) {
84 return file.equals(new Path(parent, "a", EnumSet.of(Path.Type.file)));
86 });
87 cache.put(parent, list);
88 assertFalse(cache.isHidden(new Path(parent, "a", EnumSet.of(Path.Type.file))));
89 assertTrue(cache.isHidden(new Path(parent, "b", EnumSet.of(Path.Type.file))));