1 package ch
.cyberduck
.core
;
5 import java
.util
.Arrays
;
6 import java
.util
.EnumSet
;
8 import static org
.junit
.Assert
.*;
13 public class PathCacheTest
extends AbstractTestCase
{
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
));
22 cache
.put(new Path("p", EnumSet
.of(Path
.Type
.directory
)), list
);
23 assertNotNull(cache
.lookup(new DefaultPathReference(file
)));
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());
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
));
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
));
51 assertFalse(cache
.get(f
).attributes().isInvalid());
53 assertTrue(cache
.get(f
).attributes().isInvalid());
54 assertTrue(cache
.containsKey(f
));
55 assertTrue(cache
.isCached(f
));
56 assertFalse(cache
.isValid(f
));
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
));
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());
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
>() {
83 public boolean accept(final Path file
) {
84 return file
.equals(new Path(parent
, "a", EnumSet
.of(Path
.Type
.file
)));
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
))));