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
.core
.tests
.event
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventSource
;
20 * <b><u>TmfEventSourceTest</u></b>
22 * Test suite for the TmfEventSource class.
24 @SuppressWarnings("nls")
25 public class TmfEventSourceTest
extends TestCase
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 private final Object source1
= new String("Some source");
32 private final Object source2
= new String("Some other source");
34 private final TmfEventSource fSource0
= new TmfEventSource(source1
);
35 private final TmfEventSource fSource1
= new TmfEventSource(source1
);
36 private final TmfEventSource fSource2
= new TmfEventSource(source1
);
37 private final TmfEventSource fSource3
= new TmfEventSource(source2
);
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * @param name the test name
46 public TmfEventSourceTest(String name
) {
51 protected void setUp() throws Exception
{
56 protected void tearDown() throws Exception
{
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 public void testTmfEventSourceDefault() {
65 TmfEventSource source
= new TmfEventSource();
66 assertEquals("getSourceId", null, source
.getSourceId());
69 public void testTmfEventSource() {
70 TmfEventSource source
= new TmfEventSource(source1
);
71 assertSame("getSourceId", source1
, source
.getSourceId());
74 public void testTmfEventSourceCopy() {
75 TmfEventSource original
= new TmfEventSource(source1
);
76 TmfEventSource source
= new TmfEventSource(original
);
77 assertSame("getSourceId", source1
, source
.getSourceId());
80 public void testTmfEventSourceCopy2() {
82 @SuppressWarnings("unused")
83 TmfEventSource source
= new TmfEventSource(null);
86 catch (IllegalArgumentException e
) {
91 // ------------------------------------------------------------------------
93 // ------------------------------------------------------------------------
95 public void testEqualsReflexivity() throws Exception
{
96 assertTrue("equals", fSource0
.equals(fSource0
));
97 assertTrue("equals", fSource3
.equals(fSource3
));
99 assertTrue("equals", !fSource0
.equals(fSource3
));
100 assertTrue("equals", !fSource3
.equals(fSource0
));
103 public void testEqualsSymmetry() throws Exception
{
104 assertTrue("equals", fSource0
.equals(fSource2
));
105 assertTrue("equals", fSource2
.equals(fSource0
));
107 assertTrue("equals", !fSource0
.equals(fSource3
));
108 assertTrue("equals", !fSource3
.equals(fSource0
));
111 public void testEqualsTransivity() throws Exception
{
112 assertTrue("equals", fSource0
.equals(fSource1
));
113 assertTrue("equals", fSource1
.equals(fSource2
));
114 assertTrue("equals", fSource0
.equals(fSource2
));
117 public void testEqualsNull() throws Exception
{
118 assertTrue("equals", !fSource0
.equals(null));
119 assertTrue("equals", !fSource3
.equals(null));
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
126 public void testHashCode() throws Exception
{
127 assertTrue("hashCode", fSource0
.hashCode() == fSource1
.hashCode());
128 assertTrue("hashCode", fSource0
.hashCode() != fSource3
.hashCode());
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
135 public void testToString() {
136 String expected1
= "[TmfEventSource(" + "null" + ")]";
137 TmfEventSource nullSource
= new TmfEventSource();
138 assertEquals("toString", expected1
, nullSource
.toString());
140 String expected2
= "[TmfEventSource(" + source1
.toString() + ")]";
141 TmfEventSource source
= new TmfEventSource(source1
);
142 assertEquals("toString", expected2
, source
.toString());