Skip to content

Package: EMFFormsViewServiceManagerImpl_Test

EMFFormsViewServiceManagerImpl_Test

nameinstructionbranchcomplexitylinemethod
EMFFormsViewServiceManagerImpl_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: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testCreateGlobalImmediateService_nonNull()
M: 0 C: 49
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testCreateGlobalImmediateService_notExisting()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testCreateGlobalImmediateService_null()
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testCreateGlobalLazyService_nonNull()
M: 0 C: 49
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testCreateGlobalLazyService_notExisting()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testCreateGlobalLazyService_null()
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testCreateLocalImmediateService_nonNull()
M: 0 C: 49
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testCreateLocalImmediateService_notExisting()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testCreateLocalImmediateService_null()
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testCreateLocalLazyService_nonNull()
M: 0 C: 49
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testCreateLocalLazyService_notExisting()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testCreateLocalLazyService_null()
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
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: * eugen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.scoped;
15:
16: import static org.junit.Assert.assertFalse;
17: import static org.junit.Assert.assertTrue;
18: import static org.mockito.Matchers.any;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.when;
21:
22: import org.eclipse.emf.ecore.EClass;
23: import org.eclipse.emf.ecore.EcoreFactory;
24: import org.eclipse.emfforms.common.Optional;
25: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext;
26: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceFactory;
27: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServicePolicy;
28: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceScope;
29: import org.junit.Before;
30: import org.junit.Test;
31:
32: /**
33: * @author eugen
34: *
35: */
36: public class EMFFormsViewServiceManagerImpl_Test {
37:
38:         private EMFFormsViewServiceManagerImpl serviceManager;
39:
40:         /**
41:          * @throws java.lang.Exception
42:          */
43:         @Before
44:         public void setUp() throws Exception {
45:                 serviceManager = new EMFFormsViewServiceManagerImpl();
46:         }
47:
48:         @SuppressWarnings("unchecked")
49:         @Test
50:         public void testCreateLocalImmediateService_null() {
51:                 final EMFFormsViewServiceFactory<EClass> factory = mock(EMFFormsViewServiceFactory.class);
52:                 when(factory.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
53:                 when(factory.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
54:                 when(factory.getType()).thenReturn(EClass.class);
55:                 when(factory.createService(any(EMFFormsViewContext.class))).thenReturn(null);
56:                 serviceManager.addEMFFormsScopedServiceProvider(factory);
57:                 final Optional<?> service = serviceManager.createLocalImmediateService(EClass.class,
58:                         mock(EMFFormsViewContext.class));
59:                 assertFalse(service.isPresent());
60:         }
61:
62:         @SuppressWarnings("unchecked")
63:         @Test
64:         public void testCreateLocalImmediateService_nonNull() {
65:                 final EMFFormsViewServiceFactory<EClass> factory = mock(EMFFormsViewServiceFactory.class);
66:                 when(factory.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
67:                 when(factory.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
68:                 when(factory.getType()).thenReturn(EClass.class);
69:                 when(factory.createService(any(EMFFormsViewContext.class))).thenReturn(EcoreFactory.eINSTANCE.createEClass());
70:                 serviceManager.addEMFFormsScopedServiceProvider(factory);
71:                 final Optional<?> service = serviceManager.createLocalImmediateService(EClass.class,
72:                         mock(EMFFormsViewContext.class));
73:                 assertTrue(service.isPresent());
74:         }
75:
76:         @Test
77:         public void testCreateLocalImmediateService_notExisting() {
78:                 final Optional<?> service = serviceManager.createLocalImmediateService(EClass.class,
79:                         mock(EMFFormsViewContext.class));
80:                 assertFalse(service.isPresent());
81:         }
82:
83:         @SuppressWarnings("unchecked")
84:         @Test
85:         public void testCreateLocalLazyService_null() {
86:                 final EMFFormsViewServiceFactory<EClass> factory = mock(EMFFormsViewServiceFactory.class);
87:                 when(factory.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
88:                 when(factory.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
89:                 when(factory.getType()).thenReturn(EClass.class);
90:                 when(factory.createService(any(EMFFormsViewContext.class))).thenReturn(null);
91:                 serviceManager.addEMFFormsScopedServiceProvider(factory);
92:                 final Optional<?> service = serviceManager.createLocalLazyService(EClass.class,
93:                         mock(EMFFormsViewContext.class));
94:                 assertFalse(service.isPresent());
95:         }
96:
97:         @SuppressWarnings("unchecked")
98:         @Test
99:         public void testCreateLocalLazyService_nonNull() {
100:                 final EMFFormsViewServiceFactory<EClass> factory = mock(EMFFormsViewServiceFactory.class);
101:                 when(factory.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
102:                 when(factory.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
103:                 when(factory.getType()).thenReturn(EClass.class);
104:                 when(factory.createService(any(EMFFormsViewContext.class))).thenReturn(EcoreFactory.eINSTANCE.createEClass());
105:                 serviceManager.addEMFFormsScopedServiceProvider(factory);
106:                 final Optional<?> service = serviceManager.createLocalLazyService(EClass.class,
107:                         mock(EMFFormsViewContext.class));
108:                 assertTrue(service.isPresent());
109:         }
110:
111:         @Test
112:         public void testCreateLocalLazyService_notExisting() {
113:                 final Optional<?> service = serviceManager.createLocalLazyService(EClass.class,
114:                         mock(EMFFormsViewContext.class));
115:                 assertFalse(service.isPresent());
116:         }
117:
118:         @SuppressWarnings("unchecked")
119:         @Test
120:         public void testCreateGlobalImmediateService_null() {
121:                 final EMFFormsViewServiceFactory<EClass> factory = mock(EMFFormsViewServiceFactory.class);
122:                 when(factory.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
123:                 when(factory.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
124:                 when(factory.getType()).thenReturn(EClass.class);
125:                 when(factory.createService(any(EMFFormsViewContext.class))).thenReturn(null);
126:                 serviceManager.addEMFFormsScopedServiceProvider(factory);
127:                 final Optional<?> service = serviceManager.createGlobalImmediateService(EClass.class,
128:                         mock(EMFFormsViewContext.class));
129:                 assertFalse(service.isPresent());
130:         }
131:
132:         @SuppressWarnings("unchecked")
133:         @Test
134:         public void testCreateGlobalImmediateService_nonNull() {
135:                 final EMFFormsViewServiceFactory<EClass> factory = mock(EMFFormsViewServiceFactory.class);
136:                 when(factory.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
137:                 when(factory.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
138:                 when(factory.getType()).thenReturn(EClass.class);
139:                 when(factory.createService(any(EMFFormsViewContext.class))).thenReturn(EcoreFactory.eINSTANCE.createEClass());
140:                 serviceManager.addEMFFormsScopedServiceProvider(factory);
141:                 final Optional<?> service = serviceManager.createGlobalImmediateService(EClass.class,
142:                         mock(EMFFormsViewContext.class));
143:                 assertTrue(service.isPresent());
144:         }
145:
146:         @Test
147:         public void testCreateGlobalImmediateService_notExisting() {
148:                 final Optional<?> service = serviceManager.createGlobalImmediateService(EClass.class,
149:                         mock(EMFFormsViewContext.class));
150:                 assertFalse(service.isPresent());
151:         }
152:
153:         @SuppressWarnings("unchecked")
154:         @Test
155:         public void testCreateGlobalLazyService_null() {
156:                 final EMFFormsViewServiceFactory<EClass> factory = mock(EMFFormsViewServiceFactory.class);
157:                 when(factory.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
158:                 when(factory.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
159:                 when(factory.getType()).thenReturn(EClass.class);
160:                 when(factory.createService(any(EMFFormsViewContext.class))).thenReturn(null);
161:                 serviceManager.addEMFFormsScopedServiceProvider(factory);
162:                 final Optional<?> service = serviceManager.createGlobalLazyService(EClass.class,
163:                         mock(EMFFormsViewContext.class));
164:                 assertFalse(service.isPresent());
165:         }
166:
167:         @SuppressWarnings("unchecked")
168:         @Test
169:         public void testCreateGlobalLazyService_nonNull() {
170:                 final EMFFormsViewServiceFactory<EClass> factory = mock(EMFFormsViewServiceFactory.class);
171:                 when(factory.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
172:                 when(factory.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
173:                 when(factory.getType()).thenReturn(EClass.class);
174:                 when(factory.createService(any(EMFFormsViewContext.class))).thenReturn(EcoreFactory.eINSTANCE.createEClass());
175:                 serviceManager.addEMFFormsScopedServiceProvider(factory);
176:                 final Optional<?> service = serviceManager.createGlobalLazyService(EClass.class,
177:                         mock(EMFFormsViewContext.class));
178:                 assertTrue(service.isPresent());
179:         }
180:
181:         @Test
182:         public void testCreateGlobalLazyService_notExisting() {
183:                 final Optional<?> service = serviceManager.createGlobalLazyService(EClass.class,
184:                         mock(EMFFormsViewContext.class));
185:                 assertFalse(service.isPresent());
186:         }
187:
188: }