EMMA Coverage Report (generated Sat May 17 10:56:07 GMT 2008)
[all classes][spiffy.junit]

COVERAGE SUMMARY FOR SOURCE FILE [AssertHelper.java]

nameclass, %method, %block, %line, %
AssertHelper.java100% (1/1)90%  (9/10)54%  (177/325)71%  (30/42)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AssertHelper100% (1/1)90%  (9/10)54%  (177/325)71%  (30/42)
AssertHelper (): void 100% (1/1)100% (3/3)100% (1/1)
assertEmpty (String, Collection): void 100% (1/1)23%  (6/26)60%  (3/5)
assertEquals (String, Object [], Object []): void 100% (1/1)75%  (50/67)86%  (6/7)
assertEquals (String, byte [], byte []): void 100% (1/1)75%  (50/67)86%  (6/7)
assertEquals (String, int [], int []): void 100% (1/1)75%  (50/67)86%  (6/7)
assertGreaterThan (String, double, double): void 100% (1/1)25%  (5/20)67%  (2/3)
assertGreaterThan (String, int, int): void 100% (1/1)21%  (4/19)67%  (2/3)
assertNotEquals (String, double, double): void 100% (1/1)25%  (5/20)67%  (2/3)
assertNotEquals (String, int, int): void 100% (1/1)21%  (4/19)67%  (2/3)
assertNotEquals (int, int): void 0%   (0/1)0%   (0/17)0%   (0/3)

1package spiffy.junit;
2 
3import java.util.Collection;
4 
5import junit.framework.Assert;
6 
7/**
8 * This class provides essential assertions missing from JUnit in order to create clear JUnit test cases.
9 * 
10 * @author Kasper B. Graversen
11 */
12public class AssertHelper extends Assert {
13 
14/**
15 * Check if a collection is empty
16 * 
17 * @param collection
18 */
19public static <T> void assertEmpty(final String message, final Collection<T> collection) {
20        if( collection == null ) {
21                fail(message + "[collection is null]");
22        }
23        if( collection.size() != 0 ) {
24                fail("Collection " + collection + " is not empty!");
25        }
26}
27 
28/**
29 * Check if two arrays element for element are equal. If not an AssertionFailedError is thrown. When both argument
30 * arrays are <tt>null</tt>, the method silently returns.
31 */
32public static void assertEquals(final String message, final byte[] expected, final byte[] actual) {
33        if( expected == null && actual == null ) { return; }
34        if( expected == null || actual == null ) {
35                fail(message + " [Expected: " + expected + ", actual " + actual + ']');
36        }
37        assertEquals(message + " [Length]", expected.length, actual.length);
38        for( int i = 0; i < expected.length; i++ ) {
39                assertEquals(message + " [" + i + ']', expected[i], actual[i]);
40        }
41}
42 
43/**
44 * Check if two arrays element for element are equal. If not an AssertionFailedError is thrown. When both argument
45 * arrays are <tt>null</tt>, the method silently returns.
46 */
47public static void assertEquals(final String message, final int[] expected, final int[] actual) {
48        if( expected == null && actual == null ) { return; }
49        if( expected == null || actual == null ) {
50                fail(message + " [Expected: " + expected + ", actual " + actual + ']');
51        }
52        assertEquals(message + " [Length]", expected.length, actual.length);
53        for( int i = 0; i < expected.length; i++ ) {
54                assertEquals(message + " [" + i + ']', expected[i], actual[i]);
55        }
56}
57 
58/**
59 * Check if two arrays element for element are equal. If not an AssertionFailedError is thrown. When both argument
60 * arrays are <tt>null</tt>, the method silently returns.
61 */
62public static void assertEquals(final String message, final Object[] expected, final Object[] actual) {
63        if( expected == null && actual == null ) { return; }
64        if( expected == null || actual == null ) {
65                fail(message + " [Expected: " + expected + ", actual " + actual + ']');
66        }
67        assertEquals(message + " [Length]", expected.length, actual.length);
68        for( int i = 0; i < expected.length; i++ ) {
69                assertEquals(message + " [" + i + ']', expected[i], actual[i]);
70        }
71}
72 
73/**
74 * check that the actual value is greater than the expected
75 */
76public static void assertGreaterThan(final String message, final double expectedGreaterThan, final double actual) {
77        if( expectedGreaterThan >= actual ) {
78                fail(message + ". Actual not greater than expected, " + expectedGreaterThan + " >= " + actual);
79        }
80}
81 
82/**
83 * check that the actual value is greater than the expected
84 */
85public static void assertGreaterThan(final String message, final int expectedGreaterThan, final int actual) {
86        if( expectedGreaterThan >= actual ) {
87                fail(message + ". Actual not greater than expected, " + expectedGreaterThan + " >= " + actual);
88        }
89}
90 
91public static void assertNotEquals(final int expected, final int actual) {
92        if( expected == actual ) {
93                fail("The two values are equal! Expected: " + expected + " actual: " + actual);
94        }
95}
96 
97/**
98 * check that the actual value is not the expected
99 */
100public static void assertNotEquals(final String message, final double expected, final double actual) {
101        if( expected == actual ) {
102                fail(message + ". The two values are equal! Expected: " + expected + " actual: " + actual);
103        }
104}
105 
106/**
107 * check that the actual value is not the expected
108 */
109public static void assertNotEquals(final String message, final int expected, final int actual) {
110        if( expected == actual ) {
111                fail(message + ". The two values are equal! Expected: " + expected + " actual: " + actual);
112        }
113}
114 
115}

[all classes][spiffy.junit]
EMMA 2.0.5312 (C) Vladimir Roubtsov