Improve type safety of transactional collections by reducing visibility of private features
This commit is contained in:
@@ -4,15 +4,11 @@ import org.junit.Before;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.junit.internal.runners.JUnit4ClassRunner;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.database.support.IbatisKeyCollector;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
@@ -3,13 +3,11 @@ package org.springframework.batch.item.database;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.database.support.HsqlPagingQueryProvider;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import java.util.Collections;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -5,12 +5,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
@@ -32,17 +32,12 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class TransactionAwareListItemReaderTests extends TestCase {
|
||||
|
||||
// TransactionAwareListItemProvider provider = new
|
||||
// TransactionAwareListItemProvider(Arrays.asList(new String[] { "a",
|
||||
// "b", "c" }));
|
||||
ListItemReader<String> reader;
|
||||
private ListItemReader<String> reader;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
TransactionAwareProxyFactory factory = new TransactionAwareProxyFactory(Arrays.asList(new String[] { "a", "b",
|
||||
"c" }));
|
||||
reader = new ListItemReader<String>((List<String>) factory.createInstance());
|
||||
reader = new ListItemReader<String>(TransactionAwareProxyFactory.createTransactionalList(Arrays.asList("a", "b", "c")));
|
||||
}
|
||||
|
||||
public void testNext() throws Exception {
|
||||
|
||||
@@ -27,15 +27,12 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class TransactionAwareListFactoryTests extends TestCase {
|
||||
|
||||
TransactionAwareProxyFactory<List<String>> factory = new TransactionAwareProxyFactory<List<String>>(Arrays.asList(new String[] { "foo",
|
||||
"bar", "spam" }));
|
||||
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(new ResourcelessTransactionManager());
|
||||
|
||||
List<String> list;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
list = (List<String>) factory.createInstance();
|
||||
list = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList("foo", "bar", "spam"));
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class TransactionAwareMapFactoryTests extends TestCase {
|
||||
|
||||
TransactionAwareProxyFactory<Map<String, String>> factory;
|
||||
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(new ResourcelessTransactionManager());
|
||||
|
||||
Map<String, String> map;
|
||||
@@ -38,8 +36,7 @@ public class TransactionAwareMapFactoryTests extends TestCase {
|
||||
seed.put("foo", "oof");
|
||||
seed.put("bar", "bar");
|
||||
seed.put("spam", "maps");
|
||||
factory = new TransactionAwareProxyFactory<Map<String, String>>(seed);
|
||||
map = (Map<String, String>) factory.createInstance();
|
||||
map = TransactionAwareProxyFactory.createTransactionalMap(seed);
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.batch.support.transaction;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -23,31 +24,39 @@ import java.util.Set;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TransactionAwareProxyFactoryTests extends TestCase {
|
||||
|
||||
|
||||
public void testCreateList() throws Exception {
|
||||
List<String> list = TransactionAwareProxyFactory.createTransactionalList();
|
||||
list.add("foo");
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
public void testCreateListWithValues() throws Exception {
|
||||
List<String> list = TransactionAwareProxyFactory.createTransactionalList(Collections.singletonList("foo"));
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
public void testCreateSet() throws Exception {
|
||||
Set<String> set = TransactionAwareProxyFactory.createTransactionalSet();
|
||||
set.add("foo");
|
||||
assertEquals(1, set.size());
|
||||
}
|
||||
|
||||
|
||||
public void testCreateSetWithValues() throws Exception {
|
||||
Set<String> list = TransactionAwareProxyFactory.createTransactionalSet(Collections.singleton("foo"));
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
public void testCreateMap() throws Exception {
|
||||
Map<String, String> map = TransactionAwareProxyFactory.createTransactionalMap();
|
||||
map.put("foo", "bar");
|
||||
assertEquals(1, map.size());
|
||||
}
|
||||
|
||||
public void testCreateUnsupported() throws Exception {
|
||||
try {
|
||||
new TransactionAwareProxyFactory<Object>(new Object()).createInstance();
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
public void testCreateMapWithValues() throws Exception {
|
||||
Map<String, String> map = TransactionAwareProxyFactory.createTransactionalMap(Collections.singletonMap("foo",
|
||||
"bar"));
|
||||
assertEquals(1, map.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user