1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.core
.tests
.control
.model
.impl
;
16 import static org
.junit
.Assert
.*;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ITraceInfo
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.TraceInfo
;
20 import org
.junit
.Before
;
21 import org
.junit
.Test
;
24 * The class <code>TraceInfoTest</code> contains test for the class
25 * <code>{@link TraceInfo}</code>.
27 public class TraceInfoTest
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private ITraceInfo fTraceInfo1
= null;
34 private ITraceInfo fTraceInfo2
= null;
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
42 * Perform pre-test initialization.
46 fTraceInfo1
= new TraceInfo("event1");
47 fTraceInfo2
= new TraceInfo("event2");
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
55 * Run the BaseEventInfo() constructor test.
58 public void testTraceInfo() {
59 TraceInfo fixture
= new TraceInfo("event");
60 assertNotNull(fixture
);
62 assertEquals("event", fixture
.getName());
66 * Test Copy Constructor
69 public void testTraceInfo2() {
73 fail("null name in custructor");
75 catch (IllegalArgumentException e
) {
81 * Test Copy Constructor
84 public void testTraceInfoCopy() {
85 TraceInfo info
= new TraceInfo((TraceInfo
)fTraceInfo1
);
87 assertEquals(fTraceInfo1
.getName(), info
.getName());
91 * Test Copy Constructor
94 public void testTraceCopy2() {
96 TraceInfo info
= null;
100 catch (IllegalArgumentException e
) {
106 * Run the void setEventType(String) method test.
109 public void testSetName() {
110 TraceInfo fixture
= new TraceInfo("event");
111 fixture
.setName("newName");
112 assertEquals("newName", fixture
.getName());
116 * Run the String toString() method test.
119 public void testToString_1() {
120 String result
= fTraceInfo1
.toString();
122 // add additional test code here
123 assertEquals("[TraceInfo(Name=event1)]", result
);
126 // ------------------------------------------------------------------------
128 // ------------------------------------------------------------------------
131 * Run the equals() method test.
134 public void testEqualsReflexivity() {
135 assertTrue("equals", fTraceInfo1
.equals(fTraceInfo1
));
136 assertTrue("equals", fTraceInfo2
.equals(fTraceInfo2
));
138 assertTrue("equals", !fTraceInfo1
.equals(fTraceInfo2
));
139 assertTrue("equals", !fTraceInfo2
.equals(fTraceInfo1
));
143 * Run the equals() method test.
146 public void testEqualsSymmetry() {
147 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
148 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo2
);
150 assertTrue("equals", info1
.equals(fTraceInfo1
));
151 assertTrue("equals", fTraceInfo1
.equals(info1
));
153 assertTrue("equals", info2
.equals(fTraceInfo2
));
154 assertTrue("equals", fTraceInfo2
.equals(info2
));
157 * Run the equals() method test.
160 public void testEqualsTransivity() {
161 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
162 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo1
);
163 TraceInfo info3
= new TraceInfo((TraceInfo
)fTraceInfo1
);
165 assertTrue("equals", info1
.equals(info2
));
166 assertTrue("equals", info2
.equals(info3
));
167 assertTrue("equals", info1
.equals(info3
));
170 * Run the equals() method test.
173 public void testEqualsNull() {
174 assertTrue("equals", !fTraceInfo1
.equals(null));
175 assertTrue("equals", !fTraceInfo2
.equals(null));
178 // ------------------------------------------------------------------------
180 // ------------------------------------------------------------------------
183 * Run the hashCode() method test.
186 public void testHashCode() {
187 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
188 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo2
);
190 assertTrue("hashCode", fTraceInfo1
.hashCode() == info1
.hashCode());
191 assertTrue("hashCode", fTraceInfo2
.hashCode() == info2
.hashCode());
193 assertTrue("hashCode", fTraceInfo1
.hashCode() != info2
.hashCode());
194 assertTrue("hashCode", fTraceInfo2
.hashCode() != info1
.hashCode());