From f777e627368bbca69bd689eeb9082d7536588115 Mon Sep 17 00:00:00 2001 From: robokaso Date: Tue, 22 Jul 2008 15:57:16 +0000 Subject: [PATCH] parameterization of random classes with warnings --- .../mapping/BeanWrapperFieldSetMapper.java | 15 +++--- .../support/SubclassExceptionClassifier.java | 3 +- .../TransactionAwareProxyFactory.java | 1 + .../BeanWrapperFieldSetMapperTests.java | 47 ++++++++++--------- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java index fc0946838..231122caa 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java @@ -76,12 +76,12 @@ import org.springframework.validation.ObjectError; * @author Dave Syer * */ -public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar implements FieldSetMapper, +public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar implements FieldSetMapper, BeanFactoryAware, InitializingBean { private String name; - private Class type; + private Class 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 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(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SubclassExceptionClassifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SubclassExceptionClassifier.java index 0a4787987..6df9bdc43 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SubclassExceptionClassifier.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SubclassExceptionClassifier.java @@ -29,8 +29,9 @@ import org.springframework.util.Assert; * @author Dave Syer * */ +@SuppressWarnings("unchecked") public class SubclassExceptionClassifier extends ExceptionClassifierSupport { - + private Map classified = new HashMap(); /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java index b8639180a..5d7b40a38 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java @@ -46,6 +46,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager * @author Dave Syer * */ +@SuppressWarnings("unchecked") public class TransactionAwareProxyFactory { private Object target; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java index 77ac7d932..155722066 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java @@ -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 mapper = new BeanWrapperFieldSetMapper(); 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 mapper = new BeanWrapperFieldSetMapper(); try { mapper.afterPropertiesSet(); } @@ -57,20 +57,20 @@ public class BeanWrapperFieldSetMapperTests extends TestCase { } public void testVanillaBeanCreatedFromType() throws Exception { - BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper(); + BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper(); 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 mapper = new BeanWrapperFieldSetMapper(); 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 mapper = new BeanWrapperFieldSetMapper(); 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 mapper = (BeanWrapperFieldSetMapper) 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 mapper = new BeanWrapperFieldSetMapper(); 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 mapper = new BeanWrapperFieldSetMapper(); 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 mapper = new BeanWrapperFieldSetMapper(); 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 mapper = new BeanWrapperFieldSetMapper(); 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(); 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(); 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(); 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 mapper = new BeanWrapperFieldSetMapper(); 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 mapper = new BeanWrapperFieldSetMapper(); 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 mapper = new BeanWrapperFieldSetMapper(); mapper.setTargetType(TestObject.class); FieldSet fieldSet = new DefaultFieldSet(new String[] { "00009", "78" }, new String[] { "varLong", "varInt" });