1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.util;
20
21 import junit.framework.Assert;
22 import junit.framework.TestCase;
23
24 /***
25 * Tests {@link Queue}
26 *
27 * @author The Apache Directory Project (dev@directory.apache.org)
28 * @author Trustin Lee (trustin@apache.org)
29 * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $
30 */
31 public class QueueTest extends TestCase
32 {
33 private int pushCount;
34 private int popCount;
35
36 public void setUp()
37 {
38 pushCount = 0;
39 popCount = 0;
40 }
41
42 public void testRotation()
43 {
44 Queue q = new Queue();
45 testRotation0( q );
46 }
47
48 public void testExpandingRotation()
49 {
50 Queue q = new Queue();
51 for( int i = 0; i < 10; i ++ )
52 {
53 testRotation0( q );
54
55
56 int oldCapacity = q.capacity();
57 for( int j = q.capacity(); j >= 0; j-- )
58 {
59 q.push( new Integer( ++pushCount ) );
60 }
61
62 Assert.assertTrue( q.capacity() > oldCapacity );
63 testRotation0( q );
64 }
65 }
66
67 private void testRotation0( Queue q )
68 {
69 for( int i = 0; i < q.capacity() * 7 / 4; i ++ )
70 {
71 q.push( new Integer( ++pushCount ) );
72 Assert.assertEquals( ++popCount, ( ( Integer ) q.pop() ).intValue() );
73 }
74 }
75
76 public static void main( String[] args )
77 {
78 junit.textui.TestRunner.run( QueueTest.class );
79 }
80 }