Skip to content

Package: DefaultRealm

DefaultRealm

nameinstructionbranchcomplexitylinemethod
DefaultRealm()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
asyncExec(Runnable)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 0 C: 8
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
isCurrent()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
rule()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
syncExec(Runnable)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * http://wiki.eclipse.org/JFace_Data_Binding/Realm
13: * Lucas Koehler - initial API and implementation
14: * Christian W. Damus - bug 548592
15: ******************************************************************************/
16: package org.eclipse.emf.ecp.test.common;
17:
18: import org.eclipse.core.databinding.observable.Realm;
19: import org.junit.rules.TestRule;
20: import org.junit.rules.TestWatcher;
21: import org.junit.runner.Description;
22:
23: /**
24: * Simple realm implementation that will set itself as default when constructed. Invoke {@link #dispose()} to remove the
25: * realm from being the default. Does not support asyncExec(...).
26: *
27: * @see <a href="http://wiki.eclipse.org/JFace_Data_Binding/Realm">http://wiki.eclipse.org/JFace_Data_Binding/Realm</a>
28: * @author Lucas Koehler
29: */
30: public class DefaultRealm extends Realm {
31:         private final Realm previousRealm;
32:
33:         /**
34:          * Create a new instance of {@link DefaultRealm}.
35:          */
36:         public DefaultRealm() {
37:                 previousRealm = super.setDefault(this);
38:         }
39:
40:         /**
41:          * @return always returns true
42:          */
43:         @Override
44:         public boolean isCurrent() {
45:                 return true;
46:         }
47:
48:         @Override
49:         protected void syncExec(Runnable runnable) {
50:                 runnable.run();
51:         }
52:
53:         /**
54:          * @throws UnsupportedOperationException
55:          */
56:         @Override
57:         public void asyncExec(Runnable runnable) {
58:                 throw new UnsupportedOperationException("asyncExec is unsupported"); //$NON-NLS-1$
59:         }
60:
61:         /**
62:          * Removes the realm from being the current and sets the previous realm to the default.
63:          */
64:         public void dispose() {
65:•                if (getDefault() == this) {
66:                         setDefault(previousRealm);
67:                 }
68:         }
69:
70:         /**
71:          * Obtain a JUnit rule that ensures a {@link DefaultRealm} during its execution.
72:          *
73:          * @return a default realm rule
74:          *
75:          * @since 1.22
76:          */
77:         public static TestRule rule() {
78:                 return new TestWatcher() {
79:                         private DefaultRealm realm;
80:
81:                         @Override
82:                         protected void starting(Description description) {
83:                                 realm = new DefaultRealm();
84:                         }
85:
86:                         @Override
87:                         protected void finished(Description description) {
88:                                 realm.dispose();
89:                                 realm = null;
90:                         }
91:                 };
92:         }
93:
94: }