Skip to content

Package: GotoMarkerAdapter_Test

GotoMarkerAdapter_Test

nameinstructionbranchcomplexitylinemethod
GotoMarkerAdapter_Test()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createFixture()
M: 0 C: 29
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getEObject()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getEStructuralFeature()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
gotoMarker()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
gotoMarker_withFeature()
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%
mockFeature()
M: 12 C: 27
69%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 6
75%
M: 0 C: 1
100%
mockup()
M: 0 C: 66
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.editor;
15:
16: import static org.hamcrest.CoreMatchers.is;
17: import static org.hamcrest.CoreMatchers.sameInstance;
18: import static org.hamcrest.MatcherAssert.assertThat;
19: import static org.junit.Assert.fail;
20: import static org.mockito.Matchers.anyString;
21: import static org.mockito.Matchers.argThat;
22: import static org.mockito.Mockito.verify;
23: import static org.mockito.Mockito.when;
24:
25: import java.util.List;
26:
27: import org.eclipse.core.resources.IMarker;
28: import org.eclipse.core.runtime.CoreException;
29: import org.eclipse.emf.common.command.BasicCommandStack;
30: import org.eclipse.emf.common.util.URI;
31: import org.eclipse.emf.ecore.EObject;
32: import org.eclipse.emf.ecore.EStructuralFeature;
33: import org.eclipse.emf.ecore.EValidator;
34: import org.eclipse.emf.ecore.EcorePackage;
35: import org.eclipse.emf.ecore.resource.Resource;
36: import org.eclipse.emf.ecore.util.EcoreUtil;
37: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
38: import org.eclipse.emf.ecp.view.spi.model.VView;
39: import org.eclipse.emf.ecp.view.test.common.spi.EMFMockingRunner;
40: import org.eclipse.emf.ecp.view.test.common.spi.EMock;
41: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
42: import org.eclipse.emf.edit.domain.EditingDomain;
43: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
44: import org.eclipse.emf.edit.ui.util.EditUIMarkerHelper;
45: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealService;
46: import org.junit.Before;
47: import org.junit.Test;
48: import org.junit.runner.RunWith;
49: import org.mockito.Mock;
50:
51: /**
52: * Unit tests for the {@link GotoMarkerAdapter} class.
53: */
54: @SuppressWarnings("nls")
55: @RunWith(EMFMockingRunner.class)
56: public class GotoMarkerAdapter_Test {
57:         private final EStructuralFeature feature = EcorePackage.Literals.ECLASS__ABSTRACT;
58:
59:         @Mock
60:         private ViewModelContext context;
61:
62:         @EMock
63:         private VView view;
64:
65:         @Mock(extraInterfaces = Resource.Internal.class)
66:         private Resource resource;
67:
68:         @EMock
69:         private EObject object;
70:
71:         @Mock
72:         private IMarker marker;
73:
74:         @Mock
75:         private EMFFormsRevealService revealService;
76:
77:         private EditingDomain domain;
78:         private GotoMarkerAdapter adapter;
79:
80:         /**
81:          * Initializes me.
82:          */
83:         public GotoMarkerAdapter_Test() {
84:                 super();
85:         }
86:
87:         @Test
88:         public void gotoMarker() {
89:                 adapter.gotoMarker(marker);
90:
91:                 verify(revealService).reveal(object);
92:         }
93:
94:         @Test
95:         public void gotoMarker_withFeature() {
96:                 mockFeature();
97:
98:                 adapter.gotoMarker(marker);
99:
100:                 verify(revealService).reveal(object, feature);
101:         }
102:
103:         @Test
104:         public void getEObject() {
105:                 final List<?> targets = new EditUIMarkerHelper().getTargetObjects(domain, marker);
106:                 assertThat("Wrong EObject found", adapter.getEObject(targets), sameInstance(object));
107:         }
108:
109:         @Test
110:         public void getEStructuralFeature() {
111:                 final List<?> targets = new EditUIMarkerHelper().getTargetObjects(domain, marker);
112:                 assertThat("Wrong EStructuralFeature found", adapter.getEObject(targets), sameInstance(object));
113:         }
114:
115:         //
116:         // Test framework
117:         //
118:
119:         @Before
120:         public void mockup() throws CoreException {
121:                 final URI uri = URI.createURI("fake://bogus.xmi");
122:                 final String fragment = "e0b1ec7";
123:                 when(resource.getURI()).thenReturn(uri);
124:                 when(resource.getEObject(fragment)).thenReturn(object);
125:                 when(resource.getURIFragment(object)).thenReturn(fragment);
126:
127:                 final String uriValue = uri.appendFragment(fragment).toString();
128:                 when(marker.getAttribute(EValidator.URI_ATTRIBUTE)).thenReturn(uriValue);
129:                 when(marker.getAttribute(argThat(is(EValidator.URI_ATTRIBUTE)), anyString())).thenReturn(uriValue);
130:                 when(context.getService(EMFFormsRevealService.class)).thenReturn(revealService);
131:         }
132:
133:         @Before
134:         public void createFixture() {
135:                 domain = new AdapterFactoryEditingDomain(new ComposedAdapterFactory(), new BasicCommandStack());
136:                 domain.getResourceSet().getResources().add(resource);
137:                 adapter = new GotoMarkerAdapter(context, domain);
138:         }
139:
140:         void mockFeature() {
141:                 try {
142:                         final String featureURI = EcoreUtil.getURI(feature).toString();
143:                         when(marker.getAttribute(EValidator.RELATED_URIS_ATTRIBUTE)).thenReturn(featureURI);
144:                         when(marker.getAttribute(argThat(is(EValidator.RELATED_URIS_ATTRIBUTE)), anyString()))
145:                                 .thenReturn(featureURI);
146:                 } catch (final CoreException e) {
147:                         e.printStackTrace();
148:                         fail("Mock threw exception in stubbing: " + e.getMessage());
149:                 }
150:         }
151:
152: }