parameterization of random classes with warnings

This commit is contained in:
robokaso
2008-07-22 15:57:16 +00:00
parent d98015626d
commit f777e62736
4 changed files with 35 additions and 31 deletions

View File

@@ -76,12 +76,12 @@ import org.springframework.validation.ObjectError;
* @author Dave Syer
*
*/
public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar implements FieldSetMapper,
public class BeanWrapperFieldSetMapper<T> extends DefaultPropertyEditorRegistrar implements FieldSetMapper<T>,
BeanFactoryAware, InitializingBean {
private String name;
private Class<?> type;
private Class<? extends T> type;
private BeanFactory beanFactory;
@@ -125,7 +125,7 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im
*
* @param type the type to set
*/
public void setTargetType(Class<?> type) {
public void setTargetType(Class<? extends T> type) {
this.type = type;
}
@@ -156,8 +156,8 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im
* @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapLine(org.springframework.batch.item.file.mapping.FieldSet, int)
*/
@SuppressWarnings("unchecked")
public Object mapLine(FieldSet fs, int lineNum) {
Object copy = getBean();
public T mapLine(FieldSet fs, int lineNum) {
T copy = getBean();
DataBinder binder = createBinder(copy);
binder.bind(new MutablePropertyValues(getBeanProperties(copy, fs.getProperties())));
if (binder.getBindingResult().hasErrors()) {
@@ -204,9 +204,10 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im
protected void initBinder(DataBinder binder) {
}
private Object getBean() {
@SuppressWarnings("unchecked")
private T getBean() {
if (name != null) {
return beanFactory.getBean(name);
return (T) beanFactory.getBean(name);
}
try {
return type.newInstance();

View File

@@ -29,8 +29,9 @@ import org.springframework.util.Assert;
* @author Dave Syer
*
*/
@SuppressWarnings("unchecked")
public class SubclassExceptionClassifier extends ExceptionClassifierSupport {
private Map classified = new HashMap();
/**

View File

@@ -46,6 +46,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
* @author Dave Syer
*
*/
@SuppressWarnings("unchecked")
public class TransactionAwareProxyFactory {
private Object target;

View File

@@ -35,7 +35,7 @@ import org.springframework.context.support.StaticApplicationContext;
public class BeanWrapperFieldSetMapperTests extends TestCase {
public void testNameAndTypeSpecified() throws Exception {
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
mapper.setTargetType(TestObject.class);
mapper.setPrototypeBeanName("foo");
try {
@@ -47,7 +47,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
}
public void testNameNorTypeSpecified() throws Exception {
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
try {
mapper.afterPropertiesSet();
}
@@ -57,20 +57,20 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
}
public void testVanillaBeanCreatedFromType() throws Exception {
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
mapper.setTargetType(TestObject.class);
mapper.afterPropertiesSet();
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet, -1);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
}
public void testMapperWithSingleton() throws Exception {
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", new TestObject());
@@ -78,14 +78,14 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet, -1);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
}
public void testPropertyNameMatching() throws Exception {
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", new TestObject());
@@ -93,20 +93,21 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "VarString", "VAR_BOOLEAN", "VAR_CHAR" });
TestObject result = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet, -1);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
}
@SuppressWarnings("unchecked")
public void testMapperWithPrototype() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("bean-wrapper.xml", getClass());
BeanWrapperFieldSetMapper mapper = (BeanWrapperFieldSetMapper) context.getBean("fieldSetMapper");
BeanWrapperFieldSetMapper<TestObject> mapper = (BeanWrapperFieldSetMapper<TestObject>) context.getBean("fieldSetMapper");
FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "true", "C" },
new String[] { "varString", "varBoolean", "varChar" });
TestObject result = (TestObject) mapper.mapLine(fieldSet, -1);
TestObject result = mapper.mapLine(fieldSet, -1);
assertEquals("This is some dummy string", result.getVarString());
assertEquals(true, result.isVarBoolean());
assertEquals('C', result.getVarChar());
@@ -119,7 +120,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
testNestedA.setTestObjectB(testNestedB);
testNestedB.setTestObjectC(new TestNestedC());
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestNestedA> mapper = new BeanWrapperFieldSetMapper<TestNestedA>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", testNestedA);
@@ -129,7 +130,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
new String[] { "This is some dummy string", "1", "Another dummy", "2" }, new String[] { "valueA",
"valueB", "testObjectB.valueA", "testObjectB.testObjectC.value" });
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet, -1);
TestNestedA result = mapper.mapLine(fieldSet, -1);
assertEquals("This is some dummy string", result.getValueA());
assertEquals(1, result.getValueB());
@@ -140,7 +141,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
public void testMapperWithSimilarNamePropertyMatches() throws Exception {
TestNestedA testNestedA = new TestNestedA();
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestNestedA> mapper = new BeanWrapperFieldSetMapper<TestNestedA>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", testNestedA);
@@ -158,7 +159,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
public void testMapperWithNotVerySimilarNamePropertyMatches() throws Exception {
TestNestedC testNestedC = new TestNestedC();
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestNestedC> mapper = new BeanWrapperFieldSetMapper<TestNestedC>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", testNestedC);
@@ -166,7 +167,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "1" }, new String[] { "foo" });
TestNestedC result = (TestNestedC) mapper.mapLine(fieldSet, -1);
TestNestedC result = mapper.mapLine(fieldSet, -1);
// "foo" is similar enough to "value" that it matches - but only because
// nothing else does...
@@ -179,7 +180,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
testNestedA.setTestObjectB(testNestedB);
testNestedB.setTestObjectC(new TestNestedC());
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestNestedA> mapper = new BeanWrapperFieldSetMapper<TestNestedA>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", testNestedA);
@@ -188,7 +189,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
FieldSet fieldSet = new DefaultFieldSet(new String[] { "Another dummy", "2" }, new String[] {
"TestObjectB.ValueA", "TestObjectB.TestObjectC.Value" });
TestNestedA result = (TestNestedA) mapper.mapLine(fieldSet, -1);
TestNestedA result = mapper.mapLine(fieldSet, -1);
assertEquals("Another dummy", result.getTestObjectB().getValueA());
assertEquals(2, result.getTestObjectB().getTestObjectC().getValue());
@@ -199,7 +200,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
TestNestedB testNestedB = new TestNestedB();
testNestedA.setTestObjectB(testNestedB);
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<?> mapper = new BeanWrapperFieldSetMapper<Object>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", testNestedA);
@@ -221,7 +222,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
TestNestedB testNestedB = new TestNestedB();
testNestedA.setTestObjectB(testNestedB);
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<?> mapper = new BeanWrapperFieldSetMapper<Object>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", testNestedA);
@@ -261,7 +262,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
nestedC.add(new TestNestedC());
nestedList.setNestedC(nestedC);
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<?> mapper = new BeanWrapperFieldSetMapper<Object>();
StaticApplicationContext context = new StaticApplicationContext();
mapper.setBeanFactory(context);
context.getBeanFactory().registerSingleton("bean", nestedList);
@@ -280,7 +281,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
public void testPaddedLongWithNoEditor() throws Exception {
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
mapper.setTargetType(TestObject.class);
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009" }, new String[] { "varLong" });
@@ -291,7 +292,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
public void testPaddedLongWithEditor() throws Exception {
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
mapper.setTargetType(TestObject.class);
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009" }, new String[] { "varLong" });
@@ -305,7 +306,7 @@ public class BeanWrapperFieldSetMapperTests extends TestCase {
public void testPaddedLongWithDefaultAndCustomEditor() throws Exception {
BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper();
BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
mapper.setTargetType(TestObject.class);
FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009", "78" }, new String[] { "varLong", "varInt" });