1 21 22 package net.sourceforge.cobertura.coveragedata; 23 24 import junit.framework.TestCase; 25 26 public class LineDataTest extends TestCase 27 { 28 29 private final LineData a = new LineData(10, "test1", "(I)B"); 30 private final LineData b = new LineData(11, "test1", "(I)B"); 31 private final LineData c = new LineData(12, "test2", "(I)B"); 32 private final LineData d = new LineData(13, "test2", "(I)B"); 33 private final LineData e = new LineData(14); 34 private final LineData f = new LineData(15); 35 36 public void testEquals() 37 { 38 assertFalse(a.equals(null)); 39 assertFalse(a.equals(new Integer (4))); 40 41 assertTrue(a.equals(a)); 42 assertFalse(a.equals(b)); 43 assertFalse(a.equals(c)); 44 assertFalse(a.equals(d)); 45 assertFalse(a.equals(e)); 46 assertFalse(a.equals(f)); 47 48 LineData aPrime = new LineData(10, "test1", "(I)B"); 49 assertTrue(a.equals(aPrime)); 50 } 51 52 public void testHashCode() 53 { 54 assertEquals(a.hashCode(), a.hashCode()); 55 56 LineData aPrime = new LineData(10, "test1", "(I)B"); 57 assertEquals(a.hashCode(), aPrime.hashCode()); 58 } 59 60 public void testGetLineNumber() 61 { 62 assertEquals(10, a.getLineNumber()); 63 assertEquals(11, b.getLineNumber()); 64 assertEquals(12, c.getLineNumber()); 65 assertEquals(13, d.getLineNumber()); 66 assertEquals(14, e.getLineNumber()); 67 assertEquals(15, f.getLineNumber()); 68 } 69 70 public void testGetNumbers() 71 { 72 assertEquals(1, a.getBranchCoverageRate(), 0); 73 assertEquals(0, a.getLineCoverageRate(), 0); 74 assertEquals(0, a.getNumberOfCoveredBranches()); 75 assertEquals(0, a.getNumberOfCoveredLines()); 76 assertEquals(0, a.getNumberOfValidBranches()); 77 assertEquals(1, a.getNumberOfValidLines()); 78 79 a.setBranch(true); 80 assertEquals(0, a.getBranchCoverageRate(), 0); 81 assertEquals(0, a.getLineCoverageRate(), 0); 82 assertEquals(0, a.getNumberOfCoveredBranches()); 83 assertEquals(0, a.getNumberOfCoveredLines()); 84 assertEquals(1, a.getNumberOfValidBranches()); 85 assertEquals(1, a.getNumberOfValidLines()); 86 87 for (int i = 0; i < 5; i++) 88 { 89 a.touch(); 90 assertEquals(1, a.getBranchCoverageRate(), 0); 91 assertEquals(1, a.getLineCoverageRate(), 0); 92 assertEquals(1, a.getNumberOfCoveredBranches()); 93 assertEquals(1, a.getNumberOfCoveredLines()); 94 assertEquals(1, a.getNumberOfValidBranches()); 95 assertEquals(1, a.getNumberOfValidLines()); 96 } 97 98 a.setBranch(false); 99 assertEquals(1, a.getBranchCoverageRate(), 0); 100 assertEquals(1, a.getLineCoverageRate(), 0); 101 assertEquals(0, a.getNumberOfCoveredBranches()); 102 assertEquals(1, a.getNumberOfCoveredLines()); 103 assertEquals(0, a.getNumberOfValidBranches()); 104 assertEquals(1, a.getNumberOfValidLines()); 105 } 106 107 public void testSetConditional() 108 { 109 assertFalse(c.isBranch()); 110 c.setBranch(true); 111 assertTrue(c.isBranch()); 112 c.setBranch(false); 113 assertFalse(c.isBranch()); 114 } 115 116 public void testSetMethodNameAndDescriptor() 117 { 118 e.setMethodNameAndDescriptor("test3", "(I)B"); 119 assertEquals("test3", e.getMethodName()); 120 assertEquals("(I)B", e.getMethodDescriptor()); 121 122 f.setMethodNameAndDescriptor("test4", "(I)B"); 123 assertEquals("test4", f.getMethodName()); 124 assertEquals("(I)B", f.getMethodDescriptor()); 125 } 126 127 public void testTouch() 128 { 129 assertEquals(0, a.getHits()); 130 for (int i = 0; i < 400; i++) 131 a.touch(); 132 assertEquals(400, a.getHits()); 133 } 134 135 } 136 | Popular Tags |