analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / event / TmfEventTypeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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.tracecompass.tmf.core.tests.event;
16
17 import static org.junit.Assert.assertArrayEquals;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNull;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
23
24 import java.util.Collection;
25
26 import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
27 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
28 import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
29 import org.junit.Test;
30
31 /**
32 * Test suite for the TmfEventType class.
33 */
34 @SuppressWarnings("javadoc")
35 public class TmfEventTypeTest {
36
37 // ------------------------------------------------------------------------
38 // Variables
39 // ------------------------------------------------------------------------
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 private final String fLabel2 = "label3";
47
48 private final String[] fLabels0 = new String[] { };
49 private final String[] fLabels1 = new String[] { fLabel0, fLabel1 };
50 private final String[] fLabels2 = new String[] { fLabel1, fLabel0, fLabel2 };
51
52 private final ITmfEventType fType0 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels0));
53 private final ITmfEventType fType1 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels1));
54 private final ITmfEventType fType2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels2));
55 private final ITmfEventType fType3 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels1));
56
57 // ------------------------------------------------------------------------
58 // Constructors
59 // ------------------------------------------------------------------------
60
61 @Test
62 public void testDefaultConstructor() {
63 final ITmfEventType type = new TmfEventType();
64 assertEquals("getName", ITmfEventType.DEFAULT_TYPE_ID, type.getName());
65 assertNull("getRootField", type.getRootField());
66 assertEquals("getFieldNames", 0, type.getFieldNames().size());
67 }
68
69 @Test
70 public void testFullConstructor() {
71 final ITmfEventType type0 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels0));
72 assertEquals("getName", fTypeId1, type0.getName());
73 assertEquals("getRootField", TmfEventField.makeRoot(fLabels0), type0.getRootField());
74 final Collection<String> labels0 = type0.getFieldNames();
75 assertEquals("getFieldNames length", fLabels0.length, labels0.size());
76 assertArrayEquals(fLabels0, labels0.toArray(new String[labels0.size()]));
77
78 final ITmfEventType type1 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
79 assertEquals("getName", fTypeId1, type1.getName());
80 assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), type1.getRootField());
81 final Collection<String> labels1 = type1.getFieldNames();
82 assertEquals("getFieldNames length", fLabels1.length, labels1.size());
83 assertArrayEquals(fLabels1, labels1.toArray(new String[labels1.size()]));
84
85 final ITmfEventType type2 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels2));
86 assertEquals("getName", fTypeId2, type2.getName());
87 assertEquals("getRootField", TmfEventField.makeRoot(fLabels2), type2.getRootField());
88 final Collection<String> labels2 = type2.getFieldNames();
89 assertEquals("getFieldNames length", fLabels2.length, labels2.size());
90 assertArrayEquals(fLabels2, labels2.toArray(new String[labels2.size()]));
91 }
92
93 @Test(expected = IllegalArgumentException.class)
94 public void testConstructorCornerCases() {
95 new TmfEventType(null, null);
96 }
97
98 @Test
99 public void testCopyConstructor() {
100 final TmfEventType original = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
101 final TmfEventType copy = new TmfEventType(original);
102
103 assertEquals("getName", fTypeId1, copy.getName());
104 assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), copy.getRootField());
105 final Collection<String> labels1 = copy.getFieldNames();
106 assertEquals("getFieldNames length", fLabels1.length, labels1.size());
107 assertArrayEquals(fLabels1, labels1.toArray(new String[labels1.size()]));
108 }
109
110 @Test
111 public void testCopyConstructorCornerCases() {
112 try {
113 new TmfEventType(null);
114 fail("TmfEventType: null argument");
115 } catch (final IllegalArgumentException e) {
116 }
117 }
118
119 // ------------------------------------------------------------------------
120 // hashCode
121 // ------------------------------------------------------------------------
122
123 @Test
124 public void testHashCode() {
125 final TmfEventType copy1 = new TmfEventType(fType0);
126
127 assertTrue("hashCode", fType0.hashCode() == copy1.hashCode());
128 assertTrue("hashCode", fType0.hashCode() != fType3.hashCode());
129 }
130
131 // ------------------------------------------------------------------------
132 // equals
133 // ------------------------------------------------------------------------
134
135 @Test
136 public void testEqualsReflexivity() {
137 assertTrue("equals", fType0.equals(fType0));
138 assertTrue("equals", fType3.equals(fType3));
139
140 assertFalse("equals", fType0.equals(fType3));
141 assertFalse("equals", fType3.equals(fType0));
142 }
143
144 @Test
145 public void testEqualsSymmetry() {
146 final TmfEventType copy0 = new TmfEventType(fType0);
147 assertTrue("equals", fType0.equals(copy0));
148 assertTrue("equals", copy0.equals(fType0));
149
150 final TmfEventType copy1 = new TmfEventType(fType1);
151 assertTrue("equals", fType1.equals(copy1));
152 assertTrue("equals", copy1.equals(fType1));
153
154 final TmfEventType copy2 = new TmfEventType(fType2);
155 assertTrue("equals", fType2.equals(copy2));
156 assertTrue("equals", copy2.equals(fType2));
157 }
158
159 @Test
160 public void testEqualsTransivity() {
161 TmfEventType copy1 = new TmfEventType(fType1);
162 TmfEventType copy2 = new TmfEventType(copy1);
163 assertTrue("equals", fType1.equals(copy1));
164 assertTrue("equals", copy1.equals(copy2));
165 assertTrue("equals", fType1.equals(copy2));
166
167 copy1 = new TmfEventType(fType2);
168 copy2 = new TmfEventType(copy1);
169 assertTrue("equals", fType2.equals(copy1));
170 assertTrue("equals", copy1.equals(copy2));
171 assertTrue("equals", fType2.equals(copy2));
172
173 copy1 = new TmfEventType(fType3);
174 copy2 = new TmfEventType(copy1);
175 assertTrue("equals", fType3.equals(copy1));
176 assertTrue("equals", copy1.equals(copy2));
177 assertTrue("equals", fType3.equals(copy2));
178 }
179
180 @Test
181 public void testEqualsNull() {
182 assertFalse("equals", fType0.equals(null));
183 assertFalse("equals", fType3.equals(null));
184 }
185
186 @Test
187 public void testNonEquals() {
188 assertFalse("equals", fType0.equals(fType1));
189 assertFalse("equals", fType1.equals(fType2));
190 assertFalse("equals", fType2.equals(fType3));
191 assertFalse("equals", fType3.equals(fType0));
192 }
193
194 @Test
195 public void testNonEqualsClasses() {
196 assertFalse("equals", fType1.equals(fLabels1));
197 }
198
199 // ------------------------------------------------------------------------
200 // toString
201 // ------------------------------------------------------------------------
202
203 @Test
204 public void testToString() {
205 final String expected1 = "TmfEventType [fTypeId=" + ITmfEventType.DEFAULT_TYPE_ID + "]";
206 final TmfEventType type1 = new TmfEventType();
207 assertEquals("toString", expected1, type1.toString());
208
209 final String expected2 = "TmfEventType [fTypeId=" + fTypeId1 + "]";
210 final TmfEventType type2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
211 assertEquals("toString", expected2, type2.toString());
212 }
213
214 }
This page took 0.050779 seconds and 5 git commands to generate.