Skip to content

Package: SWTDataElementIdHelper_ITest

SWTDataElementIdHelper_ITest

nameinstructionbranchcomplexitylinemethod
SWTDataElementIdHelper_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%
setElementIdDataForVControl_noService()
M: 0 C: 29
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
setElementIdDataForVControl_service()
M: 0 C: 57
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
setElementIdDataWithSubId_noService()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
setElementIdDataWithSubId_service()
M: 0 C: 58
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.core;
15:
16: import static org.junit.Assert.assertEquals;
17:
18: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
19: import org.eclipse.emf.ecp.view.spi.model.VControl;
20: import org.eclipse.emfforms.spi.swt.core.data.EMFFormsSWTControlDataService;
21: import org.eclipse.swt.widgets.Shell;
22: import org.junit.Test;
23: import org.mockito.Mockito;
24: import org.osgi.framework.Bundle;
25: import org.osgi.framework.FrameworkUtil;
26: import org.osgi.framework.ServiceRegistration;
27:
28: public class SWTDataElementIdHelper_ITest {
29:
30:         private static final String FOO_BAR = "FooBar"; //$NON-NLS-1$
31:         private static final String CONTROL = "control"; //$NON-NLS-1$
32:         private static final String SUB_ID = "subId"; //$NON-NLS-1$
33:         private static final String UUID = "123456789"; //$NON-NLS-1$
34:
35:         @Test
36:         public void setElementIdDataForVControl_noService() {
37:                 /* setup */
38:                 final Shell shell = new Shell();
39:
40:                 final VControl element = Mockito.mock(VControl.class);
41:                 Mockito.doReturn(UUID).when(element).getUuid();
42:
43:                 final ViewModelContext context = Mockito.mock(ViewModelContext.class);
44:
45:                 /* act */
46:                 SWTDataElementIdHelper.setElementIdDataForVControl(shell, element, context);
47:
48:                 /* assert */
49:                 assertEquals("123456789#control", shell.getData(SWTDataElementIdHelper.ELEMENT_ID_KEY)); //$NON-NLS-1$
50:         }
51:
52:         @Test
53:         public void setElementIdDataWithSubId_noService() {
54:                 /* setup */
55:                 final Shell shell = new Shell();
56:
57:                 final VControl element = Mockito.mock(VControl.class);
58:                 Mockito.doReturn(UUID).when(element).getUuid();
59:
60:                 final ViewModelContext context = Mockito.mock(ViewModelContext.class);
61:
62:                 /* act */
63:                 SWTDataElementIdHelper.setElementIdDataWithSubId(shell, element, SUB_ID, context);
64:
65:                 /* assert */
66:                 assertEquals("123456789#subId", shell.getData(SWTDataElementIdHelper.ELEMENT_ID_KEY)); //$NON-NLS-1$
67:         }
68:
69:         @Test
70:         public void setElementIdDataForVControl_service() {
71:
72:                 /* setup */
73:                 final Shell shell = new Shell();
74:
75:                 final VControl element = Mockito.mock(VControl.class);
76:                 Mockito.doReturn(UUID).when(element).getUuid();
77:
78:                 final ViewModelContext context = Mockito.mock(ViewModelContext.class);
79:
80:                 /* service */
81:                 final EMFFormsSWTControlDataService dataService = Mockito.mock(EMFFormsSWTControlDataService.class);
82:                 Mockito.doReturn(FOO_BAR).when(dataService).getData(element, shell, UUID, CONTROL);
83:
84:                 final Bundle bundle = FrameworkUtil.getBundle(SWTDataElementIdHelper_ITest.class);
85:                 final ServiceRegistration<EMFFormsSWTControlDataService> service = bundle.getBundleContext()
86:                         .registerService(EMFFormsSWTControlDataService.class, dataService, null);
87:
88:                 try {
89:                         /* act */
90:                         SWTDataElementIdHelper.setElementIdDataForVControl(shell, element, context);
91:
92:                         /* assert */
93:                         assertEquals(FOO_BAR, shell.getData(SWTDataElementIdHelper.ELEMENT_ID_KEY));
94:                 } finally {
95:                         service.unregister();
96:                 }
97:         }
98:
99:         @Test
100:         public void setElementIdDataWithSubId_service() {
101:
102:                 /* setup */
103:                 final Shell shell = new Shell();
104:
105:                 final VControl element = Mockito.mock(VControl.class);
106:                 Mockito.doReturn(UUID).when(element).getUuid();
107:
108:                 final ViewModelContext context = Mockito.mock(ViewModelContext.class);
109:
110:                 /* service */
111:                 final EMFFormsSWTControlDataService dataService = Mockito.mock(EMFFormsSWTControlDataService.class);
112:                 Mockito.doReturn(FOO_BAR).when(dataService).getData(element, shell, UUID, SUB_ID);
113:
114:                 final Bundle bundle = FrameworkUtil.getBundle(SWTDataElementIdHelper_ITest.class);
115:                 final ServiceRegistration<EMFFormsSWTControlDataService> service = bundle.getBundleContext()
116:                         .registerService(EMFFormsSWTControlDataService.class, dataService, null);
117:
118:                 try {
119:                         /* act */
120:                         SWTDataElementIdHelper.setElementIdDataWithSubId(shell, element, SUB_ID, context);
121:
122:                         /* assert */
123:                         assertEquals(FOO_BAR, shell.getData(SWTDataElementIdHelper.ELEMENT_ID_KEY));
124:                 } finally {
125:                         service.unregister();
126:                 }
127:         }
128:
129: }