Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
2ba3d0a1 | 2 | * Copyright (c) 2012, 2013 Ericsson |
b0318660 | 3 | * |
eb1bab5b BH |
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 | |
b0318660 AM |
8 | * |
9 | * Contributors: | |
eb1bab5b | 10 | * Bernd Hufmann - Initial API and implementation |
2ba3d0a1 | 11 | * Alexandre Montplaisir - Port to JUnit4 |
eb1bab5b | 12 | **********************************************************************/ |
2ba3d0a1 | 13 | |
9315aeee | 14 | package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl; |
eb1bab5b | 15 | |
2ba3d0a1 | 16 | import static org.junit.Assert.*; |
eb1bab5b | 17 | |
9315aeee BH |
18 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ITraceInfo; |
19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.TraceInfo; | |
2ba3d0a1 AM |
20 | import org.junit.Before; |
21 | import org.junit.Test; | |
eb1bab5b BH |
22 | |
23 | /** | |
2ba3d0a1 AM |
24 | * The class <code>TraceInfoTest</code> contains test for the class |
25 | * <code>{@link TraceInfo}</code>. | |
eb1bab5b | 26 | */ |
2ba3d0a1 AM |
27 | @SuppressWarnings("nls") |
28 | public class TraceInfoTest { | |
eb1bab5b BH |
29 | |
30 | // ------------------------------------------------------------------------ | |
31 | // Test data | |
32 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 33 | |
eb1bab5b BH |
34 | private ITraceInfo fTraceInfo1 = null; |
35 | private ITraceInfo fTraceInfo2 = null; | |
b0318660 AM |
36 | |
37 | ||
eb1bab5b BH |
38 | // ------------------------------------------------------------------------ |
39 | // Housekeeping | |
40 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 41 | |
eb1bab5b BH |
42 | /** |
43 | * Perform pre-test initialization. | |
eb1bab5b | 44 | */ |
2ba3d0a1 AM |
45 | @Before |
46 | public void setUp() { | |
eb1bab5b BH |
47 | fTraceInfo1 = new TraceInfo("event1"); |
48 | fTraceInfo2 = new TraceInfo("event2"); | |
49 | } | |
50 | ||
eb1bab5b BH |
51 | // ------------------------------------------------------------------------ |
52 | // Tests | |
53 | // ------------------------------------------------------------------------ | |
54 | ||
55 | /** | |
56 | * Run the BaseEventInfo() constructor test. | |
eb1bab5b | 57 | */ |
2ba3d0a1 | 58 | @Test |
eb1bab5b BH |
59 | public void testTraceInfo() { |
60 | TraceInfo fixture = new TraceInfo("event"); | |
61 | assertNotNull(fixture); | |
b0318660 | 62 | |
eb1bab5b BH |
63 | assertEquals("event", fixture.getName()); |
64 | } | |
65 | ||
66 | /** | |
67 | * Test Copy Constructor | |
68 | */ | |
2ba3d0a1 | 69 | @Test |
eb1bab5b BH |
70 | public void testTraceInfo2() { |
71 | try { | |
72 | String name = null; | |
73 | new TraceInfo(name); | |
74 | fail("null name in custructor"); | |
75 | } | |
76 | catch (IllegalArgumentException e) { | |
77 | // Success | |
78 | } | |
79 | } | |
b0318660 | 80 | |
eb1bab5b BH |
81 | /** |
82 | * Test Copy Constructor | |
83 | */ | |
2ba3d0a1 | 84 | @Test |
eb1bab5b BH |
85 | public void testTraceInfoCopy() { |
86 | TraceInfo info = new TraceInfo((TraceInfo)fTraceInfo1); | |
b0318660 | 87 | |
eb1bab5b BH |
88 | assertEquals(fTraceInfo1.getName(), info.getName()); |
89 | } | |
90 | ||
91 | /** | |
92 | * Test Copy Constructor | |
93 | */ | |
2ba3d0a1 | 94 | @Test |
eb1bab5b BH |
95 | public void testTraceCopy2() { |
96 | try { | |
97 | TraceInfo info = null; | |
98 | new TraceInfo(info); | |
99 | fail("null copy"); | |
100 | } | |
101 | catch (IllegalArgumentException e) { | |
102 | // Success | |
103 | } | |
104 | } | |
b0318660 | 105 | |
eb1bab5b BH |
106 | /** |
107 | * Run the void setEventType(String) method test. | |
eb1bab5b | 108 | */ |
2ba3d0a1 | 109 | @Test |
eb1bab5b BH |
110 | public void testSetName() { |
111 | TraceInfo fixture = new TraceInfo("event"); | |
112 | fixture.setName("newName"); | |
113 | assertEquals("newName", fixture.getName()); | |
114 | } | |
115 | ||
116 | /** | |
117 | * Run the String toString() method test. | |
eb1bab5b | 118 | */ |
2ba3d0a1 | 119 | @Test |
eb1bab5b BH |
120 | public void testToString_1() { |
121 | String result = fTraceInfo1.toString(); | |
122 | ||
123 | // add additional test code here | |
124 | assertEquals("[TraceInfo(Name=event1)]", result); | |
125 | } | |
b0318660 | 126 | |
eb1bab5b BH |
127 | // ------------------------------------------------------------------------ |
128 | // equals | |
129 | // ------------------------------------------------------------------------ | |
130 | ||
2ba3d0a1 AM |
131 | /** |
132 | * Run the equals() method test. | |
133 | */ | |
134 | @Test | |
eb1bab5b BH |
135 | public void testEqualsReflexivity() { |
136 | assertTrue("equals", fTraceInfo1.equals(fTraceInfo1)); | |
137 | assertTrue("equals", fTraceInfo2.equals(fTraceInfo2)); | |
138 | ||
139 | assertTrue("equals", !fTraceInfo1.equals(fTraceInfo2)); | |
140 | assertTrue("equals", !fTraceInfo2.equals(fTraceInfo1)); | |
141 | } | |
b0318660 | 142 | |
2ba3d0a1 AM |
143 | /** |
144 | * Run the equals() method test. | |
145 | */ | |
146 | @Test | |
eb1bab5b BH |
147 | public void testEqualsSymmetry() { |
148 | TraceInfo info1 = new TraceInfo((TraceInfo)fTraceInfo1); | |
149 | TraceInfo info2 = new TraceInfo((TraceInfo)fTraceInfo2); | |
150 | ||
151 | assertTrue("equals", info1.equals(fTraceInfo1)); | |
152 | assertTrue("equals", fTraceInfo1.equals(info1)); | |
153 | ||
154 | assertTrue("equals", info2.equals(fTraceInfo2)); | |
155 | assertTrue("equals", fTraceInfo2.equals(info2)); | |
156 | } | |
2ba3d0a1 AM |
157 | /** |
158 | * Run the equals() method test. | |
159 | */ | |
160 | @Test | |
eb1bab5b BH |
161 | public void testEqualsTransivity() { |
162 | TraceInfo info1 = new TraceInfo((TraceInfo)fTraceInfo1); | |
163 | TraceInfo info2 = new TraceInfo((TraceInfo)fTraceInfo1); | |
164 | TraceInfo info3 = new TraceInfo((TraceInfo)fTraceInfo1); | |
165 | ||
166 | assertTrue("equals", info1.equals(info2)); | |
167 | assertTrue("equals", info2.equals(info3)); | |
168 | assertTrue("equals", info1.equals(info3)); | |
169 | } | |
2ba3d0a1 AM |
170 | /** |
171 | * Run the equals() method test. | |
172 | */ | |
173 | @Test | |
eb1bab5b BH |
174 | public void testEqualsNull() { |
175 | assertTrue("equals", !fTraceInfo1.equals(null)); | |
176 | assertTrue("equals", !fTraceInfo2.equals(null)); | |
177 | } | |
b0318660 | 178 | |
eb1bab5b BH |
179 | // ------------------------------------------------------------------------ |
180 | // hashCode | |
181 | // ------------------------------------------------------------------------ | |
182 | ||
2ba3d0a1 AM |
183 | /** |
184 | * Run the hashCode() method test. | |
185 | */ | |
186 | @Test | |
eb1bab5b BH |
187 | public void testHashCode() { |
188 | TraceInfo info1 = new TraceInfo((TraceInfo)fTraceInfo1); | |
189 | TraceInfo info2 = new TraceInfo((TraceInfo)fTraceInfo2); | |
190 | ||
191 | assertTrue("hashCode", fTraceInfo1.hashCode() == info1.hashCode()); | |
192 | assertTrue("hashCode", fTraceInfo2.hashCode() == info2.hashCode()); | |
193 | ||
194 | assertTrue("hashCode", fTraceInfo1.hashCode() != info2.hashCode()); | |
195 | assertTrue("hashCode", fTraceInfo2.hashCode() != info1.hashCode()); | |
196 | } | |
197 | } |