01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. 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 distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.validator.internal;
16:
17: import static org.easymock.classextension.EasyMock.createStrictMock;
18: import static org.testng.Assert.assertEquals;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.strecks.converter.Converter;
24: import org.testng.annotations.BeforeMethod;
25: import org.testng.annotations.Test;
26:
27: /**
28: * @author Phil Zoio
29: */
30: public class TestMethodValidators {
31:
32: private OrderedProperty orderedProperty;
33:
34: private List<ValidatorWrapper> list;
35:
36: private Converter converter;
37:
38: @BeforeMethod
39: public void setUp() throws Exception {
40: orderedProperty = createStrictMock(OrderedProperty.class);
41: ValidatorWrapper typed1 = createStrictMock(ValidatorWrapper.class);
42: ValidatorWrapper typed2 = createStrictMock(ValidatorWrapper.class);
43:
44: list = new ArrayList<ValidatorWrapper>();
45: list.add(typed1);
46: list.add(typed2);
47: converter = createStrictMock(Converter.class);
48: }
49:
50: @Test(expectedExceptions=IllegalArgumentException.class)
51: public void testNullValidators() throws Exception {
52: new MethodValidators(orderedProperty, null, null, false, null);
53:
54: }
55:
56: @Test(expectedExceptions=IllegalArgumentException.class)
57: public void testNullProperty() throws Exception {
58: new MethodValidators(null, list, null, false, null);
59: }
60:
61: @Test(expectedExceptions=IllegalArgumentException.class)
62: public void testConvertingOnly() throws Exception {
63: new MethodValidators(orderedProperty, null, converter, false,
64: null);
65: }
66:
67: @Test
68: public void testTypedOnly() throws Exception {
69: MethodValidators mv = new MethodValidators(orderedProperty,
70: list, null, false, null);
71: assertEquals(mv.getValidators().size(), 2);
72: assert mv.getConverterType() == null;
73: }
74:
75: @Test
76: public void testBoth() throws Exception {
77: MethodValidators mv = new MethodValidators(orderedProperty,
78: list, converter, false, String.class);
79: List<ValidatorWrapper> validators = mv.getValidators();
80: assertEquals(validators.size(), 2);
81: assert (mv.getConverterType().equals(String.class));
82:
83: }
84:
85: }
|