Skip to content

Package: CellEditorFactory_ITest

CellEditorFactory_ITest

nameinstructionbranchcomplexitylinemethod
CellEditorFactory_ITest(String, Class)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
attr(String, EDataType)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createCellEditor()
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
destroyUI()
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%
eClass(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
eClassifier(EClass, String)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
eEnum(String, String[])
M: 0 C: 34
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getEClass()
M: 0 C: 56
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
initMocks()
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
initUI()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
parameters()
M: 0 C: 56
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
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.view.control.multiattribute;
15:
16: import static org.hamcrest.CoreMatchers.instanceOf;
17: import static org.hamcrest.CoreMatchers.notNullValue;
18: import static org.hamcrest.MatcherAssert.assertThat;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.when;
21:
22: import java.util.Arrays;
23:
24: import org.eclipse.emf.ecore.EAttribute;
25: import org.eclipse.emf.ecore.EClass;
26: import org.eclipse.emf.ecore.EClassifier;
27: import org.eclipse.emf.ecore.EDataType;
28: import org.eclipse.emf.ecore.EEnum;
29: import org.eclipse.emf.ecore.EEnumLiteral;
30: import org.eclipse.emf.ecore.EObject;
31: import org.eclipse.emf.ecore.EPackage;
32: import org.eclipse.emf.ecore.EcoreFactory;
33: import org.eclipse.emf.ecore.EcorePackage;
34: import org.eclipse.emf.ecore.util.EcoreUtil;
35: import org.eclipse.emf.ecp.edit.internal.swt.table.DateCellEditor;
36: import org.eclipse.emf.ecp.edit.internal.swt.table.NumberCellEditor;
37: import org.eclipse.emf.ecp.edit.spi.swt.table.ECPEnumCellEditor;
38: import org.eclipse.emf.ecp.edit.spi.swt.table.StringCellEditor;
39: import org.eclipse.emf.ecp.test.common.DefaultRealm;
40: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
41: import org.eclipse.emfforms.internal.view.control.multiattribute.celleditor.CellEditorFactory;
42: import org.eclipse.emfforms.spi.common.report.ReportService;
43: import org.eclipse.emfforms.spi.localization.EMFFormsLocalizationService;
44: import org.eclipse.jface.viewers.CellEditor;
45: import org.eclipse.swt.SWT;
46: import org.eclipse.swt.widgets.Shell;
47: import org.eclipse.swt.widgets.Table;
48: import org.junit.After;
49: import org.junit.Before;
50: import org.junit.Test;
51: import org.junit.runner.RunWith;
52: import org.junit.runners.Parameterized;
53: import org.junit.runners.Parameterized.Parameters;
54: import org.mockito.Mock;
55: import org.mockito.MockitoAnnotations;
56:
57: /**
58: * Integration tests for the multi-attribute editor's {@link CellEditorFactory}.
59: */
60: @RunWith(Parameterized.class)
61: @SuppressWarnings("nls")
62: public class CellEditorFactory_ITest {
63:
64:         private static EPackage ePackage;
65:         private static EClass eClass;
66:
67:         private DefaultRealm realm;
68:         private Shell shell;
69:
70:         private Table table;
71:
72:         private final EAttribute attribute;
73:         private final EObject owner;
74:         private final Class<? extends CellEditor> expectedEditorType;
75:
76:         @Mock
77:         private ViewModelContext viewModelContext;
78:
79:         /**
80:          * Initializes me with my test parameters.
81:          *
82:          * @param attributeName the attribute name for which to create a cell editor
83:          * @param expectedEditorType the kind of cell editor expected to be created
84:          */
85:         public CellEditorFactory_ITest(String attributeName, Class<? extends CellEditor> expectedEditorType) {
86:                 super();
87:
88:                 attribute = (EAttribute) getEClass().getEStructuralFeature(attributeName);
89:                 owner = EcoreUtil.create(getEClass());
90:                 this.expectedEditorType = expectedEditorType;
91:         }
92:
93:         @Test
94:         public void createCellEditor() {
95:                 final CellEditor editor = CellEditorFactory.INSTANCE.createCellEditor(attribute, owner, table,
96:                         viewModelContext);
97:
98:                 assertThat("No cell editor created", editor, notNullValue());
99:                 assertThat("Wrong cell editor created", editor, instanceOf(expectedEditorType));
100:         }
101:
102:         //
103:         // Test framework
104:         //
105:
106:         @Parameters(name = "{0}")
107:         public static Iterable<Object[]> parameters() {
108:                 return Arrays.asList(new Object[][] {
109:                         { "stringAttr", StringCellEditor.class },
110:                         { "intAttr", NumberCellEditor.class },
111:                         { "dateAttr", DateCellEditor.class },
112:                         { "enumAttr", ECPEnumCellEditor.class },
113:                 });
114:         }
115:
116:         @Before
117:         public void initMocks() {
118:                 MockitoAnnotations.initMocks(this);
119:                 when(viewModelContext.getService(EMFFormsLocalizationService.class))
120:                         .thenReturn(mock(EMFFormsLocalizationService.class));
121:                 when(viewModelContext.getService(ReportService.class))
122:                         .thenReturn(mock(ReportService.class));
123:         }
124:
125:         @Before
126:         public void initUI() {
127:                 realm = new DefaultRealm();
128:                 shell = new Shell();
129:                 table = new Table(shell, SWT.BORDER);
130:         }
131:
132:         @After
133:         public void destroyUI() {
134:                 shell.dispose();
135:                 realm.dispose();
136:         }
137:
138:         private static EClass getEClass() {
139:•                if (eClass == null) {
140:                         ePackage = EcoreFactory.eINSTANCE.createEPackage();
141:                         ePackage.setName("test");
142:                         ePackage.setNsURI("http://test/test");
143:                         ePackage.setNsPrefix("test");
144:
145:                         eClass = eClass("Foo");
146:                         final EEnum flavourEnum = eEnum("Flavour", "sweet", "salty", "sour", "bitter");
147:
148:                         attr("stringAttr", EcorePackage.Literals.ESTRING);
149:                         attr("intAttr", EcorePackage.Literals.EINT);
150:                         attr("dateAttr", EcorePackage.Literals.EDATE);
151:                         attr("enumAttr", flavourEnum);
152:                 }
153:
154:                 return eClass;
155:         }
156:
157:         private static <T extends EClassifier> T eClassifier(EClass metaclass, String name) {
158:                 @SuppressWarnings("unchecked")
159:                 final T result = (T) EcoreFactory.eINSTANCE.create(metaclass);
160:                 result.setName(name);
161:                 ePackage.getEClassifiers().add(result);
162:                 return result;
163:         }
164:
165:         private static EClass eClass(String name) {
166:                 return eClassifier(EcorePackage.Literals.ECLASS, name);
167:         }
168:
169:         private static EEnum eEnum(String name, String... literal) {
170:                 final EEnum result = eClassifier(EcorePackage.Literals.EENUM, name);
171:•                for (final String next : literal) {
172:                         final EEnumLiteral eel = EcoreFactory.eINSTANCE.createEEnumLiteral();
173:                         eel.setName(next);
174:                         result.getELiterals().add(eel);
175:                 }
176:                 return result;
177:         }
178:
179:         private static EAttribute attr(String name, EDataType type) {
180:                 final EAttribute result = EcoreFactory.eINSTANCE.createEAttribute();
181:                 result.setName(name);
182:                 result.setUpperBound(-1);
183:                 result.setEType(type);
184:                 eClass.getEStructuralFeatures().add(result);
185:                 return result;
186:         }
187:
188: }