Skip to content

Package: FeatureSegmentStructuralChangeTester_Test

FeatureSegmentStructuralChangeTester_Test

nameinstructionbranchcomplexitylinemethod
FeatureSegmentStructuralChangeTester_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%
testIsApplicableNullSegment()
M: 0 C: 18
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: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIsStructureChanged()
M: 0 C: 58
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
testIsStructureChangedAttribute()
M: 0 C: 55
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
testIsStructureChangedTouch()
M: 0 C: 58
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
testIsStructureChangedWrongFeature()
M: 0 C: 61
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testIsStructureChangedWrongNotifier()
M: 0 C: 61
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
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.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: import static org.mockito.Mockito.when;
23:
24: import org.eclipse.emf.common.notify.Notification;
25: import org.eclipse.emf.common.notify.impl.NotificationImpl;
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.EStructuralFeature;
30: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
31: import org.eclipse.emf.ecore.InternalEObject;
32: import org.eclipse.emf.ecp.view.spi.model.ModelChangeNotification;
33: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
34: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
35: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
36: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
37: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
38: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.D;
39: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
40: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
41: import org.eclipse.emfforms.spi.common.report.AbstractReport;
42: import org.eclipse.emfforms.spi.common.report.ReportService;
43: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
44: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsSegmentResolver;
45: import org.eclipse.emfforms.spi.core.services.structuralchange.StructuralChangeSegmentTester;
46: import org.junit.Before;
47: import org.junit.Test;
48:
49: /**
50: * JUnit tests for {@link FeatureSegmentStructuralChangeTester}.
51: *
52: * @author Lucas Koehler
53: *
54: */
55: public class FeatureSegmentStructuralChangeTester_Test {
56:
57:         private FeatureSegmentStructuralChangeTester changeTester;
58:         private ReportService reportService;
59:         private EMFFormsSegmentResolver segmentResolver;
60:
61:         @Before
62:         public void setUp() {
63:                 changeTester = new FeatureSegmentStructuralChangeTester();
64:                 reportService = mock(ReportService.class);
65:                 changeTester.setReportService(reportService);
66:                 segmentResolver = mock(EMFFormsSegmentResolver.class);
67:                 changeTester.setEMFFormsSegmentResolver(segmentResolver);
68:         }
69:
70:         @Test
71:         public void testIsStructureChanged() throws DatabindingFailedException {
72:                 final B domain = TestFactory.eINSTANCE.createB();
73:                 final EReference feature = TestPackage.eINSTANCE.getB_C();
74:                 final C c = TestFactory.eINSTANCE.createC();
75:                 final Setting setting = ((InternalEObject) domain).eSetting(feature);
76:
77:                 final Notification rawNotification = new TestNotification(Notification.SET, null, c, domain, feature);
78:                 final ModelChangeNotification mcn = new ModelChangeNotification(rawNotification);
79:
80:                 final VFeatureDomainModelReferenceSegment segment = VViewFactory.eINSTANCE
81:                         .createFeatureDomainModelReferenceSegment();
82:                 segment.setDomainModelFeature(feature.getName());
83:                 domain.setC(c);
84:                 when(segmentResolver.resolveSegment(segment, domain)).thenReturn(setting);
85:
86:                 final boolean isChanged = changeTester.isStructureChanged(segment, domain, mcn);
87:
88:                 assertTrue(isChanged);
89:         }
90:
91:         @Test
92:         public void testIsStructureChangedTouch() throws DatabindingFailedException {
93:                 final B domain = TestFactory.eINSTANCE.createB();
94:                 final EReference feature = TestPackage.eINSTANCE.getB_C();
95:                 final C c = TestFactory.eINSTANCE.createC();
96:                 final Setting setting = ((InternalEObject) domain).eSetting(feature);
97:
98:                 final Notification rawNotification = new TestNotification(Notification.SET, c, c, domain, feature);
99:                 final ModelChangeNotification mcn = new ModelChangeNotification(rawNotification);
100:
101:                 final VFeatureDomainModelReferenceSegment segment = VViewFactory.eINSTANCE
102:                         .createFeatureDomainModelReferenceSegment();
103:                 segment.setDomainModelFeature(feature.getName());
104:                 domain.setC(c);
105:                 when(segmentResolver.resolveSegment(segment, domain)).thenReturn(setting);
106:
107:                 final boolean isChanged = changeTester.isStructureChanged(segment, domain, mcn);
108:
109:                 assertFalse(isChanged);
110:         }
111:
112:         @Test
113:         public void testIsStructureChangedAttribute() throws DatabindingFailedException {
114:                 final D domain = TestFactory.eINSTANCE.createD();
115:                 final EAttribute feature = TestPackage.eINSTANCE.getD_X();
116:                 final Setting setting = ((InternalEObject) domain).eSetting(feature);
117:
118:                 final Notification rawNotification = new TestNotification(Notification.SET, null, "Test", domain, feature); //$NON-NLS-1$
119:                 final ModelChangeNotification mcn = new ModelChangeNotification(rawNotification);
120:
121:                 final VFeatureDomainModelReferenceSegment segment = VViewFactory.eINSTANCE
122:                         .createFeatureDomainModelReferenceSegment();
123:                 segment.setDomainModelFeature(feature.getName());
124:                 domain.setX("Test"); //$NON-NLS-1$
125:                 when(segmentResolver.resolveSegment(segment, domain)).thenReturn(setting);
126:
127:                 final boolean isChanged = changeTester.isStructureChanged(segment, domain, mcn);
128:
129:                 assertFalse(isChanged);
130:         }
131:
132:         @Test
133:         public void testIsStructureChangedWrongNotifier() throws DatabindingFailedException {
134:                 final B domain = TestFactory.eINSTANCE.createB();
135:                 final B wrongNotifier = TestFactory.eINSTANCE.createB();
136:                 final EReference feature = TestPackage.eINSTANCE.getB_C();
137:                 final C c = TestFactory.eINSTANCE.createC();
138:                 final Setting setting = ((InternalEObject) domain).eSetting(feature);
139:
140:                 final Notification rawNotification = new TestNotification(Notification.SET, null, c, wrongNotifier, feature);
141:                 final ModelChangeNotification mcn = new ModelChangeNotification(rawNotification);
142:
143:                 final VFeatureDomainModelReferenceSegment segment = VViewFactory.eINSTANCE
144:                         .createFeatureDomainModelReferenceSegment();
145:                 segment.setDomainModelFeature(feature.getName());
146:                 domain.setC(c);
147:                 when(segmentResolver.resolveSegment(segment, domain)).thenReturn(setting);
148:
149:                 final boolean isChanged = changeTester.isStructureChanged(segment, domain, mcn);
150:
151:                 assertFalse(isChanged);
152:         }
153:
154:         @Test
155:         public void testIsStructureChangedWrongFeature() throws DatabindingFailedException {
156:                 final B domain = TestFactory.eINSTANCE.createB();
157:                 final EReference segmentFeature = TestPackage.eINSTANCE.getB_C();
158:                 final EReference notificationFeature = TestPackage.eINSTANCE.getB_E();
159:                 final C c = TestFactory.eINSTANCE.createC();
160:                 final Setting setting = ((InternalEObject) domain).eSetting(segmentFeature);
161:
162:                 final Notification rawNotification = new TestNotification(Notification.SET, null, c, domain,
163:                         notificationFeature);
164:                 final ModelChangeNotification mcn = new ModelChangeNotification(rawNotification);
165:
166:                 final VFeatureDomainModelReferenceSegment segment = VViewFactory.eINSTANCE
167:                         .createFeatureDomainModelReferenceSegment();
168:                 segment.setDomainModelFeature(segmentFeature.getName());
169:                 domain.setC(c);
170:                 when(segmentResolver.resolveSegment(segment, domain)).thenReturn(setting);
171:
172:                 final boolean isChanged = changeTester.isStructureChanged(segment, domain, mcn);
173:
174:                 assertFalse(isChanged);
175:         }
176:
177:         @Test
178:         public void testIsApplicable() {
179:                 final double score = changeTester.isApplicable(mock(VFeatureDomainModelReferenceSegment.class));
180:                 assertEquals(1d, score, 0d);
181:         }
182:
183:         @Test
184:         public void testIsApplicableNullSegment() {
185:                 final double score = changeTester.isApplicable(null);
186:                 assertEquals(StructuralChangeSegmentTester.NOT_APPLICABLE, score, 0d);
187:                 verify(reportService).report(any(AbstractReport.class));
188:         }
189:
190:         @Test
191:         public void testIsApplicableWrongSegmentType() {
192:                 final double score = changeTester.isApplicable(mock(VDomainModelReferenceSegment.class));
193:                 assertEquals(StructuralChangeSegmentTester.NOT_APPLICABLE, score, 0d);
194:         }
195:
196:         private class TestNotification extends NotificationImpl {
197:                 private final EObject notifier;
198:                 private final EStructuralFeature feature;
199:
200:                 TestNotification(int eventType, Object oldValue, Object newValue, EObject notifier,
201:                         EStructuralFeature feature) {
202:                         super(eventType, oldValue, newValue);
203:                         this.notifier = notifier;
204:                         this.feature = feature;
205:                 }
206:
207:                 @Override
208:                 public Object getNotifier() {
209:                         return notifier;
210:                 }
211:
212:                 @Override
213:                 public Object getFeature() {
214:                         return feature;
215:                 }
216:         }
217: }