Commit | Line | Data |
---|---|---|
d18dd09b ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 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.tests.event; | |
14 | ||
75828b1a FC |
15 | import junit.framework.TestCase; |
16 | ||
cbd4ad82 FC |
17 | import org.eclipse.linuxtools.tmf.event.TmfEventSource; |
18 | ||
d18dd09b ASL |
19 | /** |
20 | * <b><u>TmfEventSourceTest</u></b> | |
21 | * <p> | |
cbd4ad82 | 22 | * Test suite for the TmfEventSource class. |
d18dd09b ASL |
23 | */ |
24 | public class TmfEventSourceTest extends TestCase { | |
25 | ||
cbd4ad82 FC |
26 | // ------------------------------------------------------------------------ |
27 | // Variables | |
28 | // ------------------------------------------------------------------------ | |
d18dd09b | 29 | |
cbd4ad82 FC |
30 | private final Object source1 = new String("Some source"); |
31 | private final Object source2 = new String("Some other source"); | |
32 | ||
33 | private final TmfEventSource fSource0 = new TmfEventSource(source1); | |
34 | private final TmfEventSource fSource1 = new TmfEventSource(source1); | |
35 | private final TmfEventSource fSource2 = new TmfEventSource(source1); | |
36 | private final TmfEventSource fSource3 = new TmfEventSource(source2); | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
d18dd09b | 39 | // Housekeeping |
cbd4ad82 | 40 | // ------------------------------------------------------------------------ |
d18dd09b | 41 | |
cbd4ad82 FC |
42 | /** |
43 | * @param name the test name | |
44 | */ | |
d18dd09b ASL |
45 | public TmfEventSourceTest(String name) { |
46 | super(name); | |
47 | } | |
48 | ||
49 | @Override | |
50 | protected void setUp() throws Exception { | |
51 | super.setUp(); | |
52 | } | |
53 | ||
54 | @Override | |
55 | protected void tearDown() throws Exception { | |
56 | super.tearDown(); | |
57 | } | |
58 | ||
cbd4ad82 | 59 | // ------------------------------------------------------------------------ |
d18dd09b | 60 | // Constructors |
cbd4ad82 | 61 | // ------------------------------------------------------------------------ |
d18dd09b ASL |
62 | |
63 | public void testTmfEventSourceDefault() { | |
64 | TmfEventSource source = new TmfEventSource(); | |
65 | assertEquals("getSourceId", null, source.getSourceId()); | |
66 | } | |
67 | ||
68 | public void testTmfEventSource() { | |
cbd4ad82 FC |
69 | TmfEventSource source = new TmfEventSource(source1); |
70 | assertSame("getSourceId", source1, source.getSourceId()); | |
d18dd09b ASL |
71 | } |
72 | ||
73 | public void testTmfEventSourceCopy() { | |
cbd4ad82 | 74 | TmfEventSource original = new TmfEventSource(source1); |
d18dd09b | 75 | TmfEventSource source = new TmfEventSource(original); |
cbd4ad82 | 76 | assertSame("getSourceId", source1, source.getSourceId()); |
d18dd09b ASL |
77 | } |
78 | ||
cbd4ad82 FC |
79 | public void testTmfEventSourceCopy2() { |
80 | try { | |
81 | @SuppressWarnings("unused") | |
82 | TmfEventSource source = new TmfEventSource(null); | |
83 | fail("null copy"); | |
84 | } | |
85 | catch (IllegalArgumentException e) { | |
86 | // Success | |
87 | } | |
d18dd09b ASL |
88 | } |
89 | ||
cbd4ad82 FC |
90 | // ------------------------------------------------------------------------ |
91 | // equals | |
92 | // ------------------------------------------------------------------------ | |
93 | ||
94 | public void testEqualsReflexivity() throws Exception { | |
95 | assertTrue("equals", fSource0.equals(fSource0)); | |
96 | assertTrue("equals", fSource3.equals(fSource3)); | |
d18dd09b | 97 | |
cbd4ad82 FC |
98 | assertTrue("equals", !fSource0.equals(fSource3)); |
99 | assertTrue("equals", !fSource3.equals(fSource0)); | |
100 | } | |
101 | ||
102 | public void testEqualsSymmetry() throws Exception { | |
103 | assertTrue("equals", fSource0.equals(fSource2)); | |
104 | assertTrue("equals", fSource2.equals(fSource0)); | |
105 | ||
106 | assertTrue("equals", !fSource0.equals(fSource3)); | |
107 | assertTrue("equals", !fSource3.equals(fSource0)); | |
108 | } | |
109 | ||
110 | public void testEqualsTransivity() throws Exception { | |
111 | assertTrue("equals", fSource0.equals(fSource1)); | |
112 | assertTrue("equals", fSource1.equals(fSource2)); | |
113 | assertTrue("equals", fSource0.equals(fSource2)); | |
114 | } | |
115 | ||
cbd4ad82 FC |
116 | public void testEqualsNull() throws Exception { |
117 | assertTrue("equals", !fSource0.equals(null)); | |
118 | assertTrue("equals", !fSource3.equals(null)); | |
119 | } | |
120 | ||
2fb2eb37 FC |
121 | // ------------------------------------------------------------------------ |
122 | // hashCode | |
123 | // ------------------------------------------------------------------------ | |
124 | ||
125 | public void testHashCode() throws Exception { | |
126 | assertTrue("hashCode", fSource0.hashCode() == fSource1.hashCode()); | |
127 | assertTrue("hashCode", fSource0.hashCode() != fSource3.hashCode()); | |
128 | } | |
129 | ||
cbd4ad82 FC |
130 | // ------------------------------------------------------------------------ |
131 | // toString | |
132 | // ------------------------------------------------------------------------ | |
d18dd09b ASL |
133 | |
134 | public void testToString() { | |
135 | String expected1 = "[TmfEventSource(" + "null" + ")]"; | |
cbd4ad82 FC |
136 | TmfEventSource nullSource = new TmfEventSource(); |
137 | assertEquals("toString", expected1, nullSource.toString()); | |
d18dd09b | 138 | |
cbd4ad82 FC |
139 | String expected2 = "[TmfEventSource(" + source1.toString() + ")]"; |
140 | TmfEventSource source = new TmfEventSource(source1); | |
141 | assertEquals("toString", expected2, source.toString()); | |
d18dd09b ASL |
142 | } |
143 | ||
144 | } |