~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/test/java/net/sf/ehcache/store/CacheKeySetTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package net.sf.ehcache.store;
 
2
 
 
3
import org.junit.Before;
 
4
import org.junit.Test;
 
5
 
 
6
import java.util.Collection;
 
7
import java.util.HashSet;
 
8
import java.util.Set;
 
9
 
 
10
import static org.hamcrest.CoreMatchers.is;
 
11
import static org.junit.Assert.assertThat;
 
12
import static org.junit.Assert.fail;
 
13
 
 
14
/**
 
15
 * @author Alex Snaps
 
16
 */
 
17
public class CacheKeySetTest {
 
18
    
 
19
    Collection<Integer>[]  keySets = new Collection[] { new HashSet<Integer>() {{ add(1); add(2); add(3); }},
 
20
        new HashSet<Integer>() {{ add(1); add(4); add(5); }},
 
21
        new HashSet<Integer>() {{ add(1); add(4); add(6); }} };
 
22
    CacheKeySet<Integer> keySet;
 
23
    
 
24
    @Before
 
25
    public void setup() {
 
26
        keySet = new CacheKeySet<Integer>( keySets );
 
27
    }
 
28
    
 
29
    @Test
 
30
    public void testIteratesOverAllElementsOnce() {
 
31
        Set<Integer> keys = new HashSet<Integer>();
 
32
        for (Collection<Integer> set : keySets) {
 
33
            keys.addAll(set);
 
34
        }
 
35
        assertThat(keys.size(), is(6));
 
36
        for (Integer integer : keySet) {
 
37
            keys.remove(integer);
 
38
        }
 
39
        assertThat(keys.isEmpty(), is(true));
 
40
    }
 
41
    
 
42
    @Test
 
43
    public void testSizeSumsAllCollections() {
 
44
        assertThat(keySet.size(), is(9));
 
45
    }
 
46
    
 
47
    @Test
 
48
    public void testIsEmptyAccountsForAllKeySets() {
 
49
        assertThat(keySet.isEmpty(), is(false));
 
50
        assertThat(new CacheKeySet(new HashSet()).isEmpty(), is(true));
 
51
        assertThat(new CacheKeySet(new HashSet(), new HashSet()).isEmpty(), is(true));
 
52
        assertThat(new CacheKeySet(new HashSet(), new HashSet(), new HashSet()).isEmpty(), is(true));
 
53
        assertThat(new CacheKeySet(new HashSet(), new HashSet(), new HashSet() {{ add(1); }}).isEmpty(), is(false));
 
54
        assertThat(new CacheKeySet(new HashSet(), new HashSet() {{ add(1); }}, new HashSet() {{ add(1); }}).isEmpty(), is(false));
 
55
        assertThat(new CacheKeySet(new HashSet(), new HashSet() {{ add(1); }}, new HashSet()).isEmpty(), is(false));
 
56
        assertThat(new CacheKeySet(new HashSet() {{ add(1); }}, new HashSet() {{ add(1); }}, new HashSet()).isEmpty(), is(false));
 
57
        assertThat(new CacheKeySet(new HashSet() {{ add(1); }}, new HashSet(), new HashSet()).isEmpty(), is(false));
 
58
    }
 
59
    
 
60
    @Test
 
61
    public void testContainsIsSupported() {
 
62
        Set<Integer> keys = new HashSet<Integer>(keySet);
 
63
        for (Integer key : keys) {
 
64
            assertThat(keySet.contains(key), is(true));
 
65
        }
 
66
    }
 
67
    
 
68
    @Test
 
69
    public void testSupportsEmptyKeySets() {
 
70
        final CacheKeySet cacheKeySet = new CacheKeySet();
 
71
        assertThat(cacheKeySet.isEmpty(), is(true));
 
72
        for (Object o : cacheKeySet) {
 
73
            fail("Shouldn't get anything!");
 
74
        }
 
75
    }
 
76
}