Skip to content

Package: LeafConditionControlRenderer_Test

LeafConditionControlRenderer_Test

nameinstructionbranchcomplexitylinemethod
LeafConditionControlRenderer_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%
onSelectButton_conditionDmrNull()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
onSelectButton_valueDmrNullDomainModelFeature()
M: 0 C: 40
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
setUp()
M: 0 C: 53
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
tearDown()
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%

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.emf.ecp.view.internal.editor.controls;
15:
16: import static org.mockito.Matchers.any;
17: import static org.mockito.Matchers.eq;
18: import static org.mockito.Mockito.mock;
19: import static org.mockito.Mockito.spy;
20: import static org.mockito.Mockito.verify;
21:
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecp.test.common.DefaultRealm;
24: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
25: import org.eclipse.emf.ecp.view.spi.model.VControl;
26: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
27: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
28: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
29: import org.eclipse.emf.ecp.view.spi.rule.model.LeafCondition;
30: import org.eclipse.emf.ecp.view.spi.rule.model.RuleFactory;
31: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
32: import org.eclipse.emfforms.spi.common.report.ReportService;
33: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
34: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
35: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
36: import org.eclipse.swt.widgets.Label;
37: import org.eclipse.swt.widgets.Shell;
38: import org.junit.After;
39: import org.junit.Before;
40: import org.junit.Test;
41:
42: /**
43: * Unit tests for {@link LeafConditionControlRenderer}.
44: *
45: * @author Lucas Koehler
46: *
47: */
48: public class LeafConditionControlRenderer_Test {
49:         private TestLeafConditionControlRenderer renderer;
50:         private VControl vControl;
51:         private ReportService reportService;
52:         private ViewModelContext viewContext;
53:         private LeafCondition leafCondition;
54:         private DefaultRealm realm;
55:
56:         /**
57:          * @throws java.lang.Exception
58:          */
59:         @Before
60:         public void setUp() throws Exception {
61:                 realm = new DefaultRealm();
62:                 reportService = mock(ReportService.class);
63:                 vControl = VViewFactory.eINSTANCE.createControl();
64:                 viewContext = mock(ViewModelContext.class);
65:                 final EMFFormsDatabinding databinding = mock(EMFFormsDatabinding.class);
66:                 final EMFFormsLabelProvider labelProvider = mock(EMFFormsLabelProvider.class);
67:                 final VTViewTemplateProvider templateProvider = mock(VTViewTemplateProvider.class);
68:                 renderer = spy(new TestLeafConditionControlRenderer(vControl, viewContext, reportService, databinding,
69:                         labelProvider, templateProvider));
70:                 leafCondition = RuleFactory.eINSTANCE.createLeafCondition();
71:         }
72:
73:         @After
74:         public void tearDown() {
75:                 realm.dispose();
76:         }
77:
78:         @Test
79:         public void onSelectButton_valueDmrNullDomainModelFeature() {
80:                 final Label label = mock(Label.class);
81:                 final VFeaturePathDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
82:                 leafCondition.setDomainModelReference(dmr);
83:                 dmr.setDomainModelEFeature(VViewPackage.Literals.ELEMENT__LABEL);
84:                 final VFeaturePathDomainModelReference valueDmr = VViewFactory.eINSTANCE
85:                         .createFeaturePathDomainModelReference();
86:                 // do not set a domain model e feature in the value dmr
87:                 leafCondition.setValueDomainModelReference(valueDmr);
88:
89:                 renderer.onSelectButton(label);
90:
91:                 verify(renderer).showError(any(Shell.class), eq("No value selected"), //$NON-NLS-1$
92:                         eq("Please set a value to the Domain Model Reference first.")); //$NON-NLS-1$
93:         }
94:
95:         @Test
96:         public void onSelectButton_conditionDmrNull() {
97:                 final Label label = mock(Label.class);
98:
99:                 renderer.onSelectButton(label);
100:
101:                 verify(renderer).showError(any(Shell.class), eq("No Feature Path Domain Model Reference found"), //$NON-NLS-1$
102:                         eq("A Feature Path Domain Model Reference needs to be added to the condition first.")); //$NON-NLS-1$
103:         }
104:
105:         public class TestLeafConditionControlRenderer extends LeafConditionControlRenderer {
106:
107:                 /**
108:                  * @param vElement
109:                  * @param viewContext
110:                  * @param reportService
111:                  */
112:                 TestLeafConditionControlRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService,
113:                         EMFFormsDatabinding databindingService, EMFFormsLabelProvider labelProvider,
114:                         VTViewTemplateProvider viewTemplateProvider) {
115:                         super(vElement, viewContext, reportService, databindingService, labelProvider, viewTemplateProvider);
116:                 }
117:
118:                 @Override
119:                 protected void showError(Shell shell, String title, String description) {
120:                         // Do nothing
121:                 }
122:
123:                 /**
124:                  * {@inheritDoc}
125:                  *
126:                  * @see org.eclipse.emf.ecp.view.internal.editor.controls.ExpectedValueControlRenderer#getObservedEObject()
127:                  */
128:                 @Override
129:                 protected EObject getObservedEObject() throws DatabindingFailedException {
130:                         return leafCondition;
131:                 }
132:
133:                 /**
134:                  * {@inheritDoc}
135:                  *
136:                  * @see org.eclipse.emf.ecp.view.internal.editor.controls.ExpectedValueControlRenderer#promptForValue(org.eclipse.swt.widgets.Shell,
137:                  * java.lang.Object, java.lang.Class)
138:                  */
139:                 @Override
140:                 Object promptForValue(Shell shell, Object object, Class<?> attributeClazz) {
141:                         return object;
142:                 }
143:
144:         }
145: }