/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.strecks.bind.internal;
import org.strecks.bind.internal.impl.BeanWithIncorrectSetter;
import org.strecks.bind.internal.impl.BeanWithNonStringGetter;
import org.strecks.bind.internal.impl.BeanWithSetterAnnotation;
import org.strecks.bind.internal.impl.BeanWithStringArrayGetter;
import org.strecks.exceptions.ApplicationConfigurationException;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* @author Phil Zoio
*/
public class TestBindableReaderImpl
{
@Test
public void testSetterAnnotation()
{
try
{
BeanWithSetterAnnotation bean = new BeanWithSetterAnnotation();
BindAnnotationReader bindablesReader = new BindAnnotationReader();
bindablesReader.readBindables(bean);
Assert.fail("Should have caught ApplicationConfigurationException");
}
catch (ApplicationConfigurationException e)
{
Assert
.assertEquals(
e.getMessage(),
"Invalid @BindSimple annotation for method "
+ "public void org.strecks.bind.internal.impl.BeanWithSetterAnnotation.setProperty(java.lang.String): "
+ "annotation only supports getter methods of type String");
}
}
@Test
public void testBeanWithIncorrectSetter()
{
try
{
BeanWithIncorrectSetter bean = new BeanWithIncorrectSetter();
BindAnnotationReader bindablesReader = new BindAnnotationReader();
bindablesReader.readBindables(bean);
Assert.fail("Should have caught ApplicationConfigurationException");
}
catch (ApplicationConfigurationException e)
{
Assert
.assertEquals(
e.getMessage(),
"Bind annotation used for public java.lang.String org.strecks.bind.internal.impl.BeanWithIncorrectSetter.getProperty()"
+ " which has no corresponding setter method");
}
}
@Test
public void testNonStringGetter()
{
try
{
BeanWithNonStringGetter bean = new BeanWithNonStringGetter();
BindAnnotationReader bindablesReader = new BindAnnotationReader();
bindablesReader.readBindables(bean);
Assert.fail("Should have caught ApplicationConfigurationException");
}
catch (ApplicationConfigurationException e)
{
Assert
.assertEquals(
e.getMessage(),
"Method public int org.strecks.bind.internal.impl.BeanWithNonStringGetter.getProperty() "
+ "is not type compatible with the type of the converter class org.strecks.converter.SafeBeanUtilsConverter, which is parameterized with the type java.lang.String");
}
}
@Test
public void testWithStringArrayGetter()
{
try
{
BeanWithStringArrayGetter bean = new BeanWithStringArrayGetter();
BindAnnotationReader bindablesReader = new BindAnnotationReader();
bindablesReader.readBindables(bean);
}
catch (ApplicationConfigurationException e)
{
Assert
.assertEquals(
e.getMessage(),
"Method public java.lang.String[] org.strecks.bind.internal.impl.BeanWithStringArrayGetter.getProperty() is not type compatible with the type of the "
+ "converter class org.strecks.converter.SafeBeanUtilsConverter, which is parameterized with the type java.lang.String");
}
}
}