Skip to content

Package: EMFFormsSpreadsheetSingleReferenceConverter_Test

EMFFormsSpreadsheetSingleReferenceConverter_Test

nameinstructionbranchcomplexitylinemethod
EMFFormsSpreadsheetSingleReferenceConverter_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%
before()
M: 0 C: 64
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
task(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testApplicableMultiReference()
M: 0 C: 45
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testApplicableNoFeature()
M: 0 C: 42
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testApplicableNoReference()
M: 0 C: 45
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testApplicableSingleReference()
M: 0 C: 45
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testFromString()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testToString()
M: 0 C: 21
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) 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.assertEquals;
17: import static org.junit.Assert.assertTrue;
18: import static org.mockito.Matchers.any;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.when;
21:
22: import org.apache.poi.hssf.usermodel.HSSFWorkbook;
23: import org.apache.poi.ss.usermodel.BuiltinFormats;
24: import org.apache.poi.ss.usermodel.Cell;
25: import org.apache.poi.ss.usermodel.CellStyle;
26: import org.apache.poi.ss.usermodel.Row;
27: import org.apache.poi.ss.usermodel.Sheet;
28: import org.apache.poi.ss.usermodel.Workbook;
29: import org.eclipse.emf.ecore.EObject;
30: import org.eclipse.emf.ecore.EStructuralFeature;
31: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
32: import org.eclipse.emf.ecore.util.EcoreUtil;
33: import org.eclipse.emf.ecp.makeithappen.model.task.Task;
34: import org.eclipse.emf.ecp.makeithappen.model.task.TaskFactory;
35: import org.eclipse.emf.ecp.makeithappen.model.task.TaskPackage;
36: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
37: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
38: import org.eclipse.emfforms.spi.common.report.ReportService;
39: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
40: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
41: import org.eclipse.emfforms.spi.spreadsheet.core.converter.EMFFormsCellStyleConstants;
42: import org.eclipse.emfforms.spi.spreadsheet.core.converter.EMFFormsConverterException;
43: import org.eclipse.emfforms.spi.spreadsheet.core.converter.EMFFormsSpreadsheetValueConverter;
44: import org.junit.Before;
45: import org.junit.Test;
46:
47: public class EMFFormsSpreadsheetSingleReferenceConverter_Test {
48:         private static final String LINE_SEP = System.getProperty("line.separator"); //$NON-NLS-1$
49:         private static final String EXPECTED = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + LINE_SEP + //$NON-NLS-1$
50:                 "<org.eclipse.emf.ecp.makeithappen.model.task:Task xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:org.eclipse.emf.ecp.makeithappen.model.task=\"http://eclipse/org/emf/ecp/makeithappen/model/task\" description=\"1\"/>" //$NON-NLS-1$
51:                 + LINE_SEP;
52:
53:         private ReportService reportService;
54:         private EMFFormsDatabindingEMF databinding;
55:         private EMFFormsSpreadsheetSingleReferenceConverter converter;
56:         private EObject domainObject;
57:         private VDomainModelReference dmr;
58:         private Cell cell;
59:         private ViewModelContext viewModelContext;
60:
61:         @Before
62:         public void before() {
63:                 converter = new EMFFormsSpreadsheetSingleReferenceConverter();
64:                 reportService = mock(ReportService.class);
65:                 databinding = mock(EMFFormsDatabindingEMF.class);
66:                 domainObject = mock(EObject.class);
67:                 dmr = mock(VDomainModelReference.class);
68:
69:                 final Workbook wb = new HSSFWorkbook();
70:                 final CellStyle cellStyle = wb.createCellStyle();
71:                 cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); //$NON-NLS-1$
72:
73:                 final Sheet sheet = wb.createSheet("test"); //$NON-NLS-1$
74:
75:                 // Create a row and put some cells in it. Rows are 0 based.
76:                 final Row row = sheet.createRow((short) 0);
77:                 cell = row.createCell(0);
78:
79:                 viewModelContext = mock(ViewModelContext.class);
80:                 when(viewModelContext.getContextValue(EMFFormsCellStyleConstants.TEXT)).thenReturn(cellStyle);
81:         }
82:
83:         @Test
84:         public void testApplicableNoFeature() throws DatabindingFailedException {
85:                 when(databinding.getSetting(any(VDomainModelReference.class), any(EObject.class)))
86:                         .thenThrow(new DatabindingFailedException("")); //$NON-NLS-1$
87:                 converter.setDatabinding(databinding);
88:                 converter.setReportService(reportService);
89:                 assertEquals(EMFFormsSpreadsheetValueConverter.NOT_APPLICABLE, converter.isApplicable(domainObject, dmr), 0d);
90:         }
91:
92:         @Test
93:         public void testApplicableNoReference() throws DatabindingFailedException {
94:                 final Setting setting = mock(Setting.class);
95:                 when(setting.getEStructuralFeature()).thenReturn(TaskPackage.eINSTANCE.getUser_Active());
96:                 when(databinding.getSetting(any(VDomainModelReference.class), any(EObject.class)))
97:                         .thenReturn(setting);
98:                 converter.setDatabinding(databinding);
99:                 converter.setReportService(reportService);
100:                 assertEquals(EMFFormsSpreadsheetValueConverter.NOT_APPLICABLE, converter.isApplicable(domainObject, dmr), 0d);
101:         }
102:
103:         @Test
104:         public void testApplicableMultiReference() throws DatabindingFailedException {
105:                 final Setting setting = mock(Setting.class);
106:                 when(setting.getEStructuralFeature()).thenReturn(TaskPackage.eINSTANCE.getTask_SubTasks());
107:                 when(databinding.getSetting(any(VDomainModelReference.class), any(EObject.class)))
108:                         .thenReturn(setting);
109:                 converter.setDatabinding(databinding);
110:                 converter.setReportService(reportService);
111:                 assertEquals(EMFFormsSpreadsheetValueConverter.NOT_APPLICABLE, converter.isApplicable(domainObject, dmr), 0d);
112:         }
113:
114:         @Test
115:         public void testApplicableSingleReference() throws DatabindingFailedException {
116:                 final Setting setting = mock(Setting.class);
117:                 when(setting.getEStructuralFeature()).thenReturn(TaskPackage.eINSTANCE.getTask_Assignee());
118:                 when(databinding.getSetting(any(VDomainModelReference.class), any(EObject.class)))
119:                         .thenReturn(setting);
120:                 converter.setDatabinding(databinding);
121:                 converter.setReportService(reportService);
122:                 assertEquals(0d, converter.isApplicable(domainObject, dmr), 0d);
123:         }
124:
125:         @Test
126:         public void testToString() throws DatabindingFailedException, EMFFormsConverterException {
127:                 final EObject cellValue = task("1"); //$NON-NLS-1$
128:                 final EStructuralFeature eStructuralFeature = TaskPackage.eINSTANCE.getTask_Assignee();
129:                 converter.setCellValue(cell, cellValue, eStructuralFeature, viewModelContext);
130:                 assertEquals(EXPECTED, cell.getStringCellValue());
131:         }
132:
133:         @Test
134:         public void testFromString() throws DatabindingFailedException, EMFFormsConverterException {
135:                 final EObject cellValue = task("1"); //$NON-NLS-1$
136:                 cell.setCellValue(EXPECTED);
137:                 final EStructuralFeature eStructuralFeature = TaskPackage.eINSTANCE.getTask_Assignee();
138:                 final Object value = converter.getCellValue(cell, eStructuralFeature);
139:                 assertTrue(EcoreUtil.equals(cellValue, (EObject) value));
140:         }
141:
142:         private static Task task(String desc) {
143:                 final Task task = TaskFactory.eINSTANCE.createTask();
144:                 task.setDescription(desc);
145:                 return task;
146:
147:         }
148:
149: }