Skip to content

Package: DateCellStringTooltipModifier_PTest

DateCellStringTooltipModifier_PTest

nameinstructionbranchcomplexitylinemethod
DateCellStringTooltipModifier_PTest()
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%
setup()
M: 0 C: 92
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 23
100%
M: 0 C: 1
100%
testDateDE()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testDateEN()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testNullDateValues()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testNullValues()
M: 3 C: 11
79%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 4
80%
M: 0 C: 1
100%
testXMLCalendarDE()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testXMLCalendarEN()
M: 0 C: 16
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-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: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.edit.internal.swt.table;
15:
16: import java.util.Calendar;
17: import java.util.Locale;
18:
19: import org.eclipse.emf.ecore.EAttribute;
20: import org.eclipse.emf.ecore.EClass;
21: import org.eclipse.emf.ecore.EDataType;
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EPackage;
24: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
25: import org.eclipse.emf.ecore.EcoreFactory;
26: import org.eclipse.emf.ecore.EcorePackage;
27: import org.eclipse.emf.ecore.InternalEObject;
28: import org.eclipse.emf.ecore.util.EcoreUtil;
29: import org.eclipse.emf.ecp.edit.internal.swt.util.DateUtil;
30: import org.junit.Assert;
31: import org.junit.Before;
32: import org.junit.Test;
33:
34: /**
35: * Test for the {@link DateCellStringTooltipModifier}.
36: *
37: */
38: @SuppressWarnings("nls")
39: public class DateCellStringTooltipModifier_PTest {
40:
41:         private Calendar calendar;
42:         private Setting dateSetting;
43:         private Setting xmlDateSetting;
44:
45:         @Before
46:         public void setup() {
47:                 calendar = Calendar.getInstance();
48:                 calendar.set(2017, 11, 13, 1, 2, 3);
49:
50:                 final EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
51:                 ePackage.setName("package");
52:                 final EClass eClass = EcoreFactory.eINSTANCE.createEClass();
53:                 ePackage.getEClassifiers().add(eClass);
54:                 final EAttribute dateAttribute = EcoreFactory.eINSTANCE.createEAttribute();
55:                 dateAttribute.setName("date");
56:                 dateAttribute.setEType(EcorePackage.eINSTANCE.getEDate());
57:                 eClass.getEStructuralFeatures().add(dateAttribute);
58:
59:                 final EDataType xmlCalendarDataType = EcoreFactory.eINSTANCE.createEDataType();
60:                 xmlCalendarDataType.setName("XMLCalendar");
61:                 xmlCalendarDataType.setInstanceClassName("javax.xml.datatype.XMLGregorianCalendar");
62:                 final EAttribute xmlCalendarAttribute = EcoreFactory.eINSTANCE.createEAttribute();
63:                 xmlCalendarAttribute.setName("xmlCalendar");
64:                 xmlCalendarAttribute.setEType(xmlCalendarDataType);
65:                 eClass.getEStructuralFeatures().add(xmlCalendarAttribute);
66:
67:                 final EObject testObject = EcoreUtil.create(eClass);
68:                 testObject.eSet(dateAttribute, calendar.getTime());
69:                 testObject.eSet(xmlCalendarAttribute, DateUtil.convertOnlyDateToXMLGregorianCalendar(calendar));
70:                 dateSetting = ((InternalEObject) testObject).eSetting(dateAttribute);
71:                 xmlDateSetting = ((InternalEObject) testObject).eSetting(dateAttribute);
72:
73:         }
74:
75:         @Test
76:         public void testNullValues() {
77:                 final DateCellStringTooltipModifier modifier = new DateCellStringTooltipModifier();
78:                 try {
79:                         modifier.modifyString(null, null);
80:                         // BEGIN SUPRESS CATCH EXCEPTION
81:                 } catch (final Exception e) {
82:                         // END SUPRESS CATCH EXCEPTION
83:                         Assert.fail("Failed for null arguments");
84:                 }
85:         }
86:
87:         @Test
88:         public void testNullDateValues() {
89:                 final DateCellStringTooltipModifier modifier = new DateCellStringTooltipModifier();
90:                 dateSetting.set(null);
91:                 final String localizedString = modifier.modifyString("", dateSetting);
92:                 Assert.assertEquals("", localizedString);
93:         }
94:
95:         @Test
96:         public void testDateDE() {
97:                 Locale.setDefault(Locale.GERMAN);
98:                 final DateCellStringTooltipModifier modifier = new DateCellStringTooltipModifier();
99:                 final String localizedString = modifier.modifyString("", dateSetting);
100:                 Assert.assertEquals("13.12.2017", localizedString);
101:         }
102:
103:         @Test
104:         public void testDateEN() {
105:                 Locale.setDefault(Locale.ENGLISH);
106:                 final DateCellStringTooltipModifier modifier = new DateCellStringTooltipModifier();
107:                 final String localizedString = modifier.modifyString("", dateSetting);
108:                 Assert.assertEquals("Dec 13, 2017", localizedString);
109:         }
110:
111:         @Test
112:         public void testXMLCalendarDE() {
113:                 Locale.setDefault(Locale.GERMAN);
114:                 final DateCellStringTooltipModifier modifier = new DateCellStringTooltipModifier();
115:                 final String localizedString = modifier.modifyString("", xmlDateSetting);
116:                 Assert.assertEquals("13.12.2017", localizedString);
117:         }
118:
119:         @Test
120:         public void testXMLCalendarEN() {
121:                 Locale.setDefault(Locale.ENGLISH);
122:                 final DateCellStringTooltipModifier modifier = new DateCellStringTooltipModifier();
123:                 final String localizedString = modifier.modifyString("", xmlDateSetting);
124:                 Assert.assertEquals("Dec 13, 2017", localizedString);
125:         }
126:
127: }