package edu.hawaii.ics415.problem3.fieldcheck;

import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

/**
 * Provides the test case for the Account class.
 *
 * @author   Takuya Yamashita
 */
public class TestAccount extends TestCase {

  /**
   * Provides the account object to be tested.
   */
  Account account;

  /**
   * Required for JUnit.
   *
   * @param name  The name of the test.
   */
  public TestAccount(String name) {
    super(name);
  }


  /**
   * Tests the account with all the legal parameters
   */
  public void testLegalParameters() {
    try {
      account = new Account("Takuya", "Yamashita", "1973-07-23", "999-99-9999");
    }
    catch (AccountException e) {
      fail("Generates incorrect exception. " + e.getMessage());
    }
  }

  /**
   * Tests the account with all the valid parameter except the firstName
   */
  public void testIllgelFirstName() {
    try {
      account = new Account("Takuya!", "Yamashita", "1973-07-23", "999-99-9999");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the valid parameter except the lastName
   */
  public void testIllgelLastName() {
    try {
      account = new Account("Takuya", "Yamashita@", "1973-07-23", "999-99-9999");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the valid parameter except the illegal format of
   * the dob
   */
  public void testDateOfBirthWithIllegalFormat() {
    try {
      account = new Account("Takuya", "Yamashita", "1973-7-23", "999-99-9999");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the valid parameter except the illegal year in
   * the dob
   */
  public void testDateOfBirthWithIllegalYear() {
    try {
      account = new Account("Takuya", "Yamashita", "3000-07-23", "999-99-9999");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the valid parameter except the illegal month in
   * the dob
   */
  public void testDateOfBirthWithIllegalMonth() {
    try {
      account = new Account("Takuya", "Yamashita", "1973-13-23", "999-99-9999");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the valid parameter except the illegal day in
   * the dob
   */
  public void testDateOfBirthWithIllegalDay() {
    try {
      account = new Account("Takuya", "Yamashita", "1973-07-32", "999-99-9999");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the valid parameter except the illegal character
   * in the dob
   */
  public void testDateOfBirthWithCharacter() {
    try {
      account = new Account("Takuya", "Yamashita", "1973-MM-32", "999-99-9999");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the valid parameter except the illegal format in
   * the ssn
   */
  public void testSsnWithIllegalFormat() {
    try {
      account = new Account("Takuya", "Yamashita", "1973-07-23", "999-999999");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the valid parameter except the illegal char in
   * the ssn
   */
  public void testSsnWithCharacter() {
    try {
      account = new Account("Takuya", "Yamashita", "1973-07-23", "999-99-test");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Tests the account with all the illegal fields
   */
  public void testIllegalAllField() {
    try {
      account = new Account("Takuya@", "Yamashita!", "1973-7-23", "999-99-test");
      fail("Fails to generate exception. ");
    }
    catch (AccountException e) {

    }
  }

  /**
   * Tests the account with all the valid parameter except the illegal future
   * date in the dob
   */
  public void testDateOfBirthWithFutureDate() {
    try {
      account = new Account("Takuya", "Yamashita", "2003-05-13", "999-99-9999");
      fail("Fails to generate exception");
    }
    catch (AccountException e) {
    }
  }

  /**
   * Allows stand-alone testing of this testcase from the command line or from
   * within an IDE.
   *
   * @param args  Args are ignored.
   */
  public static void main(String[] args) {
    System.out.println("JUnit testing Account.");
    //Runs all no-arg methods starting with "test".
    TestRunner.run(new TestSuite(TestAccount.class));
  }
}