tmf: Disable NLS warnings in tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / event / TmfEventTypeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adjusted for new Event Model
12 * Alexandre Montplaisir - Port to JUnit4
13 *******************************************************************************/
14
15 package org.eclipse.linuxtools.tmf.core.tests.event;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertFalse;
19 import static org.junit.Assert.assertNull;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
24 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
25 import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
26 import org.junit.Test;
27
28 /**
29 * Test suite for the TmfEventType class.
30 */
31 @SuppressWarnings("javadoc")
32 public class TmfEventTypeTest {
33
34 // ------------------------------------------------------------------------
35 // Variables
36 // ------------------------------------------------------------------------
37
38 private final String fContext1 = "JUnit context 1";
39 private final String fContext2 = "JUnit context 2";
40
41 private final String fTypeId1 = "Some type";
42 private final String fTypeId2 = "Some other type";
43
44 private final String fLabel0 = "label1";
45 private final String fLabel1 = "label2";
46
47 private final String[] fLabels0 = new String[] { };
48 private final String[] fLabels1 = new String[] { fLabel0, fLabel1 };
49 private final String[] fLabels2 = new String[] { fLabel1, fLabel0, fLabel1 };
50
51 private final ITmfEventType fType0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
52 private final ITmfEventType fType1 = new TmfEventType(fContext1, fTypeId2, TmfEventField.makeRoot(fLabels1));
53 private final ITmfEventType fType2 = new TmfEventType(fContext2, fTypeId1, TmfEventField.makeRoot(fLabels2));
54 private final ITmfEventType fType3 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels1));
55
56 // ------------------------------------------------------------------------
57 // Constructors
58 // ------------------------------------------------------------------------
59
60 @Test
61 public void testDefaultConstructor() {
62 final ITmfEventType type = new TmfEventType();
63 assertEquals("getContext", ITmfEventType.DEFAULT_CONTEXT_ID, type.getContext());
64 assertEquals("getName", ITmfEventType.DEFAULT_TYPE_ID, type.getName());
65 assertNull("getRootField", type.getRootField());
66 assertEquals("getFieldNames", 0, type.getFieldNames().length);
67 assertNull("getFieldName", type.getFieldName(0));
68 }
69
70 @Test
71 public void testFullConstructor() {
72 final ITmfEventType type0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0));
73 assertEquals("getContext", fContext1, type0.getContext());
74 assertEquals("getName", fTypeId1, type0.getName());
75 assertEquals("getRootField", TmfEventField.makeRoot(fLabels0), type0.getRootField());
76 final String[] labels0 = type0.getFieldNames();
77 assertEquals("getFieldNames length", fLabels0.length, labels0.length);
78 for (int i = 0; i < labels0.length; i++) {
79 assertEquals("getFieldNames", fLabels0[i], labels0[i]);
80 }
81 assertNull("getFieldName", type0.getFieldName(labels0.length));
82
83 final ITmfEventType type1 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
84 assertEquals("getContext", fContext1, type1.getContext());
85 assertEquals("getName", fTypeId1, type1.getName());
86 assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), type1.getRootField());
87 final String[] labels1 = type1.getFieldNames();
88 assertEquals("getFieldNames length", fLabels1.length, labels1.length);
89 for (int i = 0; i < labels1.length; i++) {
90 assertEquals("getFieldNames", fLabels1[i], labels1[i]);
91 }
92 assertNull("getFieldName", type1.getFieldName(labels1.length));
93
94 final ITmfEventType type2 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels2));
95 assertEquals("getContext", fContext2, type2.getContext());
96 assertEquals("getName", fTypeId2, type2.getName());
97 assertEquals("getRootField", TmfEventField.makeRoot(fLabels2), type2.getRootField());
98 final String[] labels2 = type2.getFieldNames();
99 assertEquals("getFieldNames length", fLabels2.length, labels2.length);
100 for (int i = 0; i < labels2.length; i++) {
101 assertEquals("getFieldNames", fLabels2[i], labels2[i]);
102 }
103 assertNull("getFieldName", type2.getFieldName(labels2.length));
104 }
105
106 @Test
107 public void testConstructorCornerCases() {
108 try {
109 new TmfEventType(null, fTypeId1, null);
110 fail("TmfEventType: null context");
111 } catch (final IllegalArgumentException e) {
112 }
113
114 try {
115 new TmfEventType(fContext1, null, null);
116 fail("TmfEventType: null type");
117 } catch (final IllegalArgumentException e) {
118 }
119 }
120
121 @Test
122 public void testCopyConstructor() {
123 final TmfEventType original = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
124 final TmfEventType copy = new TmfEventType(original);
125
126 assertEquals("getContext", fContext1, copy.getContext());
127 assertEquals("getName", fTypeId1, copy.getName());
128 assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), copy.getRootField());
129 final String[] labels1 = copy.getFieldNames();
130 assertEquals("getFieldNames length", fLabels1.length, labels1.length);
131 for (int i = 0; i < labels1.length; i++) {
132 assertEquals("getFieldNames", fLabels1[i], labels1[i]);
133 }
134 assertNull("getFieldName", copy.getFieldName(labels1.length));
135 }
136
137 @Test
138 public void testCopyConstructorCornerCases() {
139 try {
140 new TmfEventType(null);
141 fail("TmfEventType: null argument");
142 } catch (final IllegalArgumentException e) {
143 }
144 }
145
146 // ------------------------------------------------------------------------
147 // clone
148 // ------------------------------------------------------------------------
149
150 @Test
151 public void testClone() {
152 final ITmfEventType clone = fType1.clone();
153
154 assertTrue("clone", fType1.clone().equals(fType1));
155 assertTrue("clone", clone.clone().equals(clone));
156
157 assertEquals("clone", clone, fType1);
158 assertEquals("clone", fType1, clone);
159 }
160
161 @Test
162 public void testClone2() {
163 final ITmfEventType type = new TmfEventType();
164 final ITmfEventType clone = type.clone();
165
166 assertTrue("clone", type.clone().equals(type));
167 assertTrue("clone", clone.clone().equals(clone));
168
169 assertEquals("clone", clone, type);
170 assertEquals("clone", type, clone);
171 }
172
173 // ------------------------------------------------------------------------
174 // hashCode
175 // ------------------------------------------------------------------------
176
177 @Test
178 public void testHashCode() {
179 final TmfEventType copy1 = new TmfEventType(fType0);
180
181 assertTrue("hashCode", fType0.hashCode() == copy1.hashCode());
182 assertTrue("hashCode", fType0.hashCode() != fType3.hashCode());
183 }
184
185 // ------------------------------------------------------------------------
186 // equals
187 // ------------------------------------------------------------------------
188
189 @Test
190 public void testEqualsReflexivity() {
191 assertTrue("equals", fType0.equals(fType0));
192 assertTrue("equals", fType3.equals(fType3));
193
194 assertFalse("equals", fType0.equals(fType3));
195 assertFalse("equals", fType3.equals(fType0));
196 }
197
198 @Test
199 public void testEqualsSymmetry() {
200 final TmfEventType copy0 = new TmfEventType(fType0);
201 assertTrue("equals", fType0.equals(copy0));
202 assertTrue("equals", copy0.equals(fType0));
203
204 final TmfEventType copy1 = new TmfEventType(fType1);
205 assertTrue("equals", fType1.equals(copy1));
206 assertTrue("equals", copy1.equals(fType1));
207
208 final TmfEventType copy2 = new TmfEventType(fType2);
209 assertTrue("equals", fType2.equals(copy2));
210 assertTrue("equals", copy2.equals(fType2));
211 }
212
213 @Test
214 public void testEqualsTransivity() {
215 TmfEventType copy1 = new TmfEventType(fType1);
216 TmfEventType copy2 = new TmfEventType(copy1);
217 assertTrue("equals", fType1.equals(copy1));
218 assertTrue("equals", copy1.equals(copy2));
219 assertTrue("equals", fType1.equals(copy2));
220
221 copy1 = new TmfEventType(fType2);
222 copy2 = new TmfEventType(copy1);
223 assertTrue("equals", fType2.equals(copy1));
224 assertTrue("equals", copy1.equals(copy2));
225 assertTrue("equals", fType2.equals(copy2));
226
227 copy1 = new TmfEventType(fType3);
228 copy2 = new TmfEventType(copy1);
229 assertTrue("equals", fType3.equals(copy1));
230 assertTrue("equals", copy1.equals(copy2));
231 assertTrue("equals", fType3.equals(copy2));
232 }
233
234 @Test
235 public void testEqualsNull() {
236 assertFalse("equals", fType0.equals(null));
237 assertFalse("equals", fType3.equals(null));
238 }
239
240 @Test
241 public void testNonEquals() {
242 assertFalse("equals", fType0.equals(fType1));
243 assertFalse("equals", fType1.equals(fType2));
244 assertFalse("equals", fType2.equals(fType3));
245 assertFalse("equals", fType3.equals(fType0));
246 }
247
248 @Test
249 public void testNonEqualsClasses() {
250 assertFalse("equals", fType1.equals(fLabels1));
251 }
252
253 // ------------------------------------------------------------------------
254 // toString
255 // ------------------------------------------------------------------------
256
257 @Test
258 public void testToString() {
259 final String expected1 = "TmfEventType [fContext=" + ITmfEventType.DEFAULT_CONTEXT_ID +
260 ", fTypeId=" + ITmfEventType.DEFAULT_TYPE_ID + "]";
261 final TmfEventType type1 = new TmfEventType();
262 assertEquals("toString", expected1, type1.toString());
263
264 final String expected2 = "TmfEventType [fContext=" + fContext1 + ", fTypeId=" + fTypeId1 + "]";
265 final TmfEventType type2 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1));
266 assertEquals("toString", expected2, type2.toString());
267 }
268
269 }
This page took 0.037066 seconds and 5 git commands to generate.