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 / FieldInfoTest.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.*;
17
18 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo;
19 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.FieldInfo;
20 import org.junit.Before;
21 import org.junit.Test;
22
23 /**
24 * The class <code>FieldInfoTest</code> contains test for the class
25 * <code>{@link FieldInfo}</code>.
26 */
27 @SuppressWarnings("nls")
28 public class FieldInfoTest {
29
30 // ------------------------------------------------------------------------
31 // Test data
32 // ------------------------------------------------------------------------
33
34 private IFieldInfo fFieldInfo1 = null;
35 private IFieldInfo fFieldInfo2 = null;
36
37 // ------------------------------------------------------------------------
38 // Housekeeping
39 // ------------------------------------------------------------------------
40
41 /**
42 * Perform pre-test initialization.
43 */
44 @Before
45 public void setUp() {
46 ModelImplFactory factory = new ModelImplFactory();
47 fFieldInfo1 = factory.getFieldInfo1();
48 fFieldInfo2 = factory.getFieldInfo2();
49 }
50
51 // ------------------------------------------------------------------------
52 // Tests
53 // ------------------------------------------------------------------------
54
55 /**
56 * Run the BaseEventInfo() constructor test.
57 */
58 @Test
59 public void testFiledInfo() {
60 FieldInfo fixture = new FieldInfo("field");
61 assertNotNull(fixture);
62
63 assertEquals("field", fixture.getName());
64 assertNull(fixture.getFieldType());
65 }
66
67 /**
68 * Test Copy Constructor
69 */
70 @Test
71 public void testEventInfoCopy() {
72 FieldInfo info = new FieldInfo((FieldInfo)fFieldInfo1);
73
74 assertEquals(fFieldInfo1.getName(), info.getName());
75 assertEquals(fFieldInfo1.getFieldType(), info.getFieldType());
76 }
77
78 /**
79 * Test Copy Constructor
80 */
81 @Test
82 public void testEventCopy2() {
83 try {
84 FieldInfo info = null;
85 new FieldInfo(info);
86 fail("null copy");
87 }
88 catch (IllegalArgumentException e) {
89 // Success
90 }
91 }
92
93 /**
94 * Run the TraceEventType getEventType() method test.
95 */
96 @Test
97 public void testSetFieldType() {
98 FieldInfo info = new FieldInfo((FieldInfo)fFieldInfo1);
99
100 info.setFieldType("string");
101 assertEquals("string", info.getFieldType());
102 }
103
104 /**
105 * Run the toString() method test.
106 */
107 @Test
108 public void testToString() {
109 String result = fFieldInfo1.toString();
110
111 // add additional test code here
112 assertEquals("[FieldInfo([TraceInfo(Name=intfield)],type=int", result);
113 }
114
115 // ------------------------------------------------------------------------
116 // equals
117 // ------------------------------------------------------------------------
118
119 /**
120 * Run the equals() method test.
121 */
122 @Test
123 public void testEqualsReflexivity() {
124 assertTrue("equals", fFieldInfo1.equals(fFieldInfo1));
125 assertTrue("equals", fFieldInfo2.equals(fFieldInfo2));
126
127 assertTrue("equals", !fFieldInfo1.equals(fFieldInfo2));
128 assertTrue("equals", !fFieldInfo2.equals(fFieldInfo1));
129 }
130
131 /**
132 * Run the equals() method test.
133 */
134 @Test
135 public void testEqualsSymmetry() {
136 FieldInfo info1 = new FieldInfo((FieldInfo)fFieldInfo1);
137 FieldInfo info2 = new FieldInfo((FieldInfo)fFieldInfo2);
138
139 assertTrue("equals", info1.equals(fFieldInfo1));
140 assertTrue("equals", fFieldInfo1.equals(info1));
141
142 assertTrue("equals", info2.equals(fFieldInfo2));
143 assertTrue("equals", fFieldInfo2.equals(info2));
144 }
145
146 /**
147 * Run the equals() method test.
148 */
149 @Test
150 public void testEqualsTransivity() {
151 FieldInfo info1 = new FieldInfo((FieldInfo)fFieldInfo1);
152 FieldInfo info2 = new FieldInfo((FieldInfo)fFieldInfo1);
153 FieldInfo info3 = new FieldInfo((FieldInfo)fFieldInfo1);
154
155 assertTrue("equals", info1.equals(info2));
156 assertTrue("equals", info2.equals(info3));
157 assertTrue("equals", info1.equals(info3));
158 }
159
160 /**
161 * Run the equals() method test.
162 */
163 @Test
164 public void testEqualsNull() {
165 assertTrue("equals", !fFieldInfo1.equals(null));
166 assertTrue("equals", !fFieldInfo2.equals(null));
167 }
168
169 // ------------------------------------------------------------------------
170 // hashCode
171 // ------------------------------------------------------------------------
172
173 /**
174 * Run the equals() method test.
175 */
176 @Test
177 public void testHashCode() {
178 FieldInfo info1 = new FieldInfo((FieldInfo)fFieldInfo1);
179 FieldInfo info2 = new FieldInfo((FieldInfo)fFieldInfo2);
180
181 assertTrue("hashCode", fFieldInfo1.hashCode() == info1.hashCode());
182 assertTrue("hashCode", fFieldInfo2.hashCode() == info2.hashCode());
183
184 assertTrue("hashCode", fFieldInfo1.hashCode() != info2.hashCode());
185 assertTrue("hashCode", fFieldInfo2.hashCode() != info1.hashCode());
186 }
187 }
This page took 0.049272 seconds and 5 git commands to generate.