1 package org.apache.commons.jcs3.auxiliary.disk;
2
3 import org.apache.commons.jcs3.engine.CacheElement;
4 import org.apache.commons.jcs3.engine.ElementAttributes;
5 import org.apache.commons.jcs3.engine.behavior.ICacheElement;
6 import org.apache.commons.jcs3.engine.behavior.IElementAttributes;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import junit.framework.TestCase;
28
29
30 public class PurgatoryElementUnitTest
31 extends TestCase
32 {
33
34 public void testSpoolable_normal()
35 {
36
37 final String cacheName = "myCacheName";
38 final String key = "myKey";
39 final String value = "myValue";
40 final IElementAttributes elementAttributes = new ElementAttributes();
41 final ICacheElement<String, String> cacheElement = new CacheElement<>( cacheName, key, value, elementAttributes );
42 final PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<>( cacheElement );
43 purgatoryElement.setSpoolable( false );
44
45
46 final boolean result = purgatoryElement.isSpoolable();
47
48
49 assertFalse( "Should not be spoolable.", result );
50 }
51
52
53 public void testElementAttributes_normal()
54 {
55
56 final String cacheName = "myCacheName";
57 final String key = "myKey";
58 final String value = "myValue";
59 final IElementAttributes elementAttributes = new ElementAttributes();
60
61 final ICacheElement<String, String> cacheElement = new CacheElement<>( cacheName, key, value );
62 final PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<>( cacheElement );
63 purgatoryElement.setElementAttributes( elementAttributes );
64
65
66 final IElementAttributes result = cacheElement.getElementAttributes();
67
68
69 assertEquals( "Should have set the attributes on the element", elementAttributes, result );
70 }
71
72
73 public void testToString_normal()
74 {
75
76 final String cacheName = "myCacheName";
77 final String key = "myKey";
78 final String value = "myValue";
79 final IElementAttributes elementAttributes = new ElementAttributes();
80 final ICacheElement<String, String> cacheElement = new CacheElement<>( cacheName, key, value, elementAttributes );
81 final PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<>( cacheElement );
82
83
84 final String result = purgatoryElement.toString();
85
86
87 assertTrue( "Should have the cacheName.", result.indexOf( cacheName ) != -1 );
88 assertTrue( "Should have the key.", result.indexOf( key ) != -1 );
89 assertTrue( "Should have the value.", result.indexOf( value ) != -1 );
90 }
91 }