Changed use of AssertThrows to @Test(expected = ...)
This commit is contained in:
@@ -19,73 +19,68 @@ package org.springframework.jdbc.core.namedparam;
|
|||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
import org.springframework.test.AssertThrows;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class BeanPropertySqlParameterSourceTests extends TestCase {
|
public class BeanPropertySqlParameterSourceTests {
|
||||||
|
|
||||||
public void testWithNullBeanPassedToCtor() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
new AssertThrows(IllegalArgumentException.class) {
|
public void withNullBeanPassedToCtor() throws Exception {
|
||||||
public void test() throws Exception {
|
new BeanPropertySqlParameterSource(null);
|
||||||
new BeanPropertySqlParameterSource(null);
|
|
||||||
}
|
|
||||||
}.runTest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValueWhereTheUnderlyingBeanHasNoSuchProperty() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
new AssertThrows(IllegalArgumentException.class) {
|
public void getValueWhereTheUnderlyingBeanHasNoSuchProperty() throws Exception {
|
||||||
public void test() throws Exception {
|
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean());
|
||||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean());
|
source.getValue("thisPropertyDoesNotExist");
|
||||||
source.getValue("thisPropertyDoesNotExist");
|
|
||||||
}
|
|
||||||
}.runTest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSuccessfulPropertyAccess(){
|
@Test
|
||||||
|
public void successfulPropertyAccess() {
|
||||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
||||||
assertTrue(Arrays.asList(source.getReadablePropertyNames()).contains("name"));
|
assertTrue(Arrays.asList(source.getReadablePropertyNames()).contains("name"));
|
||||||
assertTrue(Arrays.asList(source.getReadablePropertyNames()).contains("age"));
|
assertTrue(Arrays.asList(source.getReadablePropertyNames()).contains("age"));
|
||||||
assertEquals("tb", source.getValue("name"));
|
assertEquals("tb", source.getValue("name"));
|
||||||
assertEquals(new Integer(99), source.getValue("age"));
|
assertEquals(99, source.getValue("age"));
|
||||||
assertEquals(Types.VARCHAR, source.getSqlType("name"));
|
assertEquals(Types.VARCHAR, source.getSqlType("name"));
|
||||||
assertEquals(Types.INTEGER, source.getSqlType("age"));
|
assertEquals(Types.INTEGER, source.getSqlType("age"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSuccessfulPropertyAccessWithOverriddenSqlType(){
|
@Test
|
||||||
|
public void successfulPropertyAccessWithOverriddenSqlType() {
|
||||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
||||||
source.registerSqlType("age", Types.NUMERIC);
|
source.registerSqlType("age", Types.NUMERIC);
|
||||||
assertEquals("tb", source.getValue("name"));
|
assertEquals("tb", source.getValue("name"));
|
||||||
assertEquals(new Integer(99), source.getValue("age"));
|
assertEquals(99, source.getValue("age"));
|
||||||
assertEquals(Types.VARCHAR, source.getSqlType("name"));
|
assertEquals(Types.VARCHAR, source.getSqlType("name"));
|
||||||
assertEquals(Types.NUMERIC, source.getSqlType("age"));
|
assertEquals(Types.NUMERIC, source.getSqlType("age"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasValueWhereTheUnderlyingBeanHasNoSuchProperty() throws Exception {
|
@Test
|
||||||
|
public void hasValueWhereTheUnderlyingBeanHasNoSuchProperty() throws Exception {
|
||||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean());
|
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean());
|
||||||
assertFalse(source.hasValue("thisPropertyDoesNotExist"));
|
assertFalse(source.hasValue("thisPropertyDoesNotExist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetValueWhereTheUnderlyingBeanPropertyIsNotReadable() throws Exception {
|
@Test(expected = IllegalArgumentException.class)
|
||||||
new AssertThrows(IllegalArgumentException.class) {
|
public void getValueWhereTheUnderlyingBeanPropertyIsNotReadable() throws Exception {
|
||||||
public void test() throws Exception {
|
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties());
|
||||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties());
|
source.getValue("noOp");
|
||||||
source.getValue("noOp");
|
|
||||||
}
|
|
||||||
}.runTest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasValueWhereTheUnderlyingBeanPropertyIsNotReadable() throws Exception {
|
@Test
|
||||||
|
public void hasValueWhereTheUnderlyingBeanPropertyIsNotReadable() throws Exception {
|
||||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties());
|
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties());
|
||||||
assertFalse(source.hasValue("noOp"));
|
assertFalse(source.hasValue("noOp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class NoReadableProperties {
|
private static final class NoReadableProperties {
|
||||||
|
|
||||||
public void setNoOp(String noOp) {
|
public void setNoOp(String noOp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user