Skip to content

Package: EMFFormsMappingProviderTable_Test

EMFFormsMappingProviderTable_Test

nameinstructionbranchcomplexitylinemethod
EMFFormsMappingProviderTable_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%
containsSettingWithEObject(Set, EObject)
M: 2 C: 18
90%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 3
75%
M: 0 C: 1
100%
setUp()
M: 0 C: 26
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testGetMappingFor_InvalidColumnDmr()
M: 0 C: 137
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 23
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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.mappingprovider.table;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertTrue;
18: import static org.mockito.Matchers.any;
19: import static org.mockito.Matchers.anyBoolean;
20: import static org.mockito.Matchers.same;
21: import static org.mockito.Mockito.mock;
22: import static org.mockito.Mockito.times;
23: import static org.mockito.Mockito.verify;
24: import static org.mockito.Mockito.when;
25:
26: import java.util.Collections;
27: import java.util.Set;
28:
29: import org.eclipse.emf.ecore.EObject;
30: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
31: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
32: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
33: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
34: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
35: import org.eclipse.emf.ecp.view.spi.table.model.VTableFactory;
36: import org.eclipse.emfforms.spi.common.report.AbstractReport;
37: import org.eclipse.emfforms.spi.common.report.ReportService;
38: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
39: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
40: import org.junit.Before;
41: import org.junit.Test;
42:
43: /**
44: * Unit tests for {@link EMFFormsMappingProviderTable}.
45: *
46: * @author Lucas Koehler
47: *
48: */
49: public class EMFFormsMappingProviderTable_Test {
50:
51:         private EMFFormsMappingProviderTable provider;
52:         private ReportService reportService;
53:         private EMFFormsDatabindingEMF databinding;
54:
55:         @Before
56:         public void setUp() {
57:                 provider = new EMFFormsMappingProviderTable();
58:                 reportService = mock(ReportService.class);
59:                 databinding = mock(EMFFormsDatabindingEMF.class);
60:
61:                 provider.setReportService(reportService);
62:                 provider.setEMFFormsDatabinding(databinding);
63:         }
64:
65:         /**
66:          * Tests that the get mapping for method does not fail and does not report an error if the data binding of a column
67:          * dmr fails.
68:          *
69:          * @throws DatabindingFailedException
70:          */
71:         @SuppressWarnings("unchecked")
72:         @Test
73:         public void testGetMappingFor_InvalidColumnDmr() throws DatabindingFailedException {
74:                 final VTableDomainModelReference tableDmr = VTableFactory.eINSTANCE.createTableDomainModelReference();
75:                 final Setting tableSetting = mock(Setting.class);
76:                 when(tableSetting.get(anyBoolean())).thenReturn(Collections.singletonList(mock(EObject.class)));
77:                 final Setting columnValidSetting = mock(Setting.class);
78:
79:                 // Return mocked EObject's to avoid the created unique settings being equal.
80:                 final EObject tableSettingEObject = mock(EObject.class);
81:                 final EObject columSettingEObject = mock(EObject.class);
82:                 when(tableSetting.getEObject()).thenReturn(tableSettingEObject);
83:                 when(columnValidSetting.getEObject()).thenReturn(columSettingEObject);
84:
85:                 // Cannot mock dmrs because mocked dmrs cannot be added to an EList
86:                 final VDomainModelReference columnInvalid = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
87:                 final VDomainModelReference columnValid = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
88:                 tableDmr.getColumnDomainModelReferences().add(columnInvalid);
89:                 tableDmr.getColumnDomainModelReferences().add(columnValid);
90:
91:                 when(databinding.getSetting(same(columnInvalid), any(EObject.class)))
92:                         .thenThrow(DatabindingFailedException.class);
93:                 when(databinding.getSetting(same(columnValid), any(EObject.class))).thenReturn(columnValidSetting);
94:                 when(databinding.getSetting(same(tableDmr), any(EObject.class))).thenReturn(tableSetting);
95:
96:                 final Set<UniqueSetting> result = provider.getMappingFor(tableDmr, mock(EObject.class));
97:
98:                 assertEquals(2, result.size());
99:                 assertTrue("Result must contain the table setting.", containsSettingWithEObject(result, tableSettingEObject)); //$NON-NLS-1$
100:                 assertTrue("Result must contain the valid column's setting.", //$NON-NLS-1$
101:                         containsSettingWithEObject(result, columSettingEObject));
102:                 verify(reportService, times(0)).report(any(AbstractReport.class));
103:         }
104:
105:         private boolean containsSettingWithEObject(Set<UniqueSetting> set, EObject eObject) {
106:•                for (final UniqueSetting unique : set) {
107:•                        if (unique.getEObject().equals(eObject)) {
108:                                 return true;
109:                         }
110:                 }
111:                 return false;
112:         }
113: }