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
.core
.tests
.event
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
21 * <b><u>TmfEventFieldTest</u></b>
23 * Test suite for the TmfEventField class.
25 @SuppressWarnings("nls")
26 public class TmfEventFieldTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 private final String fFieldId
= "Field";
33 private final Object fValue1
= new String("Value");
34 private final Object fValue2
= new Integer(10);
36 private TmfEventField fField0
;
37 private TmfEventField fField1
;
38 private TmfEventField fField2
;
39 private TmfEventField fField3
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * @param name the test name
48 public TmfEventFieldTest(String name
) {
50 fField0
= new TmfEventField(fFieldId
, fValue1
, null);
51 fField1
= new TmfEventField(fFieldId
, fValue1
, null);
52 fField2
= new TmfEventField(fFieldId
, fValue1
, null);
53 fField3
= new TmfEventField(fFieldId
, fValue2
, null);
57 protected void setUp() throws Exception
{
62 protected void tearDown() throws Exception
{
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 public void testTmfEventField() {
71 assertSame("getId", fFieldId
, fField0
.getName());
72 assertSame("getValue", fValue1
, fField0
.getValue());
75 public void testTmfEventFieldBadArg() {
77 new TmfEventField(null, fValue1
, null);
80 catch (IllegalArgumentException e
) {
85 public void testTmfEventFieldCopy() {
86 TmfEventField original
= new TmfEventField(fFieldId
, fValue1
, null);
87 TmfEventField field
= new TmfEventField(original
);
88 assertSame("getId", fFieldId
, field
.getName());
89 assertSame("getValue", fValue1
, field
.getValue());
92 public void testTmfEventFieldCopy2() {
94 new TmfEventField(null);
97 catch (IllegalArgumentException e
) {
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
106 private class MyField
extends TmfEventField
{
107 public MyField(String id
, Object value
) {
110 public MyField(TmfEventField field
) {
114 public void setValue(Object value
, ITmfEventField
[] subfields
) {
115 super.setValue(value
, subfields
);
119 public void testSetValue() {
120 // TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1);
121 TmfEventField original
= new TmfEventField(fFieldId
, fValue1
, null);
122 TmfEventField field
= new TmfEventField(original
);
124 MyField myField
= new MyField(field
);
125 assertSame("getValue", fValue1
, myField
.getValue());
127 myField
.setValue(fValue2
, null);
128 assertSame("getValue", fValue2
, myField
.getValue());
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
135 public void testEqualsReflexivity() throws Exception
{
136 assertTrue("equals", fField0
.equals(fField0
));
137 assertTrue("equals", fField3
.equals(fField3
));
139 assertTrue("equals", !fField0
.equals(fField3
));
140 assertTrue("equals", !fField3
.equals(fField0
));
143 public void testEqualsSymmetry() throws Exception
{
144 assertTrue("equals", fField0
.equals(fField1
));
145 assertTrue("equals", fField1
.equals(fField0
));
147 assertTrue("equals", !fField0
.equals(fField3
));
148 assertTrue("equals", !fField3
.equals(fField0
));
151 public void testEqualsTransivity() throws Exception
{
152 assertTrue("equals", fField0
.equals(fField1
));
153 assertTrue("equals", fField1
.equals(fField2
));
154 assertTrue("equals", fField0
.equals(fField2
));
157 public void testEqualsNull() throws Exception
{
158 assertTrue("equals", !fField0
.equals(null));
159 assertTrue("equals", !fField3
.equals(null));
162 // ------------------------------------------------------------------------
164 // ------------------------------------------------------------------------
166 public void testHashCode() throws Exception
{
167 assertTrue("hashCode", fField0
.hashCode() == fField1
.hashCode());
168 assertTrue("hashCode", fField0
.hashCode() != fField3
.hashCode());
171 // ------------------------------------------------------------------------
173 // ------------------------------------------------------------------------
175 public void testToString() {
176 String expected1
= "TmfEventField [fFieldId=" + fFieldId
+ ", fValue=" + fValue1
.toString() + "]";
177 // TmfEventField field = new TmfEventField(fContent, fFieldId, fValue1);
178 TmfEventField field
= new TmfEventField(fFieldId
, fValue1
, null);
179 assertEquals("toString", expected1
, field
.toString());
181 String expected2
= "TmfEventField [fFieldId=" + fFieldId
+ ", fValue=" + fValue2
.toString() + "]";
182 // field = new TmfEventField(fContent, fFieldId, fValue2);
183 field
= new TmfEventField(fFieldId
, fValue2
, null);
184 assertEquals("toString", expected2
, field
.toString());