1 package org.apache.commons.jcs.auxiliary.lateral;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23 import org.apache.commons.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
24
25
26
27
28 public class LateralCacheNoWaitFacadeUnitTest
29 extends TestCase
30 {
31
32
33
34 public void testAddThenRemoveNoWait_InList()
35 {
36
37 @SuppressWarnings("unchecked")
38 LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
39 ILateralCacheAttributes cattr = new LateralCacheAttributes();
40 cattr.setCacheName( "testCache1" );
41
42 LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
43
44 LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
45 LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
46
47
48 facade.addNoWait( noWait );
49
50
51 assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
52
53
54 facade.removeNoWait( noWait );
55
56
57 assertEquals( "Should have 0", 0, facade.noWaits.length );
58 assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) );
59 }
60
61
62
63
64 public void testAddThenRemoveNoWait_InListSize2()
65 {
66
67 @SuppressWarnings("unchecked")
68 LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
69 ILateralCacheAttributes cattr = new LateralCacheAttributes();
70 cattr.setCacheName( "testCache1" );
71
72 LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
73
74 LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
75 LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
76 LateralCacheNoWait<String, String> noWait2 = new LateralCacheNoWait<String, String>( cache );
77
78
79 facade.addNoWait( noWait );
80 facade.addNoWait( noWait2 );
81
82
83 assertEquals( "Should have 2", 2, facade.noWaits.length );
84 assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
85 assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) );
86
87
88 facade.removeNoWait( noWait );
89
90
91 assertEquals( "Should only have 1", 1, facade.noWaits.length );
92 assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) );
93 assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) );
94 }
95
96
97
98
99 public void testAdd_InList()
100 {
101
102 @SuppressWarnings("unchecked")
103 LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
104 ILateralCacheAttributes cattr = new LateralCacheAttributes();
105 cattr.setCacheName( "testCache1" );
106
107 LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
108
109 LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
110 LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
111
112
113 facade.addNoWait( noWait );
114 facade.addNoWait( noWait );
115
116
117 assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
118 assertEquals( "Should only have 1", 1, facade.noWaits.length );
119 }
120
121
122
123
124 public void testAddThenRemoveNoWait_NotInList()
125 {
126
127 @SuppressWarnings("unchecked")
128 LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
129 ILateralCacheAttributes cattr = new LateralCacheAttributes();
130 cattr.setCacheName( "testCache1" );
131
132 LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
133
134 LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
135 LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
136
137
138 facade.removeNoWait( noWait );
139
140
141 assertFalse( "Should not be in the list.", facade.containsNoWait( noWait ) );
142 }
143 }