1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.control
.core
.tests
.model
.impl
;
16 import static org
.junit
.Assert
.*;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.IFieldInfo
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.FieldInfo
;
20 import org
.junit
.Before
;
21 import org
.junit
.Test
;
24 * The class <code>FieldInfoTest</code> contains test for the class
25 * <code>{@link FieldInfo}</code>.
27 public class FieldInfoTest
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private IFieldInfo fFieldInfo1
= null;
34 private IFieldInfo fFieldInfo2
= null;
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
41 * Perform pre-test initialization.
45 ModelImplFactory factory
= new ModelImplFactory();
46 fFieldInfo1
= factory
.getFieldInfo1();
47 fFieldInfo2
= factory
.getFieldInfo2();
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
55 * Run the BaseEventInfo() constructor test.
58 public void testFiledInfo() {
59 FieldInfo fixture
= new FieldInfo("field");
60 assertNotNull(fixture
);
62 assertEquals("field", fixture
.getName());
63 assertNull(fixture
.getFieldType());
67 * Test Copy Constructor
70 public void testEventInfoCopy() {
71 FieldInfo info
= new FieldInfo((FieldInfo
)fFieldInfo1
);
73 assertEquals(fFieldInfo1
.getName(), info
.getName());
74 assertEquals(fFieldInfo1
.getFieldType(), info
.getFieldType());
78 * Test Copy Constructor
81 public void testEventCopy2() {
83 FieldInfo info
= null;
87 catch (IllegalArgumentException e
) {
93 * Run the TraceEventType getEventType() method test.
96 public void testSetFieldType() {
97 FieldInfo info
= new FieldInfo((FieldInfo
)fFieldInfo1
);
99 info
.setFieldType("string");
100 assertEquals("string", info
.getFieldType());
104 * Run the toString() method test.
107 public void testToString() {
108 String result
= fFieldInfo1
.toString();
110 // add additional test code here
111 assertEquals("[FieldInfo([TraceInfo(Name=intfield)],type=int", result
);
114 // ------------------------------------------------------------------------
116 // ------------------------------------------------------------------------
119 * Run the equals() method test.
122 public void testEqualsReflexivity() {
123 assertTrue("equals", fFieldInfo1
.equals(fFieldInfo1
));
124 assertTrue("equals", fFieldInfo2
.equals(fFieldInfo2
));
126 assertTrue("equals", !fFieldInfo1
.equals(fFieldInfo2
));
127 assertTrue("equals", !fFieldInfo2
.equals(fFieldInfo1
));
131 * Run the equals() method test.
134 public void testEqualsSymmetry() {
135 FieldInfo info1
= new FieldInfo((FieldInfo
)fFieldInfo1
);
136 FieldInfo info2
= new FieldInfo((FieldInfo
)fFieldInfo2
);
138 assertTrue("equals", info1
.equals(fFieldInfo1
));
139 assertTrue("equals", fFieldInfo1
.equals(info1
));
141 assertTrue("equals", info2
.equals(fFieldInfo2
));
142 assertTrue("equals", fFieldInfo2
.equals(info2
));
146 * Run the equals() method test.
149 public void testEqualsTransivity() {
150 FieldInfo info1
= new FieldInfo((FieldInfo
)fFieldInfo1
);
151 FieldInfo info2
= new FieldInfo((FieldInfo
)fFieldInfo1
);
152 FieldInfo info3
= new FieldInfo((FieldInfo
)fFieldInfo1
);
154 assertTrue("equals", info1
.equals(info2
));
155 assertTrue("equals", info2
.equals(info3
));
156 assertTrue("equals", info1
.equals(info3
));
160 * Run the equals() method test.
163 public void testEqualsNull() {
164 assertTrue("equals", !fFieldInfo1
.equals(null));
165 assertTrue("equals", !fFieldInfo2
.equals(null));
168 // ------------------------------------------------------------------------
170 // ------------------------------------------------------------------------
173 * Run the equals() method test.
176 public void testHashCode() {
177 FieldInfo info1
= new FieldInfo((FieldInfo
)fFieldInfo1
);
178 FieldInfo info2
= new FieldInfo((FieldInfo
)fFieldInfo2
);
180 assertTrue("hashCode", fFieldInfo1
.hashCode() == info1
.hashCode());
181 assertTrue("hashCode", fFieldInfo2
.hashCode() == info2
.hashCode());
183 assertTrue("hashCode", fFieldInfo1
.hashCode() != info2
.hashCode());
184 assertTrue("hashCode", fFieldInfo2
.hashCode() != info1
.hashCode());