Package test

Source Code of test.TEST

package test;
/**
*
*/

import controller.check.AddressChecker;
import controller.check.EmailChecker;
import controller.check.TelephoneNumberChecker;
import controller.enums.Country;
import controller.enums.EmailContact;
import controller.enums.PhoneContact;

/**
* @author Mister Creeper
*
*/
public class TEST {

  /**
   * @param args
   */
  public static void main(String[] args) {
    TEST test = new TEST();
    boolean passed = true;
    //check AddressChecker
    try{
      System.out.print("starting AddressChecker test ... ");
      test.checkAddressChecker();
      System.out.println("passed");
    } catch(Exception e){
      System.out.println("failed");
      System.out.println("error: " + e.getMessage());
      passed = false;
    }
    //check TelephoneNumberChecker
    try{
      System.out.print("starting TelephoneNumberChecker test ... ");
      test.checkTelephoneNumberChecker();
      System.out.println("passed");
    } catch(Exception e){
      System.out.println("failed");
      System.out.println("error: " + e.getMessage());
      passed = false;
    }
    //check EmailChecker
    try{
      System.out.print("starting EmailChecker test ... ");
      test.checkEmailChecker();
      System.out.println("passed");
    } catch(Exception e){
      System.out.println("failed");
      System.out.println("error: " + e.getMessage());
      passed = false;
    }
    if (!passed){
      System.out.println("\ntest failed");
      return;
    }
    System.out.println("\ntest passed");
    return;
  }
 
  private void checkAddressChecker() throws Exception{
    //pass configuration
    String road = "Gartenstra�e";
    String houseNumber = "12A";
    String location = "Leverkusen";
    String postalNumber = "79348";
    Country ccountry = Country.GERMANY;
    String scountry = null;
    if (new AddressChecker(road, houseNumber, location, postalNumber, ccountry).check() != true ||
        new AddressChecker(road, houseNumber, location, postalNumber, scountry).check() != true){
      throw new Exception("valid Address configuration declared invalid");
    }
    ccountry = null;
    scountry = "Deutschland";
    if (new AddressChecker(road, houseNumber, location, postalNumber, ccountry).check() != true ||
        new AddressChecker(road, houseNumber, location, postalNumber, scountry).check() != true){
      throw new Exception("valid Address configuration declared invalid");
    }
    //invalid postalNumber
    postalNumber = "1234";
    if (new AddressChecker(road, houseNumber, location, postalNumber, ccountry).check() != false ||
        new AddressChecker(road, houseNumber, location, postalNumber, scountry).check() != false){
      throw new Exception("invalid postalNumber declared valid");
    }
    postalNumber = "ABCDE";
    if (new AddressChecker(road, houseNumber, location, postalNumber, ccountry).check() != false ||
        new AddressChecker(road, houseNumber, location, postalNumber, scountry).check() != false){
      throw new Exception("invalid postalNumber declared valid");
    }
    //wrong combination of road and housenumber
    postalNumber = null;
    road = null;
    if (new AddressChecker(road, houseNumber, location, postalNumber, ccountry).check() != false ||
        new AddressChecker(road, houseNumber, location, postalNumber, scountry).check() != false){
      throw new Exception("invalid combination of road and houseNumber declared valid");
    }
    //invalid country name
    houseNumber = null;
    scountry = "12324";
    if (new AddressChecker(road, houseNumber, location, postalNumber, ccountry).check() != true ||
        new AddressChecker(road, houseNumber, location, postalNumber, scountry).check() != false){
      throw new Exception("invalid countryName declared valid");
    }
  }
 
  private void checkTelephoneNumberChecker() throws Exception{
    //shortest valid combination
    String countryCode = null;
    Country country = null;
    String areaCode = "07645";
    String number = "913635";
    String directAccess = null;
    PhoneContact contactType = null;
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != true
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != true){
      throw new Exception("shortest valid combination declared invalid");
    }
    //valid combination
    countryCode = "+49";
    directAccess = "123";
    contactType = PhoneContact.NO_CONTACT;
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != true
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != true){
      throw new Exception("valid combination declared invalid");
    }
    countryCode = null;
    country = Country.GERMANY;
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != true
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != true){
      throw new Exception("valid combination declared invalid");
    }
    //invalid because areaCode is missing
    areaCode = null;
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid combination declared valid");
    }
    //invalid because number is missing
    areaCode = "07654";
    number = "";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid combination declared valid");
    }
    //invalid type of coutryCode
    number = "123";
    countryCode = "12";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != true){
      throw new Exception("invalid countryCode declared valid");
    }
    countryCode = "+1";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != true){
      throw new Exception("invalid countryCode declared valid");
    }
    //invalid type of postalNumber
    countryCode = "+49";
    areaCode = "1234";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid areaCode declared valid (not beginning with '0')");
    }
    areaCode = "ABCDE";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid areaCode declared valid (not a number)");
    }
    areaCode = "012";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid areaCode declared valid (too short)");
    }
    //invalid number
    areaCode = "07645";
    number = "1";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid number declared valid (too short)");
    }
    number = "123456789012345";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid number declared valid (too long)");
    }
    number = "ABCDE";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid number declared valid (not a number)");
    }
    //invalid directAccess
    number = "1234";
    directAccess = "123456789012345";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid number directAccess valid (too long)");
    }
    directAccess = "ABCDE";
    if (new TelephoneNumberChecker(countryCode, areaCode, number, directAccess, contactType).check() != false
        || new TelephoneNumberChecker(country, areaCode, number, directAccess, contactType).check() != false){
      throw new Exception("invalid directAccess declared valid (not a number)");
    }
  }
 
  private void checkEmailChecker() throws Exception{
    //valid configuration
    String emailAddress = "patrick.jeschall@t-online.de";
    EmailContact contactType = EmailContact.NO_CONTACT;
    if (new EmailChecker(emailAddress, contactType).check() != true){
      throw new Exception("valid configuration declared invalid");
    }
    //valid -> shortest emailAddress
    emailAddress = "a@b.c";
    if (new EmailChecker(emailAddress, contactType).check() != true){
      throw new Exception("valid configuration declared invalid");
    }
    //invalid because '@' is missing
    emailAddress = "patrick.jeschallt-online.de";
    if (new EmailChecker(emailAddress, contactType).check() != false){
      throw new Exception("invalid emailAddress declared valid (missing '@')");
    }
    //invalid because no domain is found
    emailAddress = "patrick.jeschall@t-onlinede";
    if (new EmailChecker(emailAddress, contactType).check() != false){
      throw new Exception("invalid emailAddress declared valid (missing domain)");
    }
    //invalid because no address before '@'
    emailAddress = "@t-online.de";
    if (new EmailChecker(emailAddress, contactType).check() != false){
      throw new Exception("invalid emailAddress declared valid (missing address in front of '@')");
    }
    //invalid because no provider found
    emailAddress = "patrick.jeschall@.de";
    if (new EmailChecker(emailAddress, contactType).check() != false){
      throw new Exception("invalid emailAddress declared valid (missing provider)");
    }
    //invalid too short
    emailAddress = "@.";
    if (new EmailChecker(emailAddress, contactType).check() != false){
      throw new Exception("invalid emailAddress declared valid (too short)");
    }
  }
}
TOP

Related Classes of test.TEST

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.