1
package net.sf.ehcache.store;
3
import org.junit.Before;
6
import java.util.Collection;
7
import java.util.HashSet;
10
import static org.hamcrest.CoreMatchers.is;
11
import static org.junit.Assert.assertThat;
12
import static org.junit.Assert.fail;
17
public class CacheKeySetTest {
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;
26
keySet = new CacheKeySet<Integer>( keySets );
30
public void testIteratesOverAllElementsOnce() {
31
Set<Integer> keys = new HashSet<Integer>();
32
for (Collection<Integer> set : keySets) {
35
assertThat(keys.size(), is(6));
36
for (Integer integer : keySet) {
39
assertThat(keys.isEmpty(), is(true));
43
public void testSizeSumsAllCollections() {
44
assertThat(keySet.size(), is(9));
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));
61
public void testContainsIsSupported() {
62
Set<Integer> keys = new HashSet<Integer>(keySet);
63
for (Integer key : keys) {
64
assertThat(keySet.contains(key), is(true));
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!");