Skip to content

Package: EMFFormsRevealServiceFixture$1

EMFFormsRevealServiceFixture$1

nameinstructionbranchcomplexitylinemethod
featureValueOf(RevealStep)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
{...}
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.test.common.spi;
15:
16: import static org.hamcrest.CoreMatchers.is;
17: import static org.mockito.Mockito.mock;
18:
19: import java.util.Arrays;
20: import java.util.List;
21: import java.util.function.Supplier;
22:
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecore.EStructuralFeature;
25: import org.eclipse.emf.ecp.view.spi.model.VElement;
26: import org.eclipse.emfforms.bazaar.Bid;
27: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealProvider;
28: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealService;
29: import org.eclipse.emfforms.spi.core.services.reveal.RevealStep;
30: import org.eclipse.emfforms.spi.core.services.reveal.RevealStepKind;
31: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext;
32: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceManager;
33: import org.hamcrest.FeatureMatcher;
34: import org.hamcrest.Matcher;
35: import org.junit.runner.Description;
36:
37: /**
38: * A convenient fixture for JUnit testing with the {@link EMFFormsRevealService}.
39: *
40: * @param <T> the type of view context to mock up
41: *
42: * @since 1.22
43: */
44: public class EMFFormsRevealServiceFixture<T extends EMFFormsViewContext> extends EMFFormsViewContextFixture<T>
45:         implements EMFFormsRevealService {
46:
47:         private EMFFormsRevealService service;
48:
49:         //
50:         // Creation
51:         //
52:
53:         /**
54:          * Initializes me.
55:          */
56:         protected EMFFormsRevealServiceFixture(Class<T> contextType,
57:                 Supplier<? extends VElement> viewSupplier, Supplier<? extends EObject> domainModelSupplier) {
58:
59:                 super(contextType, viewSupplier, domainModelSupplier);
60:         }
61:
62:         /**
63:          * Initializes me.
64:          */
65:         protected EMFFormsRevealServiceFixture(Class<T> contextType, Object owner) {
66:                 super(contextType, owner);
67:         }
68:
69:         /**
70:          * Create a new fixture instance.
71:          */
72:         public static EMFFormsRevealServiceFixture<EMFFormsViewContext> create() {
73:                 return create(EMFFormsViewContext.class);
74:         }
75:
76:         /**
77:          * Create a new fixture instance.
78:          */
79:         public static <T extends EMFFormsViewContext> EMFFormsRevealServiceFixture<T> create(Class<T> contextType) {
80:                 return create(contextType, () -> mock(VElement.class), () -> mock(EObject.class));
81:         }
82:
83:         /**
84:          * Create a new fixture instance.
85:          */
86:         public static EMFFormsRevealServiceFixture<EMFFormsViewContext> create(
87:                 Supplier<? extends VElement> viewSupplier, Supplier<? extends EObject> domainModelSupplier) {
88:
89:                 return create(EMFFormsViewContext.class, viewSupplier, domainModelSupplier);
90:         }
91:
92:         /**
93:          * Create a new fixture instance.
94:          */
95:         public static <T extends EMFFormsViewContext> EMFFormsRevealServiceFixture<T> create(Class<T> contextType,
96:                 Supplier<? extends VElement> viewSupplier, Supplier<? extends EObject> domainModelSupplier) {
97:
98:                 return new EMFFormsRevealServiceFixture<>(contextType, viewSupplier, domainModelSupplier);
99:         }
100:
101:         /**
102:          * Create a new fixture instance.
103:          */
104:         public static EMFFormsRevealServiceFixture<EMFFormsViewContext> create(Object owner) {
105:                 return create(EMFFormsViewContext.class, owner);
106:         }
107:
108:         /**
109:          * Create a new fixture instance.
110:          */
111:         public static <T extends EMFFormsViewContext> EMFFormsRevealServiceFixture<T> create(Class<T> contextType,
112:                 Object owner) {
113:
114:                 return new EMFFormsRevealServiceFixture<>(contextType, owner);
115:         }
116:
117:         //
118:         // Test fixture protocol
119:         //
120:
121:         public final EMFFormsRevealService getService() {
122:                 return service;
123:         }
124:
125:         //
126:         // Test lifecycle
127:         //
128:
129:         @Override
130:         protected void starting(Description description) {
131:                 super.starting(description);
132:
133:                 final EMFFormsViewServiceManager serviceManager = getService(EMFFormsViewServiceManager.class);
134:                 service = serviceManager.createGlobalImmediateService(EMFFormsRevealService.class, getViewContext()).get();
135:         }
136:
137:         @Override
138:         protected void finished(Description description) {
139:                 super.finished(description);
140:
141:                 service = null;
142:         }
143:
144:         //
145:         // Service protocol delegation
146:         //
147:
148:         @Override
149:         public boolean reveal(EObject object) {
150:                 return service.reveal(object);
151:         }
152:
153:         @Override
154:         public boolean reveal(EObject object, EStructuralFeature feature) {
155:                 return service.reveal(object, feature);
156:         }
157:
158:         @Override
159:         public RevealStep reveal(EObject object, VElement scope) {
160:                 return service.reveal(object, scope);
161:         }
162:
163:         @Override
164:         public RevealStep reveal(EObject object, EStructuralFeature feature, VElement scope) {
165:                 return reveal(object, feature, scope);
166:         }
167:
168:         @Override
169:         public void addRevealProvider(EMFFormsRevealProvider provider) {
170:                 service.addRevealProvider(provider);
171:         }
172:
173:         @Override
174:         public void removeRevealProvider(EMFFormsRevealProvider provider) {
175:                 service.removeRevealProvider(provider);
176:         }
177:
178:         //
179:         // Test framework
180:         //
181:
182:         public static Matcher<RevealStep> isA(RevealStepKind stepKind) {
183:                 return new FeatureMatcher<RevealStep, RevealStepKind>(is(stepKind), "isA", "stepKind") {
184:
185:                         @Override
186:                         protected RevealStepKind featureValueOf(RevealStep actual) {
187:                                 return actual.getType();
188:                         }
189:                 };
190:         }
191:
192:         @SafeVarargs
193:         public static <T> Matcher<List<? super T>> isListOf(T... items) {
194:                 return is(Arrays.asList(items));
195:         }
196:
197:         public static Runnable pass() {
198:                 return EMFFormsRevealServiceFixture::pass;
199:         }
200:
201:         //
202:         // Nested types
203:         //
204:
205:         public static class TestProvider implements EMFFormsRevealProvider {
206:
207:                 private final Double bid;
208:
209:                 /**
210:                  * Initializes me.
211:                  */
212:                 public TestProvider() {
213:                         this(1.0);
214:                 }
215:
216:                 /**
217:                  * Initializes me.
218:                  */
219:                 public TestProvider(Double bid) {
220:                         super();
221:
222:                         this.bid = bid;
223:                 }
224:
225:                 @Bid
226:                 public Double bid() {
227:                         return bid;
228:                 }
229:
230:         }
231:
232: }