Skip to content

Package: TemplateInstanceRendererService_Test

TemplateInstanceRendererService_Test

nameinstructionbranchcomplexitylinemethod
TemplateInstanceRendererService_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%
setUp()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testGetRendererClass()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testIsApplicableCorrectFeature()
M: 0 C: 59
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
testIsApplicableDatabindingException()
M: 0 C: 80
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
testIsApplicableForEmptyControl()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIsApplicableForView()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIsApplicableWrongFeature()
M: 0 C: 59
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
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: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.datatemplate.tooling.editor;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertSame;
18: import static org.mockito.Matchers.any;
19: import static org.mockito.Mockito.inOrder;
20: import static org.mockito.Mockito.mock;
21: import static org.mockito.Mockito.times;
22: import static org.mockito.Mockito.when;
23:
24: import org.eclipse.core.databinding.property.value.IValueProperty;
25: import org.eclipse.emf.ecore.EObject;
26: import org.eclipse.emf.ecore.EcorePackage;
27: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
28: import org.eclipse.emf.ecp.view.spi.model.VControl;
29: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
30: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
31: import org.eclipse.emfforms.datatemplate.DataTemplatePackage;
32: import org.eclipse.emfforms.spi.common.report.AbstractReport;
33: import org.eclipse.emfforms.spi.common.report.ReportService;
34: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
35: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
36: import org.eclipse.emfforms.spi.swt.core.di.EMFFormsDIRendererService;
37: import org.junit.Before;
38: import org.junit.Test;
39:
40: public class TemplateInstanceRendererService_Test {
41:
42:         private TemplateInstanceRendererService service;
43:
44:         @Before
45:         public void setUp() throws Exception {
46:                 service = new TemplateInstanceRendererService();
47:         }
48:
49:         @Test
50:         public void testIsApplicableForView() {
51:                 assertEquals(EMFFormsDIRendererService.NOT_APPLICABLE,
52:                         service.isApplicable(VViewFactory.eINSTANCE.createView(), null), 0);
53:         }
54:
55:         @Test
56:         public void testIsApplicableForEmptyControl() {
57:                 assertEquals(EMFFormsDIRendererService.NOT_APPLICABLE,
58:                         service.isApplicable(VViewFactory.eINSTANCE.createControl(), null), 0);
59:         }
60:
61:         @Test
62:         public void testIsApplicableDatabindingException() throws DatabindingFailedException {
63:                 final VControl control = VViewFactory.eINSTANCE.createControl();
64:                 final VDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
65:                 control.setDomainModelReference(dmr);
66:                 final EMFFormsDatabinding databinding = mock(EMFFormsDatabinding.class);
67:                 final ReportService reportService = mock(ReportService.class);
68:                 service.setEMFFormsDatabinding(databinding);
69:                 service.setReportService(reportService);
70:                 final ViewModelContext vmc = mock(ViewModelContext.class);
71:                 final EObject domainModel = mock(EObject.class);
72:                 when(vmc.getDomainModel()).thenReturn(domainModel);
73:                 when(databinding.getValueProperty(dmr, domainModel)).thenThrow(new DatabindingFailedException("Test Error")); //$NON-NLS-1$
74:                 assertEquals(EMFFormsDIRendererService.NOT_APPLICABLE, service.isApplicable(control, vmc), 0);
75:                 inOrder(reportService).verify(reportService, times(1)).report(any(AbstractReport.class));
76:         }
77:
78:         @Test
79:         public void testIsApplicableWrongFeature() throws DatabindingFailedException {
80:                 final VControl control = VViewFactory.eINSTANCE.createControl();
81:                 final VDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
82:                 control.setDomainModelReference(dmr);
83:                 final EMFFormsDatabinding databinding = mock(EMFFormsDatabinding.class);
84:                 service.setEMFFormsDatabinding(databinding);
85:                 final ViewModelContext vmc = mock(ViewModelContext.class);
86:                 final EObject domainModel = mock(EObject.class);
87:                 when(vmc.getDomainModel()).thenReturn(domainModel);
88:                 final IValueProperty property = mock(IValueProperty.class);
89:                 when(property.getValueType()).thenReturn(EcorePackage.eINSTANCE.getENamedElement_Name());
90:                 when(databinding.getValueProperty(dmr, domainModel)).thenReturn(property);
91:                 assertEquals(EMFFormsDIRendererService.NOT_APPLICABLE, service.isApplicable(control, vmc), 0);
92:         }
93:
94:         @Test
95:         public void testIsApplicableCorrectFeature() throws DatabindingFailedException {
96:                 final VControl control = VViewFactory.eINSTANCE.createControl();
97:                 final VDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
98:                 control.setDomainModelReference(dmr);
99:                 final EMFFormsDatabinding databinding = mock(EMFFormsDatabinding.class);
100:                 service.setEMFFormsDatabinding(databinding);
101:                 final ViewModelContext vmc = mock(ViewModelContext.class);
102:                 final EObject domainModel = mock(EObject.class);
103:                 when(vmc.getDomainModel()).thenReturn(domainModel);
104:                 final IValueProperty property = mock(IValueProperty.class);
105:                 when(property.getValueType()).thenReturn(DataTemplatePackage.eINSTANCE.getTemplate_Instance());
106:                 when(databinding.getValueProperty(dmr, domainModel)).thenReturn(property);
107:                 assertEquals(10, service.isApplicable(control, vmc), 0);
108:         }
109:
110:         @Test
111:         public void testGetRendererClass() {
112:                 assertSame(TemplateInstanceRenderer.class, service.getRendererClass());
113:         }
114:
115: }