KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > util > IntQueueTest


1 package com.thoughtworks.xstream.core.util;
2
3 import junit.framework.TestCase;
4
5 public class IntQueueTest extends TestCase {
6
7     public void testReadsInSameOrderItemsWereWritten() {
8         IntQueue q = new IntQueue(4);
9
10         assertTrue(q.isEmpty());
11
12         q.write(10);
13         q.write(20);
14         q.write(30);
15
16         assertFalse(q.isEmpty());
17         assertEquals(10, q.read());
18         assertEquals(20, q.read());
19         assertFalse(q.isEmpty());
20
21         q.write(40);
22         q.write(50);
23         q.write(60);
24
25         assertFalse(q.isEmpty());
26         assertEquals(30, q.read());
27         assertEquals(40, q.read());
28         assertEquals(50, q.read());
29         assertFalse(q.isEmpty());
30         assertEquals(60, q.read());
31         assertTrue(q.isEmpty());
32     }
33
34     public void testThrowsExceptionIfSizeExceeded() {
35         IntQueue q = new IntQueue(4);
36         q.write(1);
37         q.write(2);
38         q.write(3);
39         q.write(4);
40         try {
41             q.write(5);
42             fail("Expected exeption");
43         } catch (IntQueue.OverflowException expectedException) {
44             // good
45
}
46     }
47
48     public void testThrowsExceptionWhenReadingNothing() {
49         IntQueue q = new IntQueue(4);
50
51         try {
52             q.read();
53             fail("Expected exeption");
54         } catch (IntQueue.NothingToReadException expectedException) {
55             // good
56
}
57
58         q.write(1);
59         q.write(2);
60
61         q.read();
62         q.read();
63
64         try {
65             q.read();
66             fail("Expected exeption");
67         } catch (IntQueue.NothingToReadException expectedException) {
68             // good
69
}
70
71     }
72 }
73
Popular Tags