Source Code Cross Referenced for CollectionFactoryTest.java in  » Web-Framework » Tapestry » org » apache » tapestry » ioc » internal » 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 » Web Framework » Tapestry » org.apache.tapestry.ioc.internal.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright 2006, 2007 The Apache Software Foundation
002:        //
003:        // Licensed under the Apache License, Version 2.0 (the "License");
004:        // you may not use this file except in compliance with the License.
005:        // You may obtain a copy of the License at
006:        //
007:        //     http://www.apache.org/licenses/LICENSE-2.0
008:        //
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:
015:        package org.apache.tapestry.ioc.internal.util;
016:
017:        import static java.util.Arrays.asList;
018:        import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
019:        import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
020:        import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
021:
022:        import java.util.ArrayList;
023:        import java.util.Arrays;
024:        import java.util.HashMap;
025:        import java.util.HashSet;
026:        import java.util.List;
027:        import java.util.Map;
028:        import java.util.Set;
029:
030:        import org.testng.Assert;
031:        import org.testng.annotations.Test;
032:
033:        public class CollectionFactoryTest extends Assert {
034:
035:            @Test
036:            public void new_map() {
037:                Map<String, Class> map = newMap();
038:
039:                assertTrue(map instanceof  HashMap);
040:            }
041:
042:            @Test
043:            public void copy_map() {
044:                Map<String, Class> map = newMap();
045:
046:                map.put("this", CollectionFactoryTest.class);
047:
048:                Map<String, Class> copy = CollectionFactory.newMap(map);
049:
050:                assertEquals(copy, map);
051:
052:                map.put("other", Map.class);
053:
054:                assertFalse(copy.equals(map));
055:            }
056:
057:            @Test
058:            public void new_set() {
059:                Set<String> set = newSet();
060:
061:                assertTrue(set instanceof  HashSet);
062:            }
063:
064:            @Test
065:            public void copy_set() {
066:                List<String> start = asList("fred", "barney");
067:
068:                Set<String> set = newSet(start);
069:
070:                assertEquals(set.size(), 2);
071:                assertTrue(set.contains("fred"));
072:                assertTrue(set.contains("barney"));
073:            }
074:
075:            @Test
076:            public void set_from_varargs() {
077:                Set<String> set = newSet("fred", "barney");
078:
079:                assertEquals(set.size(), 2);
080:                assertTrue(set.contains("fred"));
081:                assertTrue(set.contains("barney"));
082:            }
083:
084:            @Test
085:            public void new_list() {
086:                List<String> list = newList();
087:
088:                assertTrue(list instanceof  ArrayList);
089:            }
090:
091:            @Test
092:            public void new_list_copy() {
093:                List<String> start = Arrays.asList("Fred", "Barney", "Wilma");
094:                List<String> copy = newList(start);
095:
096:                assertNotSame(copy, start);
097:                assertEquals(copy, start);
098:            }
099:
100:            @Test
101:            public void new_list_from_elements() {
102:                List<String> list = newList("Fred", "Barney");
103:
104:                assertEquals(list.size(), 2);
105:                assertEquals(list.get(0), "Fred");
106:                assertEquals(list.get(1), "Barney");
107:            }
108:
109:            private static final int THREAD_COUNT = 20;
110:
111:            @Test
112:            public void new_threadsafe_list() throws Exception {
113:                final List<String> threadNames = CollectionFactory
114:                        .newThreadSafeList();
115:
116:                List<Thread> threads = CollectionFactory.newList();
117:
118:                Runnable r = new Runnable() {
119:                    public void run() {
120:                        String name = Thread.currentThread().getName();
121:                        threadNames.add(name);
122:                    }
123:                };
124:
125:                for (int i = 0; i < THREAD_COUNT; i++) {
126:                    Thread t = new Thread(r);
127:                    threads.add(t);
128:                }
129:
130:                // Start all the threads at the same time.
131:
132:                for (Thread t : threads) {
133:                    t.start();
134:                }
135:
136:                // Wait for all threads to complete
137:
138:                for (Thread t : threads) {
139:                    t.join();
140:                }
141:
142:                // Make sure they all executed. If the list was not thread safe, highly unlikely this
143:                // would work.
144:
145:                assertEquals(threadNames.size(), THREAD_COUNT);
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.