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