Skip to content

Package: StackItemViewService_PTest

StackItemViewService_PTest

nameinstructionbranchcomplexitylinemethod
StackItemViewService_PTest()
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%
after()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
before()
M: 0 C: 59
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
domainToFemale()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
domainToMale()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
dynamicFemaleToMale()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
dynamicUnrelatedChange()
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%
enumSetToValueWithoutItem()
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
initFemale()
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%
initMale()
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%
initMultipleStacksDifferentDMRs()
M: 0 C: 42
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
initMultipleStacksSameDMRs()
M: 0 C: 38
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
initWithNullExpected()
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%
initWithUnusableDMR()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
initWithoutDMR()
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%
viewService()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (c) 2011-2014 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: * Johannes Faltermeier - initial API and implementation
13: */
14: package org.eclipse.emf.ecp.view.stack.ui.swt.test;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertNull;
18:
19: import org.eclipse.emf.ecp.test.common.DefaultRealm;
20: import org.eclipse.emf.ecp.view.internal.stack.ui.swt.StackItemViewService;
21: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
22: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
23: import org.eclipse.emf.ecp.view.spi.model.VView;
24: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
25: import org.eclipse.emf.ecp.view.spi.stack.model.VStackItem;
26: import org.eclipse.emf.ecp.view.spi.stack.model.VStackLayout;
27: import org.eclipse.emf.emfstore.bowling.BowlingFactory;
28: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
29: import org.eclipse.emf.emfstore.bowling.Gender;
30: import org.eclipse.emf.emfstore.bowling.Player;
31: import org.junit.After;
32: import org.junit.Before;
33: import org.junit.Test;
34:
35: public class StackItemViewService_PTest {
36:
37:         private static final String NAME = "Name";
38:         private DefaultRealm realm;
39:         private Player domain;
40:         private ViewModelContext context;
41:         private VView view;
42:         private VStackLayout stackLayout;
43:         private VStackItem femaleItem;
44:         private VStackItem maleItem;
45:
46:         @After
47:         public void after() {
48:                 context.dispose();
49:                 realm.dispose();
50:         }
51:
52:         @Before
53:         public void before() {
54:                 realm = new DefaultRealm();
55:
56:                 domain = BowlingFactory.eINSTANCE.createPlayer();
57:
58:                 view = VViewFactory.eINSTANCE.createView();
59:                 view.setRootEClass(BowlingPackage.eINSTANCE.getPlayer());
60:
61:                 stackLayout = TestUtil.createStack(BowlingPackage.eINSTANCE.getPlayer_Gender());
62:                 view.getChildren().add(stackLayout);
63:
64:                 femaleItem = TestUtil.createItem(Gender.FEMALE, BowlingPackage.eINSTANCE.getPlayer_DateOfBirth());
65:                 stackLayout.getStackItems().add(femaleItem);
66:
67:                 maleItem = TestUtil.createItem(Gender.MALE, BowlingPackage.eINSTANCE.getPlayer_EMails());
68:                 stackLayout.getStackItems().add(maleItem);
69:         }
70:
71:         private void domainToMale() {
72:                 domain.setGender(Gender.MALE);
73:         }
74:
75:         private void domainToFemale() {
76:                 domain.setGender(Gender.FEMALE);
77:         }
78:
79:         private StackItemViewService viewService() {
80:                 final StackItemViewService stackService = new StackItemViewService();
81:                 context = ViewModelContextFactory.INSTANCE.createViewModelContext(view, domain);
82:                 stackService.instantiate(context);
83:                 return stackService;
84:         }
85:
86:         @Test
87:         public void initMale() {
88:                 domainToMale();
89:                 viewService();
90:                 assertEquals(maleItem, stackLayout.getTopElement());
91:         }
92:
93:         @Test
94:         public void initFemale() {
95:                 domainToFemale();
96:                 viewService();
97:                 assertEquals(femaleItem, stackLayout.getTopElement());
98:         }
99:
100:         @Test
101:         public void initMultipleStacksDifferentDMRs() {
102:                 final VStackLayout stack2 = TestUtil.createStack(BowlingPackage.eINSTANCE.getPlayer_Name());
103:                 final VStackItem item2 = TestUtil.createItem(NAME, BowlingPackage.eINSTANCE.getPlayer_IsProfessional());
104:                 stack2.getStackItems().add(item2);
105:                 view.getChildren().add(stack2);
106:                 domainToMale();
107:                 domain.setName(NAME);
108:
109:                 viewService();
110:
111:                 assertEquals(maleItem, stackLayout.getTopElement());
112:                 assertEquals(item2, stack2.getTopElement());
113:         }
114:
115:         @Test
116:         public void initMultipleStacksSameDMRs() {
117:                 final VStackLayout stack2 = TestUtil.createStack(BowlingPackage.eINSTANCE.getPlayer_Gender());
118:                 final VStackItem item2 = TestUtil
119:                         .createItem(Gender.FEMALE, BowlingPackage.eINSTANCE.getPlayer_IsProfessional());
120:                 stack2.getStackItems().add(item2);
121:                 view.getChildren().add(stack2);
122:                 domainToFemale();
123:
124:                 viewService();
125:
126:                 assertEquals(femaleItem, stackLayout.getTopElement());
127:                 assertEquals(item2, stack2.getTopElement());
128:         }
129:
130:         @Test
131:         public void initWithNullExpected() {
132:                 stackLayout.setDomainModelReference(TestUtil.createDMR(BowlingPackage.eINSTANCE.getPlayer_Name()));
133:                 maleItem.setValue(null);
134:                 domain.setName(null);
135:                 viewService();
136:                 assertEquals(maleItem, stackLayout.getTopElement());
137:         }
138:
139:         /**
140:          * Should not cause exceptions.
141:          */
142:         @Test
143:         public void initWithoutDMR() {
144:                 stackLayout.setDomainModelReference(null);
145:                 viewService();
146:                 assertNull(stackLayout.getTopElement());
147:         }
148:
149:         /**
150:          * Should not cause exceptions.
151:          */
152:         @Test
153:         public void initWithUnusableDMR() {
154:                 stackLayout.setDomainModelReference(TestUtil.createDMR(BowlingPackage.eINSTANCE.getFan_DateOfBirth()));
155:                 viewService();
156:                 assertNull(stackLayout.getTopElement());
157:         }
158:
159:         @Test
160:         public void dynamicFemaleToMale() {
161:                 domainToFemale();
162:                 viewService();
163:                 domainToMale();
164:                 assertEquals(maleItem, stackLayout.getTopElement());
165:         }
166:
167:         /**
168:          * Should not cause problems.
169:          */
170:         @Test
171:         public void dynamicUnrelatedChange() {
172:                 domainToFemale();
173:                 viewService();
174:                 domain.setName(NAME);
175:                 assertEquals(femaleItem, stackLayout.getTopElement());
176:         }
177:
178:         @Test
179:         public void enumSetToValueWithoutItem() {
180:                 stackLayout.getStackItems().remove(maleItem);
181:                 domainToFemale();
182:                 viewService();
183:                 assertEquals(femaleItem, stackLayout.getTopElement());
184:                 domainToMale();
185:                 assertNull(stackLayout.getTopElement());
186:         }
187:
188: }