/**
 * Purpose: Tests the PostalApp barcode application.
 *
 * @author Ed Parrish
 * @version 1.1 1/07/09
 */
public class PostalTester {
    private static int numErrors;

    /**
     * The main method begins execution of the tests.
     *
     * @param args not used
     */
    public static void main(final String[] args) {
        testMakeBarcode();
        if (numErrors == 0) {
            System.out.println("*** All tests passed ***");
        }
        System.exit(0);
    }

    /**
     * Convenience method to test for assertions.
     *
     * @param condition The test condition that must be true to pass.
     * @param message The reason for the failure.
     */
    public static void assertTrue(boolean condition, String message) {
        if (!condition) {
            System.out.println("Error: " + message);
            numErrors++;
        }
    }

    /**
     * Test method: getBarcode()
     */
    public static void testMakeBarcode() {
        PostalApp p = new PostalApp();
        String barcode = p.makeBarcode("95003");
        assertTrue(barcode.equals("||,|,,,|,|,||,,,||,,,,,||,,,||,|"),
            "For 95003, wrong value returned by makeBarcode(): " + barcode);
        barcode = p.makeBarcode("00509");
        assertTrue(barcode.equals("|||,,,||,,,,|,|,||,,,|,|,,,||,,|"),
            "For 509, wrong value returned by makeBarcode(): " + barcode);
        barcode = p.makeBarcode("90210");
        assertTrue(barcode.equals("||,|,,||,,,,,|,|,,,||||,,,|,,|,|"),
            "For 90210, wrong value returned by makeBarcode(): " + barcode);
    }
}


