Skip to content

Package: EMFFormsScopedServicesFactoryImpl_ITest

EMFFormsScopedServicesFactoryImpl_ITest

nameinstructionbranchcomplexitylinemethod
EMFFormsScopedServicesFactoryImpl_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: 78
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
setUpBeforeClass()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testServiceType()
M: 0 C: 27
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) 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: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.scoped;
15:
16: import static org.junit.Assert.assertTrue;
17: import static org.mockito.Matchers.any;
18: import static org.mockito.Mockito.atLeastOnce;
19: import static org.mockito.Mockito.doReturn;
20: import static org.mockito.Mockito.mock;
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.emfforms.spi.core.services.databinding.DatabindingFailedException;
28: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext;
29: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceFactory;
30: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceManager;
31: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServicePolicy;
32: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceScope;
33: import org.junit.After;
34: import org.junit.Before;
35: import org.junit.BeforeClass;
36: import org.junit.Test;
37: import org.osgi.framework.BundleContext;
38: import org.osgi.framework.FrameworkUtil;
39: import org.osgi.framework.ServiceReference;
40:
41: public class EMFFormsScopedServicesFactoryImpl_ITest {
42:
43:         private static BundleContext bundleContext;
44:         private EMFFormsViewServiceManager service;
45:         private ServiceReference<EMFFormsViewServiceManager> serviceReference;
46:         private EMFFormsViewServiceFactory<?> scopedServiceProvider;
47:
48:         @BeforeClass
49:         public static void setUpBeforeClass() {
50:                 bundleContext = FrameworkUtil.getBundle(EMFFormsScopedServicesFactoryImpl_ITest.class)
51:                         .getBundleContext();
52:         }
53:
54:         @Before
55:         public void setUp() throws DatabindingFailedException {
56:                 final Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
57:                 dictionary.put("service.ranking", 50); //$NON-NLS-1$
58:                 scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
59:                 doReturn(Object.class).when(scopedServiceProvider).getType();
60:                 doReturn(mock(Object.class)).when(scopedServiceProvider).createService(any(EMFFormsViewContext.class));
61:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
62:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
63:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
64:
65:                 bundleContext.registerService(EMFFormsViewServiceFactory.class, scopedServiceProvider, dictionary);
66:                 serviceReference = bundleContext.getServiceReference(EMFFormsViewServiceManager.class);
67:                 service = bundleContext.getService(serviceReference);
68:         }
69:
70:         @After
71:         public void tearDown() {
72:                 bundleContext.ungetService(serviceReference);
73:         }
74:
75:         @Test
76:         public void testServiceType() throws DatabindingFailedException {
77:                 assertTrue(EMFFormsViewServiceManagerImpl.class.isInstance(service));
78:                 verify(scopedServiceProvider, atLeastOnce()).getPolicy();
79:                 verify(scopedServiceProvider, atLeastOnce()).getScope();
80:                 verify(scopedServiceProvider, atLeastOnce()).getPriority();
81:                 // verify(scopedServiceProvider, atLeastOnce()).getType();
82:
83:         }
84:
85: }