Skip to content

Package: ViewModelContextContextFunction_ITest

ViewModelContextContextFunction_ITest

nameinstructionbranchcomplexitylinemethod
ViewModelContextContextFunction_ITest()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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: 3
100%
M: 0 C: 1
100%
destroyContext()
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%
failureCase()
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
successCase()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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.emf.ecp.view.internal.context;
15:
16: import static org.hamcrest.CoreMatchers.nullValue;
17: import static org.hamcrest.CoreMatchers.sameInstance;
18: import static org.junit.Assert.assertThat;
19: import static org.mockito.Mockito.mock;
20:
21: import org.eclipse.e4.core.contexts.EclipseContextFactory;
22: import org.eclipse.e4.core.contexts.IEclipseContext;
23: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
24: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewContext;
25: import org.junit.After;
26: import org.junit.Before;
27: import org.junit.Test;
28: import org.osgi.framework.Bundle;
29: import org.osgi.framework.FrameworkUtil;
30:
31: /**
32: * Integration tests for the context function that casts the
33: * {@link EMFFormsViewContext} value as {@link ViewModelContext} when
34: * it is such.
35: */
36: public class ViewModelContextContextFunction_ITest {
37:
38:         private IEclipseContext e4Context;
39:
40:         /**
41:          * Initializes me.
42:          */
43:         public ViewModelContextContextFunction_ITest() {
44:                 super();
45:         }
46:
47:         @Test
48:         public void successCase() {
49:                 final EMFFormsViewContext viewContext = mock(ViewModelContext.class);
50:                 e4Context.set(EMFFormsViewContext.class, viewContext);
51:
52:                 assertThat(e4Context.get(ViewModelContext.class), sameInstance(viewContext));
53:         }
54:
55:         @Test
56:         public void failureCase() {
57:                 final EMFFormsViewContext viewContext = mock(EMFFormsViewContext.class);
58:                 e4Context.set(EMFFormsViewContext.class, viewContext);
59:
60:                 assertThat(e4Context.get(EMFFormsViewContext.class), sameInstance(viewContext));
61:                 assertThat(e4Context.get(ViewModelContext.class), nullValue());
62:         }
63:
64:         //
65:         // Test framework
66:         //
67:
68:         @Before
69:         public void createContext() {
70:                 final Bundle self = FrameworkUtil.getBundle(ViewModelContextContextFunction_ITest.class);
71:                 e4Context = EclipseContextFactory.createServiceContext(self.getBundleContext());
72:         }
73:
74:         @After
75:         public void destroyContext() {
76:                 e4Context.dispose();
77:         }
78:
79: }