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.converter.internal;
16:
17: import java.lang.reflect.Method;
18:
19: import org.strecks.converter.Converter;
20: import org.strecks.converter.DatePatternConverter;
21: import org.strecks.converter.internal.impl.BeanWithReorderedConverters;
22: import org.strecks.converter.internal.impl.BeanWithTwoConverters;
23: import org.strecks.converter.internal.impl.FormWithDateConverter;
24: import org.strecks.exceptions.ApplicationConfigurationException;
25: import org.testng.Assert;
26: import org.testng.annotations.Test;
27:
28: /**
29: * @author Phil Zoio
30: */
31: public class TestConverterReader {
32:
33: @Test
34: public void testConverterReader() throws Exception {
35: Class c = FormWithDateConverter.class;
36: Method method = c.getMethod("getStartDate");
37:
38: ConverterReader converterReader = new ConverterReader();
39: Converter converter = converterReader.readConverter(method);
40:
41: assert converter instanceof DatePatternConverter;
42: }
43:
44: @Test
45: public void testReorderedConverter() throws Exception {
46: Class c = BeanWithReorderedConverters.class;
47: Method method = c.getMethod("getDate");
48:
49: ConverterReader converterReader = new ConverterReader();
50: Converter converter = converterReader.readConverter(method);
51:
52: assert converter instanceof DatePatternConverter;
53: }
54:
55: @Test
56: public void testDuplicatedConverterReader() throws Exception {
57:
58: try {
59:
60: Class c = BeanWithTwoConverters.class;
61: Method method = c.getMethod("getDate");
62:
63: ConverterReader converterReader = new ConverterReader();
64: converterReader.readConverter(method);
65:
66: } catch (ApplicationConfigurationException e) {
67: Assert
68: .assertEquals(
69: e.getMessage(),
70: "Only one converter annotation may be placed in method getDate() "
71: + "in class org.strecks.converter.internal.impl.BeanWithTwoConverters");
72: }
73: }
74: }
|