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 @SuppressWarnings("nls")
28 public class TraceInfoTest
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 private ITraceInfo fTraceInfo1
= null;
35 private ITraceInfo fTraceInfo2
= null;
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
43 * Perform pre-test initialization.
47 fTraceInfo1
= new TraceInfo("event1");
48 fTraceInfo2
= new TraceInfo("event2");
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * Run the BaseEventInfo() constructor test.
59 public void testTraceInfo() {
60 TraceInfo fixture
= new TraceInfo("event");
61 assertNotNull(fixture
);
63 assertEquals("event", fixture
.getName());
67 * Test Copy Constructor
70 public void testTraceInfo2() {
74 fail("null name in custructor");
76 catch (IllegalArgumentException e
) {
82 * Test Copy Constructor
85 public void testTraceInfoCopy() {
86 TraceInfo info
= new TraceInfo((TraceInfo
)fTraceInfo1
);
88 assertEquals(fTraceInfo1
.getName(), info
.getName());
92 * Test Copy Constructor
95 public void testTraceCopy2() {
97 TraceInfo info
= null;
101 catch (IllegalArgumentException e
) {
107 * Run the void setEventType(String) method test.
110 public void testSetName() {
111 TraceInfo fixture
= new TraceInfo("event");
112 fixture
.setName("newName");
113 assertEquals("newName", fixture
.getName());
117 * Run the String toString() method test.
120 public void testToString_1() {
121 String result
= fTraceInfo1
.toString();
123 // add additional test code here
124 assertEquals("[TraceInfo(Name=event1)]", result
);
127 // ------------------------------------------------------------------------
129 // ------------------------------------------------------------------------
132 * Run the equals() method test.
135 public void testEqualsReflexivity() {
136 assertTrue("equals", fTraceInfo1
.equals(fTraceInfo1
));
137 assertTrue("equals", fTraceInfo2
.equals(fTraceInfo2
));
139 assertTrue("equals", !fTraceInfo1
.equals(fTraceInfo2
));
140 assertTrue("equals", !fTraceInfo2
.equals(fTraceInfo1
));
144 * Run the equals() method test.
147 public void testEqualsSymmetry() {
148 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
149 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo2
);
151 assertTrue("equals", info1
.equals(fTraceInfo1
));
152 assertTrue("equals", fTraceInfo1
.equals(info1
));
154 assertTrue("equals", info2
.equals(fTraceInfo2
));
155 assertTrue("equals", fTraceInfo2
.equals(info2
));
158 * Run the equals() method test.
161 public void testEqualsTransivity() {
162 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
163 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo1
);
164 TraceInfo info3
= new TraceInfo((TraceInfo
)fTraceInfo1
);
166 assertTrue("equals", info1
.equals(info2
));
167 assertTrue("equals", info2
.equals(info3
));
168 assertTrue("equals", info1
.equals(info3
));
171 * Run the equals() method test.
174 public void testEqualsNull() {
175 assertTrue("equals", !fTraceInfo1
.equals(null));
176 assertTrue("equals", !fTraceInfo2
.equals(null));
179 // ------------------------------------------------------------------------
181 // ------------------------------------------------------------------------
184 * Run the hashCode() method test.
187 public void testHashCode() {
188 TraceInfo info1
= new TraceInfo((TraceInfo
)fTraceInfo1
);
189 TraceInfo info2
= new TraceInfo((TraceInfo
)fTraceInfo2
);
191 assertTrue("hashCode", fTraceInfo1
.hashCode() == info1
.hashCode());
192 assertTrue("hashCode", fTraceInfo2
.hashCode() == info2
.hashCode());
194 assertTrue("hashCode", fTraceInfo1
.hashCode() != info2
.hashCode());
195 assertTrue("hashCode", fTraceInfo2
.hashCode() != info1
.hashCode());