1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.event
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventContent
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventField
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventReference
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
22 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
23 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventTypeStub
;
24 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
27 * <b><u>TmfEventFieldTest</u></b>
29 * Test suite for the TmfEventField class.
31 @SuppressWarnings("nls")
32 public class TmfEventFieldTest
extends TestCase
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 private final TmfEventContent fContent
;
39 private final String fFieldId
= "Field";
40 private final Object fValue1
= new String("Value");
41 private final Object fValue2
= new Integer(10);
43 private TmfEventField fField0
;
44 private TmfEventField fField1
;
45 private TmfEventField fField2
;
46 private TmfEventField fField3
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * @param name the test name
55 public TmfEventFieldTest(String name
) {
57 TmfTimestamp fTimestamp
= new TmfTimestamp();
58 TmfEventSource fEventSource
= new TmfEventSource();
59 TmfEventType fEventType
= new TmfEventTypeStub();
60 TmfEventReference fReference
= new TmfEventReference();
61 TmfEvent fEvent
= new TmfEvent(fTimestamp
, fEventSource
, fEventType
, fReference
);
63 fContent
= new TmfEventContent(fEvent
, "Some content");
65 fField0
= new TmfEventField(fContent
, fFieldId
, fValue1
);
66 fField1
= new TmfEventField(fContent
, fFieldId
, fValue1
);
67 fField2
= new TmfEventField(fContent
, fFieldId
, fValue1
);
68 fField3
= new TmfEventField(fContent
, fFieldId
, fValue2
);
72 protected void setUp() throws Exception
{
77 protected void tearDown() throws Exception
{
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
85 public void testTmfEventField() {
86 assertSame("getParent", fContent
, fField0
.getParent());
87 assertSame("getId", fFieldId
, fField0
.getId());
88 assertSame("getValue", fValue1
, fField0
.getValue());
91 public void testTmfEventFieldBadArg() {
93 new TmfEventField(fContent
, null, fValue1
);
96 catch (IllegalArgumentException e
) {
101 public void testTmfEventFieldCopy() {
102 TmfEventField original
= new TmfEventField(fContent
, fFieldId
, fValue1
);
103 TmfEventField field
= new TmfEventField(original
);
104 assertSame("getParent", fContent
, field
.getParent());
105 assertSame("getId", fFieldId
, field
.getId());
106 assertSame("getValue", fValue1
, field
.getValue());
109 public void testTmfEventFieldCopy2() {
111 new TmfEventField(null);
114 catch (IllegalArgumentException e
) {
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
123 private class MyField
extends TmfEventField
{
124 public MyField(TmfEventContent parent
, String id
, Object value
) {
125 super(parent
, id
, value
);
127 public MyField(TmfEventField field
) {
131 public void setValue(Object value
) {
132 super.setValue(value
);
136 public void testSetValue() {
137 TmfEventField original
= new TmfEventField(fContent
, fFieldId
, fValue1
);
138 TmfEventField field
= new TmfEventField(original
);
140 MyField myField
= new MyField(field
);
141 assertSame("getValue", fValue1
, myField
.getValue());
143 myField
.setValue(fValue2
);
144 assertSame("getValue", fValue2
, myField
.getValue());
147 // ------------------------------------------------------------------------
149 // ------------------------------------------------------------------------
151 public void testEqualsReflexivity() throws Exception
{
152 assertTrue("equals", fField0
.equals(fField0
));
153 assertTrue("equals", fField3
.equals(fField3
));
155 assertTrue("equals", !fField0
.equals(fField3
));
156 assertTrue("equals", !fField3
.equals(fField0
));
159 public void testEqualsSymmetry() throws Exception
{
160 assertTrue("equals", fField0
.equals(fField1
));
161 assertTrue("equals", fField1
.equals(fField0
));
163 assertTrue("equals", !fField0
.equals(fField3
));
164 assertTrue("equals", !fField3
.equals(fField0
));
167 public void testEqualsTransivity() throws Exception
{
168 assertTrue("equals", fField0
.equals(fField1
));
169 assertTrue("equals", fField1
.equals(fField2
));
170 assertTrue("equals", fField0
.equals(fField2
));
173 public void testEqualsNull() throws Exception
{
174 assertTrue("equals", !fField0
.equals(null));
175 assertTrue("equals", !fField3
.equals(null));
178 // ------------------------------------------------------------------------
180 // ------------------------------------------------------------------------
182 public void testHashCode() throws Exception
{
183 assertTrue("hashCode", fField0
.hashCode() == fField1
.hashCode());
184 assertTrue("hashCode", fField0
.hashCode() != fField3
.hashCode());
187 // ------------------------------------------------------------------------
189 // ------------------------------------------------------------------------
191 public void testToString() {
192 String expected1
= "[TmfEventField(" + fFieldId
+ ":" + fValue1
.toString() + ")]";
193 TmfEventField field
= new TmfEventField(fContent
, fFieldId
, fValue1
);
194 assertEquals("toString", expected1
, field
.toString());
196 String expected2
= "[TmfEventField(" + fFieldId
+ ":" + fValue2
.toString() + ")]";
197 field
= new TmfEventField(fContent
, fFieldId
, fValue2
);
198 assertEquals("toString", expected2
, field
.toString());