01: /*
02: * Copyright 2004-2006 Fouad HAMDI with the idea
03: * of SameLAN, S.L. Soluciones Tecnológicas.
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.csvbeans.validators;
18:
19: import org.csvbeans.exceptions.ValidationException;
20: import org.jmock.core.Constraint;
21:
22: /**
23: * Tests for the digits validator.
24: *
25: * @author Fouad Hamdi
26: * @since 0.7
27: */
28: public class DigitValidatorTest extends ValidatorTestCase {
29: private DigitValidator validator;
30:
31: protected void setUp() throws Exception {
32: super .setUp();
33: validator = new DigitValidator();
34: }
35:
36: public void testValidation() throws Exception {
37: validator.validate("1232455465456487456156233");
38: try {
39: messageContainer.expects(once()).method("getMessage").with(
40: new Constraint[] { eq("value.digit"),
41: eq("4545645645A545121312") }).will(
42: returnValue("errorMessage"));
43:
44: validator.validate("4545645645A545121312");
45: fail("An exception should have been thrown");
46: } catch (ValidationException e) {
47: assertTrue(true);
48: }
49: validator.validate(null);
50: validator.validate("");
51: }
52:
53: }
|