Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 204   Methods: 11
NCLOC: 151   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
GlobalTransactionTest.java - 93.3% 81.8% 92.1%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache;
 8   
 9   
 10    import junit.framework.Test;
 11    import junit.framework.TestCase;
 12    import junit.framework.TestSuite;
 13    import org.jgroups.stack.IpAddress;
 14   
 15    import java.io.ByteArrayInputStream;
 16    import java.io.ByteArrayOutputStream;
 17    import java.io.IOException;
 18    import java.io.ObjectInputStream;
 19    import java.io.ObjectOutputStream;
 20    import java.net.UnknownHostException;
 21   
 22   
 23    /**
 24    * @author <a href="mailto:bela@jboss.org">Bela Ban</a> Apr 14, 2003
 25    * @version $Id: GlobalTransactionTest.java,v 1.8 2006/12/06 13:10:31 msurtani Exp $
 26    */
 27    public class GlobalTransactionTest extends TestCase
 28    {
 29   
 30  7 public GlobalTransactionTest(String name)
 31    {
 32  7 super(name);
 33    }
 34   
 35   
 36  1 public void testEquality() throws UnknownHostException
 37    {
 38  1 IpAddress a1 = new IpAddress("localhost", 4444);
 39  1 GlobalTransaction tx1, tx2;
 40   
 41  1 tx1 = GlobalTransaction.create(a1);
 42  1 tx2 = GlobalTransaction.create(a1);
 43   
 44  1 System.out.println("\ntx1: " + tx1 + "\ntx2: " + tx2);
 45  1 assertTrue(tx1.equals(tx2) == false);
 46   
 47  1 tx2 = tx1;
 48  1 assertTrue(tx1.equals(tx2));
 49   
 50    }
 51   
 52  1 public void testEqualityWithOtherObject() throws UnknownHostException
 53    {
 54  1 IpAddress a1 = new IpAddress("localhost", 4444);
 55  1 GlobalTransaction tx1 = GlobalTransaction.create(a1);
 56  1 System.out.println("\ntx1: " + tx1);
 57  1 assertFalse(tx1.equals(Thread.currentThread()));
 58    }
 59   
 60  1 public void testEqualityWithNull() throws UnknownHostException
 61    {
 62  1 IpAddress a1 = new IpAddress("localhost", 4444);
 63  1 GlobalTransaction tx1 = GlobalTransaction.create(a1);
 64  1 System.out.println("\ntx1: " + tx1);
 65  1 assertFalse(tx1.equals(null));
 66    }
 67   
 68  1 public void testHashcode() throws UnknownHostException
 69    {
 70  1 IpAddress a1 = new IpAddress("localhost", 4444);
 71  1 GlobalTransaction tx1, tx2;
 72   
 73   
 74  1 tx1 = GlobalTransaction.create(a1);
 75  1 tx2 = GlobalTransaction.create(a1);
 76   
 77  1 System.out.println("\ntx1: " + tx1 + "\ntx2: " + tx2);
 78  1 assertTrue(tx1.equals(tx2) == false);
 79   
 80  1 int hcode_1 = tx1.hashCode();
 81  1 int hcode_2 = tx2.hashCode();
 82  1 assertFalse(hcode_1 == hcode_2);
 83   
 84  1 tx2 = tx1;
 85  1 assertTrue(tx1.equals(tx2));
 86  1 hcode_1 = tx1.hashCode();
 87  1 hcode_2 = tx2.hashCode();
 88  1 assertEquals(hcode_1, hcode_2);
 89    }
 90   
 91   
 92  1 public void testExternalization() throws UnknownHostException
 93    {
 94  1 IpAddress a1 = new IpAddress("localhost", 4444);
 95  1 IpAddress a2 = new IpAddress("localhost", 5555);
 96  1 GlobalTransaction tx1, tx2, tx1_copy = null, tx2_copy = null;
 97  1 ByteArrayOutputStream bos = null;
 98  1 ByteArrayInputStream bis = null;
 99  1 ObjectOutputStream out = null;
 100  1 ObjectInputStream in = null;
 101  1 byte[] buf = null;
 102   
 103  1 tx1 = GlobalTransaction.create(a1);
 104  1 tx2 = GlobalTransaction.create(a2);
 105   
 106  1 try
 107    {
 108  1 bos = new ByteArrayOutputStream(1024);
 109  1 out = new ObjectOutputStream(bos);
 110  1 out.writeObject(tx1);
 111  1 out.writeObject(tx2);
 112  1 out.flush();
 113  1 buf = bos.toByteArray();
 114    }
 115    catch (IOException ex)
 116    {
 117  0 fail("creation of output stream");
 118    }
 119   
 120  1 try
 121    {
 122  1 bis = new ByteArrayInputStream(buf);
 123  1 in = new ObjectInputStream(bis);
 124  1 tx1_copy = (GlobalTransaction) in.readObject();
 125  1 tx2_copy = (GlobalTransaction) in.readObject();
 126    }
 127    catch (IOException ex)
 128    {
 129  0 fail("creation of input stream");
 130    }
 131    catch (ClassNotFoundException e)
 132    {
 133  0 e.printStackTrace();
 134  0 fail();
 135    }
 136   
 137  1 System.out.println("\ntx1: " + tx1 + ", tx1_copy: " + tx1_copy +
 138    "\ntx2: " + tx2 + ", tx2_copy: " + tx2_copy);
 139   
 140  1 assertNotNull(tx1_copy);
 141  1 assertNotNull(tx2_copy);
 142  1 assertEquals(tx1, tx1_copy);
 143  1 assertEquals(tx2, tx2_copy);
 144   
 145  1 int hcode_1 = tx1.hashCode();
 146  1 int hcode_2 = tx2.hashCode();
 147  1 int hcode_3 = tx1_copy.hashCode();
 148  1 int hcode_4 = tx2_copy.hashCode();
 149  1 assertFalse(hcode_1 == hcode_2);
 150  1 assertFalse(hcode_3 == hcode_4);
 151  1 assertEquals(hcode_1, hcode_3);
 152  1 assertEquals(hcode_2, hcode_4);
 153    }
 154   
 155   
 156  1 public void testWithNullAddress()
 157    {
 158  1 GlobalTransaction tx1, tx2, tmp_tx1;
 159   
 160  1 tx1 = GlobalTransaction.create(null);
 161  1 tx2 = GlobalTransaction.create(null);
 162   
 163  1 tmp_tx1 = tx1;
 164  1 assertEquals(tx1, tmp_tx1);
 165  1 assertTrue(tx1.equals(tx2) == false);
 166    }
 167   
 168  1 public void testOneNullAddress() throws UnknownHostException
 169    {
 170  1 GlobalTransaction tx1, tx2;
 171  1 tx1 = GlobalTransaction.create(null);
 172   
 173  1 assertFalse(tx1.equals(null));
 174   
 175  1 tx2 = GlobalTransaction.create(null);
 176   
 177  1 assertFalse(tx1.equals(tx2));
 178  1 assertFalse(tx2.equals(tx1));
 179   
 180  1 IpAddress a1 = new IpAddress("localhost", 4444);
 181  1 tx2 = GlobalTransaction.create(a1);
 182   
 183  1 assertFalse(tx1.equals(tx2));
 184  1 assertFalse(tx2.equals(tx1));
 185    }
 186   
 187   
 188  0 void log(String msg)
 189    {
 190  0 System.out.println("-- [" + Thread.currentThread() + "]: " + msg);
 191    }
 192   
 193  1 public static Test suite()
 194    {
 195  1 TestSuite s = new TestSuite(GlobalTransactionTest.class);
 196  1 return s;
 197    }
 198   
 199  0 public static void main(String[] args)
 200    {
 201  0 junit.textui.TestRunner.run(suite());
 202    }
 203   
 204    }