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
.control
.core
.tests
.model
.impl
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertTrue
;
19 import static org
.junit
.Assert
.fail
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.ITraceInfo
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.TraceInfo
;
23 import org
.junit
.Before
;
24 import org
.junit
.Test
;
27 * The class <code>TraceInfoTest</code> contains test for the class
28 * <code>{@link TraceInfo}</code>.
30 public class TraceInfoTest
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 private ITraceInfo fTraceInfo1
= null;
37 private ITraceInfo fTraceInfo2
= null;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * Perform pre-test initialization.
49 fTraceInfo1
= new TraceInfo("event1");
50 fTraceInfo2
= new TraceInfo("event2");
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * Run the BaseEventInfo() constructor test.
61 public void testTraceInfo() {
62 TraceInfo fixture
= new TraceInfo("event");
63 assertNotNull(fixture
);
65 assertEquals("event", fixture
.getName());
69 * Test Copy Constructor
72 public void testTraceInfo2() {
76 fail("null name in custructor");
78 catch (IllegalArgumentException e
) {
84 * Test Copy Constructor
87 public void testTraceInfoCopy() {
88 TraceInfo info
= new TraceInfo((TraceInfo
)fTraceInfo1
);
90 assertEquals(fTraceInfo1
.getName(), info
.getName());
94 * Test Copy Constructor
97 public void testTraceCopy2() {
99 TraceInfo info
= null;
103 catch (IllegalArgumentException e
) {
109 * Run the void setEventType(String) method test.
112 public void testSetName() {
113 TraceInfo fixture
= new TraceInfo("event");
114 fixture
.setName("newName");
115 assertEquals("newName", fixture
.getName());
119 * Run the String toString() method test.
122 public void testToString_1() {
123 String result
= fTraceInfo1
.toString();
125 // add additional test code here
126 assertEquals("[TraceInfo(Name=event1)]", result
);
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
134 * Run the equals() method test.
137 public void testEqualsReflexivity() {
138 assertTrue("equals", fTraceInfo1
.equals(fTraceInfo1
));
139 assertTrue("equals", fTraceInfo2
.equals(fTraceInfo2
));
141 assertTrue("equals", !fTraceInfo1
.equals(fTraceInfo2
));
142 assertTrue("equals", !fTraceInfo2
.equals(fTraceInfo1
));
146 * Run the equals() method test.
149 public void testEqualsSymmetry() {
150 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
151 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo2
);
153 assertTrue("equals", info1
.equals(fTraceInfo1
));
154 assertTrue("equals", fTraceInfo1
.equals(info1
));
156 assertTrue("equals", info2
.equals(fTraceInfo2
));
157 assertTrue("equals", fTraceInfo2
.equals(info2
));
160 * Run the equals() method test.
163 public void testEqualsTransivity() {
164 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
165 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo1
);
166 TraceInfo info3
= new TraceInfo((TraceInfo
)fTraceInfo1
);
168 assertTrue("equals", info1
.equals(info2
));
169 assertTrue("equals", info2
.equals(info3
));
170 assertTrue("equals", info1
.equals(info3
));
173 * Run the equals() method test.
176 public void testEqualsNull() {
177 assertTrue("equals", !fTraceInfo1
.equals(null));
178 assertTrue("equals", !fTraceInfo2
.equals(null));
181 // ------------------------------------------------------------------------
183 // ------------------------------------------------------------------------
186 * Run the hashCode() method test.
189 public void testHashCode() {
190 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
191 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo2
);
193 assertTrue("hashCode", fTraceInfo1
.hashCode() == info1
.hashCode());
194 assertTrue("hashCode", fTraceInfo2
.hashCode() == info2
.hashCode());
196 assertTrue("hashCode", fTraceInfo1
.hashCode() != info2
.hashCode());
197 assertTrue("hashCode", fTraceInfo2
.hashCode() != info1
.hashCode());