1 package org.apache.torque.om; 2 3 21 22 import java.util.Arrays ; 23 24 import junit.framework.Assert; 25 import junit.framework.TestCase; 26 27 33 public class NumberKeyTest extends TestCase 34 { 35 36 37 private NumberKey n1a = new NumberKey(1); 38 39 private NumberKey n1b = new NumberKey(1); 40 41 private NumberKey n1c = new NumberKey(1); 42 43 private NumberKey n2a = new NumberKey(2); 44 45 50 public NumberKeyTest(String name) 51 { 52 super(name); 53 } 54 55 58 public void testReflexive() 59 { 60 Assert.assertTrue(n1a.equals(n1a)); 61 } 62 63 66 public void testSymmetric() 67 { 68 Assert.assertTrue(n1a.equals(n1b)); 69 Assert.assertTrue(n1b.equals(n1a)); 70 71 Assert.assertTrue(!"1".equals(n1a)); 72 try 77 { 78 Assert.assertTrue(!n1a.equals("1")); 79 } 80 catch (IllegalArgumentException e) 81 { 82 } 84 Assert.assertTrue(!n1a.equals(new Integer (1))); 85 Assert.assertTrue(!new Integer (1).equals(n1a)); 86 } 87 88 91 public void testTransitive() 92 { 93 Assert.assertTrue(n1a.equals(n1b)); 94 Assert.assertTrue(n1b.equals(n1c)); 95 Assert.assertTrue(n1c.equals(n1a)); 96 } 97 98 101 public void testNull() 102 { 103 Assert.assertTrue(!n1a.equals(null)); 104 } 105 106 109 public void testList() 110 { 111 Object [] array = new Object [] { n1a, n2a, n1b }; 112 Arrays.sort(array); 113 114 Assert.assertEquals(n1a, array[0]); 115 Assert.assertEquals(n1b, array[1]); 116 Assert.assertEquals(n2a, array[2]); 117 } 118 119 122 public void testLongConstructor() 123 { 124 NumberKey key = new NumberKey(9900000000000001L); 125 assertEquals("9900000000000001", key.toString()); 126 } 127 } 128 | Popular Tags |