Skip to content

Package: EMFFormsScopedServicesFactoryImpl_Test

EMFFormsScopedServicesFactoryImpl_Test

nameinstructionbranchcomplexitylinemethod
EMFFormsScopedServicesFactoryImpl_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%
before()
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%
testAddedToGlobalImmediate()
M: 0 C: 83
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testAddedToGlobalLazy()
M: 0 C: 82
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testAddedToLocalImmediate()
M: 0 C: 82
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testAddedToLocalLazy()
M: 0 C: 83
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testAddedToLocalLazyPriorityFirstHighThenLow()
M: 0 C: 109
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
testAddedToLocalLazyPriorityFirstLowThenHigh()
M: 0 C: 107
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
testCreateGlobalImmediateServicePassesContext()
M: 0 C: 63
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
testCreateGlobalLazyServicePassesContext()
M: 0 C: 63
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
testCreateLocalImmediateServicePassesContext()
M: 0 C: 63
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
testCreateLocalLazyServicePassesContext()
M: 0 C: 63
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
testGetAllGlobalImmediateServiceTypes()
M: 0 C: 62
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
testGetAllGlobalImmediateServiceTypesAreSorted()
M: 0 C: 113
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 21
100%
M: 0 C: 1
100%
testGetAllGlobalImmediateServiceTypesNoRegistered()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testGetAllLocalImmediateServiceTypes()
M: 0 C: 62
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
testGetAllLocalImmediateServiceTypesAreSorted()
M: 0 C: 113
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 21
100%
M: 0 C: 1
100%
testGetAllLocalImmediateServiceTypesNoRegistered()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testRemoveFromGlobalImmediate()
M: 0 C: 86
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
testRemoveFromGlobalLazy()
M: 0 C: 86
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
testRemoveFromLocalImmediate()
M: 0 C: 86
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
testRemoveFromLocalLazy()
M: 0 C: 86
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 17
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.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertNotNull;
19: import static org.junit.Assert.assertSame;
20: import static org.junit.Assert.assertTrue;
21: import static org.mockito.Matchers.any;
22: import static org.mockito.Mockito.doReturn;
23: import static org.mockito.Mockito.mock;
24: import static org.mockito.Mockito.verify;
25: import static org.mockito.Mockito.when;
26:
27: import java.util.Iterator;
28: import java.util.Set;
29:
30: import org.eclipse.emfforms.common.Optional;
31: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext;
32: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceFactory;
33: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServicePolicy;
34: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceScope;
35: import org.junit.Before;
36: import org.junit.Test;
37:
38: public class EMFFormsScopedServicesFactoryImpl_Test {
39:
40:         private EMFFormsViewServiceManagerImpl emfFormsScopedServicesFactory;
41:
42:         @Before
43:         public void before() {
44:                 emfFormsScopedServicesFactory = new EMFFormsViewServiceManagerImpl();
45:         }
46:
47:         @Test
48:         public void testAddedToLocalLazy() {
49:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
50:                 doReturn(Object.class).when(scopedServiceProvider).getType();
51:                 doReturn(mock(Object.class)).when(scopedServiceProvider).createService(any(EMFFormsViewContext.class));
52:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
53:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
54:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
55:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
56:                 assertTrue(emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class))
57:                         .isPresent());
58:                 assertFalse(emfFormsScopedServicesFactory
59:                         .createLocalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
60:                 assertFalse(emfFormsScopedServicesFactory
61:                         .createGlobalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
62:                 assertFalse(emfFormsScopedServicesFactory.createGlobalLazyService(Object.class, mock(EMFFormsViewContext.class))
63:                         .isPresent());
64:         }
65:
66:         @Test
67:         public void testAddedToGlobalImmediate() {
68:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
69:                 doReturn(Object.class).when(scopedServiceProvider).getType();
70:                 doReturn(mock(Object.class)).when(scopedServiceProvider).createService(any(EMFFormsViewContext.class));
71:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
72:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
73:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
74:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
75:                 assertFalse(emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class))
76:                         .isPresent());
77:                 assertFalse(emfFormsScopedServicesFactory
78:                         .createLocalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
79:                 assertTrue(emfFormsScopedServicesFactory
80:                         .createGlobalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
81:                 assertFalse(emfFormsScopedServicesFactory.createGlobalLazyService(Object.class, mock(EMFFormsViewContext.class))
82:                         .isPresent());
83:         }
84:
85:         @Test
86:         public void testAddedToGlobalLazy() {
87:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
88:                 doReturn(Object.class).when(scopedServiceProvider).getType();
89:                 doReturn(Object.class).when(scopedServiceProvider).createService(any(EMFFormsViewContext.class));
90:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
91:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
92:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
93:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
94:                 assertFalse(emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class))
95:                         .isPresent());
96:                 assertFalse(emfFormsScopedServicesFactory
97:                         .createLocalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
98:                 assertFalse(emfFormsScopedServicesFactory
99:                         .createGlobalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
100:                 assertTrue(emfFormsScopedServicesFactory.createGlobalLazyService(Object.class, mock(EMFFormsViewContext.class))
101:                         .isPresent());
102:         }
103:
104:         @Test
105:         public void testAddedToLocalImmediate() {
106:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
107:                 doReturn(Object.class).when(scopedServiceProvider).getType();
108:                 doReturn(Object.class).when(scopedServiceProvider).createService(any(EMFFormsViewContext.class));
109:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
110:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
111:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
112:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
113:                 assertFalse(emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class))
114:                         .isPresent());
115:                 assertTrue(emfFormsScopedServicesFactory
116:                         .createLocalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
117:                 assertFalse(emfFormsScopedServicesFactory
118:                         .createGlobalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
119:                 assertFalse(emfFormsScopedServicesFactory.createGlobalLazyService(Object.class, mock(EMFFormsViewContext.class))
120:                         .isPresent());
121:         }
122:
123:         @Test
124:         public void testRemoveFromLocalLazy() {
125:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
126:                 doReturn(Object.class).when(scopedServiceProvider).getType();
127:                 doReturn(Object.class).when(scopedServiceProvider).createService(mock(EMFFormsViewContext.class));
128:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
129:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
130:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
131:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
132:                 emfFormsScopedServicesFactory.removeEMFFormsScopedServiceProvider(scopedServiceProvider);
133:                 assertFalse(emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class))
134:                         .isPresent());
135:                 assertFalse(emfFormsScopedServicesFactory
136:                         .createLocalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
137:                 assertFalse(emfFormsScopedServicesFactory
138:                         .createGlobalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
139:                 assertFalse(emfFormsScopedServicesFactory.createGlobalLazyService(Object.class, mock(EMFFormsViewContext.class))
140:                         .isPresent());
141:         }
142:
143:         @Test
144:         public void testRemoveFromGlobalImmediate() {
145:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
146:                 doReturn(Object.class).when(scopedServiceProvider).getType();
147:                 doReturn(Object.class).when(scopedServiceProvider).createService(mock(EMFFormsViewContext.class));
148:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
149:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
150:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
151:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
152:                 emfFormsScopedServicesFactory.removeEMFFormsScopedServiceProvider(scopedServiceProvider);
153:                 assertFalse(emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class))
154:                         .isPresent());
155:                 assertFalse(emfFormsScopedServicesFactory
156:                         .createLocalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
157:                 assertFalse(emfFormsScopedServicesFactory
158:                         .createGlobalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
159:                 assertFalse(emfFormsScopedServicesFactory.createGlobalLazyService(Object.class, mock(EMFFormsViewContext.class))
160:                         .isPresent());
161:         }
162:
163:         @Test
164:         public void testRemoveFromGlobalLazy() {
165:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
166:                 doReturn(Object.class).when(scopedServiceProvider).getType();
167:                 doReturn(Object.class).when(scopedServiceProvider).createService(mock(EMFFormsViewContext.class));
168:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
169:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
170:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
171:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
172:                 emfFormsScopedServicesFactory.removeEMFFormsScopedServiceProvider(scopedServiceProvider);
173:                 assertFalse(emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class))
174:                         .isPresent());
175:                 assertFalse(emfFormsScopedServicesFactory
176:                         .createLocalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
177:                 assertFalse(emfFormsScopedServicesFactory
178:                         .createGlobalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
179:                 assertFalse(emfFormsScopedServicesFactory.createGlobalLazyService(Object.class, mock(EMFFormsViewContext.class))
180:                         .isPresent());
181:         }
182:
183:         @Test
184:         public void testRemoveFromLocalImmediate() {
185:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
186:                 doReturn(Object.class).when(scopedServiceProvider).getType();
187:                 doReturn(Object.class).when(scopedServiceProvider).createService(mock(EMFFormsViewContext.class));
188:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
189:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
190:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
191:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
192:                 emfFormsScopedServicesFactory.removeEMFFormsScopedServiceProvider(scopedServiceProvider);
193:                 assertFalse(emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class))
194:                         .isPresent());
195:                 assertFalse(emfFormsScopedServicesFactory
196:                         .createLocalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
197:                 assertFalse(emfFormsScopedServicesFactory
198:                         .createGlobalImmediateService(Object.class, mock(EMFFormsViewContext.class)).isPresent());
199:                 assertFalse(emfFormsScopedServicesFactory.createGlobalLazyService(Object.class, mock(EMFFormsViewContext.class))
200:                         .isPresent());
201:         }
202:
203:         @Test
204:         public void testAddedToLocalLazyPriorityFirstLowThenHigh() {
205:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider1 = mock(EMFFormsViewServiceFactory.class);
206:                 doReturn(Object.class).when(scopedServiceProvider1).getType();
207:                 final Object mock1 = mock(Object.class);
208:                 doReturn(mock1).when(scopedServiceProvider1).createService(any(EMFFormsViewContext.class));
209:                 when(scopedServiceProvider1.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
210:                 when(scopedServiceProvider1.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
211:                 when(scopedServiceProvider1.getPriority()).thenReturn(1d);
212:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider1);
213:
214:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider2 = mock(EMFFormsViewServiceFactory.class);
215:                 doReturn(Object.class).when(scopedServiceProvider2).getType();
216:                 final Object mock2 = mock(Object.class);
217:                 doReturn(mock2).when(scopedServiceProvider2).createService(any(EMFFormsViewContext.class));
218:                 when(scopedServiceProvider2.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
219:                 when(scopedServiceProvider2.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
220:                 when(scopedServiceProvider2.getPriority()).thenReturn(2d);
221:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider2);
222:
223:                 assertSame(mock2,
224:                         emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class)).get());
225:         }
226:
227:         @Test
228:         public void testAddedToLocalLazyPriorityFirstHighThenLow() {
229:
230:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider2 = mock(EMFFormsViewServiceFactory.class);
231:                 doReturn(Object.class).when(scopedServiceProvider2).getType();
232:                 final Optional<Object> mock2 = Optional.of(mock(Object.class));
233:                 doReturn(mock2).when(scopedServiceProvider2).createService(any(EMFFormsViewContext.class));
234:                 when(scopedServiceProvider2.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
235:                 when(scopedServiceProvider2.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
236:                 when(scopedServiceProvider2.getPriority()).thenReturn(2d);
237:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider2);
238:
239:                 final EMFFormsViewServiceFactory<?> scopedServiceProvider1 = mock(EMFFormsViewServiceFactory.class);
240:                 doReturn(Object.class).when(scopedServiceProvider1).getType();
241:                 final Optional<Object> mock1 = Optional.of(mock(Object.class));
242:                 doReturn(mock1).when(scopedServiceProvider1).createService(any(EMFFormsViewContext.class));
243:                 when(scopedServiceProvider1.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
244:                 when(scopedServiceProvider1.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
245:                 when(scopedServiceProvider1.getPriority()).thenReturn(1d);
246:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider1);
247:                 assertSame(mock2,
248:                         emfFormsScopedServicesFactory.createLocalLazyService(Object.class, mock(EMFFormsViewContext.class)).get());
249:         }
250:
251:         @Test
252:         public void testGetAllGlobalImmediateServiceTypesNoRegistered() {
253:                 final Set<Class<?>> serviceTypes = emfFormsScopedServicesFactory.getAllGlobalImmediateServiceTypes();
254:                 assertNotNull(serviceTypes);
255:                 assertTrue(serviceTypes.isEmpty());
256:         }
257:
258:         @SuppressWarnings("unchecked")
259:         @Test
260:         public void testGetAllGlobalImmediateServiceTypes() {
261:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
262:                 doReturn(Object.class).when(scopedServiceProvider).getType();
263:                 when(scopedServiceProvider.createService(mock(EMFFormsViewContext.class))).thenReturn(mock(Object.class));
264:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
265:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
266:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
267:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
268:
269:                 final Set<Class<?>> serviceTypes = emfFormsScopedServicesFactory.getAllGlobalImmediateServiceTypes();
270:                 assertNotNull(serviceTypes);
271:                 assertEquals(1, serviceTypes.size());
272:                 assertEquals(Object.class, serviceTypes.iterator().next());
273:         }
274:
275:         @Test
276:         public void testGetAllLocalImmediateServiceTypesNoRegistered() {
277:                 final Set<Class<?>> serviceTypes = emfFormsScopedServicesFactory.getAllLocalImmediateServiceTypes();
278:                 assertNotNull(serviceTypes);
279:                 assertTrue(serviceTypes.isEmpty());
280:         }
281:
282:         @SuppressWarnings("unchecked")
283:         @Test
284:         public void testGetAllLocalImmediateServiceTypes() {
285:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
286:                 doReturn(Object.class).when(scopedServiceProvider).getType();
287:                 when(scopedServiceProvider.createService(mock(EMFFormsViewContext.class))).thenReturn(mock(Object.class));
288:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
289:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
290:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
291:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
292:
293:                 final Set<Class<?>> serviceTypes = emfFormsScopedServicesFactory.getAllLocalImmediateServiceTypes();
294:                 assertNotNull(serviceTypes);
295:                 assertEquals(1, serviceTypes.size());
296:                 assertEquals(Object.class, serviceTypes.iterator().next());
297:         }
298:
299:         @SuppressWarnings("unchecked")
300:         @Test
301:         public void testGetAllLocalImmediateServiceTypesAreSorted() {
302:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
303:                 doReturn(Object.class).when(scopedServiceProvider).getType();
304:                 when(scopedServiceProvider.createService(mock(EMFFormsViewContext.class))).thenReturn(mock(Object.class));
305:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
306:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
307:                 when(scopedServiceProvider.getPriority()).thenReturn(5d);
308:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
309:
310:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider2 = mock(EMFFormsViewServiceFactory.class);
311:                 doReturn(Exception.class).when(scopedServiceProvider2).getType();
312:                 when(scopedServiceProvider2.createService(mock(EMFFormsViewContext.class))).thenReturn(mock(Exception.class));
313:                 when(scopedServiceProvider2.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
314:                 when(scopedServiceProvider2.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
315:                 when(scopedServiceProvider2.getPriority()).thenReturn(1d);
316:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider2);
317:
318:                 final Set<Class<?>> serviceTypes = emfFormsScopedServicesFactory.getAllLocalImmediateServiceTypes();
319:                 assertNotNull(serviceTypes);
320:                 assertEquals(2, serviceTypes.size());
321:                 final Iterator<Class<?>> iterator = serviceTypes.iterator();
322:                 assertEquals(Exception.class, iterator.next());
323:                 assertEquals(Object.class, iterator.next());
324:         }
325:
326:         @SuppressWarnings("unchecked")
327:         @Test
328:         public void testGetAllGlobalImmediateServiceTypesAreSorted() {
329:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
330:                 doReturn(Object.class).when(scopedServiceProvider).getType();
331:                 when(scopedServiceProvider.createService(mock(EMFFormsViewContext.class))).thenReturn(mock(Object.class));
332:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
333:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
334:                 when(scopedServiceProvider.getPriority()).thenReturn(5d);
335:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
336:
337:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider2 = mock(EMFFormsViewServiceFactory.class);
338:                 doReturn(Exception.class).when(scopedServiceProvider2).getType();
339:                 when(scopedServiceProvider2.createService(mock(EMFFormsViewContext.class))).thenReturn(mock(Exception.class));
340:                 when(scopedServiceProvider2.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
341:                 when(scopedServiceProvider2.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
342:                 when(scopedServiceProvider2.getPriority()).thenReturn(1d);
343:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider2);
344:
345:                 final Set<Class<?>> serviceTypes = emfFormsScopedServicesFactory.getAllGlobalImmediateServiceTypes();
346:                 assertNotNull(serviceTypes);
347:                 assertEquals(2, serviceTypes.size());
348:                 final Iterator<Class<?>> iterator = serviceTypes.iterator();
349:                 assertEquals(Exception.class, iterator.next());
350:                 assertEquals(Object.class, iterator.next());
351:         }
352:
353:         @SuppressWarnings("unchecked")
354:         @Test
355:         public void testCreateLocalImmediateServicePassesContext() {
356:                 final EMFFormsViewContext emfFormsViewContext = mock(EMFFormsViewContext.class);
357:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
358:                 doReturn(Object.class).when(scopedServiceProvider).getType();
359:                 when(scopedServiceProvider.createService(emfFormsViewContext)).thenReturn(mock(Object.class));
360:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
361:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
362:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
363:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
364:                 final Optional<Object> createLocalImmediateService = emfFormsScopedServicesFactory
365:                         .createLocalImmediateService(Object.class, emfFormsViewContext);
366:                 assertTrue(createLocalImmediateService.isPresent());
367:                 verify(scopedServiceProvider).createService(emfFormsViewContext);
368:         }
369:
370:         @SuppressWarnings("unchecked")
371:         @Test
372:         public void testCreateGlobalImmediateServicePassesContext() {
373:                 final EMFFormsViewContext emfFormsViewContext = mock(EMFFormsViewContext.class);
374:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
375:                 doReturn(Object.class).when(scopedServiceProvider).getType();
376:                 when(scopedServiceProvider.createService(emfFormsViewContext)).thenReturn(mock(Object.class));
377:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.IMMEDIATE);
378:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
379:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
380:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
381:                 final Optional<Object> createGlobalImmediateService = emfFormsScopedServicesFactory
382:                         .createGlobalImmediateService(Object.class, emfFormsViewContext);
383:                 assertTrue(createGlobalImmediateService.isPresent());
384:                 verify(scopedServiceProvider).createService(emfFormsViewContext);
385:         }
386:
387:         @SuppressWarnings("unchecked")
388:         @Test
389:         public void testCreateLocalLazyServicePassesContext() {
390:                 final EMFFormsViewContext emfFormsViewContext = mock(EMFFormsViewContext.class);
391:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
392:                 doReturn(Object.class).when(scopedServiceProvider).getType();
393:                 when(scopedServiceProvider.createService(emfFormsViewContext)).thenReturn(mock(Object.class));
394:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
395:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.LOCAL);
396:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
397:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
398:                 final Optional<Object> createLocalLazyService = emfFormsScopedServicesFactory
399:                         .createLocalLazyService(Object.class, emfFormsViewContext);
400:                 assertTrue(createLocalLazyService.isPresent());
401:                 verify(scopedServiceProvider).createService(emfFormsViewContext);
402:         }
403:
404:         @SuppressWarnings("unchecked")
405:         @Test
406:         public void testCreateGlobalLazyServicePassesContext() {
407:                 final EMFFormsViewContext emfFormsViewContext = mock(EMFFormsViewContext.class);
408:                 final EMFFormsViewServiceFactory<Object> scopedServiceProvider = mock(EMFFormsViewServiceFactory.class);
409:                 doReturn(Object.class).when(scopedServiceProvider).getType();
410:                 when(scopedServiceProvider.createService(emfFormsViewContext)).thenReturn(mock(Object.class));
411:                 when(scopedServiceProvider.getPolicy()).thenReturn(EMFFormsViewServicePolicy.LAZY);
412:                 when(scopedServiceProvider.getScope()).thenReturn(EMFFormsViewServiceScope.GLOBAL);
413:                 when(scopedServiceProvider.getPriority()).thenReturn(1d);
414:                 emfFormsScopedServicesFactory.addEMFFormsScopedServiceProvider(scopedServiceProvider);
415:                 final Optional<Object> createGlobalLazyService = emfFormsScopedServicesFactory
416:                         .createGlobalLazyService(Object.class, emfFormsViewContext);
417:                 assertTrue(createGlobalLazyService.isPresent());
418:                 verify(scopedServiceProvider).createService(emfFormsViewContext);
419:         }
420: }