tmf/lttng: Update 2014 copyrights
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / event / TmfTimePreferencesTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.event;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17
18 import java.util.Map;
19 import java.util.TimeZone;
20
21 import org.eclipse.core.runtime.preferences.DefaultScope;
22 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
23 import org.eclipse.core.runtime.preferences.InstanceScope;
24 import org.eclipse.linuxtools.internal.tmf.core.Activator;
25 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimePreferencesConstants;
26 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimePreferences;
27 import org.junit.Test;
28 import org.osgi.service.prefs.BackingStoreException;
29
30 /**
31 * Test suite for the TmfTimePreferences class.
32 */
33 public class TmfTimePreferencesTest {
34
35 private static final String TIME_PATTERN = "HH:mm:ss.SSS SSS SSS";
36 private static final String INTERVAL_PATTERN = "TTT.SSS SSS SSS";
37
38 /**
39 * Test that the preferences get initialized to the default
40 */
41 @Test
42 public void testInit() {
43 assertEquals(DefaultScope.INSTANCE.getNode(Activator.PLUGIN_ID).get(ITmfTimePreferencesConstants.DATIME, null), ITmfTimePreferencesConstants.TIME_HOUR_FMT);
44 }
45
46 /**
47 * Test that getInstance returns an instance
48 */
49 @Test
50 public void testGetInstance() {
51 assertNotNull(TmfTimePreferences.getInstance());
52 }
53
54 /**
55 * Test that getTimePattern returns the appropriate time pattern (from the default)
56 */
57 @Test
58 public void testGetTimePattern() {
59 assertEquals(TIME_PATTERN, TmfTimePreferences.getInstance().getTimePattern());
60 }
61
62 /**
63 * Test that getIntervalPattern returns the appropriate interval pattern (from the default)
64 */
65 @Test
66 public void testGetIntervalPattern() {
67 assertEquals(INTERVAL_PATTERN, TmfTimePreferences.getInstance().getIntervalPattern());
68 }
69
70 /**
71 * Test that getTimeZone returns the appropriate time zone (from the default)
72 */
73 @Test
74 public void testGetTimeZone() {
75 assertEquals(TimeZone.getDefault(), TmfTimePreferences.getInstance().getTimeZone());
76 }
77
78 /**
79 * Test that getPreferenceMap returns the appropriate map even after preferences get modified
80 * and make sure it doesn't affect the defaults
81 */
82 @Test
83 public void testGetPreferenceMap() {
84 Map<String, String> defaultPreferenceMap = TmfTimePreferences.getInstance().getDefaultPreferenceMap();
85 assertEquals(ITmfTimePreferencesConstants.TIME_HOUR_FMT, defaultPreferenceMap.get(ITmfTimePreferencesConstants.DATIME));
86
87 // Modify the preferences
88 String testValue = ITmfTimePreferencesConstants.TIME_HOUR_FMT + "foo";
89 IEclipsePreferences node = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
90 node.put(ITmfTimePreferencesConstants.DATIME, testValue);
91 try {
92 node.flush();
93 } catch (BackingStoreException e) {
94 }
95 // Make sure the modification is in the map
96 Map<String, String> preferenceMap = TmfTimePreferences.getInstance().getPreferenceMap();
97 assertEquals(testValue, preferenceMap.get(ITmfTimePreferencesConstants.DATIME));
98
99 // Make sure the default is still the same
100 defaultPreferenceMap = TmfTimePreferences.getInstance().getDefaultPreferenceMap();
101 assertEquals(ITmfTimePreferencesConstants.TIME_HOUR_FMT, defaultPreferenceMap.get(ITmfTimePreferencesConstants.DATIME));
102 }
103
104 /**
105 * Test that computeTimePattern computes the appropriate time pattern from a preference map (from the default)
106 */
107 @Test
108 public void testComputeTimePattern() {
109 assertEquals(TIME_PATTERN, TmfTimePreferences.getInstance().computeTimePattern(TmfTimePreferences.getInstance().getPreferenceMap()));
110 }
111
112 }
This page took 0.038746 seconds and 6 git commands to generate.