Skip to content

Package: EMFIndexedValueProperty_Test

EMFIndexedValueProperty_Test

nameinstructionbranchcomplexitylinemethod
EMFIndexedValueProperty_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%
testDoGetValueIndex0()
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testDoGetValueIndex1()
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testDoGetValueNoChildrenIndex0()
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%
testDoGetValueNullNoChildrenIndex1()
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%
testDoGetValueNullOneChildIndex1()
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testDoSetValueObjectAdd()
M: 0 C: 43
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
testDoSetValueObjectIndexTooBig()
M: 0 C: 54
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
testDoSetValueObjectReplace()
M: 0 C: 51
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
testEMFIndexedValuePropertyNegativeIndex()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

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.segments.index;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertNull;
19: import static org.junit.Assert.assertTrue;
20:
21: import org.eclipse.emf.common.command.BasicCommandStack;
22: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
23: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
24: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
25: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
26: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
27: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
28: import org.junit.Test;
29:
30: /**
31: * JUnit test cases for {@link EMFIndexedValueProperty}.
32: *
33: * @author Lucas Koehler
34: *
35: */
36: public class EMFIndexedValueProperty_Test {
37:         /**
38:          * Test method for
39:          * {@link EMFIndexedValueProperty#EMFIndexedValueProperty(org.eclipse.emf.edit.domain.EditingDomain,int, org.eclipse.emf.ecore.EStructuralFeature)}
40:          * .
41:          */
42:         @Test(expected = IllegalArgumentException.class)
43:         public void testEMFIndexedValuePropertyNegativeIndex() {
44:                 new EMFIndexedValueProperty(null, -1, TestPackage.eINSTANCE.getB_CList());
45:         }
46:
47:         /**
48:          * Test method for {@link EMFIndexedValueProperty#doGetValue(java.lang.Object)} .
49:          */
50:         @Test
51:         public void testDoGetValueNoChildrenIndex0() {
52:                 final EMFIndexedValueProperty indexedValueProperty = new EMFIndexedValueProperty(null, 0,
53:                         TestPackage.eINSTANCE.getB_CList());
54:                 final B b = TestFactory.eINSTANCE.createB();
55:                 assertNull(indexedValueProperty.doGetValue(b));
56:         }
57:
58:         /**
59:          * Test method for {@link EMFIndexedValueProperty#doGetValue(java.lang.Object)} .
60:          */
61:         @Test
62:         public void testDoGetValueNullNoChildrenIndex1() {
63:                 final EMFIndexedValueProperty indexedValueProperty = new EMFIndexedValueProperty(null, 1,
64:                         TestPackage.eINSTANCE.getB_CList());
65:                 final B b = TestFactory.eINSTANCE.createB();
66:                 assertNull(indexedValueProperty.doGetValue(b));
67:         }
68:
69:         /**
70:          * Test method for {@link EMFIndexedValueProperty#doGetValue(java.lang.Object)} .
71:          */
72:         @Test
73:         public void testDoGetValueNullOneChildIndex1() {
74:                 final EMFIndexedValueProperty indexedValueProperty = new EMFIndexedValueProperty(null, 1,
75:                         TestPackage.eINSTANCE.getB_CList());
76:                 final B b = TestFactory.eINSTANCE.createB();
77:                 final C c0 = TestFactory.eINSTANCE.createC();
78:                 b.getCList().add(c0);
79:                 assertNull(indexedValueProperty.doGetValue(b));
80:         }
81:
82:         /**
83:          * Test method for {@link EMFIndexedValueProperty#doGetValue(java.lang.Object)} .
84:          */
85:         @Test
86:         public void testDoGetValueIndex0() {
87:                 final EMFIndexedValueProperty indexedValueProperty = new EMFIndexedValueProperty(null, 0,
88:                         TestPackage.eINSTANCE.getB_CList());
89:                 final B b = TestFactory.eINSTANCE.createB();
90:                 final C c1 = TestFactory.eINSTANCE.createC();
91:                 final C c2 = TestFactory.eINSTANCE.createC();
92:                 b.getCList().add(c1);
93:                 b.getCList().add(c2);
94:
95:                 assertEquals(c1, indexedValueProperty.doGetValue(b));
96:         }
97:
98:         /**
99:          * Test method for {@link EMFIndexedValueProperty#doGetValue(java.lang.Object)} .
100:          */
101:         @Test
102:         public void testDoGetValueIndex1() {
103:                 final EMFIndexedValueProperty indexedValueProperty = new EMFIndexedValueProperty(null, 1,
104:                         TestPackage.eINSTANCE.getB_CList());
105:                 final B b = TestFactory.eINSTANCE.createB();
106:                 final C c1 = TestFactory.eINSTANCE.createC();
107:                 final C c2 = TestFactory.eINSTANCE.createC();
108:                 b.getCList().add(c1);
109:                 b.getCList().add(c2);
110:
111:                 assertEquals(c2, indexedValueProperty.doGetValue(b));
112:         }
113:
114:         /**
115:          * Test method for {@link EMFIndexedValueProperty#doSetValue(java.lang.Object, java.lang.Object)} .
116:          */
117:         @Test
118:         public void testDoSetValueObjectReplace() {
119:                 final AdapterFactoryEditingDomain domain = new AdapterFactoryEditingDomain(
120:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE),
121:                         new BasicCommandStack());
122:                 final EMFIndexedValueProperty indexedValueProperty = new EMFIndexedValueProperty(domain, 1,
123:                         TestPackage.eINSTANCE.getB_CList());
124:                 final B b = TestFactory.eINSTANCE.createB();
125:                 final C c1 = TestFactory.eINSTANCE.createC();
126:                 final C c2 = TestFactory.eINSTANCE.createC();
127:                 final C c3 = TestFactory.eINSTANCE.createC();
128:                 b.getCList().add(c1);
129:                 b.getCList().add(c2);
130:                 indexedValueProperty.doSetValue(b, c3);
131:
132:                 assertEquals(indexedValueProperty.doGetValue(b), c3);
133:         }
134:
135:         /**
136:          * Test method for {@link EMFIndexedValueProperty#doSetValue(java.lang.Object, java.lang.Object)} .
137:          */
138:         @Test
139:         public void testDoSetValueObjectAdd() {
140:                 final AdapterFactoryEditingDomain domain = new AdapterFactoryEditingDomain(
141:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE),
142:                         new BasicCommandStack());
143:                 final EMFIndexedValueProperty indexedValueProperty = new EMFIndexedValueProperty(domain, 1,
144:                         TestPackage.eINSTANCE.getB_CList());
145:                 final B b = TestFactory.eINSTANCE.createB();
146:                 final C c1 = TestFactory.eINSTANCE.createC();
147:                 final C c2 = TestFactory.eINSTANCE.createC();
148:                 b.getCList().add(c1);
149:                 indexedValueProperty.doSetValue(b, c2);
150:
151:                 assertEquals(c2, indexedValueProperty.doGetValue(b));
152:         }
153:
154:         /**
155:          * Test method for {@link EMFIndexedValueProperty#doSetValue(java.lang.Object, java.lang.Object)} .
156:          */
157:         @Test
158:         public void testDoSetValueObjectIndexTooBig() {
159:                 final AdapterFactoryEditingDomain domain = new AdapterFactoryEditingDomain(
160:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE),
161:                         new BasicCommandStack());
162:                 final EMFIndexedValueProperty indexedValueProperty = new EMFIndexedValueProperty(domain, 5,
163:                         TestPackage.eINSTANCE.getB_CList());
164:                 final B b = TestFactory.eINSTANCE.createB();
165:                 final C c1 = TestFactory.eINSTANCE.createC();
166:                 final C c2 = TestFactory.eINSTANCE.createC();
167:                 b.getCList().add(c1);
168:                 indexedValueProperty.doSetValue(b, c2);
169:                 assertEquals(1, b.getCList().size());
170:                 assertTrue(b.getCList().contains(c1));
171:                 assertFalse(b.getCList().contains(c2));
172:         }
173: }