| 1 |
|
package com.atlassian.xwork.validator.validators; |
| 2 |
|
|
| 3 |
|
import com.opensymphony.xwork.LocaleProvider; |
| 4 |
|
import com.opensymphony.xwork.TextProviderSupport; |
| 5 |
|
import com.opensymphony.xwork.ValidationAwareSupport; |
| 6 |
|
import com.opensymphony.xwork.validator.DelegatingValidatorContext; |
| 7 |
|
import com.opensymphony.xwork.validator.ValidatorContext; |
| 8 |
|
import org.jmock.MockObjectTestCase; |
| 9 |
|
|
| 10 |
|
import java.util.List; |
| 11 |
|
import java.util.Locale; |
| 12 |
|
|
|
|
|
| 95.5% |
Uncovered Elements: 2 (44) |
Complexity: 10 |
Complexity Density: 0.29 |
|
| 13 |
|
public class TestCommaSeparatedEmailValidator extends MockObjectTestCase |
| 14 |
|
{ |
| 15 |
|
private ValidatorContext validatorContext; |
| 16 |
|
private CommaSeparatedEmailValidator validator; |
| 17 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 18 |
7
|
protected void setUp() throws Exception... |
| 19 |
|
{ |
| 20 |
7
|
super.setUp(); |
| 21 |
7
|
LocaleProvider localeProvider = new LocaleProvider() |
| 22 |
|
{ |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 23 |
0
|
public Locale getLocale()... |
| 24 |
|
{ |
| 25 |
0
|
return Locale.getDefault(); |
| 26 |
|
} |
| 27 |
|
}; |
| 28 |
7
|
validatorContext = new DelegatingValidatorContext(new ValidationAwareSupport(), |
| 29 |
|
new TextProviderSupport(getClass(), localeProvider), localeProvider); |
| 30 |
7
|
validator = new CommaSeparatedEmailValidator(); |
| 31 |
7
|
validator.setValidatorContext(validatorContext); |
| 32 |
7
|
validator.setFieldName("email"); |
| 33 |
7
|
validator.setDefaultMessage("invalid"); |
| 34 |
|
} |
| 35 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 36 |
3
|
protected static void assertSingletonList(Object expected, List actual)... |
| 37 |
|
{ |
| 38 |
3
|
assertEquals("List has more than one item: " + actual.toString(), 1, actual.size()); |
| 39 |
3
|
assertEquals(expected, actual.get(0)); |
| 40 |
|
} |
| 41 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 42 |
1
|
public void testSingleEmailIsValid() throws Exception... |
| 43 |
|
{ |
| 44 |
1
|
validator.validate(new EmailBean("admin@example.org")); |
| 45 |
1
|
assertFalse(validatorContext.hasActionErrors()); |
| 46 |
1
|
assertFalse(validatorContext.hasFieldErrors()); |
| 47 |
|
} |
| 48 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 49 |
1
|
public void testNonEmailIsInvalid() throws Exception... |
| 50 |
|
{ |
| 51 |
1
|
validator.validate(new EmailBean("notanemail")); |
| 52 |
1
|
assertFalse(validatorContext.hasActionErrors()); |
| 53 |
1
|
assertTrue(validatorContext.hasFieldErrors()); |
| 54 |
1
|
assertSingletonList("invalid", (List) validatorContext.getFieldErrors().get("email")); |
| 55 |
|
} |
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 57 |
1
|
public void testMultipleNonEmailIsInvalid() throws Exception... |
| 58 |
|
{ |
| 59 |
1
|
validator.validate(new EmailBean("notanemail, stillnotanemail")); |
| 60 |
1
|
assertFalse(validatorContext.hasActionErrors()); |
| 61 |
1
|
assertTrue(validatorContext.hasFieldErrors()); |
| 62 |
1
|
assertSingletonList("invalid", (List) validatorContext.getFieldErrors().get("email")); |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 65 |
1
|
public void testEmptyStringIsValid() throws Exception... |
| 66 |
|
{ |
| 67 |
1
|
validator.validate(new EmailBean("")); |
| 68 |
1
|
assertFalse(validatorContext.hasActionErrors()); |
| 69 |
1
|
assertFalse(validatorContext.hasFieldErrors()); |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 72 |
1
|
public void testNullIsValid() throws Exception... |
| 73 |
|
{ |
| 74 |
1
|
validator.validate(new EmailBean(null)); |
| 75 |
1
|
assertFalse(validatorContext.hasActionErrors()); |
| 76 |
1
|
assertFalse(validatorContext.hasFieldErrors()); |
| 77 |
|
} |
| 78 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 79 |
1
|
public void testMultipleEmailsAreValid() throws Exception... |
| 80 |
|
{ |
| 81 |
1
|
validator.validate(new EmailBean("admin@example.org, user@example.org")); |
| 82 |
1
|
assertFalse(validatorContext.hasActionErrors()); |
| 83 |
1
|
assertFalse(validatorContext.hasFieldErrors()); |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 86 |
1
|
public void testMultipleMixedAreInvalid() throws Exception... |
| 87 |
|
{ |
| 88 |
1
|
validator.validate(new EmailBean("admin@example.org, notanemail, user@example.org")); |
| 89 |
1
|
assertFalse(validatorContext.hasActionErrors()); |
| 90 |
1
|
assertTrue(validatorContext.hasFieldErrors()); |
| 91 |
1
|
assertSingletonList("invalid", (List) validatorContext.getFieldErrors().get("email")); |
| 92 |
|
} |
| 93 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 94 |
|
private static class EmailBean |
| 95 |
|
{ |
| 96 |
|
private final String email; |
| 97 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 98 |
7
|
private EmailBean(String email)... |
| 99 |
|
{ |
| 100 |
7
|
this.email = email; |
| 101 |
|
} |
| 102 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 103 |
7
|
public String getEmail()... |
| 104 |
|
{ |
| 105 |
7
|
return email; |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
} |