Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / src / org / eclipse / linuxtools / tmf / tests / event / TmfEventSourceTest.java
CommitLineData
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
13package org.eclipse.linuxtools.tmf.tests.event;
14
75828b1a
FC
15import junit.framework.TestCase;
16
cbd4ad82
FC
17import 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 23 */
3b38ea61 24@SuppressWarnings("nls")
d18dd09b
ASL
25public class TmfEventSourceTest extends TestCase {
26
cbd4ad82
FC
27 // ------------------------------------------------------------------------
28 // Variables
29 // ------------------------------------------------------------------------
d18dd09b 30
cbd4ad82
FC
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 // ------------------------------------------------------------------------
d18dd09b 40 // Housekeeping
cbd4ad82 41 // ------------------------------------------------------------------------
d18dd09b 42
cbd4ad82
FC
43 /**
44 * @param name the test name
45 */
d18dd09b
ASL
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
cbd4ad82 60 // ------------------------------------------------------------------------
d18dd09b 61 // Constructors
cbd4ad82 62 // ------------------------------------------------------------------------
d18dd09b
ASL
63
64 public void testTmfEventSourceDefault() {
65 TmfEventSource source = new TmfEventSource();
66 assertEquals("getSourceId", null, source.getSourceId());
67 }
68
69 public void testTmfEventSource() {
cbd4ad82
FC
70 TmfEventSource source = new TmfEventSource(source1);
71 assertSame("getSourceId", source1, source.getSourceId());
d18dd09b
ASL
72 }
73
74 public void testTmfEventSourceCopy() {
cbd4ad82 75 TmfEventSource original = new TmfEventSource(source1);
d18dd09b 76 TmfEventSource source = new TmfEventSource(original);
cbd4ad82 77 assertSame("getSourceId", source1, source.getSourceId());
d18dd09b
ASL
78 }
79
cbd4ad82
FC
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 }
d18dd09b
ASL
89 }
90
cbd4ad82
FC
91 // ------------------------------------------------------------------------
92 // equals
93 // ------------------------------------------------------------------------
94
95 public void testEqualsReflexivity() throws Exception {
96 assertTrue("equals", fSource0.equals(fSource0));
97 assertTrue("equals", fSource3.equals(fSource3));
d18dd09b 98
cbd4ad82
FC
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
cbd4ad82
FC
117 public void testEqualsNull() throws Exception {
118 assertTrue("equals", !fSource0.equals(null));
119 assertTrue("equals", !fSource3.equals(null));
120 }
121
2fb2eb37
FC
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
cbd4ad82
FC
131 // ------------------------------------------------------------------------
132 // toString
133 // ------------------------------------------------------------------------
d18dd09b
ASL
134
135 public void testToString() {
136 String expected1 = "[TmfEventSource(" + "null" + ")]";
cbd4ad82
FC
137 TmfEventSource nullSource = new TmfEventSource();
138 assertEquals("toString", expected1, nullSource.toString());
d18dd09b 139
cbd4ad82
FC
140 String expected2 = "[TmfEventSource(" + source1.toString() + ")]";
141 TmfEventSource source = new TmfEventSource(source1);
142 assertEquals("toString", expected2, source.toString());
d18dd09b
ASL
143 }
144
145}
This page took 0.034124 seconds and 5 git commands to generate.