Deal with compiler warnings

This commit is contained in:
Dave Syer
2010-11-22 14:44:37 +00:00
parent 28eb5b02d3
commit 3dd0c7f776
26 changed files with 74 additions and 99 deletions

View File

@@ -55,7 +55,6 @@ import org.springframework.util.StringUtils;
public class ChunkElementParserTests {
@Test
@SuppressWarnings("unchecked")
public void testSimpleAttributes() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementSimpleAttributeParserTests-context.xml");

View File

@@ -81,7 +81,7 @@ public class StepParserTests {
public void testTaskletStepAttributes() throws Exception {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml");
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
Map<String, StepParserStepFactoryBean> beans = ctx.getBeansOfType(StepParserStepFactoryBean.class);
String factoryName = (String) beans.keySet().toArray()[0];
@SuppressWarnings("unchecked")

View File

@@ -62,9 +62,8 @@ public class StepWithBasicProcessTaskJobParserTests {
@Autowired
private TestWriter writer;
@SuppressWarnings("unchecked")
@Autowired
private StepParserStepFactoryBean factory;
private StepParserStepFactoryBean<?,?> factory;
@Test
public void testStepWithTask() throws Exception {

View File

@@ -68,9 +68,8 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
@Autowired
private TestWriter writer;
@SuppressWarnings("unchecked")
@Autowired
private StepParserStepFactoryBean factory;
private StepParserStepFactoryBean<?, ?> factory;
@Test
public void testStepWithTask() throws Exception {
@@ -83,10 +82,10 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
assertEquals("wrong retry-limit:", 3, rl);
Object cc = ReflectionTestUtils.getField(factory, "cacheCapacity");
assertEquals("wrong cache-capacity:", 100, cc);
assertEquals("wrong transaction-attribute:", Propagation.REQUIRED, ReflectionTestUtils.getField(factory,
"propagation"));
assertEquals("wrong transaction-attribute:", Isolation.DEFAULT, ReflectionTestUtils.getField(factory,
"isolation"));
assertEquals("wrong transaction-attribute:", Propagation.REQUIRED,
ReflectionTestUtils.getField(factory, "propagation"));
assertEquals("wrong transaction-attribute:", Isolation.DEFAULT,
ReflectionTestUtils.getField(factory, "isolation"));
assertEquals("wrong transaction-attribute:", 10, ReflectionTestUtils.getField(factory, "transactionTimeout"));
Object txq = ReflectionTestUtils.getField(factory, "readerTransactionalQueue");
assertEquals("wrong reader-transactional-queue:", true, txq);

View File

@@ -99,7 +99,7 @@ public class StepListenerFactoryBeanTests {
((ChunkListener) listener).afterChunk();
((ItemReadListener<String>) listener).beforeRead();
((ItemReadListener<String>) listener).afterRead(readItem);
((ItemReadListener) listener).onReadError(new Exception());
((ItemReadListener<String>) listener).onReadError(new Exception());
((ItemProcessListener<String, Integer>) listener).beforeProcess(readItem);
((ItemProcessListener<String, Integer>) listener).afterProcess(readItem, writeItem);
((ItemProcessListener<String, Integer>) listener).onProcessError(readItem, new Exception());

View File

@@ -23,8 +23,7 @@ import org.springframework.util.ReflectionUtils;
public class StepSynchronizationManagerTests {
private StepExecution stepExecution = new StepExecution("step",
new JobExecution(0L));
private StepExecution stepExecution = new StepExecution("step", new JobExecution(0L));
@Before
@After
@@ -44,8 +43,7 @@ public class StepSynchronizationManagerTests {
@Test
public void testClose() throws Exception {
final List<String> list = new ArrayList<String>();
StepContext context = StepSynchronizationManager
.register(stepExecution);
StepContext context = StepSynchronizationManager.register(stepExecution);
context.registerDestructionCallback("foo", new Runnable() {
public void run() {
list.add("foo");
@@ -54,51 +52,45 @@ public class StepSynchronizationManagerTests {
StepSynchronizationManager.close();
assertNull(StepSynchronizationManager.getContext());
assertEquals(0, list.size());
// check for possible memory leak
// check for possible memory leak
assertEquals(0, extractStaticMap("counts").size());
assertEquals(0, extractStaticMap("contexts").size());
}
@SuppressWarnings("unchecked")
private Map extractStaticMap(String name) throws IllegalAccessException {
Field field = ReflectionUtils.findField(
StepSynchronizationManager.class, name);
private Map<?, ?> extractStaticMap(String name) throws IllegalAccessException {
Field field = ReflectionUtils.findField(StepSynchronizationManager.class, name);
ReflectionUtils.makeAccessible(field);
Map map = (Map) field.get(StepSynchronizationManager.class);
Map<?, ?> map = (Map<?, ?>) field.get(StepSynchronizationManager.class);
return map;
}
@Test
public void testMultithreaded() throws Exception {
StepContext context = StepSynchronizationManager
.register(stepExecution);
StepContext context = StepSynchronizationManager.register(stepExecution);
ExecutorService executorService = Executors.newFixedThreadPool(2);
FutureTask<StepContext> task = new FutureTask<StepContext>(
new Callable<StepContext>() {
public StepContext call() throws Exception {
try {
StepSynchronizationManager.register(stepExecution);
StepContext context = StepSynchronizationManager
.getContext();
context.setAttribute("foo", "bar");
return context;
} finally {
StepSynchronizationManager.close();
}
}
});
FutureTask<StepContext> task = new FutureTask<StepContext>(new Callable<StepContext>() {
public StepContext call() throws Exception {
try {
StepSynchronizationManager.register(stepExecution);
StepContext context = StepSynchronizationManager.getContext();
context.setAttribute("foo", "bar");
return context;
}
finally {
StepSynchronizationManager.close();
}
}
});
executorService.execute(task);
executorService.awaitTermination(1, TimeUnit.SECONDS);
assertEquals(context.attributeNames().length, task.get()
.attributeNames().length);
assertEquals(context.attributeNames().length, task.get().attributeNames().length);
StepSynchronizationManager.close();
assertNull(StepSynchronizationManager.getContext());
}
@Test
public void testRelease() {
StepContext context = StepSynchronizationManager
.register(stepExecution);
StepContext context = StepSynchronizationManager.register(stepExecution);
final List<String> list = new ArrayList<String>();
context.registerDestructionCallback("foo", new Runnable() {
public void run() {