| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009 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 | * Francois Chouinard - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.tests.event; |
| 14 | |
| 15 | import junit.framework.TestCase; |
| 16 | |
| 17 | import org.eclipse.linuxtools.tmf.event.TmfEventReference; |
| 18 | |
| 19 | /** |
| 20 | * <b><u>TmfEventReferenceTest</u></b> |
| 21 | * <p> |
| 22 | * Test suite for the TmfEventReference class. |
| 23 | */ |
| 24 | @SuppressWarnings("nls") |
| 25 | public class TmfEventReferenceTest extends TestCase { |
| 26 | |
| 27 | // ------------------------------------------------------------------------ |
| 28 | // Variables |
| 29 | // ------------------------------------------------------------------------ |
| 30 | |
| 31 | private final Object reference0 = new String("Some reference"); |
| 32 | private final Object reference2 = new String("Some other reference"); |
| 33 | |
| 34 | private TmfEventReference fReference0 = new TmfEventReference(reference0); |
| 35 | private TmfEventReference fReference1 = new TmfEventReference(reference0); |
| 36 | private TmfEventReference fReference2 = new TmfEventReference(reference0); |
| 37 | private TmfEventReference fReference3 = new TmfEventReference(reference2); |
| 38 | |
| 39 | // ------------------------------------------------------------------------ |
| 40 | // Housekeeping |
| 41 | // ------------------------------------------------------------------------ |
| 42 | |
| 43 | /** |
| 44 | * @param name the test name |
| 45 | */ |
| 46 | public TmfEventReferenceTest(String name) { |
| 47 | super(name); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | protected void setUp() throws Exception { |
| 52 | super.setUp(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected void tearDown() throws Exception { |
| 57 | super.tearDown(); |
| 58 | } |
| 59 | |
| 60 | // ------------------------------------------------------------------------ |
| 61 | // Constructors |
| 62 | // ------------------------------------------------------------------------ |
| 63 | |
| 64 | public void testTmfEventReferenceDefault() { |
| 65 | TmfEventReference reference = new TmfEventReference(); |
| 66 | assertEquals("getReference", null, reference.getReference()); |
| 67 | } |
| 68 | |
| 69 | public void testTmfEventReference() { |
| 70 | TmfEventReference reference = new TmfEventReference(reference0); |
| 71 | assertSame("getReference", reference0, reference.getReference()); |
| 72 | } |
| 73 | |
| 74 | public void testTmfEventReferenceCopy() { |
| 75 | TmfEventReference original = new TmfEventReference(reference0); |
| 76 | TmfEventReference reference = new TmfEventReference(original); |
| 77 | assertSame("getReference", reference0, reference.getReference()); |
| 78 | } |
| 79 | |
| 80 | public void testTmfEventReferenceCopy2() { |
| 81 | try { |
| 82 | @SuppressWarnings("unused") |
| 83 | TmfEventReference reference = new TmfEventReference(null); |
| 84 | fail("null copy"); |
| 85 | } |
| 86 | catch (IllegalArgumentException e) { |
| 87 | // Success |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // ------------------------------------------------------------------------ |
| 92 | // equals |
| 93 | // ------------------------------------------------------------------------ |
| 94 | |
| 95 | public void testEqualsReflexivity() throws Exception { |
| 96 | assertTrue("equals", fReference0.equals(fReference0)); |
| 97 | assertTrue("equals", fReference3.equals(fReference3)); |
| 98 | |
| 99 | assertTrue("equals", !fReference0.equals(fReference3)); |
| 100 | assertTrue("equals", !fReference3.equals(fReference0)); |
| 101 | } |
| 102 | |
| 103 | public void testEqualsSymmetry() throws Exception { |
| 104 | assertTrue("equals", fReference0.equals(fReference1)); |
| 105 | assertTrue("equals", fReference1.equals(fReference0)); |
| 106 | |
| 107 | assertTrue("equals", !fReference0.equals(fReference3)); |
| 108 | assertTrue("equals", !fReference3.equals(fReference0)); |
| 109 | } |
| 110 | |
| 111 | public void testEqualsTransivity() throws Exception { |
| 112 | assertTrue("equals", fReference0.equals(fReference1)); |
| 113 | assertTrue("equals", fReference1.equals(fReference2)); |
| 114 | assertTrue("equals", fReference0.equals(fReference2)); |
| 115 | } |
| 116 | |
| 117 | public void testEqualsNull() throws Exception { |
| 118 | assertTrue("equals", !fReference0.equals(null)); |
| 119 | assertTrue("equals", !fReference3.equals(null)); |
| 120 | } |
| 121 | |
| 122 | // ------------------------------------------------------------------------ |
| 123 | // hashCode |
| 124 | // ------------------------------------------------------------------------ |
| 125 | |
| 126 | public void testHashCode() throws Exception { |
| 127 | assertTrue("hashCode", fReference0.hashCode() == fReference1.hashCode()); |
| 128 | assertTrue("hashCode", fReference0.hashCode() != fReference3.hashCode()); |
| 129 | } |
| 130 | |
| 131 | public void testHashCode2() throws Exception { |
| 132 | TmfEventReference reference0 = new TmfEventReference(); |
| 133 | assertTrue("hashCode", fReference0.hashCode() != reference0.hashCode()); |
| 134 | assertTrue("hashCode", fReference3.hashCode() != reference0.hashCode()); |
| 135 | } |
| 136 | |
| 137 | // ------------------------------------------------------------------------ |
| 138 | // toString |
| 139 | // ------------------------------------------------------------------------ |
| 140 | |
| 141 | public void testToString() { |
| 142 | String expected1 = "[TmfEventReference(" + "null" + ")]"; |
| 143 | TmfEventReference reference1 = new TmfEventReference(); |
| 144 | assertEquals("toString", expected1, reference1.toString()); |
| 145 | |
| 146 | String expected2 = "[TmfEventReference(" + reference0.toString() + ")]"; |
| 147 | TmfEventReference reference2 = new TmfEventReference(reference0); |
| 148 | assertEquals("toString", expected2, reference2.toString()); |
| 149 | } |
| 150 | |
| 151 | } |