1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.cache;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import java.util.HashSet;
21 import java.util.Set;
22
23 import org.apache.ibatis.cache.decorators.LoggingCache;
24 import org.apache.ibatis.cache.decorators.ScheduledCache;
25 import org.apache.ibatis.cache.decorators.SerializedCache;
26 import org.apache.ibatis.cache.decorators.SynchronizedCache;
27 import org.apache.ibatis.cache.impl.PerpetualCache;
28 import org.junit.jupiter.api.Test;
29
30 class BaseCacheTest {
31
32 @Test
33 void shouldDemonstrateEqualsAndHashCodeForVariousCacheTypes() {
34 PerpetualCache cache = new PerpetualCache("test_cache");
35 assertEquals(cache, cache);
36 assertEquals(cache, new SynchronizedCache(cache));
37 assertEquals(cache, new SerializedCache(cache));
38 assertEquals(cache, new LoggingCache(cache));
39 assertEquals(cache, new ScheduledCache(cache));
40
41 assertEquals(cache.hashCode(), new SynchronizedCache(cache).hashCode());
42 assertEquals(cache.hashCode(), new SerializedCache(cache).hashCode());
43 assertEquals(cache.hashCode(), new LoggingCache(cache).hashCode());
44 assertEquals(cache.hashCode(), new ScheduledCache(cache).hashCode());
45
46 Set<Cache> caches = new HashSet<>();
47 caches.add(cache);
48 caches.add(new SynchronizedCache(cache));
49 caches.add(new SerializedCache(cache));
50 caches.add(new LoggingCache(cache));
51 caches.add(new ScheduledCache(cache));
52 assertEquals(1, caches.size());
53 }
54
55 }