Skip to content

Package: MoveRowDownAction_Test

MoveRowDownAction_Test

nameinstructionbranchcomplexitylinemethod
MoveRowDownAction_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%
setUp()
M: 0 C: 174
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 31
100%
M: 0 C: 1
100%
testCanExecute()
M: 0 C: 31
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testExecute()
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
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: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.table.swt.action;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertTrue;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.spy;
21: import static org.mockito.Mockito.verify;
22: import static org.mockito.Mockito.when;
23:
24: import org.eclipse.core.databinding.observable.list.IObservableList;
25: import org.eclipse.emf.common.command.BasicCommandStack;
26: import org.eclipse.emf.common.notify.AdapterFactory;
27: import org.eclipse.emf.common.util.URI;
28: import org.eclipse.emf.ecore.EClass;
29: import org.eclipse.emf.ecore.EPackage;
30: import org.eclipse.emf.ecore.EcoreFactory;
31: import org.eclipse.emf.ecore.EcorePackage;
32: import org.eclipse.emf.ecore.InternalEObject;
33: import org.eclipse.emf.ecore.resource.Resource;
34: import org.eclipse.emf.ecore.resource.ResourceSet;
35: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
36: import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
37: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
38: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
39: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
40: import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
41: import org.eclipse.jface.viewers.AbstractTableViewer;
42: import org.eclipse.jface.viewers.StructuredSelection;
43: import org.junit.Before;
44: import org.junit.Test;
45:
46: public class MoveRowDownAction_Test {
47:
48:         private MoveRowDownAction action;
49:         private AbstractTableViewer viewer;
50:         private EPackage ePackage;
51:         private EClass eClass1;
52:         private EClass eClass2;
53:
54:         @Before
55:         public void setUp() throws Exception {
56:                 ePackage = EcoreFactory.eINSTANCE.createEPackage();
57:                 eClass1 = EcoreFactory.eINSTANCE.createEClass();
58:                 ePackage.getEClassifiers().add(eClass1);
59:                 eClass2 = EcoreFactory.eINSTANCE.createEClass();
60:                 ePackage.getEClassifiers().add(eClass2);
61:
62:                 final ResourceSet rs = new ResourceSetImpl();
63:                 rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
64:                 final ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
65:                         new ReflectiveItemProviderAdapterFactory(),
66:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) });
67:                 final AdapterFactoryEditingDomain domain = new AdapterFactoryEditingDomain(
68:                         adapterFactory,
69:                         new BasicCommandStack(), rs);
70:                 rs.eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(domain));
71:                 final Resource resource = rs.createResource(URI.createURI("VIRTAUAL_URI")); //$NON-NLS-1$
72:                 resource.getContents().add(ePackage);
73:
74:                 final TableRendererViewerActionContext actionContext = mock(TableRendererViewerActionContext.class);
75:                 when(actionContext.getEditingDomain()).thenReturn(domain);
76:                 when(actionContext.getSetting())
77:                         .thenReturn(((InternalEObject) ePackage).eSetting(EcorePackage.eINSTANCE.getEPackage_EClassifiers()));
78:                 action = spy(new MoveRowDownAction(actionContext));
79:                 viewer = mock(AbstractTableViewer.class);
80:                 when(actionContext.getViewer()).thenReturn(viewer);
81:                 final IObservableList<?> input = mock(IObservableList.class);
82:                 when(input.size()).thenReturn(2);
83:                 when(viewer.getInput()).thenReturn(input);
84:
85:                 final VTableControl tableControl = mock(VTableControl.class);
86:                 when(actionContext.getVElement()).thenReturn(tableControl);
87:                 when(tableControl.isEffectivelyReadonly()).thenReturn(false);
88:                 when(tableControl.isEffectivelyEnabled()).thenReturn(true);
89:         }
90:
91:         @Test
92:         public void testCanExecute() {
93:                 // test that the top most element can be moved down
94:                 when(viewer.getSelection()).thenReturn(new StructuredSelection(eClass1));
95:                 assertTrue(action.canExecute());
96:                 // test that the last element cannot be moved down
97:                 when(viewer.getSelection()).thenReturn(new StructuredSelection(eClass2));
98:                 assertFalse(action.canExecute());
99:         }
100:
101:         @Test
102:         public void testExecute() {
103:
104:                 // test that the top most element cannot be moved up
105:                 when(viewer.getSelection()).thenReturn(new StructuredSelection(eClass1));
106:                 action.execute();
107:
108:                 assertEquals(eClass1, ePackage.getEClassifiers().get(1));
109:                 verify(viewer).refresh();
110:         }
111:
112: }