KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sablecc > sablecc > util > WorkSetTest


1 /* This file is part of SableCC ( http://sablecc.org ).
2  *
3  * Copyright 2007 Raymond Audet <raymond.audet@gmail.com>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.sablecc.sablecc.util;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.sablecc.sablecc.exception.InternalException;
28
29 public class WorkSetTest {
30
31     private WorkSet<Integer JavaDoc> workSet;
32
33     @Before
34     public void setUp()
35             throws Exception JavaDoc {
36
37         this.workSet = new WorkSet<Integer JavaDoc>();
38     }
39
40     @Test
41     public void testHasNext() {
42
43         // Case with empty workSet.
44
assertFalse("the WorkSet is empty.", this.workSet.hasNext());
45
46         // Case with at least one element.
47
this.workSet.add(5);
48         this.workSet.add(10);
49         assertTrue("the WorkSet contains one element.", this.workSet.hasNext());
50     }
51
52     @Test
53     public void testNext() {
54
55         // Adding elements
56
this.workSet.add(100);
57         this.workSet.add(25);
58         this.workSet.add(50);
59
60         assertEquals("the first element should be 100", 100, this.workSet
61                 .next());
62         assertEquals("the first element should be 25", 25, this.workSet.next());
63         assertEquals("the first element should be 50", 50, this.workSet.next());
64
65         assertFalse("the WorkSet is empty.", this.workSet.hasNext());
66
67         // Case adding the same elements
68
this.workSet.add(100);
69         this.workSet.add(25);
70         this.workSet.add(50);
71
72         assertFalse("the WorkSet should still be empty.", this.workSet
73                 .hasNext());
74     }
75
76     @Test
77     public void testAdd() {
78
79         // Case with null element.
80
try {
81             this.workSet.add(null);
82             fail("element may not be null");
83         }
84         catch (InternalException e) {
85             // Excepted
86
}
87
88     }
89 }
90
Popular Tags