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 java.util.ArrayList;
18: import java.util.Collections;
19: import java.util.List;
20:
21: import org.strecks.validator.IntegerValidator;
22: import org.strecks.validator.message.DefaultMessageParameterProvider;
23: import org.testng.annotations.Test;
24:
25: /**
26: * @author Phil Zoio
27: */
28: public class TestSortableValidator {
29:
30: @Test
31: public void test() {
32: List<SortableValidator> list = new ArrayList<SortableValidator>();
33:
34: SortableValidator v1 = getSortableValidator(Integer.class);
35: SortableValidator v2 = getSortableValidator(Number.class);
36: SortableValidator v3 = getSortableValidator(Object.class);
37:
38: list.add(v1);
39: list.add(v2);
40: list.add(v3);
41:
42: Collections.sort(list);
43: assert v1 == list.iterator().next();
44:
45: list.clear();
46:
47: list.add(v3);
48: list.add(v2);
49: list.add(v1);
50:
51: Collections.sort(list);
52: assert v1 == list.iterator().next();
53: }
54:
55: private SortableValidator getSortableValidator(Class<?> type) {
56: DefaultMessageParameterProvider provider = new DefaultMessageParameterProvider();
57: ValidatorWrapper wrapper = new ValidatorWrapper("key1", 20,
58: Collections.emptyList(), new IntegerValidator(), this
59: .getClass().getMethods()[0], provider, true,
60: type);
61: ValidatorWrapper wrapper1 = wrapper;
62: SortableValidator v = new SortableValidator(wrapper1);
63: return v;
64: }
65:
66: }
|