lttng: Rename lttng2 feature/plugins to lttng2.control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core.tests / src / org / eclipse / linuxtools / lttng2 / control / core / tests / model / impl / TraceInfoTest.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.control.core.tests.model.impl;
15
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;
20
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;
25
26 /**
27 * The class <code>TraceInfoTest</code> contains test for the class
28 * <code>{@link TraceInfo}</code>.
29 */
30 public class TraceInfoTest {
31
32 // ------------------------------------------------------------------------
33 // Test data
34 // ------------------------------------------------------------------------
35
36 private ITraceInfo fTraceInfo1 = null;
37 private ITraceInfo fTraceInfo2 = null;
38
39
40 // ------------------------------------------------------------------------
41 // Housekeeping
42 // ------------------------------------------------------------------------
43
44 /**
45 * Perform pre-test initialization.
46 */
47 @Before
48 public void setUp() {
49 fTraceInfo1 = new TraceInfo("event1");
50 fTraceInfo2 = new TraceInfo("event2");
51 }
52
53 // ------------------------------------------------------------------------
54 // Tests
55 // ------------------------------------------------------------------------
56
57 /**
58 * Run the BaseEventInfo() constructor test.
59 */
60 @Test
61 public void testTraceInfo() {
62 TraceInfo fixture = new TraceInfo("event");
63 assertNotNull(fixture);
64
65 assertEquals("event", fixture.getName());
66 }
67
68 /**
69 * Test Copy Constructor
70 */
71 @Test
72 public void testTraceInfo2() {
73 try {
74 String name = null;
75 new TraceInfo(name);
76 fail("null name in custructor");
77 }
78 catch (IllegalArgumentException e) {
79 // Success
80 }
81 }
82
83 /**
84 * Test Copy Constructor
85 */
86 @Test
87 public void testTraceInfoCopy() {
88 TraceInfo info = new TraceInfo((TraceInfo)fTraceInfo1);
89
90 assertEquals(fTraceInfo1.getName(), info.getName());
91 }
92
93 /**
94 * Test Copy Constructor
95 */
96 @Test
97 public void testTraceCopy2() {
98 try {
99 TraceInfo info = null;
100 new TraceInfo(info);
101 fail("null copy");
102 }
103 catch (IllegalArgumentException e) {
104 // Success
105 }
106 }
107
108 /**
109 * Run the void setEventType(String) method test.
110 */
111 @Test
112 public void testSetName() {
113 TraceInfo fixture = new TraceInfo("event");
114 fixture.setName("newName");
115 assertEquals("newName", fixture.getName());
116 }
117
118 /**
119 * Run the String toString() method test.
120 */
121 @Test
122 public void testToString_1() {
123 String result = fTraceInfo1.toString();
124
125 // add additional test code here
126 assertEquals("[TraceInfo(Name=event1)]", result);
127 }
128
129 // ------------------------------------------------------------------------
130 // equals
131 // ------------------------------------------------------------------------
132
133 /**
134 * Run the equals() method test.
135 */
136 @Test
137 public void testEqualsReflexivity() {
138 assertTrue("equals", fTraceInfo1.equals(fTraceInfo1));
139 assertTrue("equals", fTraceInfo2.equals(fTraceInfo2));
140
141 assertTrue("equals", !fTraceInfo1.equals(fTraceInfo2));
142 assertTrue("equals", !fTraceInfo2.equals(fTraceInfo1));
143 }
144
145 /**
146 * Run the equals() method test.
147 */
148 @Test
149 public void testEqualsSymmetry() {
150 TraceInfo info1 = new TraceInfo((TraceInfo)fTraceInfo1);
151 TraceInfo info2 = new TraceInfo((TraceInfo)fTraceInfo2);
152
153 assertTrue("equals", info1.equals(fTraceInfo1));
154 assertTrue("equals", fTraceInfo1.equals(info1));
155
156 assertTrue("equals", info2.equals(fTraceInfo2));
157 assertTrue("equals", fTraceInfo2.equals(info2));
158 }
159 /**
160 * Run the equals() method test.
161 */
162 @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);
167
168 assertTrue("equals", info1.equals(info2));
169 assertTrue("equals", info2.equals(info3));
170 assertTrue("equals", info1.equals(info3));
171 }
172 /**
173 * Run the equals() method test.
174 */
175 @Test
176 public void testEqualsNull() {
177 assertTrue("equals", !fTraceInfo1.equals(null));
178 assertTrue("equals", !fTraceInfo2.equals(null));
179 }
180
181 // ------------------------------------------------------------------------
182 // hashCode
183 // ------------------------------------------------------------------------
184
185 /**
186 * Run the hashCode() method test.
187 */
188 @Test
189 public void testHashCode() {
190 TraceInfo info1 = new TraceInfo((TraceInfo)fTraceInfo1);
191 TraceInfo info2 = new TraceInfo((TraceInfo)fTraceInfo2);
192
193 assertTrue("hashCode", fTraceInfo1.hashCode() == info1.hashCode());
194 assertTrue("hashCode", fTraceInfo2.hashCode() == info2.hashCode());
195
196 assertTrue("hashCode", fTraceInfo1.hashCode() != info2.hashCode());
197 assertTrue("hashCode", fTraceInfo2.hashCode() != info1.hashCode());
198 }
199 }
This page took 0.035765 seconds and 5 git commands to generate.