Skip to content

Package: GenericEditor_PTest$1

GenericEditor_PTest$1

nameinstructionbranchcomplexitylinemethod
customizeTree(TreeMasterDetailSWTBuilder)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
enableValidation()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
handleDetailActivated(ViewModelContext)
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%
loadResource(IEditorInput)
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
{...}
M: 0 C: 6
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) 2020 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.notNullValue;
17: import static org.hamcrest.MatcherAssert.assertThat;
18:
19: import org.eclipse.emf.common.util.URI;
20: import org.eclipse.emf.ecore.EcoreFactory;
21: import org.eclipse.emf.ecore.resource.Resource;
22: import org.eclipse.emf.ecore.resource.ResourceSet;
23: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
24: import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
25: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
26: import org.eclipse.emfforms.spi.swt.treemasterdetail.TreeMasterDetailSWTBuilder;
27: import org.eclipse.swt.widgets.Composite;
28: import org.eclipse.swt.widgets.Display;
29: import org.eclipse.swt.widgets.Shell;
30: import org.eclipse.ui.IEditorInput;
31: import org.eclipse.ui.IEditorSite;
32: import org.eclipse.ui.PartInitException;
33: import org.junit.After;
34: import org.junit.Before;
35: import org.junit.Test;
36: import org.junit.runner.RunWith;
37: import org.mockito.Answers;
38: import org.mockito.Mock;
39: import org.mockito.runners.MockitoJUnitRunner;
40:
41: /**
42: * Unit tests for the {@link GenericEditor} class.
43: */
44: @RunWith(MockitoJUnitRunner.class)
45: @SuppressWarnings("nls")
46: public class GenericEditor_PTest {
47:
48:         private GenericEditor editor;
49:
50:         private final Composite parentComposite = new Shell();
51:
52:         @Mock(answer = Answers.RETURNS_MOCKS)
53:         private IEditorSite editorSite;
54:
55:         @Mock(answer = Answers.RETURNS_MOCKS)
56:         private IEditorInput editorInput;
57:
58:         private TreeMasterDetailSWTBuilder builder;
59:
60:         private ViewModelContext detailContext;
61:
62:         /**
63:          * Initializes me.
64:          */
65:         public GenericEditor_PTest() {
66:                 super();
67:         }
68:
69:         @Test
70:         public void customizeTree() {
71:                 editor.createPartControl(parentComposite);
72:
73:                 assertThat("Tree builder not customized", builder, notNullValue());
74:         }
75:
76:         @Test
77:         public void handleDetailActivated() {
78:                 editor.createPartControl(parentComposite);
79:
80:                 while (Display.getCurrent().readAndDispatch()) {
81:                         // pass
82:                 }
83:
84:                 assertThat("Detail context not activated", detailContext, notNullValue());
85:         }
86:
87:         //
88:         // Test framework
89:         //
90:
91:         @Before
92:         public void createFixture() throws PartInitException {
93:                 editor = new GenericEditor() {
94:                         @Override
95:                         protected boolean enableValidation() {
96:                                 return false;
97:                         }
98:
99:                         @Override
100:                         protected ResourceSet loadResource(IEditorInput editorInput) throws PartInitException {
101:                                 final ResourceSet result = new ResourceSetImpl();
102:                                 final Resource resource = new XMIResourceImpl(URI.createURI("platform:/resource/test/resource.xmi"));
103:                                 resource.getContents().add(EcoreFactory.eINSTANCE.createEObject());
104:                                 result.getResources().add(resource);
105:                                 return result;
106:                         }
107:
108:                         @Override
109:                         protected TreeMasterDetailSWTBuilder customizeTree(TreeMasterDetailSWTBuilder builder) {
110:                                 GenericEditor_PTest.this.builder = super.customizeTree(builder);
111:                                 return builder;
112:                         }
113:
114:                         @Override
115:                         protected void handleDetailActivated(ViewModelContext detailContext) {
116:                                 GenericEditor_PTest.this.detailContext = detailContext;
117:                         }
118:                 };
119:
120:                 editor.init(editorSite, editorInput);
121:         }
122:
123:         @After
124:         public void dispose() {
125:                 parentComposite.dispose();
126:         }
127:
128: }