Source Code Cross Referenced for LinkedListTest.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Rule Engine » drolls Rule Engine » org.drools.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.util;
002:
003:        /*
004:         * Copyright 2005 JBoss Inc
005:         * 
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *      http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        import junit.framework.Assert;
020:        import junit.framework.TestCase;
021:
022:        public class LinkedListTest extends TestCase {
023:
024:            LinkedList list = null;
025:            LinkedListNode node1 = null;
026:            LinkedListNode node2 = null;
027:            LinkedListNode node3 = null;
028:
029:            protected void setUp() throws Exception {
030:                super .setUp();
031:                this .list = new LinkedList();
032:                this .node1 = new AbstractBaseLinkedListNode();
033:                this .node2 = new AbstractBaseLinkedListNode();
034:                this .node3 = new AbstractBaseLinkedListNode();
035:            }
036:
037:            protected void tearDown() throws Exception {
038:                super .tearDown();
039:            }
040:
041:            /*
042:             * Test method for 'org.drools.util.LinkedList.add(LinkedListNode)'
043:             */
044:            public void testAdd() {
045:                this .list.add(this .node1);
046:                Assert.assertNull("Node1 previous should be null", this .node1
047:                        .getPrevious());
048:                Assert.assertNull("Node1 next should be null", this .node1
049:                        .getNext());
050:                Assert.assertSame("First node should be node1", this .list
051:                        .getFirst(), this .node1);
052:                Assert.assertSame("Last node should be node1", this .list
053:                        .getLast(), this .node1);
054:
055:                this .list.add(this .node2);
056:                Assert.assertSame("node1 next should be node2", this .node1
057:                        .getNext(), this .node2);
058:                Assert.assertSame("node2 previous should be node1", this .node2
059:                        .getPrevious(), this .node1);
060:                Assert.assertSame("First node should be node1", this .list
061:                        .getFirst(), this .node1);
062:                Assert.assertSame("Last node should be node2", this .list
063:                        .getLast(), this .node2);
064:
065:                this .list.add(this .node3);
066:                Assert.assertSame("node2 next should be node3", this .node2
067:                        .getNext(), this .node3);
068:                Assert.assertSame("node3 previous should be node2", this .node3
069:                        .getPrevious(), this .node2);
070:                Assert.assertEquals("LinkedList should have 3 nodes", this .list
071:                        .size(), 3);
072:                Assert.assertSame("First node should be node1", this .list
073:                        .getFirst(), this .node1);
074:                Assert.assertSame("Last node should be node3", this .list
075:                        .getLast(), this .node3);
076:            }
077:
078:            /*
079:             * Test method for 'org.drools.util.LinkedList.remove(LinkedListNode)'
080:             */
081:            public void testRemove() {
082:                this .list.add(this .node1);
083:                this .list.add(this .node2);
084:                this .list.add(this .node3);
085:
086:                Assert.assertSame("Node2 previous should be node1", this .node2
087:                        .getPrevious(), this .node1);
088:                Assert.assertSame("Node2 next should be node3", this .node2
089:                        .getNext(), this .node3);
090:                this .list.remove(this .node2);
091:                Assert.assertNull("Node2 previous should be null", this .node2
092:                        .getPrevious());
093:                Assert.assertNull("Node2 next should be null", this .node2
094:                        .getNext());
095:
096:                Assert.assertNull("Node1 previous should be null", this .node1
097:                        .getPrevious());
098:                Assert.assertSame("Node1 next should be node3", this .node1
099:                        .getNext(), this .node3);
100:                this .list.remove(this .node1);
101:                Assert.assertNull("Node1 previous should be null", this .node1
102:                        .getPrevious());
103:                Assert.assertNull("Node1 next should be null", this .node1
104:                        .getNext());
105:
106:                Assert.assertNull("Node3 previous should be null", this .node3
107:                        .getPrevious());
108:                Assert.assertNull("Node3 next should be null", this .node3
109:                        .getNext());
110:                this .list.remove(this .node3);
111:                Assert.assertNull("Node3 previous should be null", this .node3
112:                        .getPrevious());
113:                Assert.assertNull("Node3 next should be null", this .node3
114:                        .getNext());
115:            }
116:
117:            /*
118:             * Test method for 'org.drools.util.LinkedList.getFirst()'
119:             */
120:            public void testGetFirst() {
121:                Assert.assertNull(
122:                        "Empty list should return null on getFirst()",
123:                        this .list.getFirst());
124:                this .list.add(this .node1);
125:                Assert.assertSame("List should return node1 on getFirst()",
126:                        this .list.getFirst(), this .node1);
127:                this .list.add(this .node2);
128:                Assert.assertSame("List should return node1 on getFirst()",
129:                        this .list.getFirst(), this .node1);
130:                this .list.add(this .node3);
131:                Assert.assertSame("List should return node1 on getFirst()",
132:                        this .list.getFirst(), this .node1);
133:            }
134:
135:            /*
136:             * Test method for 'org.drools.util.LinkedList.getLast()'
137:             */
138:            public void testGetLast() {
139:                Assert.assertNull("Empty list should return null on getLast()",
140:                        this .list.getLast());
141:                this .list.add(this .node1);
142:                Assert.assertSame("List should return node1 on getLast()",
143:                        this .list.getLast(), this .node1);
144:                this .list.add(this .node2);
145:                Assert.assertSame("List should return node2 on getLast()",
146:                        this .list.getLast(), this .node2);
147:                this .list.add(this .node3);
148:                Assert.assertSame("List should return node3 on getLast()",
149:                        this .list.getLast(), this .node3);
150:            }
151:
152:            /*
153:             * Test method for 'org.drools.util.LinkedList.removeFirst()'
154:             */
155:            public void testRemoveFirst() {
156:                this .list.add(this .node1);
157:                this .list.add(this .node2);
158:                this .list.add(this .node3);
159:
160:                Assert.assertSame("List should return node1 on getFirst()",
161:                        this .list.getFirst(), this .node1);
162:                this .list.removeFirst();
163:                Assert.assertSame("List should return node2 on getFirst()",
164:                        this .list.getFirst(), this .node2);
165:                this .list.removeFirst();
166:                Assert.assertSame("List should return node3 on getFirst()",
167:                        this .list.getFirst(), this .node3);
168:                this .list.removeFirst();
169:                Assert.assertNull(
170:                        "Empty list should return null on getFirst()",
171:                        this .list.getFirst());
172:            }
173:
174:            /*
175:             * Test method for 'org.drools.util.LinkedList.removeLast()'
176:             */
177:            public void testRemoveLast() {
178:                this .list.add(this .node1);
179:                this .list.add(this .node2);
180:                this .list.add(this .node3);
181:
182:                Assert.assertSame("List should return node1 on getLast()",
183:                        this .list.getLast(), this .node3);
184:                this .list.removeLast();
185:                Assert.assertSame("List should return node2 on getLast()",
186:                        this .list.getLast(), this .node2);
187:                this .list.removeLast();
188:                Assert.assertSame("List should return node3 on getLast()",
189:                        this .list.getLast(), this .node1);
190:                this .list.removeLast();
191:                Assert.assertNull("Empty list should return null on getLast()",
192:                        this .list.getLast());
193:            }
194:
195:            /*
196:             * Test method for 'org.drools.util.LinkedList.isEmpty()'
197:             */
198:            public void testIsEmpty() {
199:                Assert.assertTrue("Empty list should return true on isEmpty()",
200:                        this .list.isEmpty());
201:                this .list.add(this .node1);
202:                Assert.assertFalse(
203:                        "Not empty list should return false on isEmpty()",
204:                        this .list.isEmpty());
205:            }
206:
207:            /*
208:             * Test method for 'org.drools.util.LinkedList.clear()'
209:             */
210:            public void testClear() {
211:                this .list.add(this .node1);
212:                this .list.add(this .node2);
213:                this .list.add(this .node3);
214:
215:                Assert.assertEquals("List size should be 3", this .list.size(),
216:                        3);
217:                this .list.clear();
218:                Assert.assertEquals("Empty list should have size 0", this .list
219:                        .size(), 0);
220:            }
221:
222:            /*
223:             * Test method for 'org.drools.util.LinkedList.size()'
224:             */
225:            public void testSize() {
226:                this .list.add(this .node1);
227:                Assert.assertEquals("LinkedList should have 1 node", this .list
228:                        .size(), 1);
229:
230:                this .list.add(this .node2);
231:                Assert.assertEquals("LinkedList should have 2 nodes", this .list
232:                        .size(), 2);
233:
234:                this .list.add(this .node3);
235:                Assert.assertEquals("LinkedList should have 3 nodes", this .list
236:                        .size(), 3);
237:            }
238:
239:            public void testInsertAfter() {
240:                try {
241:                    this .list.insertAfter(null, this .node1);
242:                } catch (NullPointerException e) {
243:                    e.printStackTrace();
244:                    fail("Should NOT raise NPE!");
245:                }
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.