Skip to content

Package: EMFFormsContextViewServiceFactory_PTest

EMFFormsContextViewServiceFactory_PTest

nameinstructionbranchcomplexitylinemethod
EMFFormsContextViewServiceFactory_PTest()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createContext()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
destroyContext()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
test_default()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
test_success()
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.core.di;
15:
16: import static org.hamcrest.CoreMatchers.not;
17: import static org.hamcrest.CoreMatchers.notNullValue;
18: import static org.hamcrest.CoreMatchers.sameInstance;
19: import static org.junit.Assert.assertThat;
20:
21: import org.eclipse.e4.core.contexts.EclipseContextFactory;
22: import org.eclipse.e4.core.contexts.IEclipseContext;
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecore.EcoreFactory;
25: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
26: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
27: import org.eclipse.emf.ecp.view.spi.model.VElement;
28: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
29: import org.junit.After;
30: import org.junit.Before;
31: import org.junit.Test;
32:
33: /**
34: * Tests for the {@code EMFFormsContextViewServiceFactory} class.
35: */
36: @SuppressWarnings("nls")
37: public class EMFFormsContextViewServiceFactory_PTest {
38:
39:         private final VElement viewModel = VViewFactory.eINSTANCE.createView();
40:
41:         private final EObject domainModel = EcoreFactory.eINSTANCE.createEObject();
42:
43:         private ViewModelContext viewModelContext;
44:
45:         /**
46:          * Initializes me.
47:          */
48:         public EMFFormsContextViewServiceFactory_PTest() {
49:                 super();
50:         }
51:
52:         @Test
53:         public void test_default() {
54:                 final IEclipseContext e4Context = viewModelContext.getService(IEclipseContext.class);
55:                 assertThat("Should have got an Eclipse context", e4Context, notNullValue());
56:         }
57:
58:         @Test
59:         public void test_success() {
60:                 final IEclipseContext expected = EclipseContextFactory.create();
61:
62:                 // Bootstrap the Eclipse context
63:                 viewModelContext.putContextValue(IEclipseContext.class.getName(), expected);
64:
65:                 final IEclipseContext e4Context = viewModelContext.getService(IEclipseContext.class);
66:                 assertThat("Should not have got the exact Eclipse context", e4Context, not(sameInstance(expected)));
67:                 assertThat("Should have got a child of the Eclipse context", e4Context.getParent(), sameInstance(expected));
68:         }
69:
70:         //
71:         // Test framework
72:         //
73:
74:         @Before
75:         public void createContext() {
76:                 viewModelContext = ViewModelContextFactory.INSTANCE.createViewModelContext(viewModel, domainModel);
77:         }
78:
79:         @After
80:         public void destroyContext() {
81:                 viewModelContext.dispose();
82:                 viewModelContext = null;
83:         }
84: }