Skip to content

Package: EMFFormsLabelProviderImpl_ITest

EMFFormsLabelProviderImpl_ITest

nameinstructionbranchcomplexitylinemethod
EMFFormsLabelProviderImpl_ITest()
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: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
setUpBeforeClass()
M: 0 C: 123
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 28
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
tearDownAfterClass()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testServiceUsageDescriptionOneParam()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testServiceUsageDescriptionTwoParam()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testServiceUsageDisplayNameOneParam()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testServiceUsageDisplayNameTwoParam()
M: 0 C: 31
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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.label;
15:
16: import static org.mockito.Matchers.any;
17: import static org.mockito.Matchers.isNull;
18: import static org.mockito.Matchers.same;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.reset;
21: import static org.mockito.Mockito.verify;
22: import static org.mockito.Mockito.when;
23:
24: import java.util.Dictionary;
25: import java.util.Hashtable;
26:
27: import org.eclipse.emf.databinding.IEMFValueProperty;
28: import org.eclipse.emf.ecore.EClass;
29: import org.eclipse.emf.ecore.EObject;
30: import org.eclipse.emf.ecore.EStructuralFeature;
31: import org.eclipse.emf.ecp.test.common.DefaultRealm;
32: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
33: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
34: import org.eclipse.emfforms.spi.common.BundleResolver;
35: import org.eclipse.emfforms.spi.common.BundleResolver.NoBundleFoundException;
36: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
37: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
38: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
39: import org.eclipse.emfforms.spi.core.services.label.NoLabelFoundException;
40: import org.eclipse.emfforms.spi.localization.EMFFormsLocalizationService;
41: import org.junit.After;
42: import org.junit.AfterClass;
43: import org.junit.Before;
44: import org.junit.BeforeClass;
45: import org.junit.Test;
46: import org.osgi.framework.Bundle;
47: import org.osgi.framework.BundleContext;
48: import org.osgi.framework.FrameworkUtil;
49: import org.osgi.framework.ServiceReference;
50: import org.osgi.framework.ServiceRegistration;
51:
52: /**
53: * JUnit integration test that tests that {@link EMFFormsLabelProviderImpl} uses the correct services.
54: *
55: * @author Lucas Koehler
56: *
57: */
58: public class EMFFormsLabelProviderImpl_ITest {
59:
60:         private static BundleContext bundleContext;
61:         private static EMFFormsDatabindingEMF databindingService;
62:         private static ServiceRegistration<EMFFormsDatabindingEMF> databindingRegisterService;
63:         private static EMFFormsLabelProviderImpl labelProvider;
64:         private static ServiceReference<EMFFormsLabelProvider> serviceReference;
65:         private static EMFFormsLocalizationService localizationService;
66:         private static ServiceRegistration<EMFFormsLocalizationService> localizationServiceReference;
67:         private static IEMFValueProperty valueProperty;
68:         private DefaultRealm realm;
69:
70:         /**
71:          * Set up that is executed before every test case.
72:          * Registers a databinding and an emf specific service.
73:          * Mocks various objects for the tests.
74:          *
75:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
76:          * defines the throw in its interface.
77:          * @throws NoBundleFoundException
78:          */
79:         @BeforeClass
80:         public static void setUpBeforeClass() throws DatabindingFailedException, NoBundleFoundException {
81:                 bundleContext = FrameworkUtil.getBundle(EMFFormsLabelProviderImpl_Test.class).getBundleContext();
82:
83:                 final Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
84:                 dictionary.put("service.ranking", 5); //$NON-NLS-1$
85:
86:                 databindingService = mock(EMFFormsDatabindingEMF.class);
87:                 databindingRegisterService = bundleContext.registerService(EMFFormsDatabindingEMF.class, databindingService,
88:                         dictionary);
89:
90:                 localizationService = mock(EMFFormsLocalizationService.class);
91:                 localizationServiceReference = bundleContext.registerService(EMFFormsLocalizationService.class,
92:                         localizationService,
93:                         dictionary);
94:
95:                 final EClass eContainingClass = TestPackage.eINSTANCE.getD();
96:                 final EStructuralFeature structuralFeature = mock(EStructuralFeature.class);
97:                 when(structuralFeature.getEContainingClass()).thenReturn(eContainingClass);
98:                 when(structuralFeature.getName()).thenReturn("My Feature"); //$NON-NLS-1$
99:                 valueProperty = mock(IEMFValueProperty.class);
100:                 when(valueProperty.getValueType()).thenReturn(structuralFeature);
101:                 final EObject eObject = mock(EObject.class);
102:                 final EClass eClass = mock(EClass.class);
103:                 when(eClass.getName()).thenReturn("My EClass"); //$NON-NLS-1$
104:                 when(eObject.eClass()).thenReturn(eClass);
105:
106:                 final Bundle bundle = mock(Bundle.class);
107:                 final BundleResolver bundleResolver = mock(BundleResolver.class);
108:                 when(bundleResolver.getEditBundle(eContainingClass)).thenReturn(bundle);
109:
110:                 when(localizationService.getString(same(bundle), any(String.class))).thenReturn("Test"); //$NON-NLS-1$
111:
112:                 serviceReference = bundleContext.getServiceReference(EMFFormsLabelProvider.class);
113:                 labelProvider = (EMFFormsLabelProviderImpl) bundleContext.getService(serviceReference);
114:                 labelProvider.setBundleResolver(bundleResolver);
115:         }
116:
117:         /**
118:          * Resets and newly configures the services for every test.
119:          *
120:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
121:          * defines the throw in its interface.
122:          */
123:         @Before
124:         public void setUp() throws DatabindingFailedException {
125:                 reset(databindingService);
126:                 when(databindingService.getValueProperty(any(VDomainModelReference.class), any(EObject.class))).thenReturn(
127:                         valueProperty);
128:                 when(databindingService.getValueProperty(any(VDomainModelReference.class), any(EClass.class))).thenReturn(
129:                         valueProperty);
130:                 realm = new DefaultRealm();
131:         }
132:
133:         /**
134:          * Dispose the realm.
135:          */
136:         @After
137:         public void tearDown() {
138:                 realm.dispose();
139:         }
140:
141:         /**
142:          * Unregisters the services after every test.
143:          */
144:         @AfterClass
145:         public static void tearDownAfterClass() {
146:                 databindingRegisterService.unregister();
147:                 localizationServiceReference.unregister();
148:                 bundleContext.ungetService(serviceReference);
149:         }
150:
151:         /**
152:          * Tests that {@link EMFFormsLabelProviderImpl#getDisplayName(VDomainModelReference)} uses the databinding and emf
153:          * specific services.
154:          *
155:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
156:          * defines the throw in its interface.
157:          * @throws NoLabelFoundException
158:          */
159:         @Test
160:         public void testServiceUsageDisplayNameOneParam() throws DatabindingFailedException, NoLabelFoundException {
161:                 final VDomainModelReference domainModelReference = mock(VDomainModelReference.class);
162:                 labelProvider.getDisplayName(domainModelReference);
163:
164:                 verify(databindingService).getValueProperty(same(domainModelReference), isNull(EObject.class));
165:         }
166:
167:         /**
168:          * Tests that {@link EMFFormsLabelProviderImpl#getDescription(VDomainModelReference)} uses the databinding and emf
169:          * specific services.
170:          *
171:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
172:          * defines the throw in its interface.
173:          * @throws NoLabelFoundException
174:          */
175:         @Test
176:         public void testServiceUsageDescriptionOneParam() throws DatabindingFailedException, NoLabelFoundException {
177:                 final VDomainModelReference domainModelReference = mock(VDomainModelReference.class);
178:                 labelProvider.getDescription(domainModelReference);
179:
180:                 verify(databindingService).getValueProperty(same(domainModelReference), isNull(EObject.class));
181:         }
182:
183:         /**
184:          * Tests that {@link EMFFormsLabelProviderImpl#getDisplayName(VDomainModelReference, EObject)} uses the databinding
185:          * and emf specific services.
186:          *
187:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
188:          * defines the throw in its interface.
189:          * @throws NoLabelFoundException
190:          */
191:         @Test
192:         public void testServiceUsageDisplayNameTwoParam() throws DatabindingFailedException, NoLabelFoundException {
193:                 final VDomainModelReference domainModelReference = mock(VDomainModelReference.class);
194:                 final EObject eObject = mock(EObject.class);
195:                 final EClass eClass = mock(EClass.class);
196:                 when(eObject.eClass()).thenReturn(eClass);
197:                 labelProvider.getDisplayName(domainModelReference, eObject);
198:
199:                 verify(databindingService).getValueProperty(domainModelReference, eClass);
200:         }
201:
202:         /**
203:          * Tests that {@link EMFFormsLabelProviderImpl#getDescription(VDomainModelReference, EObject)} uses the databinding
204:          * and emf specific services.
205:          *
206:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
207:          * defines the throw in its interface.
208:          * @throws NoLabelFoundException
209:          */
210:         @Test
211:         public void testServiceUsageDescriptionTwoParam() throws DatabindingFailedException, NoLabelFoundException {
212:                 final VDomainModelReference domainModelReference = mock(VDomainModelReference.class);
213:                 final EObject eObject = mock(EObject.class);
214:                 labelProvider.getDescription(domainModelReference, eObject);
215:
216:                 verify(databindingService).getValueProperty(domainModelReference, eObject);
217:         }
218: }