1 package org.apache.jcs.utils.struct;
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
24 /***
25 * Unit tests for the bounded queue.
26 * <p>
27 * @author Aaron Smuts
28 */
29 public class BoundedQueueUnitTest
30 extends TestCase
31 {
32 /***
33 * Verify null returned for empty.
34 */
35 public void testTakeLastEmpty()
36 {
37
38 int maxSize = 10;
39 BoundedQueue queue = new BoundedQueue( maxSize );
40
41
42 Object result = queue.take();
43
44
45 assertNull( "Result should be null", result );
46 }
47
48 /***
49 * Verify that the queue returns the number of elements and the it does not exceed the max.
50 */
51 public void testSize()
52 {
53
54 int maxSize = 10;
55 BoundedQueue queue = new BoundedQueue( maxSize );
56
57
58 for ( int i = 0; i < maxSize * 2; i++ )
59 {
60 queue.add( "adfadsf sad " + i );
61 }
62
63 int result = queue.size();
64
65
66 assertEquals( "Result size not as expected", maxSize, result );
67 }
68
69 /***
70 * Verify that the items come back in the order put in.
71 */
72 public void testFIFOOrderedTake()
73 {
74
75 int maxSize = 10;
76 BoundedQueue queue = new BoundedQueue( maxSize );
77
78
79 for ( int i = 0; i < maxSize; i++ )
80 {
81 queue.add( String.valueOf( i ) );
82 }
83
84
85
86
87 for ( int i = 0; i < maxSize; i++ )
88 {
89 String result = (String)queue.take();
90 assertEquals( "Result not as expected", String.valueOf( i ) , result );
91 }
92 }
93 }