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 public class TmfEventFieldTest
extends TestCase
{
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
37 private final TmfEventContent fContent
;
38 private final String fFieldId
= "Field";
39 private final Object fValue1
= new String("Value");
40 private final Object fValue2
= new Integer(10);
42 private TmfEventField fField0
;
43 private TmfEventField fField1
;
44 private TmfEventField fField2
;
45 private TmfEventField fField3
;
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
52 * @param name the test name
54 public TmfEventFieldTest(String name
) {
56 TmfTimestamp fTimestamp
= new TmfTimestamp();
57 TmfEventSource fEventSource
= new TmfEventSource();
58 TmfEventType fEventType
= new TmfEventTypeStub();
59 TmfEventReference fReference
= new TmfEventReference();
60 TmfEvent fEvent
= new TmfEvent(fTimestamp
, fEventSource
, fEventType
, fReference
);
62 fContent
= new TmfEventContent(fEvent
, "Some content");
64 fField0
= new TmfEventField(fContent
, fFieldId
, fValue1
);
65 fField1
= new TmfEventField(fContent
, fFieldId
, fValue1
);
66 fField2
= new TmfEventField(fContent
, fFieldId
, fValue1
);
67 fField3
= new TmfEventField(fContent
, fFieldId
, fValue2
);
71 protected void setUp() throws Exception
{
76 protected void tearDown() throws Exception
{
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
84 public void testTmfEventField() {
85 assertSame("getParent", fContent
, fField0
.getParent());
86 assertSame("getId", fFieldId
, fField0
.getId());
87 assertSame("getValue", fValue1
, fField0
.getValue());
90 public void testTmfEventFieldBadArg() {
92 new TmfEventField(fContent
, null, fValue1
);
95 catch (IllegalArgumentException e
) {
100 public void testTmfEventFieldCopy() {
101 TmfEventField original
= new TmfEventField(fContent
, fFieldId
, fValue1
);
102 TmfEventField field
= new TmfEventField(original
);
103 assertSame("getParent", fContent
, field
.getParent());
104 assertSame("getId", fFieldId
, field
.getId());
105 assertSame("getValue", fValue1
, field
.getValue());
108 public void testTmfEventFieldCopy2() {
110 new TmfEventField(null);
113 catch (IllegalArgumentException e
) {
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
122 private class MyField
extends TmfEventField
{
123 public MyField(TmfEventContent parent
, String id
, Object value
) {
124 super(parent
, id
, value
);
126 public MyField(TmfEventField field
) {
130 public void setValue(Object value
) {
131 super.setValue(value
);
135 public void testSetValue() {
136 TmfEventField original
= new TmfEventField(fContent
, fFieldId
, fValue1
);
137 TmfEventField field
= new TmfEventField(original
);
139 MyField myField
= new MyField(field
);
140 assertSame("getValue", fValue1
, myField
.getValue());
142 myField
.setValue(fValue2
);
143 assertSame("getValue", fValue2
, myField
.getValue());
146 // ------------------------------------------------------------------------
148 // ------------------------------------------------------------------------
150 public void testEqualsReflexivity() throws Exception
{
151 assertTrue("equals", fField0
.equals(fField0
));
152 assertTrue("equals", fField3
.equals(fField3
));
154 assertTrue("equals", !fField0
.equals(fField3
));
155 assertTrue("equals", !fField3
.equals(fField0
));
158 public void testEqualsSymmetry() throws Exception
{
159 assertTrue("equals", fField0
.equals(fField1
));
160 assertTrue("equals", fField1
.equals(fField0
));
162 assertTrue("equals", !fField0
.equals(fField3
));
163 assertTrue("equals", !fField3
.equals(fField0
));
166 public void testEqualsTransivity() throws Exception
{
167 assertTrue("equals", fField0
.equals(fField1
));
168 assertTrue("equals", fField1
.equals(fField2
));
169 assertTrue("equals", fField0
.equals(fField2
));
172 public void testEqualsConsistency() throws Exception
{
173 assertTrue("equals", fField0
.equals(fField0
));
174 assertTrue("equals", fField0
.equals(fField0
));
176 assertTrue("equals", fField3
.equals(fField3
));
177 assertTrue("equals", fField3
.equals(fField3
));
180 public void testEqualsNull() throws Exception
{
181 assertTrue("equals", !fField0
.equals(null));
182 assertTrue("equals", !fField3
.equals(null));
185 // ------------------------------------------------------------------------
187 // ------------------------------------------------------------------------
189 public void testToString() {
190 String expected1
= "[TmfEventField(" + fFieldId
+ ":" + fValue1
.toString() + ")]";
191 TmfEventField field
= new TmfEventField(fContent
, fFieldId
, fValue1
);
192 assertEquals("toString", expected1
, field
.toString());
194 String expected2
= "[TmfEventField(" + fFieldId
+ ":" + fValue2
.toString() + ")]";
195 field
= new TmfEventField(fContent
, fFieldId
, fValue2
);
196 assertEquals("toString", expected2
, field
.toString());