Skip to content

Package: AbstractConditionTest

AbstractConditionTest

nameinstructionbranchcomplexitylinemethod
AbstractConditionTest()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
assertReports(VerificationMode)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createFixture()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createModel()
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%
destroyFixture()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
evaluate(Condition, EObject)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
evaluate(EObject)
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%
evaluateChangedValues(Condition, EObject, Map)
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%
evaluateChangedValues(EObject, Map)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getConditionSettings(Condition, EObject)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getConditionSettings(EObject)
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%
getDomainModelReferences()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDomainModelReferences(Condition)
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%
getFixture()
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%
getModel()
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%
getServices()
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
nameSetting(ENamedElement)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
ungetServices()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017 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.rule.test;
15:
16: import static org.mockito.Matchers.any;
17: import static org.mockito.Mockito.mock;
18: import static org.mockito.Mockito.verify;
19: import static org.mockito.Mockito.verifyNoMoreInteractions;
20:
21: import java.util.Map;
22: import java.util.Set;
23:
24: import org.eclipse.emf.ecore.ENamedElement;
25: import org.eclipse.emf.ecore.EObject;
26: import org.eclipse.emf.ecore.EPackage;
27: import org.eclipse.emf.ecore.EStructuralFeature;
28: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
29: import org.eclipse.emf.ecore.EcoreFactory;
30: import org.eclipse.emf.ecore.EcorePackage;
31: import org.eclipse.emf.ecore.InternalEObject;
32: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
33: import org.eclipse.emf.ecp.view.internal.rule.ConditionServiceManager;
34: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
35: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
36: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
37: import org.eclipse.emf.ecp.view.spi.model.VView;
38: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
39: import org.eclipse.emf.ecp.view.spi.rule.model.Condition;
40: import org.eclipse.emfforms.spi.common.report.AbstractReport;
41: import org.eclipse.emfforms.spi.common.report.ReportService;
42: import org.eclipse.emfforms.spi.common.report.ReportServiceConsumer;
43: import org.junit.After;
44: import org.junit.AfterClass;
45: import org.junit.Before;
46: import org.junit.BeforeClass;
47: import org.mockito.verification.VerificationMode;
48:
49: /**
50: * Framework for condition tests.
51: *
52: * @author Christian W. Damus
53: */
54: public abstract class AbstractConditionTest<C extends Condition> {
55:
56:         private static ReportServiceConsumer reportConsumer;
57:         private static ViewModelContext context;
58:         private static ConditionServiceManager manager;
59:
60:         private C fixture;
61:
62:         private EPackage model;
63:
64:         /**
65:          * Initializes me.
66:          */
67:         public AbstractConditionTest() {
68:                 super();
69:         }
70:
71:         //
72:         // Test framework
73:         //
74:
75:         @BeforeClass
76:         public static void getServices() {
77:                 final VView view = VViewFactory.eINSTANCE.createView();
78:                 final EObject model = EcoreFactory.eINSTANCE.createEObject();
79:
80:                 context = ViewModelContextFactory.INSTANCE.createViewModelContext(view, model);
81:                 manager = context.getService(ConditionServiceManager.class);
82:
83:                 reportConsumer = mock(ReportServiceConsumer.class);
84:                 context.getService(ReportService.class).addConsumer(reportConsumer);
85:         }
86:
87:         @Before
88:         public void createFixture() {
89:                 fixture = createCondition();
90:                 model = createModel();
91:         }
92:
93:         @After
94:         public void destroyFixture() {
95:                 model = null;
96:                 fixture = null;
97:
98:                 verifyNoMoreInteractions(reportConsumer);
99:         }
100:
101:         protected void assertReports(VerificationMode assertion) {
102:                 verify(reportConsumer, assertion).reported(any(AbstractReport.class));
103:         }
104:
105:         @AfterClass
106:         public static void ungetServices() {
107:                 context.getService(ReportService.class).removeConsumer(reportConsumer);
108:
109:                 manager = null;
110:
111:                 context.dispose();
112:                 context = null;
113:         }
114:
115:         protected abstract C createCondition();
116:
117:         protected final C getFixture() {
118:                 return fixture;
119:         }
120:
121:         protected EPackage createModel() {
122:                 return EcoreFactory.eINSTANCE.createEPackage();
123:         }
124:
125:         protected final EPackage getModel() {
126:                 return model;
127:         }
128:
129:         protected Set<UniqueSetting> getConditionSettings(EObject domainModel) {
130:                 return getConditionSettings(getFixture(), domainModel);
131:         }
132:
133:         protected Set<UniqueSetting> getConditionSettings(Condition condition, EObject domainModel) {
134:                 return manager.getConditionSettings(condition, domainModel);
135:         }
136:
137:         protected boolean evaluate(EObject domainModel) {
138:                 return evaluate(getFixture(), domainModel);
139:         }
140:
141:         protected boolean evaluate(Condition condition, EObject domainModel) {
142:                 return manager.evaluate(condition, domainModel);
143:         }
144:
145:         protected boolean evaluateChangedValues(EObject domainModel, Map<Setting, Object> possibleNewValues) {
146:                 return evaluateChangedValues(getFixture(), domainModel, possibleNewValues);
147:         }
148:
149:         protected boolean evaluateChangedValues(Condition condition, EObject domainModel,
150:                 Map<Setting, Object> possibleNewValues) {
151:                 return manager.evaluateChangedValues(condition, domainModel, possibleNewValues);
152:         }
153:
154:         protected Set<VDomainModelReference> getDomainModelReferences() {
155:                 return getDomainModelReferences(getFixture());
156:         }
157:
158:         protected Set<VDomainModelReference> getDomainModelReferences(Condition condition) {
159:                 return manager.getDomainModelReferences(condition);
160:         }
161:
162:         protected EStructuralFeature.Setting nameSetting(ENamedElement element) {
163:                 return ((InternalEObject) element).eSetting(EcorePackage.Literals.ENAMED_ELEMENT__NAME);
164:         }
165: }