1 4 package com.tc.util.diff; 5 6 import com.tc.test.TCTestCase; 7 8 11 public class PrimitiveDifferenceTest extends TCTestCase { 12 13 public void testConstructionAandBandToString() throws Exception { 14 PrimitiveDifference diff; 15 DifferenceContext ctx = DifferenceContext.createInitial().sub("a").sub("q"); 16 17 diff = new PrimitiveDifference(ctx, true, false); 18 assertEquals(Boolean.TRUE, diff.a()); 19 assertEquals(Boolean.FALSE, diff.b()); 20 assertTrue(diff.toString().indexOf("true") >= 0); 21 assertTrue(diff.toString().indexOf("false") >= 0); 22 23 diff = new PrimitiveDifference(ctx, (byte) 14, (byte) 37); 24 assertEquals(new Byte ((byte) 14), diff.a()); 25 assertEquals(new Byte ((byte) 37), diff.b()); 26 assertTrue(diff.toString().indexOf("14") >= 0); 27 assertTrue(diff.toString().indexOf("37") >= 0); 28 29 diff = new PrimitiveDifference(ctx, 'a', 'q'); 30 assertEquals(new Character ('a'), diff.a()); 31 assertEquals(new Character ('q'), diff.b()); 32 assertTrue(diff.toString().indexOf("a") >= 0); 33 assertTrue(diff.toString().indexOf("q") >= 0); 34 35 diff = new PrimitiveDifference(ctx, (short) 14, (short) 37); 36 assertEquals(new Short ((short) 14), diff.a()); 37 assertEquals(new Short ((short) 37), diff.b()); 38 assertTrue(diff.toString().indexOf("14") >= 0); 39 assertTrue(diff.toString().indexOf("37") >= 0); 40 41 diff = new PrimitiveDifference(ctx, 14, 37); 42 assertEquals(new Integer (14), diff.a()); 43 assertEquals(new Integer (37), diff.b()); 44 assertTrue(diff.toString().indexOf("14") >= 0); 45 assertTrue(diff.toString().indexOf("37") >= 0); 46 47 diff = new PrimitiveDifference(ctx, (long) 14, (long) 37); 48 assertEquals(new Long (14), diff.a()); 49 assertEquals(new Long (37), diff.b()); 50 assertTrue(diff.toString().indexOf("14") >= 0); 51 assertTrue(diff.toString().indexOf("37") >= 0); 52 53 diff = new PrimitiveDifference(ctx, 14.0f, 37.0f); 54 assertEquals(new Float (14.0f), diff.a()); 55 assertEquals(new Float (37.0f), diff.b()); 56 assertTrue(diff.toString().indexOf("14.0") >= 0); 57 assertTrue(diff.toString().indexOf("37.0") >= 0); 58 59 diff = new PrimitiveDifference(ctx, 14.0, 37.0); 60 assertEquals(new Double (14.0), diff.a()); 61 assertEquals(new Double (37.0), diff.b()); 62 assertTrue(diff.toString().indexOf("14.0") >= 0); 63 assertTrue(diff.toString().indexOf("37.0") >= 0); 64 } 65 66 public void testEquals() throws Exception { 67 assertEquals(new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 14, 37), 68 new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 14, 37)); 69 assertFalse(new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 14, 37) 70 .equals(new PrimitiveDifference(DifferenceContext.createInitial().sub("bar"), 14, 37))); 71 assertFalse(new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 14, 37) 72 .equals(new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 15, 37))); 73 assertFalse(new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 14, 37) 74 .equals(new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 14, 38))); 75 assertFalse(new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 14, 37).equals("foo")); 76 assertFalse(new PrimitiveDifference(DifferenceContext.createInitial().sub("foo"), 14, 37).equals(null)); 77 } 78 79 } | Popular Tags |