Skip to content

Package: AbstractControlSWTRenderer_PTest$TestAbstractControlSWTRenderer

AbstractControlSWTRenderer_PTest$TestAbstractControlSWTRenderer

nameinstructionbranchcomplexitylinemethod
AbstractControlSWTRenderer_PTest.TestAbstractControlSWTRenderer(AbstractControlSWTRenderer_PTest, VControl, ViewModelContext, ReportService, EMFFormsDatabinding, EMFFormsLabelProvider, VTViewTemplateProvider)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
AbstractControlSWTRenderer_PTest.TestAbstractControlSWTRenderer(AbstractControlSWTRenderer_PTest, VControl, ViewModelContext, ReportService, EMFFormsDatabinding, EMFFormsLabelProvider, VTViewTemplateProvider, SWTValidationHelper)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
AbstractControlSWTRenderer_PTest.TestAbstractControlSWTRenderer(AbstractControlSWTRenderer_PTest, VControl, ViewModelContext, ReportService, EMFFormsDatabinding, EMFFormsLabelProvider, VTViewTemplateProvider, SWTValidationUiService)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
getGridDescription(SWTGridDescription)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
renderControl(SWTGridCell, Composite)
M: 0 C: 4
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) 2011-2017 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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.core.swt;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertNotEquals;
18: import static org.junit.Assert.assertSame;
19: import static org.junit.Assert.assertTrue;
20: import static org.mockito.Matchers.any;
21: import static org.mockito.Mockito.mock;
22: import static org.mockito.Mockito.when;
23:
24: import java.util.ArrayList;
25: import java.util.Collections;
26: import java.util.LinkedHashSet;
27: import java.util.List;
28: import java.util.Set;
29:
30: import org.eclipse.core.databinding.observable.Observables;
31: import org.eclipse.core.databinding.property.value.IValueProperty;
32: import org.eclipse.emf.common.util.Diagnostic;
33: import org.eclipse.emf.ecore.EObject;
34: import org.eclipse.emf.ecore.EStructuralFeature;
35: import org.eclipse.emf.ecore.EcorePackage;
36: import org.eclipse.emf.ecp.test.common.DefaultRealm;
37: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
38: import org.eclipse.emf.ecp.view.spi.model.LabelAlignment;
39: import org.eclipse.emf.ecp.view.spi.model.VControl;
40: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
41: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
42: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
43: import org.eclipse.emf.ecp.view.template.model.VTStyleProperty;
44: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
45: import org.eclipse.emf.ecp.view.template.style.alignment.model.AlignmentType;
46: import org.eclipse.emf.ecp.view.template.style.alignment.model.VTAlignmentFactory;
47: import org.eclipse.emf.ecp.view.template.style.alignment.model.VTControlLabelAlignmentStyleProperty;
48: import org.eclipse.emf.ecp.view.template.style.wrap.model.VTLabelWrapStyleProperty;
49: import org.eclipse.emf.ecp.view.template.style.wrap.model.VTWrapFactory;
50: import org.eclipse.emfforms.spi.common.report.ReportService;
51: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
52: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
53: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
54: import org.eclipse.emfforms.spi.core.services.label.NoLabelFoundException;
55: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
56: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
57: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
58: import org.eclipse.emfforms.spi.swt.core.ui.SWTValidationHelper;
59: import org.eclipse.emfforms.spi.swt.core.ui.SWTValidationUiService;
60: import org.eclipse.emfforms.swt.common.test.AbstractControl_PTest.TestObservableValue;
61: import org.eclipse.swt.SWT;
62: import org.eclipse.swt.graphics.Color;
63: import org.eclipse.swt.graphics.Image;
64: import org.eclipse.swt.widgets.Composite;
65: import org.eclipse.swt.widgets.Control;
66: import org.eclipse.swt.widgets.Display;
67: import org.eclipse.swt.widgets.Label;
68: import org.eclipse.swt.widgets.Shell;
69: import org.junit.After;
70: import org.junit.Before;
71: import org.junit.Test;
72: import org.mockito.Mockito;
73:
74: public class AbstractControlSWTRenderer_PTest {
75:
76:         private DefaultRealm realm;
77:         private Shell shell;
78:
79:         private VControl vControl;
80:         private ViewModelContext viewModelContext;
81:         private ReportService reportService;
82:         private EMFFormsDatabinding emfFormsDatabinding;
83:         private EMFFormsLabelProvider emfFormsLabelProvider;
84:         private VTViewTemplateProvider viewTemplateProvider;
85:
86:         private TestAbstractControlSWTRenderer renderer;
87:
88:         private SWTGridCell swtGridCell;
89:
90:         @Before
91:         public void before() throws DatabindingFailedException, NoLabelFoundException {
92:                 realm = new DefaultRealm();
93:                 shell = new Shell();
94:
95:                 vControl = Mockito.mock(VControl.class);
96:                 Mockito.when(vControl.getLabelAlignment()).thenReturn(LabelAlignment.LEFT);
97:
98:                 viewModelContext = Mockito.mock(ViewModelContext.class);
99:                 reportService = Mockito.mock(ReportService.class);
100:
101:                 emfFormsDatabinding = Mockito.mock(EMFFormsDatabinding.class);
102:                 final TestObservableValue mockedObservableValue = mock(TestObservableValue.class);
103:                 Mockito.when(mockedObservableValue.getRealm()).thenReturn(realm);
104:                 final EObject mockedEObject = mock(EObject.class);
105:                 Mockito.when(mockedEObject.eIsSet(any(EStructuralFeature.class))).thenReturn(true);
106:                 Mockito.when(mockedObservableValue.getObserved()).thenReturn(mockedEObject);
107:                 final EStructuralFeature mockedEStructuralFeature = EcorePackage.eINSTANCE.getENamedElement_Name();
108:                 Mockito.when(mockedObservableValue.getValueType()).thenReturn(mockedEStructuralFeature);
109:                 Mockito.when(emfFormsDatabinding.getObservableValue(
110:                         any(VDomainModelReference.class),
111:                         any(EObject.class)))
112:                         .thenReturn(mockedObservableValue);
113:                 final IValueProperty valueProperty = Mockito.mock(IValueProperty.class);
114:                 Mockito.when(valueProperty.getValueType()).thenReturn(mockedEStructuralFeature);
115:                 Mockito.when(emfFormsDatabinding.getValueProperty(
116:                         any(VDomainModelReference.class),
117:                         any(EObject.class)))
118:                         .thenReturn(valueProperty);
119:
120:                 emfFormsLabelProvider = Mockito.mock(EMFFormsLabelProvider.class);
121:                 Mockito.when(emfFormsLabelProvider.getDisplayName(
122:                         any(VDomainModelReference.class),
123:                         any(EObject.class)))
124:                         .thenReturn(Observables.constantObservableValue("I am display name", String.class)); //$NON-NLS-1$
125:                 Mockito.when(emfFormsLabelProvider.getDescription(
126:                         any(VDomainModelReference.class),
127:                         any(EObject.class)))
128:                         .thenReturn(Observables.constantObservableValue("I am description", String.class)); //$NON-NLS-1$
129:
130:                 viewTemplateProvider = Mockito.mock(VTViewTemplateProvider.class);
131:
132:                 renderer = new TestAbstractControlSWTRenderer(
133:                         vControl,
134:                         viewModelContext,
135:                         reportService,
136:                         emfFormsDatabinding,
137:                         emfFormsLabelProvider,
138:                         viewTemplateProvider);
139:
140:                 renderer.init();
141:         }
142:
143:         @After
144:         public void tearDown() {
145:                 shell.dispose();
146:                 realm.dispose();
147:         }
148:
149:         @Test
150:         public void testDefaultLabelStyleBits() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
151:                 /* act */
152:                 final Control render = renderer.renderControl(swtGridCell, shell);
153:                 /* assert */
154:                 assertTrue(Label.class.isInstance(render));
155:                 assertEquals(SWT.LEFT, Label.class.cast(render).getAlignment());
156:         }
157:
158:         @Test
159:         public void testDefaultLabelStyleBitsLeft() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
160:                 /* setup */
161:                 final VTControlLabelAlignmentStyleProperty property = VTAlignmentFactory.eINSTANCE
162:                         .createControlLabelAlignmentStyleProperty();
163:                 property.setType(AlignmentType.LEFT);
164:                 final Set<VTStyleProperty> properties = Collections.<VTStyleProperty> singleton(property);
165:                 Mockito.when(viewTemplateProvider.getStyleProperties(vControl, viewModelContext)).thenReturn(properties);
166:
167:                 /* act */
168:                 final Control render = renderer.renderControl(swtGridCell, shell);
169:                 /* assert */
170:                 assertTrue(Label.class.isInstance(render));
171:                 assertEquals(SWT.LEFT, Label.class.cast(render).getAlignment());
172:         }
173:
174:         @Test
175:         public void testLabelWrapStylePropertyNull() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
176:                 /* act */
177:                 final Control render = renderer.renderControl(swtGridCell, shell);
178:                 /* assert */
179:                 assertTrue(Label.class.isInstance(render));
180:                 assertEquals(0, render.getStyle() & SWT.WRAP);
181:         }
182:
183:         @Test
184:         public void testLabelWrapStylePropertyNonWrapping()
185:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
186:                 /* setup */
187:                 final VTLabelWrapStyleProperty labelWrapStyleProperty = VTWrapFactory.eINSTANCE.createLabelWrapStyleProperty();
188:                 labelWrapStyleProperty.setWrapLabel(false);
189:                 final Set<VTStyleProperty> properties = Collections.<VTStyleProperty> singleton(labelWrapStyleProperty);
190:                 Mockito.when(viewTemplateProvider.getStyleProperties(vControl, viewModelContext)).thenReturn(properties);
191:                 /* act */
192:                 final Control render = renderer.renderControl(swtGridCell, shell);
193:                 /* assert */
194:                 assertTrue(Label.class.isInstance(render));
195:                 assertEquals(0, render.getStyle() & SWT.WRAP);
196:         }
197:
198:         @Test
199:         public void testLabelWrapStylePropertyWrapping()
200:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
201:                 /* setup */
202:                 final VTLabelWrapStyleProperty labelWrapStyleProperty = VTWrapFactory.eINSTANCE.createLabelWrapStyleProperty();
203:                 labelWrapStyleProperty.setWrapLabel(true);
204:                 final Set<VTStyleProperty> properties = Collections.<VTStyleProperty> singleton(labelWrapStyleProperty);
205:                 Mockito.when(viewTemplateProvider.getStyleProperties(vControl, viewModelContext)).thenReturn(properties);
206:                 /* act */
207:                 final Control render = renderer.renderControl(swtGridCell, shell);
208:                 /* assert */
209:                 assertTrue(Label.class.isInstance(render));
210:                 assertNotEquals(0, render.getStyle() & SWT.WRAP);
211:         }
212:
213:         @Test
214:         public void testMixedStylePropertiesInfluencingStyleBits()
215:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
216:                 /* setup */
217:                 final VTControlLabelAlignmentStyleProperty alignProperty = VTAlignmentFactory.eINSTANCE
218:                         .createControlLabelAlignmentStyleProperty();
219:                 alignProperty.setType(AlignmentType.RIGHT);
220:
221:                 final VTLabelWrapStyleProperty labelWrapStyleProperty = VTWrapFactory.eINSTANCE.createLabelWrapStyleProperty();
222:                 labelWrapStyleProperty.setWrapLabel(true);
223:
224:                 final Set<VTStyleProperty> properties = new LinkedHashSet<>();
225:                 properties.add(alignProperty);
226:                 properties.add(labelWrapStyleProperty);
227:                 Mockito.when(viewTemplateProvider.getStyleProperties(vControl, viewModelContext)).thenReturn(properties);
228:
229:                 /* act */
230:                 final Control render = renderer.renderControl(swtGridCell, shell);
231:
232:                 /* assert */
233:                 assertTrue(Label.class.isInstance(render));
234:                 assertNotEquals(0, render.getStyle() & SWT.WRAP);
235:                 assertEquals(SWT.RIGHT, Label.class.cast(render).getAlignment());
236:         }
237:
238:         @SuppressWarnings("deprecation")
239:         @Test
240:         public void testgetValidationBackgroundColorLegacy()
241:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
242:                 /* setup */
243:                 final SWTValidationHelper validationHelper = Mockito.mock(SWTValidationHelper.class);
244:
245:                 renderer = new TestAbstractControlSWTRenderer(
246:                         vControl,
247:                         viewModelContext,
248:                         reportService,
249:                         emfFormsDatabinding,
250:                         emfFormsLabelProvider,
251:                         viewTemplateProvider, validationHelper);
252:
253:                 renderer.init();
254:
255:                 final List<Integer> severityList = createListOfSeverities();
256:                 // Create a list of sample colors
257:                 final List<Color> colorList0 = createColorList(0, severityList);
258:
259:                 mockBackGroundColorSet(validationHelper, severityList, colorList0);
260:
261:                 // Check that all colors are retrieved correctly on the first run
262:                 int i = 0;
263:                 for (final Integer severity : severityList) {
264:                         final Color validationBackgroundColor = renderer.getValidationBackgroundColor(severity);
265:                         assertEquals(colorList0.get(i), validationBackgroundColor);
266:                         i++;
267:                 }
268:
269:                 // change the colors in the validation helper mock
270:                 final List<Color> colorList1 = createColorList(1, severityList);
271:                 mockBackGroundColorSet(validationHelper, severityList, colorList1);
272:
273:                 // Check that still color set 0 is returned
274:                 i = 0;
275:                 for (final Integer severity : severityList) {
276:                         final Color validationBackgroundColor = renderer.getValidationBackgroundColor(severity);
277:                         assertEquals(colorList0.get(i), validationBackgroundColor);
278:                         i++;
279:                 }
280:
281:         }
282:
283:         @SuppressWarnings("deprecation")
284:         @Test
285:         public void testgetValidationForeGroundColorLegacy()
286:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
287:                 /* setup */
288:                 final SWTValidationHelper validationHelper = Mockito.mock(SWTValidationHelper.class);
289:
290:                 renderer = new TestAbstractControlSWTRenderer(
291:                         vControl,
292:                         viewModelContext,
293:                         reportService,
294:                         emfFormsDatabinding,
295:                         emfFormsLabelProvider,
296:                         viewTemplateProvider, validationHelper);
297:
298:                 renderer.init();
299:                 final List<Integer> severityList = createListOfSeverities();
300:                 // Create a list of sample colors
301:                 final List<Color> colorList0 = createColorList(0, severityList);
302:
303:                 mockForeGroundColorSet(validationHelper, severityList, colorList0);
304:
305:                 // Check that all colors are retrieved correctly on the first run
306:                 int i = 0;
307:                 for (final Integer severity : severityList) {
308:                         final Color validationBackgroundColor = renderer.getValidationForegroundColor(severity);
309:                         assertEquals(colorList0.get(i), validationBackgroundColor);
310:                         i++;
311:                 }
312:
313:                 // change the colors in the validation helper mock
314:                 final List<Color> colorList1 = createColorList(1, severityList);
315:                 mockForeGroundColorSet(validationHelper, severityList, colorList1);
316:
317:                 // Check that still color set 0 is returned
318:                 i = 0;
319:                 for (final Integer severity : severityList) {
320:                         final Color validationBackgroundColor = renderer.getValidationForegroundColor(severity);
321:                         assertEquals(colorList0.get(i), validationBackgroundColor);
322:                         i++;
323:                 }
324:
325:         }
326:
327:         @SuppressWarnings("deprecation")
328:         @Test
329:         public void testgetValidationIconLegacy() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
330:                 /* setup */
331:                 final SWTValidationHelper validationHelper = Mockito.mock(SWTValidationHelper.class);
332:
333:                 renderer = new TestAbstractControlSWTRenderer(
334:                         vControl,
335:                         viewModelContext,
336:                         reportService,
337:                         emfFormsDatabinding,
338:                         emfFormsLabelProvider,
339:                         viewTemplateProvider, validationHelper);
340:
341:                 renderer.init();
342:                 final List<Integer> severityList = createListOfSeverities();
343:                 // Create a list of sample Icons
344:                 final List<Image> iconList0 = createIconList(0, severityList);
345:
346:                 mockIconList(validationHelper, severityList, iconList0);
347:
348:                 // Check that all icons are retrieved correctly on the first run
349:                 int i = 0;
350:                 for (final Integer severity : severityList) {
351:                         final Image validationIcon = renderer.getValidationIcon(severity);
352:                         assertEquals(iconList0.get(i), validationIcon);
353:                         i++;
354:                 }
355:
356:                 // change the icons in the validation helper mock
357:                 final List<Image> iconList1 = createIconList(1, severityList);
358:
359:                 mockIconList(validationHelper, severityList, iconList1);
360:
361:                 // Check that still icon set 0 is returned
362:                 i = 0;
363:                 for (final Integer severity : severityList) {
364:                         final Image validationIcon = renderer.getValidationIcon(severity);
365:                         assertEquals(iconList0.get(i), validationIcon);
366:                         i++;
367:                 }
368:
369:         }
370:
371:         /**
372:          * @param i
373:          * @param severityList
374:          * @return
375:          */
376:         private List<Image> createIconList(int index, List<Integer> severityList) {
377:                 final List<Image> imageList = new ArrayList<>();
378:                 for (final Integer severity : severityList) {
379:                         // Shifting index by 1, as 0 size images are not allowed
380:                         imageList.add(new Image(Display.getCurrent(), index + 1, severity + 1));
381:                 }
382:                 return imageList;
383:         }
384:
385:         /**
386:          * @param validationHelper
387:          * @param severityList
388:          * @param colorList1
389:          */
390:         private void mockForeGroundColorSet(SWTValidationHelper validationHelper, List<Integer> severityList,
391:                 List<Color> colorList1) {
392:                 int i = 0;
393:
394:                 for (final Integer severity : severityList) {
395:                         Mockito.when(validationHelper.getValidationForegroundColor(severity, vControl, viewModelContext))
396:                                 .thenReturn(colorList1.get(i));
397:                         i++;
398:
399:                 }
400:
401:         }
402:
403:         /**
404:          * @param validationHelper
405:          * @param severityList
406:          * @param colorList1
407:          */
408:         private void mockIconList(SWTValidationHelper validationHelper, List<Integer> severityList,
409:                 List<Image> imageList) {
410:                 int i = 0;
411:
412:                 for (final Integer severity : severityList) {
413:                         Mockito.when(validationHelper.getValidationIcon(severity, vControl, viewModelContext))
414:                                 .thenReturn(imageList.get(i));
415:                         i++;
416:
417:                 }
418:
419:         }
420:
421:         /**
422:          * @param validationHelper
423:          * @param severityList
424:          * @param colorList1
425:          */
426:         private void mockBackGroundColorSet(SWTValidationHelper validationHelper, List<Integer> severityList,
427:                 List<Color> colorList1) {
428:                 int i = 0;
429:
430:                 for (final Integer severity : severityList) {
431:                         Mockito.when(validationHelper.getValidationBackgroundColor(severity, vControl, viewModelContext))
432:                                 .thenReturn(colorList1.get(i));
433:                         i++;
434:
435:                 }
436:
437:         }
438:
439:         /**
440:          * @param severityList
441:          * @return
442:          */
443:         private List<Color> createColorList(int index, List<Integer> severityList) {
444:                 final List<Color> colorList = new ArrayList<>();
445:                 for (final Integer severity : severityList) {
446:                         colorList.add(new Color(Display.getCurrent(), 0, index, severity));
447:                 }
448:                 return colorList;
449:         }
450:
451:         /**
452:          * @return
453:          */
454:         private List<Integer> createListOfSeverities() {
455:                 final List<Integer> listOfSeverties = new ArrayList<>();
456:                 listOfSeverties.add(Diagnostic.OK);
457:                 listOfSeverties.add(Diagnostic.WARNING);
458:                 listOfSeverties.add(Diagnostic.ERROR);
459:                 listOfSeverties.add(Diagnostic.INFO);
460:                 listOfSeverties.add(Diagnostic.CANCEL);
461:                 return listOfSeverties;
462:         }
463:
464:         @Test
465:         public void testDefaultLabelStyleBitsRight() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
466:                 /* setup */
467:                 final VTControlLabelAlignmentStyleProperty property = VTAlignmentFactory.eINSTANCE
468:                         .createControlLabelAlignmentStyleProperty();
469:                 property.setType(AlignmentType.RIGHT);
470:                 final Set<VTStyleProperty> properties = Collections.<VTStyleProperty> singleton(property);
471:                 Mockito.when(viewTemplateProvider.getStyleProperties(vControl, viewModelContext)).thenReturn(properties);
472:
473:                 /* act */
474:                 final Control render = renderer.renderControl(swtGridCell, shell);
475:                 /* assert */
476:                 assertTrue(Label.class.isInstance(render));
477:                 assertEquals(SWT.RIGHT, Label.class.cast(render).getAlignment());
478:         }
479:
480:         /** Verify retrieving the validation icon for a VElement is forwarded to the {@link SWTValidationUiService}. */
481:         @Test
482:         public void getValidationIcon() {
483:                 final SWTValidationUiService validationUiService = mock(SWTValidationUiService.class);
484:
485:                 renderer = new TestAbstractControlSWTRenderer(
486:                         vControl,
487:                         viewModelContext,
488:                         reportService,
489:                         emfFormsDatabinding,
490:                         emfFormsLabelProvider,
491:                         viewTemplateProvider, validationUiService);
492:                 renderer.init();
493:
494:                 final Image expected = new Image(Display.getCurrent(), 1, 1);
495:                 when(validationUiService.getValidationIcon(vControl, viewModelContext)).thenReturn(expected);
496:
497:                 final Image result = renderer.getValidationIcon();
498:                 assertSame(expected, result);
499:         }
500:
501:         /**
502:          * Verify retrieving the validation foreground color for a VElement is forwarded to the
503:          * {@link SWTValidationUiService}.
504:          */
505:         @Test
506:         public void getValidationForegroundColor() {
507:                 final SWTValidationUiService validationUiService = mock(SWTValidationUiService.class);
508:
509:                 renderer = new TestAbstractControlSWTRenderer(
510:                         vControl,
511:                         viewModelContext,
512:                         reportService,
513:                         emfFormsDatabinding,
514:                         emfFormsLabelProvider,
515:                         viewTemplateProvider, validationUiService);
516:                 renderer.init();
517:
518:                 final Color expected = new Color(Display.getCurrent(), 1, 2, 3);
519:                 when(validationUiService.getValidationForegroundColor(vControl, viewModelContext)).thenReturn(expected);
520:
521:                 final Color result = renderer.getValidationForegroundColor();
522:                 assertSame(expected, result);
523:         }
524:
525:         /**
526:          * Verify retrieving the validation background color for a VElement is forwarded to the
527:          * {@link SWTValidationUiService}.
528:          */
529:         @Test
530:         public void getValidationBackgroundColor() {
531:                 final SWTValidationUiService validationUiService = mock(SWTValidationUiService.class);
532:
533:                 renderer = new TestAbstractControlSWTRenderer(
534:                         vControl,
535:                         viewModelContext,
536:                         reportService,
537:                         emfFormsDatabinding,
538:                         emfFormsLabelProvider,
539:                         viewTemplateProvider, validationUiService);
540:                 renderer.init();
541:
542:                 final Color expected = new Color(Display.getCurrent(), 1, 2, 3);
543:                 when(validationUiService.getValidationBackgroundColor(vControl, viewModelContext)).thenReturn(expected);
544:
545:                 final Color result = renderer.getValidationBackgroundColor();
546:                 assertSame(expected, result);
547:         }
548:
549:         /**
550:          * Test that the {@link SWTValidationUiService} implementation is retrieved from the view model context if it is not
551:          * given in the constructor.
552:          */
553:         @Test
554:         public void validationUiServiceRetrieval() {
555:                 final SWTValidationUiService customService = mock(SWTValidationUiService.class);
556:                 final Image expected = new Image(Display.getCurrent(), 1, 1);
557:                 when(customService.getValidationIcon(vControl, viewModelContext)).thenReturn(expected);
558:                 when(viewModelContext.getService(SWTValidationUiService.class)).thenReturn(customService);
559:                 renderer = new TestAbstractControlSWTRenderer(
560:                         vControl,
561:                         viewModelContext,
562:                         reportService,
563:                         emfFormsDatabinding,
564:                         emfFormsLabelProvider,
565:                         viewTemplateProvider);
566:                 renderer.init();
567:                 final Image result = renderer.getValidationIcon();
568:                 assertSame(expected, result);
569:
570:         }
571:
572:         private class TestAbstractControlSWTRenderer extends AbstractControlSWTRenderer<VControl> {
573:
574:                 TestAbstractControlSWTRenderer(
575:                         VControl vElement,
576:                         ViewModelContext viewContext,
577:                         ReportService reportService,
578:                         EMFFormsDatabinding emfFormsDatabinding,
579:                         EMFFormsLabelProvider emfFormsLabelProvider,
580:                         VTViewTemplateProvider vtViewTemplateProvider) {
581:                         super(
582:                                 vElement,
583:                                 viewContext,
584:                                 reportService,
585:                                 emfFormsDatabinding,
586:                                 emfFormsLabelProvider,
587:                                 vtViewTemplateProvider);
588:                 }
589:
590:                 TestAbstractControlSWTRenderer(
591:                         VControl vElement,
592:                         ViewModelContext viewContext,
593:                         ReportService reportService,
594:                         EMFFormsDatabinding emfFormsDatabinding,
595:                         EMFFormsLabelProvider emfFormsLabelProvider,
596:                         VTViewTemplateProvider vtViewTemplateProvider, SWTValidationHelper swtValidationHelper) {
597:                         super(
598:                                 vElement,
599:                                 viewContext,
600:                                 reportService,
601:                                 emfFormsDatabinding,
602:                                 emfFormsLabelProvider,
603:                                 vtViewTemplateProvider, swtValidationHelper);
604:                 }
605:
606:                 TestAbstractControlSWTRenderer(
607:                         VControl vElement,
608:                         ViewModelContext viewContext,
609:                         ReportService reportService,
610:                         EMFFormsDatabinding emfFormsDatabinding,
611:                         EMFFormsLabelProvider emfFormsLabelProvider,
612:                         VTViewTemplateProvider vtViewTemplateProvider, SWTValidationUiService validationUiService) {
613:                         super(
614:                                 vElement,
615:                                 viewContext,
616:                                 reportService,
617:                                 emfFormsDatabinding,
618:                                 emfFormsLabelProvider,
619:                                 vtViewTemplateProvider, validationUiService);
620:                 }
621:
622:                 @Override
623:                 public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
624:                         final SWTGridDescription simpleGrid = GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 1, this);
625:                         swtGridCell = simpleGrid.getGrid().get(0);
626:                         return simpleGrid;
627:                 }
628:
629:                 @Override
630:                 protected Control renderControl(SWTGridCell cell, Composite parent)
631:                         throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
632:                         return createLabel(parent);
633:                 }
634:
635:         }
636: }