Skip to content

Package: DetailViewManager_PTest

DetailViewManager_PTest

nameinstructionbranchcomplexitylinemethod
DetailViewManager_PTest()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
cacheCurrentDetail()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
configureMocks()
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%
createTestFixture()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
destroyTestFixture()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
lambda$0(EObject)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$1(InvocationOnMock)
M: 0 C: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
render()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setDetailReadOnly()
M: 0 C: 33
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) 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.emf.ecp.ui.view.spi.swt.masterdetail;
15:
16: import static org.hamcrest.CoreMatchers.is;
17: import static org.mockito.Matchers.any;
18: import static org.mockito.Matchers.argThat;
19: import static org.mockito.Mockito.times;
20: import static org.mockito.Mockito.verify;
21: import static org.mockito.Mockito.when;
22:
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecp.ui.view.ECPRendererException;
25: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTView;
26: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
27: import org.eclipse.emf.ecp.view.spi.model.VView;
28: import org.eclipse.emf.ecp.view.spi.swt.masterdetail.DetailRenderingFunction;
29: import org.eclipse.emf.ecp.view.spi.swt.masterdetail.DetailViewCache;
30: import org.eclipse.emf.ecp.view.spi.swt.masterdetail.DetailViewManager;
31: import org.eclipse.emf.ecp.view.test.common.spi.EMFMockingRunner;
32: import org.eclipse.emf.ecp.view.test.common.spi.EMock;
33: import org.eclipse.swt.SWT;
34: import org.eclipse.swt.widgets.Composite;
35: import org.eclipse.swt.widgets.Control;
36: import org.eclipse.swt.widgets.Label;
37: import org.eclipse.swt.widgets.Shell;
38: import org.junit.After;
39: import org.junit.Before;
40: import org.junit.Test;
41: import org.junit.runner.RunWith;
42: import org.mockito.Mock;
43:
44: /**
45: * Unit tests for the {@link DetailViewManager} class.
46: */
47: @RunWith(EMFMockingRunner.class)
48: public class DetailViewManager_PTest {
49:
50:         @Mock
51:         private ViewModelContext context;
52:
53:         @EMock
54:         private EObject detailObject;
55:
56:         @EMock
57:         private VView detailView;
58:
59:         @Mock
60:         private DetailViewCache cache;
61:
62:         @Mock
63:         private ECPSWTView renderedDetail;
64:
65:         @Mock
66:         private DetailRenderingFunction renderer;
67:
68:         private Shell shell;
69:         private Control detailControl;
70:         private DetailViewManager manager;
71:
72:         /**
73:          * Initializes me.
74:          */
75:         public DetailViewManager_PTest() {
76:                 super();
77:         }
78:
79:         @Test
80:         public void render() throws ECPRendererException {
81:                 manager.render(context, renderer);
82:
83:                 verify(cache).isCached(detailObject);
84:                 verify(renderer).render(any(), argThat(is(context)));
85:         }
86:
87:         @Test
88:         public void cacheCurrentDetail() {
89:                 manager.render(context, renderer);
90:                 manager.cacheCurrentDetail();
91:
92:                 verify(cache).cacheView(renderedDetail);
93:         }
94:
95:         @Test
96:         public void setDetailReadOnly() throws ECPRendererException {
97:                 manager.render(context, renderer);
98:                 manager.setDetailReadOnly(true);
99:
100:                 verify(cache).clear();
101:                 verify(renderer, times(2)).render(any(), argThat(is(context)));
102:         }
103:
104:         //
105:         // Test framework
106:         //
107:
108:         @Before
109:         public void createTestFixture() {
110:                 shell = new Shell();
111:                 manager = new DetailViewManager(shell, __ -> detailView);
112:                 manager.setCache(cache);
113:         }
114:
115:         @Before
116:         public void configureMocks() throws ECPRendererException {
117:                 when(context.getDomainModel()).thenReturn(detailObject);
118:                 when(context.getViewModel()).thenReturn(detailView);
119:
120:                 when(renderer.render(any(), any())).then(invocation -> {
121:•                        if (detailControl == null) {
122:                                 detailControl = new Label((Composite) invocation.getArguments()[0], SWT.NONE);
123:                                 when(renderedDetail.getSWTControl()).thenReturn(detailControl);
124:                                 when(renderedDetail.getViewModelContext()).thenReturn(context);
125:                         }
126:                         return renderedDetail;
127:                 });
128:         }
129:
130:         @After
131:         public void destroyTestFixture() {
132:                 manager.dispose();
133:                 manager = null;
134:
135:                 shell.dispose();
136:                 shell = null;
137:         }
138:
139: }