View Javadoc

1   package org.apache.myfaces.custom.validators;
2   
3   import javax.faces.validator.ValidatorException;
4   
5   import junit.framework.Test;
6   import junit.framework.TestSuite;
7   
8   import org.apache.myfaces.custom.emailvalidator.EmailValidator;
9   
10  public class EmailValidatorTestCase extends AbstractValidatorTestCase
11  {
12  
13    public EmailValidatorTestCase(String arg0) {
14      super(arg0);
15    }
16    
17    EmailValidator emailValidator;
18    
19    protected void setUp() throws Exception
20    {
21      super.setUp();
22      emailValidator = new EmailValidator();    
23    }
24  
25    protected void tearDown() throws Exception
26    {
27      super.tearDown();
28    }
29  
30    public static Test suite()
31    {
32      return new TestSuite(EmailValidatorTestCase.class);
33    }
34  
35    /**
36     * Test when context is set to null
37     */
38    public void testNullContext()
39    {
40  
41      doTestNullContext(component, emailValidator);
42    }
43    
44    public void testWrongEmailAddress()
45    {
46      try
47      {
48        emailValidator.validate(facesContext, component, "matzew@apache");
49        fail("Expected ValidatorException");
50      }
51      catch (ValidatorException ve)
52      {
53        // if exception then fine.
54      }
55  
56    }
57  
58    public void testGoodEmailAddress()
59    {
60        emailValidator.validate(facesContext, component, "foo@apache.org");
61    }
62    
63  }