mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-22 08:24:28 +00:00
Apply project coding conventions to Repository example
This commit is contained in:
@@ -22,9 +22,10 @@ import com.google.common.collect.Lists;
|
||||
/**
|
||||
* Test case to test the functions of {@link PersonRepository}, beside the CRUD functions, the query
|
||||
* by {@link org.springframework.data.jpa.domain.Specification} are also test.
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { AppConfig.class}, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { AppConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class AnnotationBasedRepositoryTest {
|
||||
|
||||
@Resource
|
||||
@@ -107,4 +108,3 @@ public class AnnotationBasedRepositoryTest {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,35 +20,36 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { AppConfig.class}, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { AppConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class AppConfigTest {
|
||||
|
||||
@Autowired
|
||||
DataSource dataSource;
|
||||
|
||||
/**
|
||||
* Test for bean instance
|
||||
*/
|
||||
@Test
|
||||
public void testDataSource() {
|
||||
assertNotNull(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for correct query execution
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Test
|
||||
@Transactional
|
||||
public void testQuery() throws SQLException{
|
||||
ResultSet resultSet = dataSource.getConnection().createStatement().executeQuery("SELECT 1");
|
||||
String result = null;
|
||||
String expected = "1";
|
||||
while (resultSet.next()) {
|
||||
result = resultSet.getString(1);
|
||||
|
||||
}
|
||||
assertTrue(result.equals(expected));
|
||||
}
|
||||
@Autowired
|
||||
DataSource dataSource;
|
||||
|
||||
/**
|
||||
* Test for bean instance
|
||||
*/
|
||||
@Test
|
||||
public void testDataSource() {
|
||||
assertNotNull(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for correct query execution
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Test
|
||||
@Transactional
|
||||
public void testQuery() throws SQLException {
|
||||
ResultSet resultSet = dataSource.getConnection().createStatement().executeQuery("SELECT 1");
|
||||
String result = null;
|
||||
String expected = "1";
|
||||
while (resultSet.next()) {
|
||||
result = resultSet.getString(1);
|
||||
|
||||
}
|
||||
assertTrue(result.equals(expected));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.google.common.collect.Lists;
|
||||
* by {@link org.springframework.data.jpa.domain.Specification} are also test.
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
|
||||
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
|
||||
public class RepositoryTest {
|
||||
|
||||
@Resource
|
||||
@@ -106,4 +106,3 @@ public class RepositoryTest {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user