tmf: Disable NLS warnings in tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfCheckpointTest.java
... / ...
CommitLineData
1/*******************************************************************************
2 * Copyright (c) 2009, 2013 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 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adapted for TMF Trace Model 1.0
12 * Alexandre Montplaisir - Port to JUnit4
13 * Patrick Tasse - Updated for location in checkpoint
14 *******************************************************************************/
15
16package org.eclipse.linuxtools.tmf.core.tests.trace;
17
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertTrue;
21import static org.junit.Assert.fail;
22
23import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
24import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
25import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
26import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
27import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
28import org.junit.Test;
29
30/**
31 * Test suite for the TmfCheckpoint class.
32 */
33@SuppressWarnings("javadoc")
34public class TmfCheckpointTest {
35
36 // ------------------------------------------------------------------------
37 // Variables
38 // ------------------------------------------------------------------------
39
40 private ITmfTimestamp fTimestamp1 = new TmfTimestamp();
41 private ITmfTimestamp fTimestamp2 = TmfTimestamp.BIG_BANG;
42 private ITmfTimestamp fTimestamp3 = TmfTimestamp.BIG_CRUNCH;
43
44 private Long aLong1 = 12345L;
45 private Long aLong2 = 23456L;
46 private Long aLong3 = 34567L;
47 private ITmfLocation fLocation1 = new TmfLongLocation(aLong1);
48 private ITmfLocation fLocation2 = new TmfLongLocation(aLong2);
49 private ITmfLocation fLocation3 = new TmfLongLocation(aLong3);
50
51 private TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
52 private TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2);
53 private TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3);
54
55 // ------------------------------------------------------------------------
56 // Constructors
57 // ------------------------------------------------------------------------
58
59 @Test
60 public void testTmfCheckpoint() {
61 assertEquals("TmfCheckpoint", fTimestamp1, fCheckpoint1.getTimestamp());
62 assertEquals("TmfCheckpoint", fLocation1, fCheckpoint1.getLocation());
63 }
64
65 public void testTmfLocationCopy() {
66 final TmfCheckpoint checkpoint = new TmfCheckpoint(fCheckpoint1);
67
68 assertEquals("TmfCheckpoint", fTimestamp1, checkpoint.getTimestamp());
69 assertEquals("TmfCheckpoint", fLocation1, checkpoint.getLocation());
70 }
71
72 @Test
73 public void testTmfLocationCopy2() {
74 try {
75 new TmfCheckpoint(null);
76 fail("null copy");
77 }
78 catch (final IllegalArgumentException e) {
79 // Success
80 }
81 catch (final Exception e) {
82 fail("wrong exception");
83 }
84 }
85
86 // ------------------------------------------------------------------------
87 // compareTo
88 // ------------------------------------------------------------------------
89
90 @Test
91 public void testCompareTo() {
92 assertEquals("compareTo", 0, fCheckpoint1.compareTo(fCheckpoint1));
93 assertEquals("compareTo", 1, fCheckpoint1.compareTo(fCheckpoint2));
94 assertEquals("compareTo", -1, fCheckpoint1.compareTo(fCheckpoint3));
95
96 assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint1));
97 assertEquals("compareTo", 0, fCheckpoint2.compareTo(fCheckpoint2));
98 assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint3));
99
100 assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint1));
101 assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint2));
102 assertEquals("compareTo", 0, fCheckpoint3.compareTo(fCheckpoint3));
103 }
104
105 @Test
106 public void testCompareToNull() {
107 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1);
108 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(null, fLocation2);
109 final TmfCheckpoint checkpoint3 = new TmfCheckpoint(null, fLocation3);
110 final TmfCheckpoint checkpoint4 = new TmfCheckpoint(null, fLocation1);
111
112 // Test the various 'null' vs. '!null' combinations
113 assertEquals("compareTo", 0, checkpoint1.compareTo(fCheckpoint1));
114 assertEquals("compareTo", 0, fCheckpoint1.compareTo(checkpoint1));
115 assertEquals("compareTo", -1, checkpoint1.compareTo(fCheckpoint2));
116 assertEquals("compareTo", 1, fCheckpoint2.compareTo(checkpoint1));
117 assertEquals("compareTo", -1, checkpoint1.compareTo(fCheckpoint3));
118 assertEquals("compareTo", 1, fCheckpoint3.compareTo(checkpoint1));
119
120 // Test the 'null' vs. 'null' combinations
121 assertEquals("compareTo", 0, checkpoint1.compareTo(checkpoint4));
122 assertEquals("compareTo", 0, checkpoint4.compareTo(checkpoint1));
123 assertEquals("compareTo", -1, checkpoint1.compareTo(checkpoint2));
124 assertEquals("compareTo", 1, checkpoint2.compareTo(checkpoint1));
125 assertEquals("compareTo", -1, checkpoint1.compareTo(checkpoint3));
126 assertEquals("compareTo", 1, checkpoint3.compareTo(checkpoint1));
127 }
128
129 // ------------------------------------------------------------------------
130 // hashCode
131 // ------------------------------------------------------------------------
132
133 @Test
134 public void testHashCode() {
135 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
136 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2);
137
138 assertTrue("hashCode", fCheckpoint1.hashCode() == checkpoint1.hashCode());
139 assertTrue("hashCode", fCheckpoint2.hashCode() == checkpoint2.hashCode());
140
141 assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode());
142 assertTrue("hashCode", fCheckpoint2.hashCode() != checkpoint1.hashCode());
143 }
144
145 @Test
146 public void testHashCodeNull() {
147 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1);
148 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp1, null);
149 final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint1);
150 final TmfCheckpoint checkpoint4 = new TmfCheckpoint(checkpoint2);
151
152 assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint1.hashCode());
153 assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode());
154
155 assertTrue("hashCode", checkpoint1.hashCode() == checkpoint3.hashCode());
156 assertTrue("hashCode", checkpoint2.hashCode() == checkpoint4.hashCode());
157 }
158
159 // ------------------------------------------------------------------------
160 // equals
161 // ------------------------------------------------------------------------
162
163 @Test
164 public void testEqualsReflexivity() {
165 assertTrue("equals", fCheckpoint1.equals(fCheckpoint1));
166 assertTrue("equals", fCheckpoint2.equals(fCheckpoint2));
167
168 assertTrue("equals", !fCheckpoint1.equals(fCheckpoint2));
169 assertTrue("equals", !fCheckpoint2.equals(fCheckpoint1));
170 }
171
172 @Test
173 public void testEqualsSymmetry() {
174 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
175 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2);
176
177 assertTrue("equals", checkpoint1.equals(fCheckpoint1));
178 assertTrue("equals", fCheckpoint1.equals(checkpoint1));
179
180 assertTrue("equals", checkpoint2.equals(fCheckpoint2));
181 assertTrue("equals", fCheckpoint2.equals(checkpoint2));
182 }
183
184 @Test
185 public void testEqualsTransivity() {
186 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1);
187 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(checkpoint1);
188 final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint2);
189
190 assertTrue("equals", checkpoint1.equals(checkpoint2));
191 assertTrue("equals", checkpoint2.equals(checkpoint3));
192 assertTrue("equals", checkpoint1.equals(checkpoint3));
193 }
194
195 @Test
196 public void testNotEqual() {
197 // Various checkpoints
198 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
199 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp2, fLocation1);
200 final TmfCheckpoint checkpoint3 = new TmfCheckpoint(fTimestamp1, fLocation2);
201 final TmfCheckpoint checkpoint4 = new TmfCheckpoint(fTimestamp1, null);
202 final TmfCheckpoint checkpoint5 = new TmfCheckpoint(null, fLocation1);
203
204 // Null check
205 assertFalse("equals", checkpoint1.equals(null));
206
207 // Different types
208 assertFalse("equals", checkpoint1.equals(new TmfTimestamp()));
209
210 // Null locations/location
211 assertFalse("equals", checkpoint1.equals(checkpoint4));
212 assertFalse("equals", checkpoint1.equals(checkpoint5));
213 assertFalse("equals", checkpoint4.equals(checkpoint1));
214 assertFalse("equals", checkpoint5.equals(checkpoint1));
215
216 // Different locations/location
217 assertFalse("equals", checkpoint1.equals(checkpoint2));
218 assertFalse("equals", checkpoint1.equals(checkpoint3));
219 }
220
221 // ------------------------------------------------------------------------
222 // toString
223 // ------------------------------------------------------------------------
224
225 @Test
226 public void testToString() {
227 final String expected1 = "TmfCheckpoint [fLocation=" + fCheckpoint1.getLocation() +
228 ", fTimestamp=" + fCheckpoint1.getTimestamp() + "]";
229 final String expected2 = "TmfCheckpoint [fLocation=" + fCheckpoint2.getLocation() +
230 ", fTimestamp=" + fCheckpoint2.getTimestamp() + "]";
231 final String expected3 = "TmfCheckpoint [fLocation=" + fCheckpoint3.getLocation() +
232 ", fTimestamp=" + fCheckpoint3.getTimestamp() + "]";
233
234 assertEquals("toString", expected1, fCheckpoint1.toString());
235 assertEquals("toString", expected2, fCheckpoint2.toString());
236 assertEquals("toString", expected3, fCheckpoint3.toString());
237 }
238
239}
This page took 0.025983 seconds and 5 git commands to generate.