Source Code Cross Referenced for RealmTester.java in  » IDE-Eclipse » jface » org » eclipse » jface » tests » databinding » 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 » IDE Eclipse » jface » org.eclipse.jface.tests.databinding 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006 Brad Reynolds and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     Brad Reynolds - initial API and implementation
010:         ******************************************************************************/package org.eclipse.jface.tests.databinding;
011:
012:        import junit.framework.Assert;
013:
014:        import org.eclipse.core.databinding.observable.Realm;
015:        import org.eclipse.core.runtime.AssertionFailedException;
016:
017:        /**
018:         * Aids in the testing of Realms.
019:         * 
020:         * @since 3.2
021:         */
022:        public class RealmTester {
023:
024:            /**
025:             * Sets the default realm without using Realm.runWithDefault() for testing
026:             * purposes.
027:             * 
028:             * @param realm
029:             */
030:            public static void setDefault(Realm realm) {
031:                CurrentRealm.setDefault(realm);
032:            }
033:
034:            /**
035:             * Runs the provided <code>runnable</code> when the realm is both current
036:             * and not current. It checks for AssertionFailedExceptions and if an
037:             * exception occurs or doesn't occur as expected the test fails. The realm
038:             * of an observable created before the method was invoked must be of type
039:             * {@link CurrentRealm}. The default realm during the runnable invocation
040:             * is set to an instance of {@link CurrentRealm} when the runnable is
041:             * invoked.
042:             * 
043:             * @param runnable
044:             */
045:            public static void exerciseCurrent(Runnable runnable) {
046:                CurrentRealm previousRealm = (CurrentRealm) Realm.getDefault();
047:                CurrentRealm realm = new CurrentRealm();
048:                setDefault(realm);
049:
050:                try {
051:                    realm.setCurrent(true);
052:                    if (previousRealm != null) {
053:                        previousRealm.setCurrent(true);
054:                    }
055:
056:                    try {
057:                        runnable.run();
058:                    } catch (AssertionFailedException e) {
059:                        Assert
060:                                .fail("Correct realm, exception should not have been thrown");
061:                    }
062:
063:                    realm.setCurrent(false);
064:                    if (previousRealm != null) {
065:                        previousRealm.setCurrent(false);
066:                    }
067:
068:                    try {
069:                        runnable.run();
070:                        Assert
071:                                .fail("Incorrect realm, exception should have been thrown");
072:                    } catch (AssertionFailedException e) {
073:                    }
074:                } finally {
075:                    setDefault(previousRealm);
076:                }
077:            }
078:
079:            /**
080:             * Runs the provided <code>runnable</code> when the realm is both current
081:             * and not current. It checks for AssertionFailedExceptions and if an
082:             * exception occurs or doesn't occur as expected the test fails.
083:             * 
084:             * @param runnable
085:             * @param realm
086:             */
087:            public static void exerciseCurrent(Runnable runnable,
088:                    CurrentRealm realm) {
089:                realm.setCurrent(true);
090:
091:                try {
092:                    runnable.run();
093:                } catch (AssertionFailedException e) {
094:                    Assert
095:                            .fail("Correct realm, exception should not have been thrown");
096:                }
097:
098:                realm.setCurrent(false);
099:
100:                try {
101:                    runnable.run();
102:                    Assert
103:                            .fail("Incorrect realm, exception should have been thrown");
104:                } catch (AssertionFailedException e) {
105:                }
106:            }
107:
108:            /**
109:             * Realm that will delegate to another for all operations except calls to
110:             * {@link #isCurrent()}. The current status can be set by the consumer to
111:             * enable testing of realm checks.
112:             * 
113:             * @since 3.2
114:             */
115:            public static class DelegatingRealm extends CurrentRealm {
116:                private Realm realm;
117:
118:                public DelegatingRealm(Realm realm) {
119:                    this .realm = realm;
120:                }
121:
122:                protected void syncExec(Runnable runnable) {
123:                    realm.exec(runnable);
124:                }
125:
126:                public void asyncExec(Runnable runnable) {
127:                    realm.asyncExec(runnable);
128:                }
129:            }
130:
131:            /**
132:             * Allows for the toggling of the current status of the realm. The
133:             * asyncExec(...) implementations do nothing.
134:             * 
135:             * @since 3.2
136:             */
137:            public static class CurrentRealm extends Realm {
138:                private boolean current;
139:
140:                public CurrentRealm() {
141:                    this (false);
142:                }
143:
144:                public CurrentRealm(boolean current) {
145:                    this .current = current;
146:                }
147:
148:                public boolean isCurrent() {
149:                    return current;
150:                }
151:
152:                public void setCurrent(boolean current) {
153:                    this .current = current;
154:                }
155:
156:                protected void syncExec(Runnable runnable) {
157:                    super .syncExec(runnable);
158:                }
159:
160:                public void asyncExec(Runnable runnable) {
161:                    throw new UnsupportedOperationException(
162:                            "CurrentRealm does not support asyncExec(Runnable).");
163:                }
164:
165:                protected static Realm setDefault(Realm realm) {
166:                    return Realm.setDefault(realm);
167:                }
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.