Skip to content

Package: LeafConditionDmrOpenInNewContextStrategyProvider_Test

LeafConditionDmrOpenInNewContextStrategyProvider_Test

nameinstructionbranchcomplexitylinemethod
LeafConditionDmrOpenInNewContextStrategyProvider_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%
getSelectionValidator_eAttribute()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getSelectionValidator_eReference()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
handles_generationDisabled()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
handles_generationEnabled_incorrectBoth()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
handles_generationEnabled_incorrectParent()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
handles_generationEnabled_incorrectReference()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
handles_generationEnabled_true()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setUp()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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 - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.editor.handler;
15:
16: import static org.junit.Assert.assertFalse;
17: import static org.junit.Assert.assertNotNull;
18: import static org.junit.Assert.assertNull;
19: import static org.junit.Assert.assertTrue;
20: import static org.mockito.Mockito.mock;
21:
22: import org.eclipse.emf.ecore.EcorePackage;
23: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
24: import org.eclipse.emf.ecp.view.spi.rule.model.LeafCondition;
25: import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
26: import org.junit.Before;
27: import org.junit.Test;
28:
29: /**
30: * Unit tests for {@link LeafConditionDmrOpenInNewContextStrategyProvider}.
31: *
32: * @author Lucas Koehler
33: *
34: */
35: public class LeafConditionDmrOpenInNewContextStrategyProvider_Test {
36:
37:         private EditLeafConditionDmrTestProvider strategyProvider;
38:         private LeafCondition leafCondition;
39:
40:         @Before
41:         public void setUp() {
42:                 strategyProvider = new EditLeafConditionDmrTestProvider();
43:                 leafCondition = mock(LeafCondition.class);
44:         }
45:
46:         @Test
47:         public void handles_generationEnabled_true() {
48:                 strategyProvider.setSegmentToolingEnabled(true);
49:                 assertTrue(
50:                         strategyProvider.handles(leafCondition, RulePackage.Literals.LEAF_CONDITION__DOMAIN_MODEL_REFERENCE));
51:         }
52:
53:         @Test
54:         public void handles_generationEnabled_incorrectReference() {
55:                 strategyProvider.setSegmentToolingEnabled(true);
56:                 assertFalse(
57:                         strategyProvider.handles(leafCondition, RulePackage.Literals.LEAF_CONDITION__VALUE_DOMAIN_MODEL_REFERENCE));
58:         }
59:
60:         @Test
61:         public void handles_generationEnabled_incorrectParent() {
62:                 strategyProvider.setSegmentToolingEnabled(true);
63:                 assertFalse(strategyProvider.handles(VViewFactory.eINSTANCE.createControl(),
64:                         RulePackage.Literals.LEAF_CONDITION__DOMAIN_MODEL_REFERENCE));
65:         }
66:
67:         @Test
68:         public void handles_generationEnabled_incorrectBoth() {
69:                 strategyProvider.setSegmentToolingEnabled(true);
70:                 assertFalse(
71:                         strategyProvider.handles(VViewFactory.eINSTANCE.createControl(),
72:                                 EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES));
73:         }
74:
75:         @Test
76:         public void handles_generationDisabled() {
77:                 strategyProvider.setSegmentToolingEnabled(false);
78:                 assertFalse(
79:                         strategyProvider.handles(leafCondition, RulePackage.Literals.LEAF_CONDITION__DOMAIN_MODEL_REFERENCE));
80:         }
81:
82:         @Test
83:         public void getSelectionValidator_eReference() {
84:                 final String result = strategyProvider.getSelectionValidator()
85:                         .isValid(EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE);
86:                 assertNotNull(result);
87:                 assertFalse(result.isEmpty());
88:         }
89:
90:         @Test
91:         public void getSelectionValidator_eAttribute() {
92:                 final String result = strategyProvider.getSelectionValidator()
93:                         .isValid(EcorePackage.Literals.EANNOTATION__SOURCE);
94:                 assertNull(result);
95:         }
96:
97:         /** Allows to mock the segment tooling enabled flag without the need to provide a runtime parameter. */
98:         private class EditLeafConditionDmrTestProvider extends LeafConditionDmrOpenInNewContextStrategyProvider {
99:                 private boolean segmentToolingEnabled;
100:
101:                 /**
102:                  * @param segmentToolingEnabled true to enable segment mode
103:                  */
104:                 public void setSegmentToolingEnabled(boolean segmentToolingEnabled) {
105:                         this.segmentToolingEnabled = segmentToolingEnabled;
106:                 }
107:
108:                 @Override
109:                 protected boolean isSegmentToolingEnabled() {
110:                         return segmentToolingEnabled;
111:                 }
112:         }
113: }