Developer's Daily Java Education - Test Projects
  front page | java | perl | unix | DevDirectory
   
Front Page
Java
Education
   
 


package PACKAGE_NAME;

//
//  need to add "junit.ui.TestRunner" to
//  Project | Project Properties | Run ... VM Parameters for JBuilder
//

import junit.framework.*;
import NEEDED_IMPORTS;

public class YOUR_TEST_CLASS_HERE extends TestCase
{

  /**
   * Set up work to be done before each test.
   */
  protected void setUp()
  {
    //sum   = 0.0;
    //price = 0.0;
  }

  /**
   * Cleanup work to do after each test.
   */
  protected void tearDown()
  {
  }


  //---------------------------------------------------------------------------------------------//

  public void testBlank()
  {
    String address = "";
    boolean expectedResult = false;
    boolean actualResult = EmailAddressValidator.isValidEmailAddress(address);
    assert( "\ntestBlank, EXPECTED: " + expectedResult + ", GOT: " + actualResult,
            (expectedResult==actualResult) );
  }

  //---------------------------------------------------------------------------------------------//

  public void testNull()
  {
    String address = null;
    boolean expectedResult = false;
    boolean actualResult = EmailAddressValidator.isValidEmailAddress(address);
    assert( "\ntestBlank, EXPECTED: " + expectedResult + ", GOT: " + actualResult,
            (expectedResult==actualResult) );
  }

  //---------------------------------------------------------------------------------------------//

  public void testAtSymbols()
  {
    assert( "\ntestAtSymbols1", !EmailAddressValidator.isValidEmailAddress("@") );
    assert( "\ntestAtSymbols2", !EmailAddressValidator.isValidEmailAddress("@devdaily") );
    assert( "\ntestAtSymbols3", !EmailAddressValidator.isValidEmailAddress("@devdaily.com") );
  }

  //---------------------------------------------------------------------------------------------//

  public void testSingleName()
  {
    assert( "\ntestSingleName1", !EmailAddressValidator.isValidEmailAddress("al") );
    assert( "\ntestSingleName2", !EmailAddressValidator.isValidEmailAddress("frankenstein") );
  }

  //---------------------------------------------------------------------------------------------//

  public static void main(String args[])
  {
    junit.textui.TestRunner.run(YOUR_TEST_CLASS_HERE.class);
  }

  public YOUR_TEST_CLASS_HERE(String name)
  {
    super(name);
  }

  /**
   * add one line here for each test in the suite
   */
  public static Test suite()
  {
    TestSuite suite = new TestSuite();

    // run tests manually
    //suite.addTest( new YOUR_TEST_CLASS_HERE("testBlank") );
    //suite.addTest( new YOUR_TEST_CLASS_HERE("testNull") );
    //suite.addTest( new YOUR_TEST_CLASS_HERE("testAtSymbols") );
    //return suite;

    // or, run tests dynamically
    return new TestSuite(YOUR_TEST_CLASS_HERE.class);
  }

}
Copyright © 1998-2003 DevDaily Interactive, Inc.
All Rights Reserved.