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