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
d18dd09b 1/*******************************************************************************
61759503 2 * Copyright (c) 2009, 2013 Ericsson
54a7a54c 3 *
d18dd09b
ASL
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
54a7a54c 8 *
d18dd09b
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
0316808c 11 * Francois Chouinard - Adapted for TMF Trace Model 1.0
6e1886bc 12 * Alexandre Montplaisir - Port to JUnit4
ea271da6 13 * Patrick Tasse - Updated for location in checkpoint
d18dd09b
ASL
14 *******************************************************************************/
15
6c13869b 16package org.eclipse.linuxtools.tmf.core.tests.trace;
d18dd09b 17
6e1886bc
AM
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertFalse;
6e1886bc
AM
20import static org.junit.Assert.assertTrue;
21import static org.junit.Assert.fail;
d18dd09b 22
3bd46eef
AM
23import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
24import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
cb8c854e 25import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
6c13869b 26import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
cb8c854e 27import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation;
6e1886bc 28import org.junit.Test;
d18dd09b
ASL
29
30/**
d18dd09b
ASL
31 * Test suite for the TmfCheckpoint class.
32 */
cad06250 33@SuppressWarnings("javadoc")
6e1886bc 34public class TmfCheckpointTest {
d18dd09b 35
5d837f9b
FC
36 // ------------------------------------------------------------------------
37 // Variables
38 // ------------------------------------------------------------------------
39
6e1886bc
AM
40 private ITmfTimestamp fTimestamp1 = new TmfTimestamp();
41 private ITmfTimestamp fTimestamp2 = TmfTimestamp.BIG_BANG;
42 private ITmfTimestamp fTimestamp3 = TmfTimestamp.BIG_CRUNCH;
d18dd09b 43
6e1886bc
AM
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);
d18dd09b 50
ea271da6
PT
51 private TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
52 private TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2);
53 private TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3);
d18dd09b
ASL
54
55 // ------------------------------------------------------------------------
56 // Constructors
57 // ------------------------------------------------------------------------
58
6e1886bc 59 @Test
5d837f9b
FC
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
6e1886bc 72 @Test
54a7a54c 73 public void testTmfLocationCopy2() {
5d837f9b
FC
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 }
d18dd09b 85
ff1ccee6
FC
86 // ------------------------------------------------------------------------
87 // compareTo
88 // ------------------------------------------------------------------------
89
6e1886bc 90 @Test
ff1ccee6
FC
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
6e1886bc 105 @Test
ff1ccee6 106 public void testCompareToNull() {
ea271da6
PT
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);
ff1ccee6
FC
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
6e1886bc 133 @Test
54a7a54c 134 public void testHashCode() {
ff1ccee6
FC
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
6e1886bc 145 @Test
54a7a54c 146 public void testHashCodeNull() {
ea271da6 147 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1);
ff1ccee6
FC
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
d18dd09b
ASL
159 // ------------------------------------------------------------------------
160 // equals
161 // ------------------------------------------------------------------------
162
6e1886bc 163 @Test
54a7a54c 164 public void testEqualsReflexivity() {
5d837f9b
FC
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
6e1886bc 172 @Test
54a7a54c 173 public void testEqualsSymmetry() {
5d837f9b
FC
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
6e1886bc 184 @Test
54a7a54c 185 public void testEqualsTransivity() {
5d837f9b
FC
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
6e1886bc 195 @Test
54a7a54c 196 public void testNotEqual() {
8ca8c4f1 197 // Various checkpoints
ea271da6
PT
198 final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1);
199 final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp2, fLocation1);
200 final TmfCheckpoint checkpoint3 = new TmfCheckpoint(fTimestamp1, fLocation2);
8ca8c4f1 201 final TmfCheckpoint checkpoint4 = new TmfCheckpoint(fTimestamp1, null);
ea271da6 202 final TmfCheckpoint checkpoint5 = new TmfCheckpoint(null, fLocation1);
8ca8c4f1
FC
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));
5d837f9b
FC
219 }
220
d18dd09b
ASL
221 // ------------------------------------------------------------------------
222 // toString
223 // ------------------------------------------------------------------------
224
6e1886bc 225 @Test
5d837f9b 226 public void testToString() {
ea271da6 227 final String expected1 = "TmfCheckpoint [fLocation=" + fCheckpoint1.getLocation() +
5d837f9b 228 ", fTimestamp=" + fCheckpoint1.getTimestamp() + "]";
ea271da6 229 final String expected2 = "TmfCheckpoint [fLocation=" + fCheckpoint2.getLocation() +
5d837f9b 230 ", fTimestamp=" + fCheckpoint2.getTimestamp() + "]";
ea271da6 231 final String expected3 = "TmfCheckpoint [fLocation=" + fCheckpoint3.getLocation() +
5d837f9b 232 ", fTimestamp=" + fCheckpoint3.getTimestamp() + "]";
d18dd09b 233
5d837f9b
FC
234 assertEquals("toString", expected1, fCheckpoint1.toString());
235 assertEquals("toString", expected2, fCheckpoint2.toString());
236 assertEquals("toString", expected3, fCheckpoint3.toString());
237 }
d18dd09b 238
d18dd09b 239}
This page took 0.052975 seconds and 5 git commands to generate.