Skip to content

Package: FeatureSegmentExpander_Test

FeatureSegmentExpander_Test

nameinstructionbranchcomplexitylinemethod
FeatureSegmentExpander_Test()
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%
setUp()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testIsApplicable()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testIsApplicableNull()
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIsApplicableWrongSegmentType()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testPrepareDomainObjectBothNull()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testPrepareDomainObjectChildNotPresent()
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
testPrepareDomainObjectChildNotPresentAbstractReference()
M: 7 C: 13
65%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 5
71%
M: 0 C: 1
100%
testPrepareDomainObjectChildPresent()
M: 0 C: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
testPrepareDomainObjectChildPresentAbstractReference()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testPrepareDomainObjectDomainObjectNull()
M: 7 C: 3
30%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 2
50%
M: 0 C: 1
100%
testPrepareDomainObjectEAttribute()
M: 7 C: 13
65%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 5
71%
M: 0 C: 1
100%
testPrepareDomainObjectNullReference()
M: 7 C: 6
46%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 3
60%
M: 0 C: 1
100%
testPrepareDomainObjectSegmentNull()
M: 7 C: 3
30%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
testPrepareDomainObjectWrongSegmentType()
M: 7 C: 7
50%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 2
50%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.segments.featurepath;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertNotNull;
18: import static org.junit.Assert.assertNull;
19: import static org.junit.Assert.assertTrue;
20: import static org.mockito.Matchers.any;
21: import static org.mockito.Mockito.mock;
22: import static org.mockito.Mockito.verify;
23:
24: import java.util.Optional;
25:
26: import org.eclipse.emf.ecore.EAttribute;
27: import org.eclipse.emf.ecore.EObject;
28: import org.eclipse.emf.ecore.EReference;
29: import org.eclipse.emf.ecore.EcoreFactory;
30: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
31: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
32: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
33: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.A;
34: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
35: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
36: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
37: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
38: import org.eclipse.emfforms.spi.common.report.AbstractReport;
39: import org.eclipse.emfforms.spi.common.report.ReportService;
40: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsDMRSegmentExpander;
41: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsExpandingFailedException;
42: import org.junit.Before;
43: import org.junit.Test;
44:
45: /**
46: * JUnit tests for {@link FeatureSegmentExpander}.
47: *
48: * @author Lucas Koehler
49: *
50: */
51: public class FeatureSegmentExpander_Test {
52:
53:         private FeatureSegmentExpander expander;
54:         private ReportService reportService;
55:
56:         /**
57:          * @throws java.lang.Exception
58:          */
59:         @Before
60:         public void setUp() throws Exception {
61:                 expander = new FeatureSegmentExpander();
62:                 reportService = mock(ReportService.class);
63:                 expander.setReportService(reportService);
64:         }
65:
66:         @Test
67:         public void testPrepareDomainObjectChildPresent() throws EMFFormsExpandingFailedException {
68:                 final B domainObject = TestFactory.eINSTANCE.createB();
69:                 final C child = TestFactory.eINSTANCE.createC();
70:                 domainObject.setC(child);
71:
72:                 final VFeatureDomainModelReferenceSegment featureSegment = VViewFactory.eINSTANCE
73:                         .createFeatureDomainModelReferenceSegment();
74:                 final EReference reference = TestPackage.eINSTANCE.getB_C();
75:                 featureSegment.setDomainModelFeature(reference.getName());
76:
77:                 final Optional<EObject> result = expander.prepareDomainObject(featureSegment, domainObject);
78:
79:                 assertEquals(child, domainObject.getC());
80:                 assertTrue(result.isPresent());
81:                 assertEquals(child, result.get());
82:         }
83:
84:         @Test
85:         public void testPrepareDomainObjectChildNotPresent() throws EMFFormsExpandingFailedException {
86:                 final B domainObject = TestFactory.eINSTANCE.createB();
87:
88:                 final VFeatureDomainModelReferenceSegment featureSegment = VViewFactory.eINSTANCE
89:                         .createFeatureDomainModelReferenceSegment();
90:                 final EReference reference = TestPackage.eINSTANCE.getB_C();
91:                 featureSegment.setDomainModelFeature(reference.getName());
92:
93:                 assertNull(domainObject.getC());
94:                 final Optional<EObject> result = expander.prepareDomainObject(featureSegment, domainObject);
95:
96:                 assertNotNull(domainObject.getC());
97:                 assertTrue(result.isPresent());
98:                 assertTrue(C.class.isInstance(result.get()));
99:         }
100:
101:         @Test
102:         public void testPrepareDomainObjectChildPresentAbstractReference() throws EMFFormsExpandingFailedException {
103:                 final B domainObject = TestFactory.eINSTANCE.createB();
104:                 final A child = TestFactory.eINSTANCE.createA();
105:                 domainObject.setE(child);
106:
107:                 final VFeatureDomainModelReferenceSegment featureSegment = VViewFactory.eINSTANCE
108:                         .createFeatureDomainModelReferenceSegment();
109:                 final EReference reference = TestPackage.eINSTANCE.getB_E();
110:                 featureSegment.setDomainModelFeature(reference.getName());
111:
112:                 expander.prepareDomainObject(featureSegment, domainObject);
113:
114:                 assertEquals(child, domainObject.getE());
115:         }
116:
117:         @Test(expected = IllegalArgumentException.class)
118:         public void testPrepareDomainObjectDomainObjectNull() throws EMFFormsExpandingFailedException {
119:                 final VFeatureDomainModelReferenceSegment featureSegment = VViewFactory.eINSTANCE
120:                         .createFeatureDomainModelReferenceSegment();
121:                 expander.prepareDomainObject(featureSegment, null);
122:         }
123:
124:         @Test(expected = IllegalArgumentException.class)
125:         public void testPrepareDomainObjectSegmentNull() throws EMFFormsExpandingFailedException {
126:                 final EObject domainObject = EcoreFactory.eINSTANCE.createEObject();
127:                 expander.prepareDomainObject(null, domainObject);
128:         }
129:
130:         @Test(expected = IllegalArgumentException.class)
131:         public void testPrepareDomainObjectBothNull() throws EMFFormsExpandingFailedException {
132:                 expander.prepareDomainObject(null, null);
133:         }
134:
135:         @Test(expected = IllegalArgumentException.class)
136:         public void testPrepareDomainObjectWrongSegmentType() throws EMFFormsExpandingFailedException {
137:                 final VDomainModelReferenceSegment segment = mock(VDomainModelReferenceSegment.class);
138:                 final EObject domainObject = EcoreFactory.eINSTANCE.createEObject();
139:                 expander.prepareDomainObject(segment, domainObject);
140:         }
141:
142:         @Test(expected = EMFFormsExpandingFailedException.class)
143:         public void testPrepareDomainObjectChildNotPresentAbstractReference() throws EMFFormsExpandingFailedException {
144:                 final B domainObject = TestFactory.eINSTANCE.createB();
145:
146:                 final VFeatureDomainModelReferenceSegment featureSegment = VViewFactory.eINSTANCE
147:                         .createFeatureDomainModelReferenceSegment();
148:                 final EReference reference = TestPackage.eINSTANCE.getB_E();
149:                 featureSegment.setDomainModelFeature(reference.getName());
150:
151:                 expander.prepareDomainObject(featureSegment, domainObject);
152:         }
153:
154:         @Test(expected = EMFFormsExpandingFailedException.class)
155:         public void testPrepareDomainObjectEAttribute() throws EMFFormsExpandingFailedException {
156:                 final EObject domainObject = TestFactory.eINSTANCE.createD();
157:
158:                 final VFeatureDomainModelReferenceSegment featureSegment = VViewFactory.eINSTANCE
159:                         .createFeatureDomainModelReferenceSegment();
160:                 final EAttribute attribute = TestPackage.eINSTANCE.getD_X();
161:                 featureSegment.setDomainModelFeature(attribute.getName());
162:
163:                 expander.prepareDomainObject(featureSegment, domainObject);
164:         }
165:
166:         @Test(expected = EMFFormsExpandingFailedException.class)
167:         public void testPrepareDomainObjectNullReference() throws EMFFormsExpandingFailedException {
168:                 final B domainObject = TestFactory.eINSTANCE.createB();
169:
170:                 final VFeatureDomainModelReferenceSegment featureSegment = VViewFactory.eINSTANCE
171:                         .createFeatureDomainModelReferenceSegment();
172:
173:                 expander.prepareDomainObject(featureSegment, domainObject);
174:         }
175:
176:         @Test
177:         public void testIsApplicable() {
178:                 final VFeatureDomainModelReferenceSegment featureSegment = VViewFactory.eINSTANCE
179:                         .createFeatureDomainModelReferenceSegment();
180:                 assertEquals(1d, expander.isApplicable(featureSegment), 0d);
181:         }
182:
183:         @Test
184:         public void testIsApplicableWrongSegmentType() {
185:                 final VDomainModelReferenceSegment segment = mock(VDomainModelReferenceSegment.class);
186:                 assertEquals(EMFFormsDMRSegmentExpander.NOT_APPLICABLE, expander.isApplicable(segment), 0d);
187:         }
188:
189:         @Test
190:         public void testIsApplicableNull() {
191:                 assertEquals(EMFFormsDMRSegmentExpander.NOT_APPLICABLE, expander.isApplicable(null), 0d);
192:                 verify(reportService).report(any(AbstractReport.class));
193:         }
194: }