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.bind.internal;
16:
17: import org.strecks.bind.internal.impl.BeanWithIncorrectSetter;
18: import org.strecks.bind.internal.impl.BeanWithNonStringGetter;
19: import org.strecks.bind.internal.impl.BeanWithSetterAnnotation;
20: import org.strecks.bind.internal.impl.BeanWithStringArrayGetter;
21: import org.strecks.exceptions.ApplicationConfigurationException;
22: import org.testng.Assert;
23: import org.testng.annotations.Test;
24:
25: /**
26: * @author Phil Zoio
27: */
28: public class TestBindableReaderImpl {
29:
30: @Test
31: public void testSetterAnnotation() {
32: try {
33: BeanWithSetterAnnotation bean = new BeanWithSetterAnnotation();
34: BindAnnotationReader bindablesReader = new BindAnnotationReader();
35: bindablesReader.readBindables(bean);
36: Assert
37: .fail("Should have caught ApplicationConfigurationException");
38: } catch (ApplicationConfigurationException e) {
39: Assert
40: .assertEquals(
41: e.getMessage(),
42: "Invalid @BindSimple annotation for method "
43: + "public void org.strecks.bind.internal.impl.BeanWithSetterAnnotation.setProperty(java.lang.String): "
44: + "annotation only supports getter methods of type String");
45: }
46: }
47:
48: @Test
49: public void testBeanWithIncorrectSetter() {
50: try {
51: BeanWithIncorrectSetter bean = new BeanWithIncorrectSetter();
52: BindAnnotationReader bindablesReader = new BindAnnotationReader();
53: bindablesReader.readBindables(bean);
54: Assert
55: .fail("Should have caught ApplicationConfigurationException");
56: } catch (ApplicationConfigurationException e) {
57: Assert
58: .assertEquals(
59: e.getMessage(),
60: "Bind annotation used for public java.lang.String org.strecks.bind.internal.impl.BeanWithIncorrectSetter.getProperty()"
61: + " which has no corresponding setter method");
62: }
63: }
64:
65: @Test
66: public void testNonStringGetter() {
67: try {
68: BeanWithNonStringGetter bean = new BeanWithNonStringGetter();
69: BindAnnotationReader bindablesReader = new BindAnnotationReader();
70: bindablesReader.readBindables(bean);
71: Assert
72: .fail("Should have caught ApplicationConfigurationException");
73: } catch (ApplicationConfigurationException e) {
74: Assert
75: .assertEquals(
76: e.getMessage(),
77: "Method public int org.strecks.bind.internal.impl.BeanWithNonStringGetter.getProperty() "
78: + "is not type compatible with the type of the converter class org.strecks.converter.SafeBeanUtilsConverter, which is parameterized with the type java.lang.String");
79: }
80: }
81:
82: @Test
83: public void testWithStringArrayGetter() {
84: try {
85: BeanWithStringArrayGetter bean = new BeanWithStringArrayGetter();
86: BindAnnotationReader bindablesReader = new BindAnnotationReader();
87: bindablesReader.readBindables(bean);
88: } catch (ApplicationConfigurationException e) {
89: Assert
90: .assertEquals(
91: e.getMessage(),
92: "Method public java.lang.String[] org.strecks.bind.internal.impl.BeanWithStringArrayGetter.getProperty() is not type compatible with the type of the "
93: + "converter class org.strecks.converter.SafeBeanUtilsConverter, which is parameterized with the type java.lang.String");
94: }
95:
96: }
97: }
|