01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.validator;
16:
17: import org.apache.tapestry.Field;
18: import org.apache.tapestry.ValidationException;
19: import org.apache.tapestry.internal.test.InternalBaseTestCase;
20: import org.apache.tapestry.ioc.MessageFormatter;
21: import org.testng.annotations.Test;
22:
23: public class MaxTest extends InternalBaseTestCase {
24: @Test
25: public void small_enough() throws Exception {
26: Field field = mockField();
27: MessageFormatter formatter = mockMessageFormatter();
28: Long constraint = 50L;
29:
30: replay();
31:
32: Max validator = new Max();
33:
34: for (int value = 48; value <= 50; value++)
35: validator.validate(field, constraint, formatter, value);
36:
37: verify();
38: }
39:
40: @Test
41: public void value_too_large() throws Exception {
42: String label = "My Field";
43: Field field = mockFieldWithLabel(label);
44: MessageFormatter formatter = mockMessageFormatter();
45: String message = "{message}";
46: Long constraint = 100l;
47: Number value = 101;
48:
49: train_format(formatter, message, constraint, label);
50:
51: replay();
52:
53: Max validator = new Max();
54:
55: try {
56: validator.validate(field, constraint, formatter, value);
57: unreachable();
58: } catch (ValidationException ex) {
59: assertEquals(ex.getMessage(), message);
60: }
61:
62: verify();
63: }
64: }
|