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