1 /**********************************************************************
2 * Copyright (c) 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 **********************************************************************/
13 package org
.eclipse
.linuxtools
.lttng2
.core
.tests
.control
.model
.impl
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assert
.fail
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ISnapshotInfo
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.SnapshotInfo
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.TraceInfo
;
23 import org
.junit
.Before
;
24 import org
.junit
.Test
;
27 * The class <code>SnapshotInfoTest</code> contains test for the class
28 * <code>{@link SnapshotInfo}</code>.
30 public class SnapshotInfoTest
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 private ISnapshotInfo fSnapshotInfo1
= null;
37 private ISnapshotInfo fSnapshotInfo2
= null;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * Perform pre-test initialization.
49 ModelImplFactory factory
= new ModelImplFactory();
50 fSnapshotInfo1
= factory
.getSnapshotInfo1();
51 fSnapshotInfo2
= factory
.getSnapshotInfo2();
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
62 public void testSnapshotInfo() {
63 SnapshotInfo fixture
= new SnapshotInfo("event");
64 assertNotNull(fixture
);
65 assertEquals("event", fixture
.getName());
69 * Test Copy Constructor
72 public void testSnapshotInfo2() {
75 new SnapshotInfo(name
);
76 fail("null name in custructor");
78 catch (IllegalArgumentException e
) {
84 * Test Copy Constructor
87 public void testSnapshotCopy() {
88 SnapshotInfo info
= new SnapshotInfo((SnapshotInfo
)fSnapshotInfo1
);
90 assertEquals(fSnapshotInfo1
.getName(), info
.getName());
94 * Test Copy Constructor
97 public void testTraceCopy2() {
99 SnapshotInfo info
= null;
100 new SnapshotInfo(info
);
103 catch (IllegalArgumentException e
) {
109 * Run the void setEventType(String) method test.
112 public void testSetName() {
113 SnapshotInfo fixture
= new SnapshotInfo("event");
114 fixture
.setName("newName");
115 assertEquals("newName", fixture
.getName());
119 * Run the String toString() method test.
122 public void testToString_1() {
123 String result
= fSnapshotInfo1
.toString();
125 // add additional test code here
126 assertEquals("[SnapshotInfo([TraceInfo(Name=snapshot-1)],snapshotPath=/home/user/lttng-trace/mysession/,ID=1,isStreamedSnapshot=false)]", result
);
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
134 * Run the equals() method test.
137 public void testEqualsReflexivity() {
138 assertTrue("equals", fSnapshotInfo1
.equals(fSnapshotInfo1
));
139 assertTrue("equals", fSnapshotInfo2
.equals(fSnapshotInfo2
));
141 assertTrue("equals", !fSnapshotInfo1
.equals(fSnapshotInfo2
));
142 assertTrue("equals", !fSnapshotInfo2
.equals(fSnapshotInfo1
));
146 * Run the equals() method test.
149 public void testEqualsSymmetry() {
150 SnapshotInfo info1
= new SnapshotInfo((SnapshotInfo
)fSnapshotInfo1
);
151 SnapshotInfo info2
= new SnapshotInfo((SnapshotInfo
)fSnapshotInfo2
);
153 assertTrue("equals", info1
.equals(fSnapshotInfo1
));
154 assertTrue("equals", fSnapshotInfo1
.equals(info1
));
156 assertTrue("equals", info2
.equals(fSnapshotInfo2
));
157 assertTrue("equals", fSnapshotInfo2
.equals(info2
));
160 * Run the equals() method test.
163 public void testEqualsTransivity() {
164 SnapshotInfo info1
= new SnapshotInfo((SnapshotInfo
)fSnapshotInfo1
);
165 SnapshotInfo info2
= new SnapshotInfo((SnapshotInfo
)fSnapshotInfo1
);
166 SnapshotInfo info3
= new SnapshotInfo((SnapshotInfo
)fSnapshotInfo1
);
168 assertTrue("equals", info1
.equals(info2
));
169 assertTrue("equals", info2
.equals(info3
));
170 assertTrue("equals", info1
.equals(info3
));
173 * Run the equals() method test.
176 public void testEqualsNull() {
177 assertTrue("equals", !fSnapshotInfo1
.equals(null));
178 assertTrue("equals", !fSnapshotInfo2
.equals(null));
180 SnapshotInfo info
= new SnapshotInfo("snapshot-1");
181 assertTrue("equals", !fSnapshotInfo1
.equals(info
));
183 info
.setSnapshotPath(null);
184 assertTrue("equals", !fSnapshotInfo1
.equals(info
));
186 info
.setId(fSnapshotInfo1
.getId());
187 assertTrue("equals", !info
.equals(fSnapshotInfo1
));
189 info
.setSnapshotPath("/home/user/lttng-trace/mysession/");
190 assertTrue("equals", fSnapshotInfo1
.equals(info
));
192 assertTrue("equals", !fSnapshotInfo1
.equals(info
));
194 info
.setId(fSnapshotInfo1
.getId());
195 info
.setStreamedSnapshot(true);
196 assertTrue("equals", !fSnapshotInfo1
.equals(info
));
198 assertTrue("equals", !fSnapshotInfo1
.equals(new TraceInfo(fSnapshotInfo1
.getName())));
201 // ------------------------------------------------------------------------
203 // ------------------------------------------------------------------------
206 * Run the hashCode() method test.
209 public void testHashCode() {
210 SnapshotInfo info1
= new SnapshotInfo((SnapshotInfo
)fSnapshotInfo1
);
211 SnapshotInfo info2
= new SnapshotInfo((SnapshotInfo
)fSnapshotInfo2
);
213 assertTrue("hashCode", fSnapshotInfo1
.hashCode() == info1
.hashCode());
214 assertTrue("hashCode", fSnapshotInfo2
.hashCode() == info2
.hashCode());
216 assertTrue("hashCode", fSnapshotInfo1
.hashCode() != info2
.hashCode());
217 assertTrue("hashCode", fSnapshotInfo2
.hashCode() != info1
.hashCode());
220 SnapshotInfo info3
= new SnapshotInfo("snapshot-1");
221 assertTrue("hashCode", fSnapshotInfo1
.hashCode() != info3
.hashCode());
223 info3
.setSnapshotPath(null);
224 assertTrue("hashCode", fSnapshotInfo1
.hashCode() != info3
.hashCode());
226 info3
.setSnapshotPath("/home/user/lttng-trace/mysession/");
227 assertTrue("hashCode", fSnapshotInfo1
.hashCode() != info3
.hashCode());