Source Code Cross Referenced for Collection4TestCase.java in  » Database-DBMS » db4o-6.4 » com » db4o » db4ounit » common » foundation » 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 » Database DBMS » db4o 6.4 » com.db4o.db4ounit.common.foundation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (C) 2004 - 2007  db4objects Inc.  http://www.db4o.com
002:
003:        This file is part of the db4o open source object database.
004:
005:        db4o is free software; you can redistribute it and/or modify it under
006:        the terms of version 2 of the GNU General Public License as published
007:        by the Free Software Foundation and as clarified by db4objects' GPL 
008:        interpretation policy, available at
009:        http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010:        Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011:        Suite 350, San Mateo, CA 94403, USA.
012:
013:        db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:        for more details.
017:
018:        You should have received a copy of the GNU General Public License along
019:        with this program; if not, write to the Free Software Foundation, Inc.,
020:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */
021:        package com.db4o.db4ounit.common.foundation;
022:
023:        import com.db4o.foundation.*;
024:
025:        import db4ounit.*;
026:
027:        public class Collection4TestCase implements  TestCase {
028:
029:            public static void main(String[] args) {
030:                new TestRunner(Collection4TestCase.class).run();
031:            }
032:
033:            public void testReplace() {
034:                final Collection4 c = new Collection4();
035:                c.replace("one", "two");
036:                c.add("one");
037:                c.add("two");
038:                c.add("three");
039:                c.replace("two", "two.half");
040:                assertCollection(new String[] { "one", "two.half", "three" }, c);
041:                c.replace("two.half", "one");
042:                c.replace("one", "half");
043:                assertCollection(new String[] { "half", "one", "three" }, c);
044:            }
045:
046:            public void testNulls() {
047:                final Collection4 c = new Collection4();
048:                c.add("one");
049:                assertNotContainsNull(c);
050:                c.add(null);
051:                assertContainsNull(c);
052:                assertCollection(new String[] { "one", null }, c);
053:                c.prepend(null);
054:                assertCollection(new String[] { null, "one", null }, c);
055:                c.prepend("zero");
056:                c.add("two");
057:                assertCollection(new String[] { "zero", null, "one", null,
058:                        "two" }, c);
059:                assertContainsNull(c);
060:                c.remove(null);
061:                assertCollection(new String[] { "zero", "one", null, "two" }, c);
062:                c.remove(null);
063:                assertNotContainsNull(c);
064:                assertCollection(new String[] { "zero", "one", "two" }, c);
065:                c.remove(null);
066:                assertCollection(new String[] { "zero", "one", "two" }, c);
067:            }
068:
069:            public void testPrepend() {
070:                final Collection4 c = new Collection4();
071:                c.prepend("foo");
072:                assertCollection(new String[] { "foo" }, c);
073:                c.add("bar");
074:                assertCollection(new String[] { "foo", "bar" }, c);
075:                c.prepend("baz");
076:                assertCollection(new String[] { "baz", "foo", "bar" }, c);
077:                c.prepend("gazonk");
078:                assertCollection(
079:                        new String[] { "gazonk", "baz", "foo", "bar" }, c);
080:            }
081:
082:            public void testCopyConstructor() {
083:                final String[] expected = new String[] { "1", "2", "3" };
084:                final Collection4 c = newCollection(expected);
085:                assertCollection(expected, new Collection4(c));
086:            }
087:
088:            public void testInvalidIteratorException() {
089:                final Collection4 c = newCollection(new String[] { "1", "2" });
090:                final Iterator4 i = c.iterator();
091:                Assert.isTrue(i.moveNext());
092:                c.add("3");
093:                Assert.expect(InvalidIteratorException.class, new CodeBlock() {
094:                    public void run() throws Throwable {
095:                        System.out.println(i.current());
096:                    }
097:                });
098:            }
099:
100:            public void testRemove() {
101:                final Collection4 c = newCollection(new String[] { "1", "2",
102:                        "3", "4" });
103:                c.remove("3");
104:                assertCollection(new String[] { "1", "2", "4" }, c);
105:                c.remove("4");
106:                assertCollection(new String[] { "1", "2" }, c);
107:                c.add("5");
108:                assertCollection(new String[] { "1", "2", "5" }, c);
109:                c.remove("1");
110:                assertCollection(new String[] { "2", "5" }, c);
111:                c.remove("2");
112:                c.remove("5");
113:                assertCollection(new String[] {}, c);
114:                c.add("6");
115:                assertCollection(new String[] { "6" }, c);
116:            }
117:
118:            private void assertCollection(String[] expected, Collection4 c) {
119:                Assert.areEqual(expected.length, c.size());
120:                Iterator4Assert.areEqual(expected, c.iterator());
121:            }
122:
123:            private void assertContainsNull(Collection4 c) {
124:                Assert.isTrue(c.contains(null));
125:                Assert.isNull(c.get(null));
126:                int size = c.size();
127:                c.ensure(null);
128:                Assert.areEqual(size, c.size());
129:            }
130:
131:            private void assertNotContainsNull(Collection4 c) {
132:                Assert.isFalse(c.contains(null));
133:                Assert.isNull(c.get(null));
134:                int size = c.size();
135:                c.ensure(null);
136:                Assert.areEqual(size + 1, c.size());
137:                c.remove(null);
138:                Assert.areEqual(size, c.size());
139:            }
140:
141:            public void testIterator() {
142:                String[] expected = new String[] { "1", "2", "3" };
143:                Collection4 c = newCollection(expected);
144:                Iterator4Assert.areEqual(expected, c.iterator());
145:            }
146:
147:            private Collection4 newCollection(String[] expected) {
148:                Collection4 c = new Collection4();
149:                c.addAll(expected);
150:                return c;
151:            }
152:
153:            public void testToString() {
154:                Collection4 c = new Collection4();
155:                Assert.areEqual("[]", c.toString());
156:
157:                c.add("foo");
158:                Assert.areEqual("[foo]", c.toString());
159:                c.add("bar");
160:                Assert.areEqual("[foo, bar]", c.toString());
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.