01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestAbstractValidationRule.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.site;
09:
10: import junit.framework.TestCase;
11:
12: public class TestAbstractValidationRule extends TestCase {
13: private String mValue = null;
14:
15: public TestAbstractValidationRule(String name) {
16: super (name);
17: }
18:
19: public void testInstantiation() {
20: MyRule rule = new MyRule();
21: assertNotNull(rule);
22: }
23:
24: public void testGetSubject() {
25: MyRule rule = new MyRule();
26: String subject = rule.getSubject();
27: assertEquals("the value", subject);
28: assertSame(subject, rule.getSubject());
29: }
30:
31: public void testValid() {
32: MyRule rule = new MyRule();
33: mValue = "ok";
34: assertTrue(rule.validate());
35: }
36:
37: public void testInvalid() {
38: MyRule rule = new MyRule();
39: mValue = null;
40: assertFalse(rule.validate());
41: }
42:
43: public void testGetError() {
44: MyRule rule = new MyRule();
45: ValidationError error = rule.getError();
46: assertEquals(ValidationError.IDENTIFIER_MANDATORY, error
47: .getIdentifier());
48: assertEquals("the value", error.getSubject());
49: assertEquals(rule.getSubject(), error.getSubject());
50: }
51:
52: class MyRule extends AbstractValidationRule {
53: public ValidationError getError() {
54: return new ValidationError.MANDATORY("the value");
55: }
56:
57: public boolean validate() {
58: return mValue != null;
59: }
60: }
61: }
|