1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.event
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventReference
;
20 * <b><u>TmfEventReferenceTest</u></b>
22 * Test suite for the TmfEventReference class.
24 public class TmfEventReferenceTest
extends TestCase
{
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
30 private final Object reference0
= new String("Some reference");
31 private final Object reference2
= new String("Some other reference");
33 private TmfEventReference fReference0
= new TmfEventReference(reference0
);
34 private TmfEventReference fReference1
= new TmfEventReference(reference0
);
35 private TmfEventReference fReference2
= new TmfEventReference(reference0
);
36 private TmfEventReference fReference3
= new TmfEventReference(reference2
);
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
43 * @param name the test name
45 public TmfEventReferenceTest(String name
) {
50 protected void setUp() throws Exception
{
55 protected void tearDown() throws Exception
{
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 public void testTmfEventReferenceDefault() {
64 TmfEventReference reference
= new TmfEventReference();
65 assertEquals("getReference", null, reference
.getReference());
68 public void testTmfEventReference() {
69 TmfEventReference reference
= new TmfEventReference(reference0
);
70 assertSame("getReference", reference0
, reference
.getReference());
73 public void testTmfEventReferenceCopy() {
74 TmfEventReference original
= new TmfEventReference(reference0
);
75 TmfEventReference reference
= new TmfEventReference(original
);
76 assertSame("getReference", reference0
, reference
.getReference());
79 public void testTmfEventReferenceCopy2() {
81 @SuppressWarnings("unused")
82 TmfEventReference reference
= new TmfEventReference(null);
85 catch (IllegalArgumentException e
) {
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
94 public void testEqualsReflexivity() throws Exception
{
95 assertTrue("equals", fReference0
.equals(fReference0
));
96 assertTrue("equals", fReference3
.equals(fReference3
));
98 assertTrue("equals", !fReference0
.equals(fReference3
));
99 assertTrue("equals", !fReference3
.equals(fReference0
));
102 public void testEqualsSymmetry() throws Exception
{
103 assertTrue("equals", fReference0
.equals(fReference1
));
104 assertTrue("equals", fReference1
.equals(fReference0
));
106 assertTrue("equals", !fReference0
.equals(fReference3
));
107 assertTrue("equals", !fReference3
.equals(fReference0
));
110 public void testEqualsTransivity() throws Exception
{
111 assertTrue("equals", fReference0
.equals(fReference1
));
112 assertTrue("equals", fReference1
.equals(fReference2
));
113 assertTrue("equals", fReference0
.equals(fReference2
));
116 public void testEqualsNull() throws Exception
{
117 assertTrue("equals", !fReference0
.equals(null));
118 assertTrue("equals", !fReference3
.equals(null));
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
125 public void testHashCode() throws Exception
{
126 assertTrue("hashCode", fReference0
.hashCode() == fReference1
.hashCode());
127 assertTrue("hashCode", fReference0
.hashCode() != fReference3
.hashCode());
130 public void testHashCode2() throws Exception
{
131 TmfEventReference reference0
= new TmfEventReference();
132 assertTrue("hashCode", fReference0
.hashCode() != reference0
.hashCode());
133 assertTrue("hashCode", fReference3
.hashCode() != reference0
.hashCode());
136 // ------------------------------------------------------------------------
138 // ------------------------------------------------------------------------
140 public void testToString() {
141 String expected1
= "[TmfEventReference(" + "null" + ")]";
142 TmfEventReference reference1
= new TmfEventReference();
143 assertEquals("toString", expected1
, reference1
.toString());
145 String expected2
= "[TmfEventReference(" + reference0
.toString() + ")]";
146 TmfEventReference reference2
= new TmfEventReference(reference0
);
147 assertEquals("toString", expected2
, reference2
.toString());