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


001:        /*******************************************************************************
002:         * Copyright (c) 2007 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.conformance.databinding;
011:
012:        import org.eclipse.core.databinding.observable.ChangeEvent;
013:        import org.eclipse.core.databinding.observable.IChangeListener;
014:        import org.eclipse.core.databinding.observable.IObservable;
015:        import org.eclipse.core.databinding.observable.ObservableTracker;
016:        import org.eclipse.jface.tests.databinding.RealmTester;
017:        import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
018:
019:        /**
020:         * Tests for IObservable that don't require mutating the observable.
021:         * <p>
022:         * This class is experimental and can change at any time. It is recommended to
023:         * not subclass or assume the test names will not change. The only API that is
024:         * guaranteed to not change are the constructors. The tests will remain public
025:         * and not final in order to allow for consumers to turn off a test if needed by
026:         * subclassing.
027:         * </p>
028:         * 
029:         * @since 3.2
030:         */
031:        public class ObservableContractTest extends ObservableDelegateTest {
032:            private IObservable observable;
033:
034:            private IObservableContractDelegate delegate;
035:
036:            public ObservableContractTest(IObservableContractDelegate delegate) {
037:                this (null, delegate);
038:            }
039:
040:            public ObservableContractTest(String testName,
041:                    IObservableContractDelegate delegate) {
042:                super (testName, delegate);
043:
044:                this .delegate = delegate;
045:            }
046:
047:            protected void setUp() throws Exception {
048:                super .setUp();
049:                observable = getObservable();
050:            }
051:
052:            public void testGetRealm_NotNull() throws Exception {
053:                assertNotNull(
054:                        formatFail("The observable's realm should not be null."),
055:                        observable.getRealm());
056:            }
057:
058:            public void testChange_ChangeEvent() throws Exception {
059:                ChangeListener listener = new ChangeListener();
060:
061:                observable.addChangeListener(listener);
062:                delegate.change(observable);
063:
064:                assertEquals(
065:                        formatFail("A change in the observable should notify change listeners."),
066:                        listener.count, 1);
067:            }
068:
069:            public void testChange_EventObservable() throws Exception {
070:                ChangeListener listener = new ChangeListener();
071:
072:                observable.addChangeListener(listener);
073:                delegate.change(observable);
074:
075:                ChangeEvent event = listener.event;
076:                assertNotNull(formatFail("change event was null"), event);
077:
078:                assertSame(
079:                        formatFail("In the change event the source of the change should be the observable."),
080:                        observable, event.getObservable());
081:            }
082:
083:            public void testChange_RealmCheck() throws Exception {
084:                RealmTester.exerciseCurrent(new Runnable() {
085:                    public void run() {
086:                        delegate.change(observable);
087:                    }
088:                }, (CurrentRealm) observable.getRealm());
089:            }
090:
091:            public void testChange_ObservableRealmIsTheCurrentRealm()
092:                    throws Exception {
093:                ChangeListener listener = new ChangeListener();
094:                observable.addChangeListener(listener);
095:
096:                delegate.change(observable);
097:                assertTrue(
098:                        formatFail("On change the current realm should be the realm of the observable."),
099:                        listener.isCurrentRealm);
100:            }
101:
102:            public void testRemoveChangeListener_RemovesListener()
103:                    throws Exception {
104:                ChangeListener listener = new ChangeListener();
105:
106:                observable.addChangeListener(listener);
107:                delegate.change(observable);
108:
109:                // precondition check
110:                assertEquals(formatFail("change did not notify listeners"), 1,
111:                        listener.count);
112:
113:                observable.removeChangeListener(listener);
114:                delegate.change(observable);
115:
116:                assertEquals(
117:                        formatFail("When a change listener is removed it should not still receive change events."),
118:                        1, listener.count);
119:            }
120:
121:            public void testIsStale_NotStale() throws Exception {
122:                delegate.setStale(observable, false);
123:                assertFalse(
124:                        formatFail("When an observable is not stale isStale() should return false."),
125:                        observable.isStale());
126:            }
127:
128:            public void testIsStale_RealmChecks() throws Exception {
129:                RealmTester.exerciseCurrent(new Runnable() {
130:                    public void run() {
131:                        delegate.change(observable);
132:                    }
133:                }, (CurrentRealm) observable.getRealm());
134:            }
135:
136:            /**
137:             * Asserts that ObservableTracker.getterCalled(...) is invoked when the
138:             * provided <code>runnable</code> is invoked.
139:             * 
140:             * @param runnable
141:             * @param methodName
142:             *            method name to display when displaying a message
143:             * @param observable
144:             *            observable that should be collected by ObservableTracker
145:             */
146:            protected void assertGetterCalled(Runnable runnable,
147:                    String methodName, IObservable observable) {
148:                IObservable[] observables = ObservableTracker.runAndMonitor(
149:                        runnable, null, null);
150:
151:                int count = 0;
152:                for (int i = 0; i < observables.length; i++) {
153:                    if (observables[i] == observable) {
154:                        count++;
155:                    }
156:                }
157:
158:                assertEquals(
159:                        formatFail(methodName
160:                                + " should invoke ObservableTracker.getterCalled() once."),
161:                        1, count);
162:            }
163:
164:            /* package */static class ChangeListener implements 
165:                    IChangeListener {
166:                int count;
167:
168:                ChangeEvent event;
169:
170:                boolean isCurrentRealm;
171:
172:                public void handleChange(ChangeEvent event) {
173:                    count++;
174:                    this.event = event;
175:                    this.isCurrentRealm = event.getObservable().getRealm()
176:                            .isCurrent();
177:                }
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.