lttng: Port unit tests to JUnit4
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core.tests / src / org / eclipse / linuxtools / lttng2 / core / tests / control / model / impl / EventInfoTest.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.core.tests.control.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.core.control.model.IEventInfo;
22 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
23 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
24 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.EventInfo;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 /**
29 * The class <code>EventInfoTest</code> contains test for the class
30 * <code>{@link EventInfo}</code>.
31 */
32 @SuppressWarnings("nls")
33 public class EventInfoTest {
34
35 // ------------------------------------------------------------------------
36 // Test data
37 // ------------------------------------------------------------------------
38
39 private IEventInfo fEventInfo1 = null;
40 private IEventInfo fEventInfo2 = null;
41
42 // ------------------------------------------------------------------------
43 // Housekeeping
44 // ------------------------------------------------------------------------
45
46 /**
47 * Perform pre-test initialization.
48 */
49 @Before
50 public void setUp() {
51 ModelImplFactory factory = new ModelImplFactory();
52 fEventInfo1 = factory.getEventInfo1();
53 fEventInfo2 = factory.getEventInfo2();
54 }
55
56 // ------------------------------------------------------------------------
57 // Tests
58 // ------------------------------------------------------------------------
59
60 /**
61 * Run the BaseEventInfo() constructor test.
62 */
63 @Test
64 public void testBaseEventInfo() {
65 EventInfo fixture = new EventInfo("event");
66 assertNotNull(fixture);
67
68 TraceEventType result = fixture.getEventType();
69
70 assertEquals("event", fixture.getName());
71 assertEquals("unknown", result.getInName());
72 assertEquals("UNKNOWN", result.name());
73 assertEquals("UNKNOWN", result.toString());
74 assertEquals(3, result.ordinal());
75
76 TraceEnablement state = fixture.getState();
77 assertEquals("disabled", state.getInName());
78 assertEquals("DISABLED", state.name());
79 assertEquals("DISABLED", state.toString());
80 assertEquals(0, state.ordinal());
81
82 }
83
84 /**
85 * Test Copy Constructor
86 */
87 @Test
88 public void testEventInfoCopy() {
89 EventInfo info = new EventInfo((EventInfo)fEventInfo1);
90
91 assertEquals(fEventInfo1.getName(), info.getName());
92 assertEquals(fEventInfo1.getEventType(), info.getEventType());
93 assertEquals(fEventInfo1.getState(), info.getState());
94 }
95
96 /**
97 * Test Copy Constructor
98 */
99 @Test
100 public void testEventCopy2() {
101 try {
102 EventInfo info = null;
103 new EventInfo(info);
104 fail("null copy");
105 }
106 catch (IllegalArgumentException e) {
107 // Success
108 }
109 }
110
111 /**
112 * Getter/Setter tests
113 */
114 @Test
115 public void testGetAndSetter() {
116 EventInfo fixture = new EventInfo("event");
117
118 fixture.setEventType(TraceEventType.TRACEPOINT);
119 TraceEventType result = fixture.getEventType();
120
121 // setEventType(TraceEventType type)
122 assertNotNull(result);
123 assertEquals("tracepoint", result.getInName());
124 assertEquals("TRACEPOINT", result.name());
125 assertEquals("TRACEPOINT", result.toString());
126 assertEquals(0, result.ordinal());
127
128 fixture.setEventType(TraceEventType.UNKNOWN);
129 result = fixture.getEventType();
130 assertEquals("unknown", result.getInName());
131 assertEquals("UNKNOWN", result.name());
132 assertEquals("UNKNOWN", result.toString());
133 assertEquals(3, result.ordinal());
134
135 // setEventType(String typeName)
136 String typeName = "";
137 fixture.setEventType(typeName);
138 result = fixture.getEventType();
139
140 assertEquals("unknown", result.getInName());
141 assertEquals("UNKNOWN", result.name());
142 assertEquals("UNKNOWN", result.toString());
143 assertEquals(3, result.ordinal());
144
145 typeName = "unknown";
146
147 fixture.setEventType(typeName);
148 result = fixture.getEventType();
149
150 assertEquals("unknown", result.getInName());
151 assertEquals("UNKNOWN", result.name());
152 assertEquals("UNKNOWN", result.toString());
153 assertEquals(3, result.ordinal());
154
155 // setState(String stateName)
156 fixture.setState("disabled");
157 TraceEnablement state = fixture.getState();
158 assertEquals("disabled", state.getInName());
159 assertEquals("DISABLED", state.name());
160 assertEquals("DISABLED", state.toString());
161 assertEquals(0, state.ordinal());
162
163 fixture.setState("bla");
164 state = fixture.getState();
165 assertEquals("disabled", state.getInName());
166 assertEquals("DISABLED", state.name());
167 assertEquals("DISABLED", state.toString());
168 assertEquals(0, state.ordinal());
169
170 fixture.setState("enabled");
171 state = fixture.getState();
172 assertEquals("enabled", state.getInName());
173 assertEquals("ENABLED", state.name());
174 assertEquals("ENABLED", state.toString());
175 assertEquals(1, state.ordinal());
176
177 // setState(TraceEnablement state)
178 fixture.setState(TraceEnablement.DISABLED);
179 state = fixture.getState();
180 assertEquals("disabled", state.getInName());
181 assertEquals("DISABLED", state.name());
182 assertEquals("DISABLED", state.toString());
183 assertEquals(0, state.ordinal());
184
185 fixture.setState(TraceEnablement.ENABLED);
186 state = fixture.getState();
187 assertEquals("enabled", state.getInName());
188 assertEquals("ENABLED", state.name());
189 assertEquals("ENABLED", state.toString());
190 assertEquals(1, state.ordinal());
191 }
192
193 /**
194 * Run the String toString() method test.
195 */
196 @Test
197 public void testToString_1() {
198 EventInfo fixture = new EventInfo("event");
199 fixture.setName("testName");
200 fixture.setEventType(TraceEventType.TRACEPOINT);
201
202 String result = fixture.toString();
203
204 // add additional test code here
205 assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED)]", result);
206 }
207
208 // ------------------------------------------------------------------------
209 // equals
210 // ------------------------------------------------------------------------
211
212 /**
213 * Run the equals() method test.
214 */
215 @Test
216 public void testEqualsReflexivity() {
217 assertTrue("equals", fEventInfo1.equals(fEventInfo1));
218 assertTrue("equals", fEventInfo2.equals(fEventInfo2));
219
220 assertTrue("equals", !fEventInfo1.equals(fEventInfo2));
221 assertTrue("equals", !fEventInfo2.equals(fEventInfo1));
222 }
223
224 /**
225 * Run the equals() method test.
226 */
227 @Test
228 public void testEqualsSymmetry() {
229 EventInfo info1 = new EventInfo((EventInfo)fEventInfo1);
230 EventInfo info2 = new EventInfo((EventInfo)fEventInfo2);
231
232 assertTrue("equals", info1.equals(fEventInfo1));
233 assertTrue("equals", fEventInfo1.equals(info1));
234
235 assertTrue("equals", info2.equals(fEventInfo2));
236 assertTrue("equals", fEventInfo2.equals(info2));
237 }
238
239 /**
240 * Run the equals() method test.
241 */
242 @Test
243 public void testEqualsTransivity() {
244 EventInfo info1 = new EventInfo((EventInfo)fEventInfo1);
245 EventInfo info2 = new EventInfo((EventInfo)fEventInfo1);
246 EventInfo info3 = new EventInfo((EventInfo)fEventInfo1);
247
248 assertTrue("equals", info1.equals(info2));
249 assertTrue("equals", info2.equals(info3));
250 assertTrue("equals", info1.equals(info3));
251 }
252
253 /**
254 * Run the equals() method test.
255 */
256 @Test
257 public void testEqualsNull() {
258 assertTrue("equals", !fEventInfo1.equals(null));
259 assertTrue("equals", !fEventInfo2.equals(null));
260 }
261
262 // ------------------------------------------------------------------------
263 // hashCode
264 // ------------------------------------------------------------------------
265
266 /**
267 * Run the hashCode() method test.
268 */
269 @Test
270 public void testHashCode() {
271 EventInfo info1 = new EventInfo((EventInfo)fEventInfo1);
272 EventInfo info2 = new EventInfo((EventInfo)fEventInfo2);
273
274 assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode());
275 assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode());
276
277 assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode());
278 assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode());
279 }
280 }
This page took 0.066021 seconds and 5 git commands to generate.