Source Code Cross Referenced for XmlArrayListTest.java in  » XML » xstream-1.3 » com » thoughtworks » xstream » persistence » 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 » XML » xstream 1.3 » com.thoughtworks.xstream.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2006 Joe Walnes.
003:         * Copyright (C) 2007 XStream Committers.
004:         * All rights reserved.
005:         *
006:         * The software in this package is published under the terms of the BSD
007:         * style license a copy of which has been included with this distribution in
008:         * the LICENSE.txt file.
009:         * 
010:         * Created on 06. July 2006 by Guilherme Silveira
011:         */
012:        package com.thoughtworks.xstream.persistence;
013:
014:        import java.util.ArrayList;
015:        import java.util.HashMap;
016:        import java.util.HashSet;
017:        import java.util.Iterator;
018:        import java.util.List;
019:        import java.util.Map;
020:        import java.util.Set;
021:
022:        import junit.framework.TestCase;
023:
024:        public class XmlArrayListTest extends TestCase {
025:            private MockedStrategy strategy;
026:
027:            public void setUp() throws Exception {
028:                super .setUp();
029:                strategy = new MockedStrategy();
030:            }
031:
032:            public void testWritesASingleObject() {
033:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
034:                xmlList.add("guilherme");
035:                assertTrue(strategy.map.containsValue("guilherme"));
036:            }
037:
038:            public void testWritesASingleObjectInANegativePosition() {
039:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
040:                try {
041:                    xmlList.add(-1, "guilherme");
042:                    fail();
043:                } catch (IndexOutOfBoundsException ex) {
044:                    // ok
045:                }
046:            }
047:
048:            public void testWritesASingleObjectInFirstPosition() {
049:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
050:                xmlList.add("guilherme");
051:                assertTrue(strategy.map.containsKey("0"));
052:            }
053:
054:            public void testWritesTwoObjects() {
055:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
056:                xmlList.add("guilherme");
057:                xmlList.add("silveira");
058:                assertTrue(strategy.map.containsValue("guilherme"));
059:                assertTrue(strategy.map.containsValue("silveira"));
060:                assertTrue(strategy.map.containsKey("0"));
061:                assertTrue(strategy.map.containsKey("1"));
062:            }
063:
064:            public void testWritesTwoObjectsGuaranteesItsEnumerationOrder() {
065:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
066:                xmlList.add("guilherme");
067:                xmlList.add("silveira");
068:                assertEquals("guilherme", strategy.map.get("0"));
069:                assertEquals("silveira", strategy.map.get("1"));
070:            }
071:
072:            public void testWritesASecondObjectInAPositionHigherThanTheListsSize() {
073:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
074:                try {
075:                    xmlList.add("silveira");
076:                    xmlList.add(3, "guilherme");
077:                    fail();
078:                } catch (IndexOutOfBoundsException ex) {
079:                    // ok
080:                }
081:            }
082:
083:            public void testRemovesAWrittenObject() {
084:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
085:                xmlList.add("guilherme");
086:                boolean changed = xmlList.remove("guilherme");
087:                assertFalse(strategy.map.containsValue("guilherme"));
088:            }
089:
090:            public void testRemovesAWrittenObjectImplyingInAChangeInTheList() {
091:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
092:                xmlList.add("guilherme");
093:                boolean changed = xmlList.remove("guilherme");
094:                assertTrue(changed);
095:            }
096:
097:            public void testRemovesAnInvalidObjectWithoutAffectingTheList() {
098:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
099:                boolean removed = xmlList.remove("guilherme");
100:                assertFalse(removed);
101:            }
102:
103:            public void testHasZeroLengthWhenInstantiated() {
104:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
105:                assertEquals(0, xmlList.size());
106:            }
107:
108:            public void testHasOneItem() {
109:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
110:                xmlList.add("guilherme");
111:                assertEquals(1, xmlList.size());
112:            }
113:
114:            public void testHasTwoItems() {
115:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
116:                xmlList.add("guilherme");
117:                xmlList.add("silveira");
118:                assertEquals(2, xmlList.size());
119:            }
120:
121:            public void testIsNotEmpty() {
122:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
123:                xmlList.add("guilherme");
124:                assertFalse(xmlList.isEmpty());
125:            }
126:
127:            public void testDoesNotContainKey() {
128:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
129:                assertFalse(xmlList.contains("guilherme"));
130:            }
131:
132:            public void testContainsKey() {
133:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
134:                xmlList.add("guilherme");
135:                assertTrue(xmlList.contains("guilherme"));
136:            }
137:
138:            public void testGetsAnObject() {
139:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
140:                xmlList.add("guilherme");
141:                Object onlyValue = xmlList.iterator().next();
142:                assertEquals("guilherme", onlyValue);
143:            }
144:
145:            public void testGetsTheFirstObject() {
146:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
147:                xmlList.add("guilherme");
148:                assertEquals("guilherme", xmlList.get(0));
149:            }
150:
151:            public void testGetsTheSecondObject() {
152:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
153:                xmlList.add("guilherme");
154:                xmlList.add("silveira");
155:                assertEquals("silveira", xmlList.get(1));
156:            }
157:
158:            public void testInsertsAnObjectInTheMiddleOfTheList() {
159:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
160:                xmlList.add("guilherme");
161:                xmlList.add("silveira");
162:                xmlList.add(1, "de azevedo");
163:                assertEquals("guilherme", xmlList.get(0));
164:                assertEquals("de azevedo", xmlList.get(1));
165:                assertEquals("silveira", xmlList.get(2));
166:            }
167:
168:            public void testIteratingGuaranteesItsEnumeration() {
169:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
170:                xmlList.add("guilherme");
171:                xmlList.add("silveira");
172:                Iterator it = xmlList.iterator();
173:                assertEquals("guilherme", it.next());
174:                assertEquals("silveira", it.next());
175:            }
176:
177:            public void testIsEmpty() {
178:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
179:                assertTrue(xmlList.isEmpty());
180:            }
181:
182:            public void testClearsItsObjects() {
183:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
184:                xmlList.add("guilherme");
185:                xmlList.add("silveira");
186:                xmlList.clear();
187:                assertEquals(0, xmlList.size());
188:            }
189:
190:            public void testPutsAllAddsTwoItems() {
191:                Set original = new HashSet();
192:                original.add("guilherme");
193:                original.add("silveira");
194:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
195:                xmlList.addAll(original);
196:                assertEquals(2, xmlList.size());
197:            }
198:
199:            public void testContainsASpecificValue() {
200:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
201:                xmlList.add("guilherme");
202:                assertTrue(xmlList.contains("guilherme"));
203:            }
204:
205:            public void testDoesNotContainASpecificValue() {
206:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
207:                assertFalse(xmlList.contains("zzzz"));
208:            }
209:
210:            public void testEntrySetContainsAllItems() {
211:                Set original = new HashSet();
212:                original.add("guilherme");
213:                original.add("silveira");
214:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
215:                xmlList.add("guilherme");
216:                xmlList.add("silveira");
217:                assertTrue(xmlList.containsAll(original));
218:            }
219:
220:            // actually an acceptance test?
221:            public void testIteratesOverEntryAndChecksWithAnotherInstance() {
222:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
223:                xmlList.add("guilherme");
224:                xmlList.add("silveira");
225:                XmlArrayList built = new XmlArrayList(this .strategy);
226:                for (Iterator iter = xmlList.iterator(); iter.hasNext();) {
227:                    Object entry = iter.next();
228:                    assertTrue(built.contains(entry));
229:                }
230:            }
231:
232:            public void testIteratesOverEntrySetContainingTwoItems() {
233:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
234:                xmlList.add("guilherme");
235:                xmlList.add("silveira");
236:                List built = new ArrayList();
237:                for (Iterator iter = xmlList.iterator(); iter.hasNext();) {
238:                    Object entry = iter.next();
239:                    built.add(entry);
240:                }
241:                assertEquals(xmlList, built);
242:            }
243:
244:            public void testRemovesAnItemThroughIteration() {
245:                XmlArrayList xmlList = new XmlArrayList(this .strategy);
246:                xmlList.add("guilherme");
247:                xmlList.add("silveira");
248:                for (Iterator iter = xmlList.iterator(); iter.hasNext();) {
249:                    Object entry = iter.next();
250:                    if (entry.equals("guilherme")) {
251:                        iter.remove();
252:                    }
253:                }
254:                assertFalse(xmlList.contains("guilherme"));
255:            }
256:
257:            private static class MockedStrategy implements  StreamStrategy {
258:
259:                private Map map = new HashMap();
260:
261:                public Iterator iterator() {
262:                    return map.entrySet().iterator();
263:                }
264:
265:                public int size() {
266:                    return map.size();
267:                }
268:
269:                public Object get(Object key) {
270:                    return map.get(key);
271:                }
272:
273:                public Object put(Object key, Object value) {
274:                    return map.put(key, value);
275:                }
276:
277:                public Object remove(Object key) {
278:                    return map.remove(key);
279:                }
280:
281:            }
282:
283:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.