1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertFalse
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertTrue
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTimestamp
.TimestampType
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
25 import org
.junit
.After
;
26 import org
.junit
.Before
;
27 import org
.junit
.Test
;
30 * The class <code>CtfTmfTimestampTest</code> contains tests for the class
31 * <code>{@link CtfTmfTimestamp}</code>.
36 public class CtfTmfTimestampTest
{
38 private CtfTmfTimestamp fixture
;
43 * @param args the command line arguments
45 public static void main(String
[] args
) {
46 new org
.junit
.runner
.JUnitCore().run(CtfTmfTimestampTest
.class);
50 * Perform pre-test initialization.
54 fixture
= new CtfTmfTimestamp(1L);
55 fixture
.setType(CtfTmfTimestamp
.TimestampType
.DAY
);
59 * Perform post-test clean-up.
62 public void tearDown() {
63 // Add additional tear down code here
68 * Run the CtfTmfTimestamp(long) constructor test.
71 public void testCtfTmfTimestamp() {
74 CtfTmfTimestamp result
= new CtfTmfTimestamp(timestamp
);
75 result
.setType(TimestampType
.NANOS
);
77 assertNotNull(result
);
78 assertEquals("1 ns", result
.toString()); //$NON-NLS-1$
79 assertEquals(0, result
.getPrecision());
80 assertEquals(-9, result
.getScale());
81 assertEquals(1L, result
.getValue());
86 * Run the boolean equals(Object) method test with another identical object.
89 public void testEquals_same() {
90 CtfTmfTimestamp obj
= new CtfTmfTimestamp(1L);
91 obj
.setType(CtfTmfTimestamp
.TimestampType
.DAY
);
93 boolean result
= fixture
.equals(obj
);
98 * Run the boolean equals(Object) method test, with an empty object.
101 public void testEquals_empty() {
102 Object obj
= new Object();
104 boolean result
= fixture
.equals(obj
);
109 * Run the ITmfTimestamp getDelta(ITmfTimestamp) method test.
112 public void testGetDelta() {
113 ITmfTimestamp ts
= new TmfTimestamp();
114 ITmfTimestamp result
= fixture
.getDelta(ts
);
116 assertNotNull(result
);
117 assertEquals(0, result
.getPrecision());
118 assertEquals(-9, result
.getScale());
119 assertEquals(1L, result
.getValue());
123 * Run the CtfTmfTimestamp.TimestampType getType() method test.
126 public void testGetType() {
127 CtfTmfTimestamp
.TimestampType result
= fixture
.getType();
129 assertNotNull(result
);
130 assertEquals("DAY", result
.name()); //$NON-NLS-1$
131 assertEquals("DAY", result
.toString()); //$NON-NLS-1$
132 assertEquals(1, result
.ordinal());
136 * Run the int hashCode() method test.
139 public void testHashCode() {
140 int result
= fixture
.hashCode();
141 assertEquals(1012115, result
);
145 * Run the int hashCode() method test.
148 public void testHashCode_nullType() {
149 fixture
.setType(null);
150 int result
= fixture
.hashCode();
151 assertEquals(944663, result
);
155 * Run the void setType(TimestampType) method test.
158 public void testSetType() {
159 CtfTmfTimestamp
.TimestampType value
= CtfTmfTimestamp
.TimestampType
.DAY
;
160 fixture
.setType(value
);
164 * Run the String toString() method test.
167 public void testToString_ns() {
168 fixture
.setType(CtfTmfTimestamp
.TimestampType
.NANOS
);
169 String result
= fixture
.toString();
170 assertEquals("1 ns", result
); //$NON-NLS-1$
174 * Run the String toString() method test.
177 public void testToString_s() {
178 fixture
.setType(CtfTmfTimestamp
.TimestampType
.SECONDS
);
179 String result
= fixture
.toString();
180 assertEquals("1.0E-9 s", result
); //$NON-NLS-1$
184 * Run the String toString() method test.
187 public void testToString_day() {
188 String result
= fixture
.toString();
189 assertEquals("19:00:00.000000001", result
); //$NON-NLS-1$
193 * Run the String toString() method test.
196 public void testToString_full() {
197 fixture
.setType(CtfTmfTimestamp
.TimestampType
.FULL_DATE
);
198 String result
= fixture
.toString();
199 assertEquals("1969-12-31 19:00:00.000000001", result
); //$NON-NLS-1$
This page took 0.038083 seconds and 6 git commands to generate.