1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.cache.cachekey; |
35 |
|
|
36 |
|
import static org.hamcrest.Matchers.*; |
37 |
|
import static org.junit.Assert.*; |
38 |
|
|
39 |
|
import java.io.File; |
40 |
|
import java.io.FileInputStream; |
41 |
|
import java.io.FileOutputStream; |
42 |
|
import java.io.NotSerializableException; |
43 |
|
import java.io.ObjectInputStream; |
44 |
|
import java.io.ObjectOutputStream; |
45 |
|
import java.io.Serializable; |
46 |
|
import java.util.SortedMap; |
47 |
|
import java.util.TreeMap; |
48 |
|
|
49 |
|
import org.junit.Test; |
50 |
|
|
51 |
|
|
52 |
|
@link |
53 |
|
|
|
|
| 95.5% |
Uncovered Elements: 1 (22) |
Complexity: 3 |
Complexity Density: 0.15 |
|
54 |
|
public class DefaultCacheKeyTest { |
55 |
|
|
56 |
|
private SortedMap<String, Serializable> additionalAttributes = new TreeMap<String, Serializable>(); |
57 |
|
private DefaultCacheKey key = new DefaultCacheKey(null, null, null, null, null, null, null, additionalAttributes); |
58 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 2 |
Complexity Density: 0.12 |
1PASS
|
|
59 |
1 |
@Test... |
60 |
|
public void testSerializable() throws Exception { |
61 |
|
|
62 |
1 |
additionalAttributes.put("key", "value"); |
63 |
1 |
File file = File.createTempFile(this.getClass().getName(), "class"); |
64 |
1 |
FileOutputStream fileOutputStream = new FileOutputStream(file); |
65 |
1 |
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); |
66 |
1 |
FileInputStream fileInputStream = new FileInputStream(file); |
67 |
1 |
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); |
68 |
1 |
try { |
69 |
|
|
70 |
1 |
objectOutputStream.writeObject(key); |
71 |
1 |
DefaultCacheKey deserializedKey = (DefaultCacheKey) objectInputStream.readObject(); |
72 |
|
|
73 |
1 |
assertThat(key, instanceOf(Serializable.class)); |
74 |
1 |
assertThat((String)deserializedKey.getAdditionalAttributes().get("key"), equalTo("value")); |
75 |
|
} catch (NotSerializableException e) { |
76 |
0 |
fail(key.getClass() + " should be serializable, failed with: " + e); |
77 |
|
} |
78 |
|
|
79 |
1 |
objectInputStream.close(); |
80 |
1 |
objectOutputStream.close(); |
81 |
1 |
fileInputStream.close(); |
82 |
1 |
fileOutputStream.close(); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
public void equals() throws Exception { |
87 |
|
|
88 |
1 |
additionalAttributes.put("key", "value"); |
89 |
1 |
DefaultCacheKey differentKey = new DefaultCacheKey(null, null, null, null, null, null, null, null); |
90 |
|
|
91 |
|
|
92 |
1 |
assertThat(key.equals(key), equalTo(true)); |
93 |
1 |
assertThat(key.equals(differentKey), equalTo(false)); |
94 |
|
} |
95 |
|
|
96 |
|
} |