Skip to content

Package: MultiReferenceCellEditor_PTest$1

MultiReferenceCellEditor_PTest$1

nameinstructionbranchcomplexitylinemethod
answer(InvocationOnMock)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
{...}
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.emf.ecp.view.internal.table.swt.cell;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertNotNull;
18: import static org.junit.Assert.assertNull;
19: import static org.mockito.Matchers.any;
20: import static org.mockito.Matchers.same;
21: import static org.mockito.Mockito.mock;
22: import static org.mockito.Mockito.when;
23:
24: import java.util.ArrayList;
25: import java.util.List;
26:
27: import org.eclipse.emf.common.command.BasicCommandStack;
28: import org.eclipse.emf.common.notify.AdapterFactory;
29: import org.eclipse.emf.common.util.URI;
30: import org.eclipse.emf.ecore.EAttribute;
31: import org.eclipse.emf.ecore.EClass;
32: import org.eclipse.emf.ecore.EPackage;
33: import org.eclipse.emf.ecore.EcoreFactory;
34: import org.eclipse.emf.ecore.EcorePackage;
35: import org.eclipse.emf.ecore.resource.Resource;
36: import org.eclipse.emf.ecore.resource.ResourceSet;
37: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
38: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
39: import org.eclipse.emf.ecp.view.spi.model.ModelChangeListener;
40: import org.eclipse.emf.ecp.view.spi.model.ModelChangeNotification;
41: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
42: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
43: import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
44: import org.eclipse.jface.viewers.TableViewer;
45: import org.eclipse.swt.widgets.Display;
46: import org.eclipse.swt.widgets.Shell;
47: import org.junit.After;
48: import org.junit.Before;
49: import org.junit.Test;
50: import org.mockito.Mockito;
51: import org.mockito.invocation.InvocationOnMock;
52: import org.mockito.stubbing.Answer;
53:
54: public class MultiReferenceCellEditor_PTest {
55:
56:         private Shell shell;
57:         private MultiReferenceCellEditor cellEditor;
58:
59:         @Before
60:         public void setUp() throws Exception {
61:                 shell = new Shell(Display.getCurrent());
62:                 cellEditor = new MultiReferenceCellEditor(shell);
63:         }
64:
65:         @After
66:         public void after() {
67:                 cellEditor.dispose();
68:                 shell.dispose();
69:         }
70:
71:         @Test
72:         public void testGetFormatedString() {
73:                 cellEditor.instantiate(null, mock(ViewModelContext.class));
74:
75:                 final ResourceSet rs = new ResourceSetImpl();
76:                 final ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
77:                         new ReflectiveItemProviderAdapterFactory(),
78:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) });
79:                 final AdapterFactoryEditingDomain domain = new AdapterFactoryEditingDomain(
80:                         adapterFactory,
81:                         new BasicCommandStack(), rs);
82:                 rs.eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(domain));
83:                 final Resource resource = rs.createResource(URI.createURI("VIRTAUAL_URI")); //$NON-NLS-1$
84:
85:                 final EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
86:                 final EClass eClass1 = EcoreFactory.eINSTANCE.createEClass();
87:                 eClass1.setName("1");
88:                 ePackage.getEClassifiers().add(eClass1);
89:                 final EClass eClass2 = EcoreFactory.eINSTANCE.createEClass();
90:                 eClass2.setName("2");
91:                 ePackage.getEClassifiers().add(eClass2);
92:
93:                 resource.getContents().add(ePackage);
94:
95:                 assertEquals("1, 2", cellEditor.getFormatedString(ePackage.getEClassifiers()));
96:         }
97:
98:         @Test
99:         public void testGetImage() {
100:                 assertNull(cellEditor.getImage(null));
101:         }
102:
103:         @Test
104:         public void testGetColumnWidthWeight() {
105:                 assertEquals(100, cellEditor.getColumnWidthWeight());
106:         }
107:
108:         @Test
109:         public void testGetTargetToModelStrategy() {
110:                 assertNull(cellEditor.getTargetToModelStrategy(null));
111:         }
112:
113:         @Test
114:         public void testGetModelToTargetStrategy() {
115:                 assertNull(cellEditor.getModelToTargetStrategy(null));
116:         }
117:
118:         @Test
119:         public void testGetMinWidth() {
120:                 assertEquals(50, cellEditor.getMinWidth());
121:         }
122:
123:         @Test
124:         public void testCreateControlComposite() {
125:                 assertNull(cellEditor.createControl(null));
126:         }
127:
128:         @Test
129:         public void testDoGetValue() {
130:                 assertNull(cellEditor.doGetValue());
131:         }
132:
133:         @Test
134:         public void testGetValueProperty() {
135:                 assertNotNull(cellEditor.getValueProperty());
136:         }
137:
138:         @Test
139:         public void testChangeTracking() {
140:
141:                 final ResourceSet rs = new ResourceSetImpl();
142:                 final ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
143:                         new ReflectiveItemProviderAdapterFactory(),
144:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) });
145:                 final AdapterFactoryEditingDomain domain = new AdapterFactoryEditingDomain(
146:                         adapterFactory,
147:                         new BasicCommandStack(), rs);
148:                 rs.eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(domain));
149:                 final Resource resource = rs.createResource(URI.createURI("VIRTAUAL_URI")); //$NON-NLS-1$
150:
151:                 final EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
152:                 final EClass eClass1 = EcoreFactory.eINSTANCE.createEClass();
153:                 eClass1.setName("1");
154:                 ePackage.getEClassifiers().add(eClass1);
155:                 final EAttribute eAttribute1 = EcoreFactory.eINSTANCE.createEAttribute();
156:                 eAttribute1.setName("Att_1");
157:                 final EAttribute eAttribute2 = EcoreFactory.eINSTANCE.createEAttribute();
158:                 eAttribute2.setName("Att_2");
159:                 eClass1.getEStructuralFeatures().add(eAttribute1);
160:                 eClass1.getEStructuralFeatures().add(eAttribute2);
161:
162:                 resource.getContents().add(ePackage);
163:
164:                 final ViewModelContext vmc = mock(ViewModelContext.class);
165:
166:                 final List<ModelChangeListener> listeners = new ArrayList<ModelChangeListener>();
167:                 Mockito.doAnswer(new Answer<Void>() {
168:
169:                         @Override
170:                         public Void answer(InvocationOnMock invocation) throws Throwable {
171:                                 listeners.add((ModelChangeListener) invocation.getArguments()[0]);
172:                                 return null;
173:                         }
174:                 }).when(vmc).registerDomainChangeListener(any(ModelChangeListener.class));
175:                 Mockito.inOrder(vmc).verify(vmc, Mockito.times(0)).registerDomainChangeListener(any(ModelChangeListener.class));
176:                 cellEditor.instantiate(EcorePackage.eINSTANCE.getEClass_EStructuralFeatures(), vmc);
177:                 final ModelChangeNotification notification = mock(ModelChangeNotification.class);
178:                 when(notification.getNotifier()).thenReturn(eAttribute1);
179:                 listeners.get(0).notifyChange(notification);
180:                 Mockito.inOrder(vmc).verify(vmc, Mockito.times(1)).registerDomainChangeListener(any(ModelChangeListener.class));
181:                 // add table viewer
182:                 final TableViewer tableViewer = mock(TableViewer.class);
183:                 cellEditor.setTableViewer(tableViewer);
184:                 listeners.get(0).notifyChange(notification);
185:                 Mockito.inOrder(tableViewer).verify(tableViewer, Mockito.times(0)).update(any(Object.class),
186:                         any(String[].class));
187:                 // add table feature
188:                 cellEditor.setTableFeature(EcorePackage.eINSTANCE.getEPackage_EClassifiers());
189:                 listeners.get(0).notifyChange(notification);
190:                 Mockito.inOrder(tableViewer).verify(tableViewer, Mockito.times(1)).update(same(eClass1),
191:                         any(String[].class));
192:         }
193: }