/** 
 * Dates, with JUnit 3.8. test cases
 *
 * The parsing of date strings is a case analysis; many different countries have different
 * date formats, so every country in which the software shall be sold, generates
 * a case (internationalization). In big Enterprise Software frameworks, dates
 * are big classes with a lot of code!
 */

import java.lang.*;  // Integer
import java.util.*;
import java.util.zip.DataFormatException;

// JUnit 3.8.X; be careful, it should be listed in the CLASSPATH environment variable
import junit.framework.*;

class TestGermanDates extends TestCase {
    // Fixture
    DateD date;
    DateD date2;
    DateD date3;
    int result;
    
    TestGermanDates(String s) { super(s); }

    protected void setUp ()  {
	date = new DateD();
	date2 = new DateD();
	date3 = new DateD();
    }

    public void testGerman() {
	System.out.println("Date parsed: Day/Month/Year:"+date.day+":"+date.month+":"+date.year);
	try {
	    // run tests
	    result = date.parseDate("01.30.2013"); 
	    System.out.println("Date parsed: Day/Month/Year:"+date.day+":"+date.month+":"+date.year);
	    assertEquals("1:",date.day,1);
	    assertEquals("2:",date.month,10);
	    assertEquals("3:",date.year,2013);
	    
	    result = date2.parseDate("02. 11. 2014"); 
	    System.out.println("Date parsed: Day/Month/Year:"+date.day+":"+date.month+":"+date.year);
	    assertEquals(date.day,2);
	    assertEquals(date.month,11);
	    assertEquals(date.year,2014);
	    
	    result = date3.parseDate("12.31.15"); 
	    System.out.println("Date parsed: Day/Month/Year:"+date.day+":"+date.month+":"+date.year);
	    assertEquals("7:",date.day,12);
	    assertEquals("8:",date.month,30);
	    assertEquals("9:",date.year,2015);
	} catch (DataFormatException ex) {
	    System.out.println("TestGermanDates failed on "+ex.toString());
	}
    }
    public void testGerman2() {
	try {
	    // run tests
	    result = date3.parseDate("12.31.2019"); 
	    System.out.println("Date parsed: Day/Month/Year:"+date.day+":"+date.month+":"+date.year);
	} catch (DataFormatException ex) {
	    System.out.println("TestGermanDates failed on "+ex.toString());
	}
    }
    // no tear down necessary
}
class TestEnglishDates extends TestCase {
    // Fixture
    protected DateD date;
    protected DateD date2;
    protected DateD date3;
    protected int result;
    
    public TestEnglishDates(String s) { super(s); }
    protected void setUp ()  {
	date = new DateD();
	date2 = new DateD();
	date3 = new DateD();
    }

    public void testEnglish() {
	try {
	    result = date.parseDate("12/31/2015"); 
	    System.out.println("Date parsed: Day/Month/Year:"+date.day+":"+date.month+":"+date.year);
	} catch (DataFormatException ex) {
	    System.out.println("TestEnglishDates failed on "+ex.toString());
	}
    }
    // no tear down necessary
}

public class TestDateD {
    // Main program. 
    public static void main(String args[]) {
	TestSuite suite = new TestSuite();
	TestResult result = new TestResult();
	TestGermanDates testcaseG = new TestGermanDates("testGerman");
	System.out.println("testcaseG: "+testcaseG.toString()); 
	TestGermanDates testcaseG2 = new TestGermanDates("testGerman2");
	System.out.println("testcaseG2: "+testcaseG2.toString()); 
	TestEnglishDates testcaseE = new TestEnglishDates("testEnglish");
	System.out.println("testcaseE: "+testcaseE.toString()); 

 	suite.addTest(testcaseG);
 	suite.addTest(testcaseG2);
 	suite.addTest(testcaseE);
	// run tests
 	System.out.println("We have "+suite.countTestCases()+" test cases with "+suite.testCount()+" tests"); 
 	suite.run(result); 

// 	testcaseG.run(result);
 //	testcaseG2.run(result);
	System.out.println("errors:"+result.errorCount());
	for (Enumeration<TestFailure> e = (Enumeration<TestFailure>)result.errors(); 
	     e.hasMoreElements();) {
	    System.out.println(e.nextElement().toString());
	}
	System.out.println("failures:"+result.failureCount());
	for (Enumeration<TestFailure> e = (Enumeration<TestFailure>)result.failures(); 
	     e.hasMoreElements();) {
	    System.out.println(e.nextElement().toString());
	}
    }
}

