tmf: Update tmf.core unit tests to JUnit4
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfIteratorTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012 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 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
22 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
23 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
24 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
25 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
26 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 /**
32 * The class <code>CtfIteratorTest</code> contains tests for the class
33 * <code>{@link CtfIterator}</code>.
34 *
35 * @author ematkho
36 * @version 1.0
37 */
38 public class CtfIteratorTest {
39
40 private CtfIterator fixture;
41
42 /**
43 * Perform pre-test initialization.
44 *
45 * @throws TmfTraceException
46 * If the test trace is not found
47 */
48 @Before
49 public void setUp() throws TmfTraceException {
50 fixture = new CtfIterator(createTrace());
51 CtfLocation ctfLocation = new CtfLocation(new CtfLocationData(1, 0));
52 fixture.setLocation(ctfLocation);
53 fixture.increaseRank();
54 }
55
56 /**
57 * Perform post-test clean-up.
58 */
59 @After
60 public void tearDown() {
61 fixture.dispose();
62 }
63
64
65 private static CtfTmfTrace createTrace() throws TmfTraceException {
66 return TestParams.createTrace();
67 }
68
69 /**
70 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
71 *
72 * @throws TmfTraceException
73 * If the test trace is not found
74 */
75 @Test
76 public void testCtfIterator_noinit() throws TmfTraceException {
77 CtfTmfTrace trace = createTrace();
78 CtfIterator result = new CtfIterator(trace);
79 assertNotNull(result);
80 }
81
82 /**
83 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
84 *
85 * @throws TmfTraceException
86 * If the test trace is not found
87 */
88 @Test
89 public void testCtfIterator_init() throws TmfTraceException {
90 CtfTmfTrace trace = createTrace();
91 trace.init("test"); //$NON-NLS-1$
92 CtfIterator result = new CtfIterator(trace);
93
94 assertNotNull(result);
95 }
96
97 /**
98 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
99 * specifies an initial position for the iterator.
100 *
101 * @throws TmfTraceException
102 * If the test trace is not found
103 */
104 @Test
105 public void testCtfIterator_position() throws TmfTraceException {
106 CtfTmfTrace trace = createTrace();
107 long timestampValue = 1L;
108 long rank = 1L;
109 CtfIterator result = new CtfIterator(trace, new CtfLocationData(timestampValue, 0), rank);
110
111 assertNotNull(result);
112 }
113
114
115 /**
116 * Run the boolean advance() method test.
117 */
118 @Test
119 public void testAdvance() {
120 boolean result = fixture.advance();
121 assertTrue(result);
122 }
123
124 /**
125 * Run the CtfIterator clone() method test.
126 */
127 @Test
128 public void testClone() {
129 CtfIterator result = fixture.clone();
130 assertNotNull(result);
131 }
132
133 /**
134 * Run the int compareTo(CtfIterator) method test.
135 *
136 * @throws TmfTraceException
137 * If the test trace is not found
138 */
139 @Test
140 public void testCompareTo() throws TmfTraceException {
141 CtfIterator o = new CtfIterator(createTrace());
142 int result = fixture.compareTo(o);
143
144 assertEquals(1L, result);
145 }
146
147 /**
148 * Run the boolean equals(Object) method test. Compare with another iterator
149 * on the same trace.
150 *
151 * @throws TmfTraceException
152 * If the test trace is not found
153 */
154 @Test
155 public void testEquals_other() throws TmfTraceException {
156 CtfIterator obj = new CtfIterator(createTrace());
157 CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationData(1, 0));
158 obj.setLocation(ctfLocation1);
159 obj.increaseRank();
160
161 boolean result = fixture.equals(obj);
162 assertTrue(result);
163 }
164
165 /**
166 * Run the boolean equals(Object) method test. Compare with an empty object.
167 */
168 @Test
169 public void testEquals_empty() {
170 Object obj = new Object();
171 boolean result = fixture.equals(obj);
172
173 assertFalse(result);
174 }
175
176 /**
177 * Run the CtfTmfTrace getCtfTmfTrace() method test.
178 */
179 @Test
180 public void testGetCtfTmfTrace() {
181 CtfTmfTrace result = fixture.getCtfTmfTrace();
182 assertNotNull(result);
183 }
184
185 /**
186 * Run the CtfTmfEvent getCurrentEvent() method test.
187 */
188 @Test
189 public void testGetCurrentEvent() {
190 CtfTmfEvent result = fixture.getCurrentEvent();
191 assertNotNull(result);
192 }
193
194 /**
195 * Run the CtfLocation getLocation() method test.
196 */
197 @Test
198 public void testGetLocation() {
199 CtfLocation result = fixture.getLocation();
200 assertNotNull(result);
201 }
202
203 /**
204 * Run the long getRank() method test.
205 */
206 @Test
207 public void testGetRank() {
208 long result = fixture.getRank();
209 assertEquals(1L, result);
210 }
211
212 /**
213 * Run the boolean hasValidRank() method test.
214 */
215 @Test
216 public void testHasValidRank() {
217 boolean result = fixture.hasValidRank();
218 assertTrue(result);
219 }
220
221 /**
222 * Run the int hashCode() method test.
223 */
224 @Test
225 public void testHashCode() {
226 int result = fixture.hashCode();
227 int result2 = fixture.hashCode();
228 assertEquals(result, result2);
229 }
230
231 /**
232 * Run the void increaseRank() method test.
233 */
234 @Test
235 public void testIncreaseRank() {
236 fixture.increaseRank();
237 }
238
239 /**
240 * Run the boolean seek(long) method test.
241 */
242 @Test
243 public void testSeek() {
244 long timestamp = 1L;
245 boolean result = fixture.seek(timestamp);
246 assertTrue(result);
247 }
248
249 /**
250 * Run the void setLocation(ITmfLocation<?>) method test.
251 */
252 @Test
253 public void testSetLocation() {
254 CtfLocation location = new CtfLocation(new CtfLocationData(1, 0));
255 fixture.setLocation(location);
256 }
257 }
This page took 0.037512 seconds and 5 git commands to generate.