Fix another pile of Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfLocationTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 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 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.trace;
14
15 import junit.framework.TestCase;
16
17 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
18 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
19 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
20
21 /**
22 * Test suite for the TmfLocation class.
23 */
24 @SuppressWarnings({"nls","javadoc"})
25 public class TmfLocationTest extends TestCase {
26
27 // ------------------------------------------------------------------------
28 // Variables
29 // ------------------------------------------------------------------------
30
31 String aString = "some location";
32 Long aLong = 12345L;
33 TmfTimestamp aTimestamp = new TmfTimestamp();
34
35 TmfLocation<String> fLocation1;
36 TmfLocation<String> fLocation2;
37 TmfLocation<Long> fLocation3;
38 TmfLocation<ITmfTimestamp> fLocation4;
39
40 // ------------------------------------------------------------------------
41 // Housekeeping
42 // ------------------------------------------------------------------------
43
44 /**
45 * @param name
46 * the test name
47 */
48 public TmfLocationTest(String name) {
49 super(name);
50 }
51
52 @Override
53 protected void setUp() throws Exception {
54 super.setUp();
55 fLocation1 = new TmfLocation<String>((String) null);
56 fLocation2 = new TmfLocation<String>(aString);
57 fLocation3 = new TmfLocation<Long>(aLong);
58 fLocation4 = new TmfLocation<ITmfTimestamp>(aTimestamp);
59 }
60
61 @Override
62 protected void tearDown() throws Exception {
63 super.tearDown();
64 }
65
66 // ------------------------------------------------------------------------
67 // Constructors
68 // ------------------------------------------------------------------------
69
70 public void testTmfLocation() {
71 assertNull("TmfLocation", fLocation1.getLocation());
72 assertEquals("TmfLocation", aString, fLocation2.getLocation());
73 assertEquals("TmfLocation", aLong, fLocation3.getLocation());
74 assertEquals("TmfLocation", aTimestamp, fLocation4.getLocation());
75 }
76
77 public void testTmfLocationCopy() {
78 TmfLocation<String> location1 = new TmfLocation<String>(fLocation1);
79 TmfLocation<String> location2 = new TmfLocation<String>(fLocation2);
80 TmfLocation<Long> location3 = new TmfLocation<Long>(fLocation3);
81 TmfLocation<ITmfTimestamp> location4 = new TmfLocation<ITmfTimestamp>(fLocation4);
82
83 assertNull("TmfLocation", location1.getLocation());
84 assertEquals("TmfLocation", aString, location2.getLocation());
85 assertEquals("TmfLocation", aLong, location3.getLocation());
86 assertEquals("TmfLocation", aTimestamp, location4.getLocation());
87 }
88
89 // ------------------------------------------------------------------------
90 // clone
91 // ------------------------------------------------------------------------
92
93 public void testClone() {
94 try {
95 TmfLocation<String> location1 = fLocation1.clone();
96 TmfLocation<String> location2 = fLocation2.clone();
97 TmfLocation<Long> location3 = fLocation3.clone();
98 TmfLocation<ITmfTimestamp> location4 = fLocation4.clone();
99
100 assertEquals("clone", fLocation1, location1);
101 assertEquals("clone", fLocation2, location2);
102 assertEquals("clone", fLocation3, location3);
103 assertEquals("clone", fLocation4, location4);
104
105 assertEquals("clone", fLocation1.getLocation(), location1.getLocation());
106 assertEquals("clone", fLocation2.getLocation(), location2.getLocation());
107 assertEquals("clone", fLocation3.getLocation(), location3.getLocation());
108 assertEquals("clone", fLocation4.getLocation(), location4.getLocation());
109
110 assertNull("clone", location1.getLocation());
111 assertEquals("clone", aString, location2.getLocation());
112 assertEquals("clone", aLong, location3.getLocation());
113 assertEquals("clone", aTimestamp, location4.getLocation());
114 } catch (InternalError e) {
115 fail("clone()");
116 }
117 }
118
119 private static class MyCloneableClass implements Cloneable, Comparable<MyCloneableClass> {
120 private String fName;
121
122 public MyCloneableClass(String name) {
123 fName = name;
124 }
125
126 @Override
127 public String toString() {
128 return fName;
129 }
130
131 @Override
132 public MyCloneableClass clone() {
133 MyCloneableClass clone = null;
134 try {
135 clone = (MyCloneableClass) super.clone();
136 clone.fName = fName;
137 } catch (CloneNotSupportedException e) {
138 }
139 return clone;
140 }
141
142 @Override
143 public int compareTo(MyCloneableClass o) {
144 return fName.compareTo(o.fName);
145 }
146
147 @Override
148 public int hashCode() {
149 final int prime = 31;
150 int result = 1;
151 result = prime * result + ((fName == null) ? 0 : fName.hashCode());
152 return result;
153 }
154
155 @Override
156 public boolean equals(Object obj) {
157 if (this == obj) {
158 return true;
159 }
160 if (obj == null) {
161 return false;
162 }
163 if (!(obj instanceof MyCloneableClass)) {
164 return false;
165 }
166 MyCloneableClass other = (MyCloneableClass) obj;
167 if (fName == null) {
168 if (other.fName != null) {
169 return false;
170 }
171 } else if (!fName.equals(other.fName)) {
172 return false;
173 }
174 return true;
175 }
176 }
177
178 public void testCloneCloneable() {
179 try {
180 MyCloneableClass myClass = new MyCloneableClass("myCloneableClass");
181 TmfLocation<MyCloneableClass> location = new TmfLocation<MyCloneableClass>(myClass);
182 TmfLocation<MyCloneableClass> clone = location.clone();
183
184 assertEquals("clone", location, clone);
185 assertEquals("clone", location.getLocation(), clone.getLocation());
186 assertEquals("clone", myClass, location.getLocation());
187 } catch (InternalError e) {
188 fail("clone a cloneable class");
189 }
190 }
191
192 private static class MyUnCloneableClass implements Comparable<MyUnCloneableClass> {
193 private String fName;
194
195 public MyUnCloneableClass(String name) {
196 fName = name;
197 }
198
199 @Override
200 public String toString() {
201 return fName;
202 }
203
204 @Override
205 public Object clone() throws CloneNotSupportedException {
206 throw new CloneNotSupportedException();
207 }
208
209 @Override
210 public int compareTo(MyUnCloneableClass o) {
211 return fName.compareTo(o.fName);
212 }
213
214 @Override
215 public int hashCode() {
216 final int prime = 31;
217 int result = 1;
218 result = prime * result + ((fName == null) ? 0 : fName.hashCode());
219 return result;
220 }
221
222 @Override
223 public boolean equals(Object obj) {
224 if (this == obj) {
225 return true;
226 }
227 if (obj == null) {
228 return false;
229 }
230 if (!(obj instanceof MyUnCloneableClass)) {
231 return false;
232 }
233 MyUnCloneableClass other = (MyUnCloneableClass) obj;
234 if (fName == null) {
235 if (other.fName != null) {
236 return false;
237 }
238 } else if (!fName.equals(other.fName)) {
239 return false;
240 }
241 return true;
242 }
243 }
244
245 public void testCloneUncloneable() {
246 try {
247 MyUnCloneableClass myClass = new MyUnCloneableClass("myUncloneableClass");
248 TmfLocation<MyUnCloneableClass> myLocation = new TmfLocation<MyUnCloneableClass>(myClass);
249 myLocation.clone();
250 fail("clone an uncloneable class");
251 } catch (InternalError e) {
252 }
253 }
254
255 // ------------------------------------------------------------------------
256 // hashCode
257 // ------------------------------------------------------------------------
258
259 public void testHashCode() {
260 TmfLocation<String> location1 = new TmfLocation<String>((String) null);
261 TmfLocation<String> location2 = new TmfLocation<String>(aString);
262 TmfLocation<Long> location3 = new TmfLocation<Long>(aLong);
263
264 assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
265 assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
266 assertTrue("hashCode", fLocation3.hashCode() == location3.hashCode());
267
268 assertTrue("hashCode", fLocation2.hashCode() != location3.hashCode());
269 assertTrue("hashCode", fLocation3.hashCode() != location2.hashCode());
270 }
271
272 // ------------------------------------------------------------------------
273 // toEquals
274 // ------------------------------------------------------------------------
275
276 private static class TmfLocation2 extends TmfLocation<String> {
277 public TmfLocation2(String location) {
278 super(location);
279 }
280 }
281
282 public void testEqualsWrongTypes() {
283 TmfLocation<String> location1 = new TmfLocation<String>(aString);
284 TmfLocation2 location2 = new TmfLocation2(aString);
285
286 assertFalse("equals", location1.equals(location2));
287 assertFalse("equals", location2.equals(location1));
288 }
289
290 public void testEqualsWithNulls() {
291 TmfLocation<String> location1 = new TmfLocation<String>(aString);
292 TmfLocation<String> location2 = new TmfLocation<String>((String) null);
293
294 assertFalse("equals", location1.equals(location2));
295 assertFalse("equals", location2.equals(location1));
296 }
297
298 public void testEqualsReflexivity() {
299 assertTrue("equals", fLocation2.equals(fLocation2));
300 assertTrue("equals", fLocation3.equals(fLocation3));
301
302 assertTrue("equals", !fLocation2.equals(fLocation3));
303 assertTrue("equals", !fLocation3.equals(fLocation2));
304 }
305
306 public void testEqualsSymmetry() {
307 TmfLocation<String> location2 = new TmfLocation<String>(aString);
308 TmfLocation<Long> location3 = new TmfLocation<Long>(aLong);
309
310 assertTrue("equals", location2.equals(fLocation2));
311 assertTrue("equals", fLocation2.equals(location2));
312
313 assertTrue("equals", location3.equals(fLocation3));
314 assertTrue("equals", fLocation3.equals(location3));
315 }
316
317 public void testEqualsTransivity() {
318 TmfLocation<String> location1 = new TmfLocation<String>(aString);
319 TmfLocation<String> location2 = new TmfLocation<String>(aString);
320 TmfLocation<String> location3 = new TmfLocation<String>(aString);
321
322 assertTrue("equals", location1.equals(location2));
323 assertTrue("equals", location2.equals(location3));
324 assertTrue("equals", location3.equals(location1));
325 }
326
327 public void testEqualsNull() {
328 assertTrue("equals", !fLocation2.equals(null));
329 assertTrue("equals", !fLocation2.equals(null));
330 }
331
332 // ------------------------------------------------------------------------
333 // toString
334 // ------------------------------------------------------------------------
335
336 @SuppressWarnings("hiding")
337 public void testToString() {
338 String aString = "some location";
339 Long aLong = 12345L;
340 TmfTimestamp aTimestamp = new TmfTimestamp();
341
342 TmfLocation<String> location1 = new TmfLocation<String>(aString);
343 TmfLocation<Long> location2 = new TmfLocation<Long>(aLong);
344 TmfLocation<ITmfTimestamp> location3 = new TmfLocation<ITmfTimestamp>(aTimestamp);
345
346 String expected1 = "TmfLocation [fLocation=" + aString + "]";
347 String expected2 = "TmfLocation [fLocation=" + aLong + "]";
348 String expected3 = "TmfLocation [fLocation=" + aTimestamp + "]";
349
350 assertEquals("toString", expected1, location1.toString());
351 assertEquals("toString", expected2, location2.toString());
352 assertEquals("toString", expected3, location3.toString());
353 }
354
355 }
This page took 0.041825 seconds and 5 git commands to generate.