Skip to content

Package: MultiSegmentExpander_Test

MultiSegmentExpander_Test

nameinstructionbranchcomplexitylinemethod
MultiSegmentExpander_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: 26
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testIsApplicable()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIsApplicableNull()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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%
testNeedsToExpandLastSegment()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testPrepareDomainObjectExpandAllChildObjectsAndChildDMRs()
M: 0 C: 83
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 20
100%
M: 0 C: 1
100%
testPrepareDomainObjectMultiAttribute()
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%
testPrepareDomainObjectNullDomainObject()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testPrepareDomainObjectNullSegment()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testPrepareDomainObjectSingleAttribute()
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%
testPrepareDomainObjectSingleReference()
M: 7 C: 29
81%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 9
82%
M: 0 C: 1
100%
testPrepareDomainObjectWrongSegmentType()
M: 11 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-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.multi;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertTrue;
19: import static org.mockito.Matchers.any;
20: import static org.mockito.Mockito.mock;
21: import static org.mockito.Mockito.verify;
22:
23: import java.util.Optional;
24:
25: import org.eclipse.emf.ecore.EAttribute;
26: import org.eclipse.emf.ecore.EObject;
27: import org.eclipse.emf.ecore.EReference;
28: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
29: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
30: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
31: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
32: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
33: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.D;
34: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
35: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
36: import org.eclipse.emfforms.spi.common.report.AbstractReport;
37: import org.eclipse.emfforms.spi.common.report.ReportService;
38: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsDMRSegmentExpander;
39: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsDomainExpander;
40: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsExpandingFailedException;
41: import org.eclipse.emfforms.view.spi.multisegment.model.VMultiDomainModelReferenceSegment;
42: import org.eclipse.emfforms.view.spi.multisegment.model.VMultisegmentFactory;
43: import org.junit.Before;
44: import org.junit.Test;
45:
46: /**
47: * JUnit tests for {@link MultiSegmentExpander}.
48: *
49: * @author Lucas Koehler
50: *
51: */
52: public class MultiSegmentExpander_Test {
53:
54:         private MultiSegmentExpander multiExpander;
55:         private ReportService reportService;
56:         private EMFFormsDomainExpander domainExpander;
57:
58:         /**
59:          * @throws java.lang.Exception
60:          */
61:         @Before
62:         public void setUp() throws Exception {
63:                 multiExpander = new MultiSegmentExpander();
64:                 reportService = mock(ReportService.class);
65:                 multiExpander.setReportService(reportService);
66:                 domainExpander = mock(EMFFormsDomainExpander.class);
67:                 multiExpander.setEMFFormsDomainExpander(domainExpander);
68:         }
69:
70:         @Test
71:         public void testPrepareDomainObjectExpandAllChildObjectsAndChildDMRs() throws EMFFormsExpandingFailedException {
72:                 final B domain = TestFactory.eINSTANCE.createB();
73:                 final C child1 = TestFactory.eINSTANCE.createC();
74:                 final C child2 = TestFactory.eINSTANCE.createC();
75:                 domain.getCList().add(child1);
76:                 domain.getCList().add(child2);
77:                 final EReference feature = TestPackage.eINSTANCE.getB_CList();
78:                 final VDomainModelReference childDMR1 = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
79:                 final VDomainModelReference childDMR2 = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
80:
81:                 final VMultiDomainModelReferenceSegment multiSegment = VMultisegmentFactory.eINSTANCE
82:                         .createMultiDomainModelReferenceSegment();
83:                 multiSegment.setDomainModelFeature(feature.getName());
84:                 multiSegment.getChildDomainModelReferences().add(childDMR1);
85:                 multiSegment.getChildDomainModelReferences().add(childDMR2);
86:
87:                 final Optional<EObject> result = multiExpander.prepareDomainObject(multiSegment, domain);
88:
89:                 assertFalse(result.isPresent());
90:                 verify(domainExpander).prepareDomainObject(childDMR1, child1);
91:                 verify(domainExpander).prepareDomainObject(childDMR2, child1);
92:                 verify(domainExpander).prepareDomainObject(childDMR1, child2);
93:                 verify(domainExpander).prepareDomainObject(childDMR2, child2);
94:         }
95:
96:         @Test(expected = EMFFormsExpandingFailedException.class)
97:         public void testPrepareDomainObjectSingleReference() throws EMFFormsExpandingFailedException {
98:                 final B domain = TestFactory.eINSTANCE.createB();
99:                 final C child1 = TestFactory.eINSTANCE.createC();
100:                 domain.getCList().add(child1);
101:                 final EReference feature = TestPackage.eINSTANCE.getB_C();
102:                 final VDomainModelReference childDMR1 = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
103:
104:                 final VMultiDomainModelReferenceSegment multiSegment = VMultisegmentFactory.eINSTANCE
105:                         .createMultiDomainModelReferenceSegment();
106:                 multiSegment.setDomainModelFeature(feature.getName());
107:                 multiSegment.getChildDomainModelReferences().add(childDMR1);
108:
109:                 multiExpander.prepareDomainObject(multiSegment, domain);
110:         }
111:
112:         @Test(expected = IllegalArgumentException.class)
113:         public void testPrepareDomainObjectNullSegment() throws EMFFormsExpandingFailedException {
114:                 multiExpander.prepareDomainObject(null, mock(EObject.class));
115:         }
116:
117:         @Test(expected = IllegalArgumentException.class)
118:         public void testPrepareDomainObjectNullDomainObject() throws EMFFormsExpandingFailedException {
119:                 multiExpander.prepareDomainObject(mock(VMultiDomainModelReferenceSegment.class), null);
120:         }
121:
122:         @Test(expected = IllegalArgumentException.class)
123:         public void testPrepareDomainObjectWrongSegmentType() throws EMFFormsExpandingFailedException {
124:                 multiExpander.prepareDomainObject(mock(VFeatureDomainModelReferenceSegment.class), mock(EObject.class));
125:         }
126:
127:         @Test(expected = EMFFormsExpandingFailedException.class)
128:         public void testPrepareDomainObjectSingleAttribute() throws EMFFormsExpandingFailedException {
129:                 final D domain = TestFactory.eINSTANCE.createD();
130:                 final EAttribute feature = TestPackage.eINSTANCE.getD_X();
131:
132:                 final VMultiDomainModelReferenceSegment multiSegment = VMultisegmentFactory.eINSTANCE
133:                         .createMultiDomainModelReferenceSegment();
134:                 multiSegment.setDomainModelFeature(feature.getName());
135:
136:                 multiExpander.prepareDomainObject(multiSegment, domain);
137:         }
138:
139:         @Test(expected = EMFFormsExpandingFailedException.class)
140:         public void testPrepareDomainObjectMultiAttribute() throws EMFFormsExpandingFailedException {
141:                 final D domain = TestFactory.eINSTANCE.createD();
142:                 final EAttribute feature = TestPackage.eINSTANCE.getD_YList();
143:
144:                 final VMultiDomainModelReferenceSegment multiSegment = VMultisegmentFactory.eINSTANCE
145:                         .createMultiDomainModelReferenceSegment();
146:                 multiSegment.setDomainModelFeature(feature.getName());
147:
148:                 multiExpander.prepareDomainObject(multiSegment, domain);
149:         }
150:
151:         @Test
152:         public void testIsApplicable() {
153:                 final double applicable = multiExpander.isApplicable(mock(VMultiDomainModelReferenceSegment.class));
154:                 assertEquals(5d, applicable, 0d);
155:         }
156:
157:         @Test
158:         public void testIsApplicableNull() {
159:                 final double applicable = multiExpander.isApplicable(null);
160:                 assertEquals(EMFFormsDMRSegmentExpander.NOT_APPLICABLE, applicable, 0d);
161:                 verify(reportService).report(any(AbstractReport.class));
162:         }
163:
164:         @Test
165:         public void testIsApplicableWrongSegmentType() {
166:                 final double applicable = multiExpander.isApplicable(mock(VFeatureDomainModelReferenceSegment.class));
167:                 assertEquals(EMFFormsDMRSegmentExpander.NOT_APPLICABLE, applicable, 0d);
168:         }
169:
170:         @Test
171:         public void testNeedsToExpandLastSegment() {
172:                 assertTrue(multiExpander.needsToExpandLastSegment());
173:         }
174:
175: }