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