Skip to content

Package: AbstractSWTRenderer_PTest$TestAbstractSWTRenderer

AbstractSWTRenderer_PTest$TestAbstractSWTRenderer

nameinstructionbranchcomplexitylinemethod
AbstractSWTRenderer_PTest.TestAbstractSWTRenderer(VControl, ViewModelContext, ReportService)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getGridDescription(SWTGridDescription)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
renderControl(SWTGridCell, Composite)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.core;
15:
16: import static org.mockito.Mockito.mock;
17: import static org.mockito.Mockito.spy;
18: import static org.mockito.Mockito.times;
19: import static org.mockito.Mockito.verify;
20:
21: import org.eclipse.emf.ecore.EAttribute;
22: import org.eclipse.emf.ecore.EcoreFactory;
23: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
24: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
25: import org.eclipse.emf.ecp.view.spi.model.VControl;
26: import org.eclipse.emf.ecp.view.spi.model.VView;
27: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
28: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
29: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
30: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTViewTestHelper;
31: import org.eclipse.emfforms.spi.common.report.ReportService;
32: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
33: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
34: import org.eclipse.swt.widgets.Composite;
35: import org.eclipse.swt.widgets.Control;
36: import org.eclipse.swt.widgets.Shell;
37: import org.junit.After;
38: import org.junit.Before;
39: import org.junit.Test;
40:
41: /**
42: * Unit tests for {@link AbstractSWTRenderer}.
43: *
44: * @author Lucas Koehler
45: *
46: */
47: public class AbstractSWTRenderer_PTest {
48:
49:         private AbstractSWTRenderer<VControl> renderer;
50:         private VView view;
51:         private VControl control;
52:         private Shell shell;
53:
54:         @Before
55:         public void setUp() throws Exception {
56:                 view = VViewFactory.eINSTANCE.createView();
57:                 control = VViewFactory.eINSTANCE.createControl();
58:                 view.getChildren().add(control);
59:                 final EAttribute domainObject = EcoreFactory.eINSTANCE.createEAttribute();
60:                 final ViewModelContext context = ViewModelContextFactory.INSTANCE.createViewModelContext(view,
61:                         domainObject);
62:
63:                 renderer = spy(new TestAbstractSWTRenderer(control, context, mock(ReportService.class)));
64:                 shell = SWTViewTestHelper.createShell();
65:         }
66:
67:         @After
68:         public void tearDown() {
69:                 if (shell != null) {
70:                         shell.dispose();
71:                 }
72:         }
73:
74:         @Test
75:         public void viewChangeListener_applyReadOnlyCalled_sameElement() {
76:                 renderer.init();
77:                 renderer.finalizeRendering(shell);
78:
79:                 control.setReadonly(true);
80:
81:                 // Once during finalizeRendering and once by the view change listener
82:                 verify(renderer, times(2)).applyReadOnly();
83:
84:                 control.setReadonly(false);
85:
86:                 verify(renderer, times(3)).applyReadOnly();
87:         }
88:
89:         @Test
90:         public void viewChangeListener_applyReadOnlyCalled_parentElement() {
91:                 renderer.init();
92:                 renderer.finalizeRendering(shell);
93:
94:                 view.setReadonly(true);
95:
96:                 // Once during finalizeRendering and once by the view change listener
97:                 verify(renderer, times(2)).applyReadOnly();
98:
99:                 view.setReadonly(false);
100:
101:                 verify(renderer, times(3)).applyReadOnly();
102:         }
103:
104:         @Test
105:         public void viewChangeListener_applyEnableCalled_sameElement() {
106:                 renderer.init();
107:                 renderer.finalizeRendering(shell);
108:
109:                 control.setEnabled(false);
110:
111:                 // Once during finalizeRendering and once by the view change listener
112:                 verify(renderer, times(2)).applyEnable();
113:
114:                 control.setEnabled(true);
115:
116:                 verify(renderer, times(3)).applyEnable();
117:         }
118:
119:         @Test
120:         public void viewChangeListener_applyEnableCalled_parentElement() {
121:                 renderer.init();
122:                 renderer.finalizeRendering(shell);
123:
124:                 view.setEnabled(false);
125:
126:                 // Once during finalizeRendering and once by the view change listener
127:                 verify(renderer, times(2)).applyEnable();
128:
129:                 view.setEnabled(true);
130:
131:                 verify(renderer, times(3)).applyEnable();
132:         }
133:
134:         // Unfortunately, this cannot be replaced by a mock because AbstractRenderer.getViewModelContext and .getVElement
135:         // are final and cannot be mocked to return needed values. Also this needs to be public for Mockito to be able to
136:         // spy it in a plugin test
137:         public static class TestAbstractSWTRenderer extends AbstractSWTRenderer<VControl> {
138:
139:                 TestAbstractSWTRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService) {
140:                         super(vElement, viewContext, reportService);
141:                 }
142:
143:                 @Override
144:                 public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
145:                         return null;
146:                 }
147:
148:                 @Override
149:                 protected Control renderControl(SWTGridCell cell, Composite parent)
150:                         throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
151:                         return null;
152:                 }
153:
154:         }
155: }