Skip to content

Package: EMFFormsSpreadsheetValueConverterRegistryImpl_Test

EMFFormsSpreadsheetValueConverterRegistryImpl_Test

nameinstructionbranchcomplexitylinemethod
EMFFormsSpreadsheetValueConverterRegistryImpl_Test()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
testAddConverter()
M: 6 C: 47
89%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 12
92%
M: 0 C: 1
100%
testGetConverterMultipleSamePrio()
M: 7 C: 46
87%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 9
82%
M: 0 C: 1
100%
testGetConverterMutipleApplicable()
M: 0 C: 53
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
testGetConverterNoApplicable()
M: 7 C: 46
87%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 9
82%
M: 0 C: 1
100%
testGetConverterOneApplicableOneNotApplicable()
M: 0 C: 53
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
testRemoveConverter()
M: 10 C: 43
81%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 3 C: 9
75%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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: * jfaltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.spreadsheet.core.converter;
15:
16: import static org.junit.Assert.assertSame;
17: import static org.junit.Assert.assertTrue;
18: import static org.junit.Assert.fail;
19: import static org.mockito.Matchers.any;
20: import static org.mockito.Mockito.mock;
21: import static org.mockito.Mockito.when;
22:
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
25: import org.eclipse.emfforms.spi.spreadsheet.core.converter.EMFFormsConverterException;
26: import org.eclipse.emfforms.spi.spreadsheet.core.converter.EMFFormsSpreadsheetValueConverter;
27: import org.junit.Test;
28:
29: public class EMFFormsSpreadsheetValueConverterRegistryImpl_Test {
30:
31:         @Test
32:         public void testAddConverter() throws EMFFormsConverterException {
33:                 final EMFFormsSpreadsheetValueConverterRegistryImpl registry = new EMFFormsSpreadsheetValueConverterRegistryImpl();
34:                 final EObject object = mock(EObject.class);
35:                 final VDomainModelReference dmr = mock(VDomainModelReference.class);
36:                 boolean exception = false;
37:                 try {
38:                         registry.getConverter(object, dmr);
39:                 } catch (final EMFFormsConverterException ex) {
40:                         exception = true;
41:                 }
42:                 assertTrue(exception);
43:                 final EMFFormsSpreadsheetValueConverter converter = mock(EMFFormsSpreadsheetValueConverter.class);
44:                 when(converter.isApplicable(any(EObject.class), any(VDomainModelReference.class))).thenReturn(0d);
45:                 registry.addConverter(converter);
46:                 assertSame(converter, registry.getConverter(object, dmr));
47:         }
48:
49:         @Test(expected = EMFFormsConverterException.class)
50:         public void testRemoveConverter() throws EMFFormsConverterException {
51:                 final EMFFormsSpreadsheetValueConverterRegistryImpl registry = new EMFFormsSpreadsheetValueConverterRegistryImpl();
52:                 final EObject object = mock(EObject.class);
53:                 final VDomainModelReference dmr = mock(VDomainModelReference.class);
54:                 final EMFFormsSpreadsheetValueConverter converter = mock(EMFFormsSpreadsheetValueConverter.class);
55:                 when(converter.isApplicable(any(EObject.class), any(VDomainModelReference.class))).thenReturn(0d);
56:                 registry.addConverter(converter);
57:                 try {
58:                         assertSame(converter, registry.getConverter(object, dmr));
59:                 } catch (final EMFFormsConverterException ex1) {
60:                         fail(ex1.getMessage());
61:                 }
62:                 registry.removeConverter(converter);
63:                 registry.getConverter(object, dmr);
64:         }
65:
66:         @Test
67:         public void testGetConverterOneApplicableOneNotApplicable() throws EMFFormsConverterException {
68:                 final EMFFormsSpreadsheetValueConverterRegistryImpl registry = new EMFFormsSpreadsheetValueConverterRegistryImpl();
69:                 final EObject object = mock(EObject.class);
70:                 final VDomainModelReference dmr = mock(VDomainModelReference.class);
71:                 final EMFFormsSpreadsheetValueConverter applicable = mock(EMFFormsSpreadsheetValueConverter.class);
72:                 when(applicable.isApplicable(object, dmr)).thenReturn(0d);
73:                 registry.addConverter(applicable);
74:                 final EMFFormsSpreadsheetValueConverter notApplicable = mock(EMFFormsSpreadsheetValueConverter.class);
75:                 when(notApplicable.isApplicable(object, dmr)).thenReturn(EMFFormsSpreadsheetValueConverter.NOT_APPLICABLE);
76:                 registry.addConverter(notApplicable);
77:                 assertSame(applicable, registry.getConverter(object, dmr));
78:         }
79:
80:         @Test
81:         public void testGetConverterMutipleApplicable() throws EMFFormsConverterException {
82:                 final EMFFormsSpreadsheetValueConverterRegistryImpl registry = new EMFFormsSpreadsheetValueConverterRegistryImpl();
83:                 final EObject object = mock(EObject.class);
84:                 final VDomainModelReference dmr = mock(VDomainModelReference.class);
85:                 final EMFFormsSpreadsheetValueConverter applicable1 = mock(EMFFormsSpreadsheetValueConverter.class);
86:                 when(applicable1.isApplicable(object, dmr)).thenReturn(1d);
87:                 registry.addConverter(applicable1);
88:                 final EMFFormsSpreadsheetValueConverter applicable0 = mock(EMFFormsSpreadsheetValueConverter.class);
89:                 when(applicable0.isApplicable(object, dmr)).thenReturn(0d);
90:                 registry.addConverter(applicable0);
91:                 assertSame(applicable1, registry.getConverter(object, dmr));
92:         }
93:
94:         @Test(expected = EMFFormsConverterException.class)
95:         public void testGetConverterNoApplicable() throws EMFFormsConverterException {
96:                 final EMFFormsSpreadsheetValueConverterRegistryImpl registry = new EMFFormsSpreadsheetValueConverterRegistryImpl();
97:                 final EObject object = mock(EObject.class);
98:                 final VDomainModelReference dmr = mock(VDomainModelReference.class);
99:                 final EMFFormsSpreadsheetValueConverter applicable1 = mock(EMFFormsSpreadsheetValueConverter.class);
100:                 when(applicable1.isApplicable(object, dmr)).thenReturn(EMFFormsSpreadsheetValueConverter.NOT_APPLICABLE);
101:                 registry.addConverter(applicable1);
102:                 final EMFFormsSpreadsheetValueConverter applicable0 = mock(EMFFormsSpreadsheetValueConverter.class);
103:                 when(applicable0.isApplicable(object, dmr)).thenReturn(EMFFormsSpreadsheetValueConverter.NOT_APPLICABLE);
104:                 registry.addConverter(applicable0);
105:                 assertSame(applicable1, registry.getConverter(object, dmr));
106:         }
107:
108:         @Test(expected = EMFFormsConverterException.class)
109:         public void testGetConverterMultipleSamePrio() throws EMFFormsConverterException {
110:                 final EMFFormsSpreadsheetValueConverterRegistryImpl registry = new EMFFormsSpreadsheetValueConverterRegistryImpl();
111:                 final EObject object = mock(EObject.class);
112:                 final VDomainModelReference dmr = mock(VDomainModelReference.class);
113:                 final EMFFormsSpreadsheetValueConverter applicable1 = mock(EMFFormsSpreadsheetValueConverter.class);
114:                 when(applicable1.isApplicable(object, dmr)).thenReturn(0d);
115:                 registry.addConverter(applicable1);
116:                 final EMFFormsSpreadsheetValueConverter applicable0 = mock(EMFFormsSpreadsheetValueConverter.class);
117:                 when(applicable0.isApplicable(object, dmr)).thenReturn(0d);
118:                 registry.addConverter(applicable0);
119:                 assertSame(applicable1, registry.getConverter(object, dmr));
120:         }
121:
122: }