Migrate JUnit 4 assertions to AssertJ
Migrate all existing JUnit 4 `assert...` based assertions to AssertJ and add a checkstyle rule to ensure they don't return. See gh-23022
This commit is contained in:
@@ -29,8 +29,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -87,7 +87,7 @@ public class InitializeDatabaseIntegrationTests {
|
||||
DataSource dataSource = context.getBean("dataSource", DataSource.class);
|
||||
assertCorrectSetup(dataSource);
|
||||
JdbcTemplate t = new JdbcTemplate(dataSource);
|
||||
assertEquals("Dave", t.queryForObject("select name from T_TEST", String.class));
|
||||
assertThat(t.queryForObject("select name from T_TEST", String.class)).isEqualTo("Dave");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,12 +109,12 @@ public class InitializeDatabaseIntegrationTests {
|
||||
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-cache-config.xml");
|
||||
assertCorrectSetup(context.getBean("dataSource", DataSource.class));
|
||||
CacheData cache = context.getBean(CacheData.class);
|
||||
assertEquals(1, cache.getCachedData().size());
|
||||
assertThat(cache.getCachedData().size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private void assertCorrectSetup(DataSource dataSource) {
|
||||
JdbcTemplate jt = new JdbcTemplate(dataSource);
|
||||
assertEquals(1, jt.queryForObject("select count(*) from T_TEST", Integer.class).intValue());
|
||||
assertThat(jt.queryForObject("select count(*) from T_TEST", Integer.class).intValue()).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ import org.springframework.tests.TestGroup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.DEFAULT_DATABASE_NAME;
|
||||
|
||||
/**
|
||||
@@ -186,7 +184,7 @@ public class JdbcNamespaceIntegrationTests {
|
||||
}
|
||||
|
||||
private void assertNumRowsInTestTable(JdbcTemplate template, int count) {
|
||||
assertEquals(count, template.queryForObject("select count(*) from T_TEST", Integer.class).intValue());
|
||||
assertThat(template.queryForObject("select count(*) from T_TEST", Integer.class).intValue()).isEqualTo(count);
|
||||
}
|
||||
|
||||
private void assertCorrectSetup(String file, String... dataSources) {
|
||||
@@ -199,7 +197,7 @@ public class JdbcNamespaceIntegrationTests {
|
||||
for (String dataSourceName : dataSources) {
|
||||
DataSource dataSource = context.getBean(dataSourceName, DataSource.class);
|
||||
assertNumRowsInTestTable(new JdbcTemplate(dataSource), count);
|
||||
assertTrue(dataSource instanceof AbstractDriverBasedDataSource);
|
||||
assertThat(dataSource instanceof AbstractDriverBasedDataSource).isTrue();
|
||||
AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource;
|
||||
assertThat(adbDataSource.getUrl()).contains(dataSourceName);
|
||||
}
|
||||
@@ -214,9 +212,9 @@ public class JdbcNamespaceIntegrationTests {
|
||||
try {
|
||||
DataSource dataSource = context.getBean(DataSource.class);
|
||||
assertNumRowsInTestTable(new JdbcTemplate(dataSource), 1);
|
||||
assertTrue(dataSource instanceof AbstractDriverBasedDataSource);
|
||||
assertThat(dataSource instanceof AbstractDriverBasedDataSource).isTrue();
|
||||
AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource;
|
||||
assertTrue(urlPredicate.test(adbDataSource.getUrl()));
|
||||
assertThat(urlPredicate.test(adbDataSource.getUrl())).isTrue();
|
||||
}
|
||||
finally {
|
||||
context.close();
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.jdbc.core.test.ConcretePerson;
|
||||
import org.springframework.jdbc.core.test.DatePerson;
|
||||
@@ -31,7 +32,7 @@ import org.springframework.jdbc.core.test.SpacePerson;
|
||||
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -48,31 +49,31 @@ import static org.mockito.Mockito.verify;
|
||||
public abstract class AbstractRowMapperTests {
|
||||
|
||||
protected void verifyPerson(Person bean) throws Exception {
|
||||
assertEquals("Bubba", bean.getName());
|
||||
assertEquals(22L, bean.getAge());
|
||||
assertEquals(new java.util.Date(1221222L), bean.getBirth_date());
|
||||
assertEquals(new BigDecimal("1234.56"), bean.getBalance());
|
||||
assertThat(bean.getName()).isEqualTo("Bubba");
|
||||
assertThat(bean.getAge()).isEqualTo(22L);
|
||||
assertThat(bean.getBirth_date()).usingComparator(Date::compareTo).isEqualTo(new java.util.Date(1221222L));
|
||||
assertThat(bean.getBalance()).isEqualTo(new BigDecimal("1234.56"));
|
||||
}
|
||||
|
||||
protected void verifyPerson(ConcretePerson bean) throws Exception {
|
||||
assertEquals("Bubba", bean.getName());
|
||||
assertEquals(22L, bean.getAge());
|
||||
assertEquals(new java.util.Date(1221222L), bean.getBirth_date());
|
||||
assertEquals(new BigDecimal("1234.56"), bean.getBalance());
|
||||
assertThat(bean.getName()).isEqualTo("Bubba");
|
||||
assertThat(bean.getAge()).isEqualTo(22L);
|
||||
assertThat(bean.getBirth_date()).usingComparator(Date::compareTo).isEqualTo(new java.util.Date(1221222L));
|
||||
assertThat(bean.getBalance()).isEqualTo(new BigDecimal("1234.56"));
|
||||
}
|
||||
|
||||
protected void verifyPerson(SpacePerson bean) {
|
||||
assertEquals("Bubba", bean.getLastName());
|
||||
assertEquals(22L, bean.getAge());
|
||||
assertEquals(new java.sql.Timestamp(1221222L).toLocalDateTime(), bean.getBirthDate());
|
||||
assertEquals(new BigDecimal("1234.56"), bean.getBalance());
|
||||
assertThat(bean.getLastName()).isEqualTo("Bubba");
|
||||
assertThat(bean.getAge()).isEqualTo(22L);
|
||||
assertThat(bean.getBirthDate()).isEqualTo(new Timestamp(1221222L).toLocalDateTime());
|
||||
assertThat(bean.getBalance()).isEqualTo(new BigDecimal("1234.56"));
|
||||
}
|
||||
|
||||
protected void verifyPerson(DatePerson bean) {
|
||||
assertEquals("Bubba", bean.getLastName());
|
||||
assertEquals(22L, bean.getAge());
|
||||
assertEquals(new java.sql.Date(1221222L).toLocalDate(), bean.getBirthDate());
|
||||
assertEquals(new BigDecimal("1234.56"), bean.getBalance());
|
||||
assertThat(bean.getLastName()).isEqualTo("Bubba");
|
||||
assertThat(bean.getAge()).isEqualTo(22L);
|
||||
assertThat(bean.getBirthDate()).isEqualTo(new java.sql.Date(1221222L).toLocalDate());
|
||||
assertThat(bean.getBalance()).isEqualTo(new BigDecimal("1234.56"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.springframework.jdbc.core.test.ExtendedPerson;
|
||||
import org.springframework.jdbc.core.test.Person;
|
||||
import org.springframework.jdbc.core.test.SpacePerson;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
@@ -58,7 +58,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
|
||||
List<Person> result = mock.getJdbcTemplate().query(
|
||||
"select name, age, birth_date, balance from people",
|
||||
new BeanPropertyRowMapper<>(Person.class));
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
verifyPerson(result.get(0));
|
||||
mock.verifyClosed();
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
|
||||
List<ConcretePerson> result = mock.getJdbcTemplate().query(
|
||||
"select name, age, birth_date, balance from people",
|
||||
new BeanPropertyRowMapper<>(ConcretePerson.class));
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
verifyPerson(result.get(0));
|
||||
mock.verifyClosed();
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
|
||||
List<ConcretePerson> result = mock.getJdbcTemplate().query(
|
||||
"select name, age, birth_date, balance from people",
|
||||
new BeanPropertyRowMapper<>(ConcretePerson.class, true));
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
verifyPerson(result.get(0));
|
||||
mock.verifyClosed();
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
|
||||
List<ExtendedPerson> result = mock.getJdbcTemplate().query(
|
||||
"select name, age, birth_date, balance from people",
|
||||
new BeanPropertyRowMapper<>(ExtendedPerson.class));
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
ExtendedPerson bean = result.get(0);
|
||||
verifyPerson(bean);
|
||||
mock.verifyClosed();
|
||||
@@ -119,7 +119,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
|
||||
List<SpacePerson> result = mock.getJdbcTemplate().query(
|
||||
"select last_name as \"Last Name\", age, birth_date, balance from people",
|
||||
new BeanPropertyRowMapper<>(SpacePerson.class));
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
verifyPerson(result.get(0));
|
||||
mock.verifyClosed();
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
|
||||
List<DatePerson> result = mock.getJdbcTemplate().query(
|
||||
"select last_name as \"Last Name\", age, birth_date, balance from people",
|
||||
new BeanPropertyRowMapper<>(DatePerson.class));
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
verifyPerson(result.get(0));
|
||||
mock.verifyClosed();
|
||||
}
|
||||
|
||||
@@ -33,10 +33,8 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -91,9 +89,9 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, true, false);
|
||||
given(this.resultSet.getObject(1)).willReturn(11, 12);
|
||||
List<Map<String, Object>> li = this.template.queryForList(sql);
|
||||
assertEquals("All rows returned", 2, li.size());
|
||||
assertEquals("First row is Integer", 11, ((Integer) li.get(0).get("age")).intValue());
|
||||
assertEquals("Second row is Integer", 12, ((Integer) li.get(1).get("age")).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(2);
|
||||
assertThat(((Integer) li.get(0).get("age")).intValue()).as("First row is Integer").isEqualTo(11);
|
||||
assertThat(((Integer) li.get(1).get("age")).intValue()).as("Second row is Integer").isEqualTo(12);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -103,7 +101,7 @@ public class JdbcTemplateQueryTests {
|
||||
String sql = "SELECT AGE FROM CUSTMR WHERE ID < 3";
|
||||
given(this.resultSet.next()).willReturn(false);
|
||||
List<Map<String, Object>> li = this.template.queryForList(sql);
|
||||
assertEquals("All rows returned", 0, li.size());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(0);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -114,8 +112,8 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getObject(1)).willReturn(11);
|
||||
List<Map<String, Object>> li = this.template.queryForList(sql);
|
||||
assertEquals("All rows returned", 1, li.size());
|
||||
assertEquals("First row is Integer", 11, ((Integer) li.get(0).get("age")).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(1);
|
||||
assertThat(((Integer) li.get(0).get("age")).intValue()).as("First row is Integer").isEqualTo(11);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -126,8 +124,8 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getInt(1)).willReturn(11);
|
||||
List<Integer> li = this.template.queryForList(sql, Integer.class);
|
||||
assertEquals("All rows returned", 1, li.size());
|
||||
assertEquals("Element is Integer", 11, li.get(0).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(1);
|
||||
assertThat(li.get(0).intValue()).as("Element is Integer").isEqualTo(11);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -138,7 +136,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getObject(1)).willReturn(11);
|
||||
Map<String, Object> map = this.template.queryForMap(sql);
|
||||
assertEquals("Wow is Integer", 11, ((Integer) map.get("age")).intValue());
|
||||
assertThat(((Integer) map.get("age")).intValue()).as("Wow is Integer").isEqualTo(11);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -165,7 +163,8 @@ public class JdbcTemplateQueryTests {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
});
|
||||
assertTrue("Correct result type", o instanceof Integer);
|
||||
boolean condition = o instanceof Integer;
|
||||
assertThat(condition).as("Correct result type").isTrue();
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -175,7 +174,7 @@ public class JdbcTemplateQueryTests {
|
||||
String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getString(1)).willReturn("myvalue");
|
||||
assertEquals("myvalue", this.template.queryForObject(sql, String.class));
|
||||
assertThat(this.template.queryForObject(sql, String.class)).isEqualTo("myvalue");
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -185,7 +184,7 @@ public class JdbcTemplateQueryTests {
|
||||
String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getObject(1, BigInteger.class)).willReturn(new BigInteger("22"));
|
||||
assertEquals(new BigInteger("22"), this.template.queryForObject(sql, BigInteger.class));
|
||||
assertThat(this.template.queryForObject(sql, BigInteger.class)).isEqualTo(new BigInteger("22"));
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -195,7 +194,7 @@ public class JdbcTemplateQueryTests {
|
||||
String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getBigDecimal(1)).willReturn(new BigDecimal("22.5"));
|
||||
assertEquals(new BigDecimal("22.5"), this.template.queryForObject(sql, BigDecimal.class));
|
||||
assertThat(this.template.queryForObject(sql, BigDecimal.class)).isEqualTo(new BigDecimal("22.5"));
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -205,7 +204,7 @@ public class JdbcTemplateQueryTests {
|
||||
String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getInt(1)).willReturn(22);
|
||||
assertEquals(Integer.valueOf(22), this.template.queryForObject(sql, Integer.class));
|
||||
assertThat(this.template.queryForObject(sql, Integer.class)).isEqualTo(Integer.valueOf(22));
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -216,7 +215,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getInt(1)).willReturn(0);
|
||||
given(this.resultSet.wasNull()).willReturn(true);
|
||||
assertNull(this.template.queryForObject(sql, Integer.class));
|
||||
assertThat(this.template.queryForObject(sql, Integer.class)).isNull();
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -227,7 +226,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getInt(1)).willReturn(22);
|
||||
int i = this.template.queryForObject(sql, Integer.class).intValue();
|
||||
assertEquals("Return of an int", 22, i);
|
||||
assertThat(i).as("Return of an int").isEqualTo(22);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -238,7 +237,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getInt(1)).willReturn(22);
|
||||
int i = this.template.queryForObject(sql, int.class);
|
||||
assertEquals("Return of an int", 22, i);
|
||||
assertThat(i).as("Return of an int").isEqualTo(22);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -249,7 +248,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getLong(1)).willReturn(87L);
|
||||
long l = this.template.queryForObject(sql, Long.class).longValue();
|
||||
assertEquals("Return of a long", 87, l);
|
||||
assertThat(l).as("Return of a long").isEqualTo(87);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -260,7 +259,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getLong(1)).willReturn(87L);
|
||||
long l = this.template.queryForObject(sql, long.class);
|
||||
assertEquals("Return of a long", 87, l);
|
||||
assertThat(l).as("Return of a long").isEqualTo(87);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.statement).close();
|
||||
}
|
||||
@@ -279,9 +278,9 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, true, false);
|
||||
given(this.resultSet.getObject(1)).willReturn(11, 12);
|
||||
List<Map<String, Object>> li = this.template.queryForList(sql, new Object[] {3});
|
||||
assertEquals("All rows returned", 2, li.size());
|
||||
assertEquals("First row is Integer", 11, ((Integer) li.get(0).get("age")).intValue());
|
||||
assertEquals("Second row is Integer", 12, ((Integer) li.get(1).get("age")).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(2);
|
||||
assertThat(((Integer) li.get(0).get("age")).intValue()).as("First row is Integer").isEqualTo(11);
|
||||
assertThat(((Integer) li.get(1).get("age")).intValue()).as("Second row is Integer").isEqualTo(12);
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -292,7 +291,7 @@ public class JdbcTemplateQueryTests {
|
||||
String sql = "SELECT AGE FROM CUSTMR WHERE ID < ?";
|
||||
given(this.resultSet.next()).willReturn(false);
|
||||
List<Map<String, Object>> li = this.template.queryForList(sql, new Object[] {3});
|
||||
assertEquals("All rows returned", 0, li.size());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(0);
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -304,8 +303,8 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getObject(1)).willReturn(11);
|
||||
List<Map<String, Object>> li = this.template.queryForList(sql, new Object[] {3});
|
||||
assertEquals("All rows returned", 1, li.size());
|
||||
assertEquals("First row is Integer", 11, ((Integer) li.get(0).get("age")).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(1);
|
||||
assertThat(((Integer) li.get(0).get("age")).intValue()).as("First row is Integer").isEqualTo(11);
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -317,8 +316,8 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getInt(1)).willReturn(11);
|
||||
List<Integer> li = this.template.queryForList(sql, new Object[] {3}, Integer.class);
|
||||
assertEquals("All rows returned", 1, li.size());
|
||||
assertEquals("First row is Integer", 11, li.get(0).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(1);
|
||||
assertThat(li.get(0).intValue()).as("First row is Integer").isEqualTo(11);
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -330,7 +329,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getObject(1)).willReturn(11);
|
||||
Map<String, Object> map = this.template.queryForMap(sql, new Object[] {3});
|
||||
assertEquals("Row is Integer", 11, ((Integer) map.get("age")).intValue());
|
||||
assertThat(((Integer) map.get("age")).intValue()).as("Row is Integer").isEqualTo(11);
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -347,7 +346,8 @@ public class JdbcTemplateQueryTests {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
});
|
||||
assertTrue("Correct result type", o instanceof Integer);
|
||||
boolean condition = o instanceof Integer;
|
||||
assertThat(condition).as("Correct result type").isTrue();
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -359,7 +359,8 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getInt(1)).willReturn(22);
|
||||
Object o = this.template.queryForObject(sql, new Object[] {3}, Integer.class);
|
||||
assertTrue("Correct result type", o instanceof Integer);
|
||||
boolean condition = o instanceof Integer;
|
||||
assertThat(condition).as("Correct result type").isTrue();
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -371,7 +372,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getInt(1)).willReturn(22);
|
||||
int i = this.template.queryForObject(sql, new Object[] {3}, Integer.class).intValue();
|
||||
assertEquals("Return of an int", 22, i);
|
||||
assertThat(i).as("Return of an int").isEqualTo(22);
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -383,7 +384,7 @@ public class JdbcTemplateQueryTests {
|
||||
given(this.resultSet.next()).willReturn(true, false);
|
||||
given(this.resultSet.getLong(1)).willReturn(87L);
|
||||
long l = this.template.queryForObject(sql, new Object[] {3}, Long.class).longValue();
|
||||
assertEquals("Return of a long", 87, l);
|
||||
assertThat(l).as("Return of a long").isEqualTo(87);
|
||||
verify(this.preparedStatement).setObject(1, 3);
|
||||
verify(this.resultSet).close();
|
||||
verify(this.preparedStatement).close();
|
||||
|
||||
@@ -54,10 +54,6 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
@@ -116,10 +112,11 @@ public class JdbcTemplateTests {
|
||||
|
||||
@Test
|
||||
public void testBeanProperties() throws Exception {
|
||||
assertTrue("datasource ok", this.template.getDataSource() == this.dataSource);
|
||||
assertTrue("ignores warnings by default", this.template.isIgnoreWarnings());
|
||||
assertThat(this.template.getDataSource() == this.dataSource).as("datasource ok").isTrue();
|
||||
assertThat(this.template.isIgnoreWarnings()).as("ignores warnings by default").isTrue();
|
||||
this.template.setIgnoreWarnings(false);
|
||||
assertTrue("can set NOT to ignore warnings", !this.template.isIgnoreWarnings());
|
||||
boolean condition = !this.template.isIgnoreWarnings();
|
||||
assertThat(condition).as("can set NOT to ignore warnings").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +126,7 @@ public class JdbcTemplateTests {
|
||||
given(this.preparedStatement.executeUpdate()).willReturn(1);
|
||||
Dispatcher d = new Dispatcher(idParam, sql);
|
||||
int rowsAffected = this.template.update(d);
|
||||
assertTrue("1 update affected 1 row", rowsAffected == 1);
|
||||
assertThat(rowsAffected == 1).as("1 update affected 1 row").isTrue();
|
||||
verify(this.preparedStatement).setInt(1, idParam);
|
||||
verify(this.preparedStatement).close();
|
||||
verify(this.connection).close();
|
||||
@@ -226,9 +223,9 @@ public class JdbcTemplateTests {
|
||||
|
||||
// Match
|
||||
String[] forenames = sh.getStrings();
|
||||
assertTrue("same length", forenames.length == results.length);
|
||||
assertThat(forenames.length == results.length).as("same length").isTrue();
|
||||
for (int i = 0; i < forenames.length; i++) {
|
||||
assertTrue("Row " + i + " matches", forenames[i].equals(results[i]));
|
||||
assertThat(forenames[i].equals(results[i])).as("Row " + i + " matches").isTrue();
|
||||
}
|
||||
|
||||
if (fetchSize != null) {
|
||||
@@ -272,12 +269,12 @@ public class JdbcTemplateTests {
|
||||
String result = this.template.execute(new ConnectionCallback<String>() {
|
||||
@Override
|
||||
public String doInConnection(Connection con) {
|
||||
assertTrue(con instanceof ConnectionProxy);
|
||||
assertSame(JdbcTemplateTests.this.connection, ((ConnectionProxy) con).getTargetConnection());
|
||||
assertThat(con instanceof ConnectionProxy).isTrue();
|
||||
assertThat(((ConnectionProxy) con).getTargetConnection()).isSameAs(JdbcTemplateTests.this.connection);
|
||||
return "test";
|
||||
}
|
||||
});
|
||||
assertEquals("test", result);
|
||||
assertThat(result).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -293,7 +290,7 @@ public class JdbcTemplateTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals("test", result);
|
||||
assertThat(result).isEqualTo("test");
|
||||
verify(this.preparedStatement).setFetchSize(10);
|
||||
verify(this.preparedStatement).setMaxRows(20);
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -352,7 +349,7 @@ public class JdbcTemplateTests {
|
||||
given(this.connection.createStatement()).willReturn(this.statement);
|
||||
|
||||
int actualRowsAffected = this.template.update(sql);
|
||||
assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected);
|
||||
assertThat(actualRowsAffected == rowsAffected).as("Actual rows affected is correct").isTrue();
|
||||
verify(this.statement).close();
|
||||
verify(this.connection).close();
|
||||
}
|
||||
@@ -368,7 +365,7 @@ public class JdbcTemplateTests {
|
||||
|
||||
int actualRowsAffected = this.template.update(sql,
|
||||
4, new SqlParameterValue(Types.NUMERIC, 2, Float.valueOf(1.4142f)));
|
||||
assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected);
|
||||
assertThat(actualRowsAffected == rowsAffected).as("Actual rows affected is correct").isTrue();
|
||||
verify(this.preparedStatement).setObject(1, 4);
|
||||
verify(this.preparedStatement).setObject(2, Float.valueOf(1.4142f), Types.NUMERIC, 2);
|
||||
verify(this.preparedStatement).close();
|
||||
@@ -399,7 +396,7 @@ public class JdbcTemplateTests {
|
||||
given(this.connection.createStatement()).willReturn(this.statement);
|
||||
|
||||
int actualRowsAffected = this.template.update(sql);
|
||||
assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected);
|
||||
assertThat(actualRowsAffected == rowsAffected).as("Actual rows affected is correct").isTrue();
|
||||
|
||||
verify(this.statement).close();
|
||||
verify(this.connection).close();
|
||||
@@ -417,7 +414,7 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = template.batchUpdate(sql);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
|
||||
verify(this.statement).addBatch(sql[0]);
|
||||
verify(this.statement).addBatch(sql[1]);
|
||||
@@ -457,7 +454,7 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = template.batchUpdate(sql);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
|
||||
verify(this.statement, never()).addBatch(anyString());
|
||||
verify(this.statement).close();
|
||||
@@ -506,9 +503,9 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = template.batchUpdate(sql, setter);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
|
||||
verify(this.preparedStatement, times(2)).addBatch();
|
||||
verify(this.preparedStatement).setInt(1, ids[0]);
|
||||
@@ -547,9 +544,9 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = template.batchUpdate(sql, setter);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
|
||||
verify(this.preparedStatement, times(2)).addBatch();
|
||||
verify(this.preparedStatement).setInt(1, ids[0]);
|
||||
@@ -584,9 +581,9 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = template.batchUpdate(sql, setter);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
|
||||
verify(this.preparedStatement, times(2)).addBatch();
|
||||
verify(this.preparedStatement).setInt(1, ids[0]);
|
||||
@@ -621,9 +618,9 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = template.batchUpdate(sql, setter);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
|
||||
verify(this.preparedStatement, never()).addBatch();
|
||||
verify(this.preparedStatement).setInt(1, ids[0]);
|
||||
@@ -652,9 +649,9 @@ public class JdbcTemplateTests {
|
||||
};
|
||||
|
||||
int[] actualRowsAffected = this.template.batchUpdate(sql, setter);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
|
||||
verify(this.preparedStatement, never()).addBatch();
|
||||
verify(this.preparedStatement).setInt(1, ids[0]);
|
||||
@@ -703,7 +700,7 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = template.batchUpdate(sql, Collections.emptyList());
|
||||
assertTrue("executed 0 updates", actualRowsAffected.length == 0);
|
||||
assertThat(actualRowsAffected.length == 0).as("executed 0 updates").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -719,9 +716,9 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = template.batchUpdate(sql, ids);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
|
||||
verify(this.preparedStatement, times(2)).addBatch();
|
||||
verify(this.preparedStatement).setObject(1, 100);
|
||||
@@ -744,9 +741,9 @@ public class JdbcTemplateTests {
|
||||
this.template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[] actualRowsAffected = this.template.batchUpdate(sql, ids, sqlTypes);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
verify(this.preparedStatement, times(2)).addBatch();
|
||||
verify(this.preparedStatement).setObject(1, 100, sqlTypes[0]);
|
||||
verify(this.preparedStatement).setObject(1, 200, sqlTypes[0]);
|
||||
@@ -768,10 +765,10 @@ public class JdbcTemplateTests {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
|
||||
int[][] actualRowsAffected = template.batchUpdate(sql, ids, 2, setter);
|
||||
assertEquals("executed 2 updates", 2, actualRowsAffected[0].length);
|
||||
assertEquals(rowsAffected1[0], actualRowsAffected[0][0]);
|
||||
assertEquals(rowsAffected1[1], actualRowsAffected[0][1]);
|
||||
assertEquals(rowsAffected2[0], actualRowsAffected[1][0]);
|
||||
assertThat(actualRowsAffected[0].length).as("executed 2 updates").isEqualTo(2);
|
||||
assertThat(actualRowsAffected[0][0]).isEqualTo(rowsAffected1[0]);
|
||||
assertThat(actualRowsAffected[0][1]).isEqualTo(rowsAffected1[1]);
|
||||
assertThat(actualRowsAffected[1][0]).isEqualTo(rowsAffected2[0]);
|
||||
|
||||
verify(this.preparedStatement, times(3)).addBatch();
|
||||
verify(this.preparedStatement).setInt(1, ids.get(0));
|
||||
@@ -860,7 +857,7 @@ public class JdbcTemplateTests {
|
||||
|
||||
PreparedStatementSetter pss = ps -> ps.setString(1, name);
|
||||
int actualRowsUpdated = new JdbcTemplate(this.dataSource).update(sql, pss);
|
||||
assertEquals("updated correct # of rows", actualRowsUpdated, expectedRowsUpdated);
|
||||
assertThat(expectedRowsUpdated).as("updated correct # of rows").isEqualTo(actualRowsUpdated);
|
||||
verify(this.preparedStatement).setString(1, name);
|
||||
verify(this.preparedStatement).close();
|
||||
verify(this.connection).close();
|
||||
@@ -1057,19 +1054,18 @@ public class JdbcTemplateTests {
|
||||
given(this.callableStatement.getUpdateCount()).willReturn(-1);
|
||||
given(this.callableStatement.getObject(1)).willReturn("X");
|
||||
|
||||
assertTrue("default should have been NOT case insensitive",
|
||||
!this.template.isResultsMapCaseInsensitive());
|
||||
boolean condition = !this.template.isResultsMapCaseInsensitive();
|
||||
assertThat(condition).as("default should have been NOT case insensitive").isTrue();
|
||||
|
||||
this.template.setResultsMapCaseInsensitive(true);
|
||||
assertTrue("now it should have been set to case insensitive",
|
||||
this.template.isResultsMapCaseInsensitive());
|
||||
assertThat(this.template.isResultsMapCaseInsensitive()).as("now it should have been set to case insensitive").isTrue();
|
||||
|
||||
Map<String, Object> out = this.template.call(
|
||||
conn -> conn.prepareCall("my query"), Collections.singletonList(new SqlOutParameter("a", 12)));
|
||||
|
||||
assertThat(out).isInstanceOf(LinkedCaseInsensitiveMap.class);
|
||||
assertNotNull("we should have gotten the result with upper case", out.get("A"));
|
||||
assertNotNull("we should have gotten the result with lower case", out.get("a"));
|
||||
assertThat(out.get("A")).as("we should have gotten the result with upper case").isNotNull();
|
||||
assertThat(out.get("a")).as("we should have gotten the result with lower case").isNotNull();
|
||||
verify(this.callableStatement).close();
|
||||
verify(this.connection).close();
|
||||
}
|
||||
@@ -1089,8 +1085,8 @@ public class JdbcTemplateTests {
|
||||
given(this.resultSet.getObject(2)).willReturn("second value");
|
||||
|
||||
Map<String, Object> map = this.template.queryForMap("my query");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals("first value", map.get("x"));
|
||||
assertThat(map.size()).isEqualTo(1);
|
||||
assertThat(map.get("x")).isEqualTo("first value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -84,14 +83,14 @@ public class RowMapperTests {
|
||||
|
||||
@After
|
||||
public void verifyResults() {
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.size()).isEqualTo(2);
|
||||
TestBean testBean1 = result.get(0);
|
||||
TestBean testBean2 = result.get(1);
|
||||
assertEquals("tb1", testBean1.getName());
|
||||
assertEquals("tb2", testBean2.getName());
|
||||
assertEquals(1, testBean1.getAge());
|
||||
assertEquals(2, testBean2.getAge());
|
||||
assertThat(testBean1.getName()).isEqualTo("tb1");
|
||||
assertThat(testBean2.getName()).isEqualTo("tb2");
|
||||
assertThat(testBean1.getAge()).isEqualTo(1);
|
||||
assertThat(testBean2.getAge()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,9 +28,8 @@ import org.junit.Test;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.dao.TypeMismatchDataAccessException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -58,7 +57,7 @@ public class SingleColumnRowMapperTests {
|
||||
|
||||
LocalDateTime actualLocalDateTime = rowMapper.mapRow(resultSet, 1);
|
||||
|
||||
assertEquals(timestamp.toLocalDateTime(), actualLocalDateTime);
|
||||
assertThat(actualLocalDateTime).isEqualTo(timestamp.toLocalDateTime());
|
||||
}
|
||||
|
||||
@Test // SPR-16483
|
||||
@@ -81,8 +80,8 @@ public class SingleColumnRowMapperTests {
|
||||
|
||||
MyLocalDateTime actualMyLocalDateTime = rowMapper.mapRow(resultSet, 1);
|
||||
|
||||
assertNotNull(actualMyLocalDateTime);
|
||||
assertEquals(timestamp.toLocalDateTime(), actualMyLocalDateTime.value);
|
||||
assertThat(actualMyLocalDateTime).isNotNull();
|
||||
assertThat(actualMyLocalDateTime.value).isEqualTo(timestamp.toLocalDateTime());
|
||||
}
|
||||
|
||||
@Test // SPR-16483
|
||||
|
||||
@@ -25,9 +25,6 @@ import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
@@ -53,28 +50,28 @@ public class BeanPropertySqlParameterSourceTests {
|
||||
@Test
|
||||
public void successfulPropertyAccess() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
||||
assertTrue(Arrays.asList(source.getReadablePropertyNames()).contains("name"));
|
||||
assertTrue(Arrays.asList(source.getReadablePropertyNames()).contains("age"));
|
||||
assertEquals("tb", source.getValue("name"));
|
||||
assertEquals(99, source.getValue("age"));
|
||||
assertEquals(Types.VARCHAR, source.getSqlType("name"));
|
||||
assertEquals(Types.INTEGER, source.getSqlType("age"));
|
||||
assertThat(Arrays.asList(source.getReadablePropertyNames()).contains("name")).isTrue();
|
||||
assertThat(Arrays.asList(source.getReadablePropertyNames()).contains("age")).isTrue();
|
||||
assertThat(source.getValue("name")).isEqualTo("tb");
|
||||
assertThat(source.getValue("age")).isEqualTo(99);
|
||||
assertThat(source.getSqlType("name")).isEqualTo(Types.VARCHAR);
|
||||
assertThat(source.getSqlType("age")).isEqualTo(Types.INTEGER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successfulPropertyAccessWithOverriddenSqlType() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
||||
source.registerSqlType("age", Types.NUMERIC);
|
||||
assertEquals("tb", source.getValue("name"));
|
||||
assertEquals(99, source.getValue("age"));
|
||||
assertEquals(Types.VARCHAR, source.getSqlType("name"));
|
||||
assertEquals(Types.NUMERIC, source.getSqlType("age"));
|
||||
assertThat(source.getValue("name")).isEqualTo("tb");
|
||||
assertThat(source.getValue("age")).isEqualTo(99);
|
||||
assertThat(source.getSqlType("name")).isEqualTo(Types.VARCHAR);
|
||||
assertThat(source.getSqlType("age")).isEqualTo(Types.NUMERIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasValueWhereTheUnderlyingBeanHasNoSuchProperty() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean());
|
||||
assertFalse(source.hasValue("thisPropertyDoesNotExist"));
|
||||
assertThat(source.hasValue("thisPropertyDoesNotExist")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +84,7 @@ public class BeanPropertySqlParameterSourceTests {
|
||||
@Test
|
||||
public void hasValueWhereTheUnderlyingBeanPropertyIsNotReadable() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties());
|
||||
assertFalse(source.hasValue("noOp"));
|
||||
assertThat(source.hasValue("noOp")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.junit.Test;
|
||||
import org.springframework.jdbc.core.SqlParameterValue;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
@@ -48,28 +48,28 @@ public class MapSqlParameterSourceTests {
|
||||
@Test
|
||||
public void sqlParameterValueRegistersSqlType() {
|
||||
MapSqlParameterSource msps = new MapSqlParameterSource("FOO", new SqlParameterValue(Types.NUMERIC, "Foo"));
|
||||
assertEquals("Correct SQL Type not registered", 2, msps.getSqlType("FOO"));
|
||||
assertThat(msps.getSqlType("FOO")).as("Correct SQL Type not registered").isEqualTo(2);
|
||||
MapSqlParameterSource msps2 = new MapSqlParameterSource();
|
||||
msps2.addValues(msps.getValues());
|
||||
assertEquals("Correct SQL Type not registered", 2, msps2.getSqlType("FOO"));
|
||||
assertThat(msps2.getSqlType("FOO")).as("Correct SQL Type not registered").isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringShowsParameterDetails() {
|
||||
MapSqlParameterSource source = new MapSqlParameterSource("FOO", new SqlParameterValue(Types.NUMERIC, "Foo"));
|
||||
assertEquals("MapSqlParameterSource {FOO=Foo (type:NUMERIC)}", source.toString());
|
||||
assertThat(source.toString()).isEqualTo("MapSqlParameterSource {FOO=Foo (type:NUMERIC)}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringShowsCustomSqlType() {
|
||||
MapSqlParameterSource source = new MapSqlParameterSource("FOO", new SqlParameterValue(Integer.MAX_VALUE, "Foo"));
|
||||
assertEquals("MapSqlParameterSource {FOO=Foo (type:" + Integer.MAX_VALUE + ")}", source.toString());
|
||||
assertThat(source.toString()).isEqualTo(("MapSqlParameterSource {FOO=Foo (type:" + Integer.MAX_VALUE + ")}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringDoesNotShowTypeUnknown() {
|
||||
MapSqlParameterSource source = new MapSqlParameterSource("FOO", new SqlParameterValue(JdbcUtils.TYPE_UNKNOWN, "Foo"));
|
||||
assertEquals("MapSqlParameterSource {FOO=Foo}", source.toString());
|
||||
assertThat(source.toString()).isEqualTo("MapSqlParameterSource {FOO=Foo}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,10 +41,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.PreparedStatementCallback;
|
||||
import org.springframework.jdbc.core.SqlParameterValue;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
@@ -128,7 +126,7 @@ public class NamedParameterJdbcTemplateTests {
|
||||
|
||||
@Test
|
||||
public void testTemplateConfiguration() {
|
||||
assertSame(dataSource, namedParameterTemplate.getJdbcTemplate().getDataSource());
|
||||
assertThat(namedParameterTemplate.getJdbcTemplate().getDataSource()).isSameAs(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,12 +137,12 @@ public class NamedParameterJdbcTemplateTests {
|
||||
params.put("priceId", 1);
|
||||
Object result = namedParameterTemplate.execute(UPDATE_NAMED_PARAMETERS, params,
|
||||
(PreparedStatementCallback<Object>) ps -> {
|
||||
assertEquals(preparedStatement, ps);
|
||||
assertThat(ps).isEqualTo(preparedStatement);
|
||||
ps.executeUpdate();
|
||||
return "result";
|
||||
});
|
||||
|
||||
assertEquals("result", result);
|
||||
assertThat(result).isEqualTo("result");
|
||||
verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1);
|
||||
verify(preparedStatement).setObject(2, 1);
|
||||
@@ -163,12 +161,12 @@ public class NamedParameterJdbcTemplateTests {
|
||||
params.put("id", 1);
|
||||
Object result = namedParameterTemplate.execute(UPDATE_ARRAY_PARAMETERS, params,
|
||||
(PreparedStatementCallback<Object>) ps -> {
|
||||
assertEquals(preparedStatement, ps);
|
||||
assertThat(ps).isEqualTo(preparedStatement);
|
||||
ps.executeUpdate();
|
||||
return "result";
|
||||
});
|
||||
|
||||
assertEquals("result", result);
|
||||
assertThat(result).isEqualTo("result");
|
||||
verify(connection).prepareStatement(UPDATE_ARRAY_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1);
|
||||
verify(preparedStatement).setObject(2, 2);
|
||||
@@ -186,12 +184,12 @@ public class NamedParameterJdbcTemplateTests {
|
||||
params.put("priceId", new SqlParameterValue(Types.INTEGER, 1));
|
||||
Object result = namedParameterTemplate.execute(UPDATE_NAMED_PARAMETERS, params,
|
||||
(PreparedStatementCallback<Object>) ps -> {
|
||||
assertEquals(preparedStatement, ps);
|
||||
assertThat(ps).isEqualTo(preparedStatement);
|
||||
ps.executeUpdate();
|
||||
return "result";
|
||||
});
|
||||
|
||||
assertEquals("result", result);
|
||||
assertThat(result).isEqualTo("result");
|
||||
verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
|
||||
verify(preparedStatement).setObject(2, 1, Types.INTEGER);
|
||||
@@ -205,12 +203,12 @@ public class NamedParameterJdbcTemplateTests {
|
||||
|
||||
Object result = namedParameterTemplate.execute(SELECT_NO_PARAMETERS,
|
||||
(PreparedStatementCallback<Object>) ps -> {
|
||||
assertEquals(preparedStatement, ps);
|
||||
assertThat(ps).isEqualTo(preparedStatement);
|
||||
ps.executeQuery();
|
||||
return "result";
|
||||
});
|
||||
|
||||
assertEquals("result", result);
|
||||
assertThat(result).isEqualTo("result");
|
||||
verify(connection).prepareStatement(SELECT_NO_PARAMETERS);
|
||||
verify(preparedStatement).close();
|
||||
verify(connection).close();
|
||||
@@ -233,8 +231,8 @@ public class NamedParameterJdbcTemplateTests {
|
||||
return cust1;
|
||||
});
|
||||
|
||||
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
|
||||
assertThat(cust.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(cust.getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
|
||||
verify(preparedStatement).setString(2, "UK");
|
||||
@@ -257,8 +255,8 @@ public class NamedParameterJdbcTemplateTests {
|
||||
return cust1;
|
||||
});
|
||||
|
||||
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
|
||||
assertThat(cust.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(cust.getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(connection).prepareStatement(SELECT_NO_PARAMETERS);
|
||||
verify(preparedStatement).close();
|
||||
verify(connection).close();
|
||||
@@ -280,9 +278,9 @@ public class NamedParameterJdbcTemplateTests {
|
||||
customers.add(cust);
|
||||
});
|
||||
|
||||
assertEquals(1, customers.size());
|
||||
assertTrue("Customer id was assigned correctly", customers.get(0).getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", customers.get(0).getForename().equals("rod"));
|
||||
assertThat(customers.size()).isEqualTo(1);
|
||||
assertThat(customers.get(0).getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(customers.get(0).getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
|
||||
verify(preparedStatement).setString(2, "UK");
|
||||
@@ -304,9 +302,9 @@ public class NamedParameterJdbcTemplateTests {
|
||||
customers.add(cust);
|
||||
});
|
||||
|
||||
assertEquals(1, customers.size());
|
||||
assertTrue("Customer id was assigned correctly", customers.get(0).getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", customers.get(0).getForename().equals("rod"));
|
||||
assertThat(customers.size()).isEqualTo(1);
|
||||
assertThat(customers.get(0).getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(customers.get(0).getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(connection).prepareStatement(SELECT_NO_PARAMETERS);
|
||||
verify(preparedStatement).close();
|
||||
verify(connection).close();
|
||||
@@ -327,9 +325,9 @@ public class NamedParameterJdbcTemplateTests {
|
||||
cust.setForename(rs.getString(COLUMN_NAMES[1]));
|
||||
return cust;
|
||||
});
|
||||
assertEquals(1, customers.size());
|
||||
assertTrue("Customer id was assigned correctly", customers.get(0).getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", customers.get(0).getForename().equals("rod"));
|
||||
assertThat(customers.size()).isEqualTo(1);
|
||||
assertThat(customers.get(0).getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(customers.get(0).getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
|
||||
verify(preparedStatement).setString(2, "UK");
|
||||
@@ -350,9 +348,9 @@ public class NamedParameterJdbcTemplateTests {
|
||||
cust.setForename(rs.getString(COLUMN_NAMES[1]));
|
||||
return cust;
|
||||
});
|
||||
assertEquals(1, customers.size());
|
||||
assertTrue("Customer id was assigned correctly", customers.get(0).getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", customers.get(0).getForename().equals("rod"));
|
||||
assertThat(customers.size()).isEqualTo(1);
|
||||
assertThat(customers.get(0).getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(customers.get(0).getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(connection).prepareStatement(SELECT_NO_PARAMETERS);
|
||||
verify(preparedStatement).close();
|
||||
verify(connection).close();
|
||||
@@ -373,8 +371,8 @@ public class NamedParameterJdbcTemplateTests {
|
||||
cust1.setForename(rs.getString(COLUMN_NAMES[1]));
|
||||
return cust1;
|
||||
});
|
||||
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
|
||||
assertThat(cust.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(cust.getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
|
||||
verify(preparedStatement).setString(2, "UK");
|
||||
@@ -390,7 +388,7 @@ public class NamedParameterJdbcTemplateTests {
|
||||
params.put("priceId", 1);
|
||||
int rowsAffected = namedParameterTemplate.update(UPDATE_NAMED_PARAMETERS, params);
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1);
|
||||
verify(preparedStatement).setObject(2, 1);
|
||||
@@ -406,7 +404,7 @@ public class NamedParameterJdbcTemplateTests {
|
||||
params.put("priceId", new SqlParameterValue(Types.INTEGER, 1));
|
||||
int rowsAffected = namedParameterTemplate.update(UPDATE_NAMED_PARAMETERS, params);
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED);
|
||||
verify(preparedStatement).setObject(1, 1, Types.DECIMAL);
|
||||
verify(preparedStatement).setObject(2, 1, Types.INTEGER);
|
||||
@@ -428,9 +426,9 @@ public class NamedParameterJdbcTemplateTests {
|
||||
|
||||
int[] actualRowsAffected = namedParameterTemplate.batchUpdate(
|
||||
"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id", ids);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
verify(connection).prepareStatement("UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?");
|
||||
verify(preparedStatement).setObject(1, 100);
|
||||
verify(preparedStatement).setObject(1, 200);
|
||||
@@ -447,7 +445,7 @@ public class NamedParameterJdbcTemplateTests {
|
||||
|
||||
int[] actualRowsAffected = namedParameterTemplate.batchUpdate(
|
||||
"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id", ids);
|
||||
assertTrue("executed 0 updates", actualRowsAffected.length == 0);
|
||||
assertThat(actualRowsAffected.length == 0).as("executed 0 updates").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,9 +461,9 @@ public class NamedParameterJdbcTemplateTests {
|
||||
|
||||
int[] actualRowsAffected = namedParameterTemplate.batchUpdate(
|
||||
"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id", ids);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
verify(connection).prepareStatement("UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?");
|
||||
verify(preparedStatement).setObject(1, 100);
|
||||
verify(preparedStatement).setObject(1, 200);
|
||||
@@ -493,7 +491,7 @@ public class NamedParameterJdbcTemplateTests {
|
||||
parameters
|
||||
);
|
||||
|
||||
assertEquals("executed 2 updates", 2, actualRowsAffected.length);
|
||||
assertThat(actualRowsAffected.length).as("executed 2 updates").isEqualTo(2);
|
||||
|
||||
InOrder inOrder = inOrder(preparedStatement);
|
||||
|
||||
@@ -522,9 +520,9 @@ public class NamedParameterJdbcTemplateTests {
|
||||
|
||||
int[] actualRowsAffected = namedParameterTemplate.batchUpdate(
|
||||
"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id", ids);
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
verify(connection).prepareStatement("UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?");
|
||||
verify(preparedStatement).setObject(1, 100, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(1, 200, Types.NUMERIC);
|
||||
|
||||
@@ -36,8 +36,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -96,11 +95,9 @@ public class NamedParameterQueryTests {
|
||||
List<Map<String, Object>> li = template.queryForList(
|
||||
"SELECT AGE FROM CUSTMR WHERE ID < :id", params);
|
||||
|
||||
assertEquals("All rows returned", 2, li.size());
|
||||
assertEquals("First row is Integer", 11,
|
||||
((Integer) li.get(0).get("age")).intValue());
|
||||
assertEquals("Second row is Integer", 12,
|
||||
((Integer) li.get(1).get("age")).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(2);
|
||||
assertThat(((Integer) li.get(0).get("age")).intValue()).as("First row is Integer").isEqualTo(11);
|
||||
assertThat(((Integer) li.get(1).get("age")).intValue()).as("Second row is Integer").isEqualTo(12);
|
||||
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
@@ -115,7 +112,7 @@ public class NamedParameterQueryTests {
|
||||
List<Map<String, Object>> li = template.queryForList(
|
||||
"SELECT AGE FROM CUSTMR WHERE ID < :id", params);
|
||||
|
||||
assertEquals("All rows returned", 0, li.size());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(0);
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -131,9 +128,8 @@ public class NamedParameterQueryTests {
|
||||
List<Map<String, Object>> li = template.queryForList(
|
||||
"SELECT AGE FROM CUSTMR WHERE ID < :id", params);
|
||||
|
||||
assertEquals("All rows returned", 1, li.size());
|
||||
assertEquals("First row is Integer", 11,
|
||||
((Integer) li.get(0).get("age")).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(1);
|
||||
assertThat(((Integer) li.get(0).get("age")).intValue()).as("First row is Integer").isEqualTo(11);
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -150,8 +146,8 @@ public class NamedParameterQueryTests {
|
||||
List<Integer> li = template.queryForList("SELECT AGE FROM CUSTMR WHERE ID < :id",
|
||||
params, Integer.class);
|
||||
|
||||
assertEquals("All rows returned", 1, li.size());
|
||||
assertEquals("First row is Integer", 11, li.get(0).intValue());
|
||||
assertThat(li.size()).as("All rows returned").isEqualTo(1);
|
||||
assertThat(li.get(0).intValue()).as("First row is Integer").isEqualTo(11);
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -166,7 +162,7 @@ public class NamedParameterQueryTests {
|
||||
params.addValue("id", 3);
|
||||
Map<String, Object> map = template.queryForMap("SELECT AGE FROM CUSTMR WHERE ID < :id", params);
|
||||
|
||||
assertEquals("Row is Integer", 11, ((Integer) map.get("age")).intValue());
|
||||
assertThat(((Integer) map.get("age")).intValue()).as("Row is Integer").isEqualTo(11);
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -186,7 +182,8 @@ public class NamedParameterQueryTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue("Correct result type", o instanceof Integer);
|
||||
boolean condition = o instanceof Integer;
|
||||
assertThat(condition).as("Correct result type").isTrue();
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -202,7 +199,8 @@ public class NamedParameterQueryTests {
|
||||
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
|
||||
params, Integer.class);
|
||||
|
||||
assertTrue("Correct result type", o instanceof Integer);
|
||||
boolean condition = o instanceof Integer;
|
||||
assertThat(condition).as("Correct result type").isTrue();
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -218,7 +216,8 @@ public class NamedParameterQueryTests {
|
||||
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
|
||||
params, Integer.class);
|
||||
|
||||
assertTrue("Correct result type", o instanceof Integer);
|
||||
boolean condition = o instanceof Integer;
|
||||
assertThat(condition).as("Correct result type").isTrue();
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -235,7 +234,8 @@ public class NamedParameterQueryTests {
|
||||
params.addValue("ids", Arrays.asList(3, 4));
|
||||
Object o = template.queryForObject(sql, params, Integer.class);
|
||||
|
||||
assertTrue("Correct result type", o instanceof Integer);
|
||||
boolean condition = o instanceof Integer;
|
||||
assertThat(condition).as("Correct result type").isTrue();
|
||||
verify(connection).prepareStatement(sqlToUse);
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -255,7 +255,8 @@ public class NamedParameterQueryTests {
|
||||
"SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN (:multiExpressionList)",
|
||||
params, Integer.class);
|
||||
|
||||
assertTrue("Correct result type", o instanceof Integer);
|
||||
boolean condition = o instanceof Integer;
|
||||
assertThat(condition).as("Correct result type").isTrue();
|
||||
verify(connection).prepareStatement(
|
||||
"SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN ((?, ?), (?, ?))");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
@@ -271,7 +272,7 @@ public class NamedParameterQueryTests {
|
||||
params.addValue("id", 3);
|
||||
int i = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id", params, Integer.class).intValue();
|
||||
|
||||
assertEquals("Return of an int", 22, i);
|
||||
assertThat(i).as("Return of an int").isEqualTo(22);
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
}
|
||||
@@ -285,7 +286,7 @@ public class NamedParameterQueryTests {
|
||||
BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(new ParameterBean(3));
|
||||
long l = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id", params, Long.class).longValue();
|
||||
|
||||
assertEquals("Return of a long", 87, l);
|
||||
assertThat(l).as("Return of a long").isEqualTo(87);
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
||||
verify(preparedStatement).setObject(1, 3, Types.INTEGER);
|
||||
}
|
||||
@@ -299,7 +300,7 @@ public class NamedParameterQueryTests {
|
||||
BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(new ParameterCollectionBean(3, 5));
|
||||
long l = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID IN (:ids)", params, Long.class).longValue();
|
||||
|
||||
assertEquals("Return of a long", 87, l);
|
||||
assertThat(l).as("Return of a long").isEqualTo(87);
|
||||
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID IN (?, ?)");
|
||||
verify(preparedStatement).setObject(1, 3);
|
||||
verify(preparedStatement).setObject(2, 5);
|
||||
|
||||
@@ -24,9 +24,8 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
@@ -40,34 +39,33 @@ public class NamedParameterUtilsTests {
|
||||
public void parseSql() {
|
||||
String sql = "xxx :a yyyy :b :c :a zzzzz";
|
||||
ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals("xxx ? yyyy ? ? ? zzzzz", NamedParameterUtils.substituteNamedParameters(psql, null));
|
||||
assertEquals("a", psql.getParameterNames().get(0));
|
||||
assertEquals("c", psql.getParameterNames().get(2));
|
||||
assertEquals("a", psql.getParameterNames().get(3));
|
||||
assertEquals(4, psql.getTotalParameterCount());
|
||||
assertEquals(3, psql.getNamedParameterCount());
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(psql, null)).isEqualTo("xxx ? yyyy ? ? ? zzzzz");
|
||||
assertThat(psql.getParameterNames().get(0)).isEqualTo("a");
|
||||
assertThat(psql.getParameterNames().get(2)).isEqualTo("c");
|
||||
assertThat(psql.getParameterNames().get(3)).isEqualTo("a");
|
||||
assertThat(psql.getTotalParameterCount()).isEqualTo(4);
|
||||
assertThat(psql.getNamedParameterCount()).isEqualTo(3);
|
||||
|
||||
String sql2 = "xxx &a yyyy ? zzzzz";
|
||||
ParsedSql psql2 = NamedParameterUtils.parseSqlStatement(sql2);
|
||||
assertEquals("xxx ? yyyy ? zzzzz", NamedParameterUtils.substituteNamedParameters(psql2, null));
|
||||
assertEquals("a", psql2.getParameterNames().get(0));
|
||||
assertEquals(2, psql2.getTotalParameterCount());
|
||||
assertEquals(1, psql2.getNamedParameterCount());
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(psql2, null)).isEqualTo("xxx ? yyyy ? zzzzz");
|
||||
assertThat(psql2.getParameterNames().get(0)).isEqualTo("a");
|
||||
assertThat(psql2.getTotalParameterCount()).isEqualTo(2);
|
||||
assertThat(psql2.getNamedParameterCount()).isEqualTo(1);
|
||||
|
||||
String sql3 = "xxx &ä+:ö" + '\t' + ":ü%10 yyyy ? zzzzz";
|
||||
ParsedSql psql3 = NamedParameterUtils.parseSqlStatement(sql3);
|
||||
assertEquals("ä", psql3.getParameterNames().get(0));
|
||||
assertEquals("ö", psql3.getParameterNames().get(1));
|
||||
assertEquals("ü", psql3.getParameterNames().get(2));
|
||||
assertThat(psql3.getParameterNames().get(0)).isEqualTo("ä");
|
||||
assertThat(psql3.getParameterNames().get(1)).isEqualTo("ö");
|
||||
assertThat(psql3.getParameterNames().get(2)).isEqualTo("ü");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void substituteNamedParameters() {
|
||||
MapSqlParameterSource namedParams = new MapSqlParameterSource();
|
||||
namedParams.addValue("a", "a").addValue("b", "b").addValue("c", "c");
|
||||
assertEquals("xxx ? ? ?", NamedParameterUtils.substituteNamedParameters("xxx :a :b :c", namedParams));
|
||||
assertEquals("xxx ? ? ? xx ? ?",
|
||||
NamedParameterUtils.substituteNamedParameters("xxx :a :b :c xx :a :a", namedParams));
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters("xxx :a :b :c", namedParams)).isEqualTo("xxx ? ? ?");
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters("xxx :a :b :c xx :a :a", namedParams)).isEqualTo("xxx ? ? ? xx ? ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,10 +74,10 @@ public class NamedParameterUtilsTests {
|
||||
paramMap.put("a", "a");
|
||||
paramMap.put("b", "b");
|
||||
paramMap.put("c", "c");
|
||||
assertSame(3, NamedParameterUtils.buildValueArray("xxx :a :b :c", paramMap).length);
|
||||
assertSame(5, NamedParameterUtils.buildValueArray("xxx :a :b :c xx :a :b", paramMap).length);
|
||||
assertSame(5, NamedParameterUtils.buildValueArray("xxx :a :a :a xx :a :a", paramMap).length);
|
||||
assertEquals("b", NamedParameterUtils.buildValueArray("xxx :a :b :c xx :a :b", paramMap)[4]);
|
||||
assertThat(NamedParameterUtils.buildValueArray("xxx :a :b :c", paramMap).length).isSameAs(3);
|
||||
assertThat(NamedParameterUtils.buildValueArray("xxx :a :b :c xx :a :b", paramMap).length).isSameAs(5);
|
||||
assertThat(NamedParameterUtils.buildValueArray("xxx :a :a :a xx :a :a", paramMap).length).isSameAs(5);
|
||||
assertThat(NamedParameterUtils.buildValueArray("xxx :a :b :c xx :a :b", paramMap)[4]).isEqualTo("b");
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).as("mixed named parameters and ? placeholders").isThrownBy(() ->
|
||||
NamedParameterUtils.buildValueArray("xxx :a :b ?", paramMap));
|
||||
}
|
||||
@@ -88,30 +86,30 @@ public class NamedParameterUtilsTests {
|
||||
public void convertTypeMapToArray() {
|
||||
MapSqlParameterSource namedParams = new MapSqlParameterSource();
|
||||
namedParams.addValue("a", "a", 1).addValue("b", "b", 2).addValue("c", "c", 3);
|
||||
assertSame(3, NamedParameterUtils
|
||||
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c"), namedParams).length);
|
||||
assertSame(5, NamedParameterUtils
|
||||
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams).length);
|
||||
assertSame(5, NamedParameterUtils
|
||||
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :a :a xx :a :a"), namedParams).length);
|
||||
assertEquals(2, NamedParameterUtils
|
||||
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams)[4]);
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c"), namedParams).length).isSameAs(3);
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams).length).isSameAs(5);
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :a :a xx :a :a"), namedParams).length).isSameAs(5);
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams)[4]).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertTypeMapToSqlParameterList() {
|
||||
MapSqlParameterSource namedParams = new MapSqlParameterSource();
|
||||
namedParams.addValue("a", "a", 1).addValue("b", "b", 2).addValue("c", "c", 3, "SQL_TYPE");
|
||||
assertSame(3, NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c"), namedParams).size());
|
||||
assertSame(5, NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams).size());
|
||||
assertSame(5, NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :a :a xx :a :a"), namedParams).size());
|
||||
assertEquals(2, NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams).get(4).getSqlType());
|
||||
assertEquals("SQL_TYPE", NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c"), namedParams).get(2).getTypeName());
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c"), namedParams).size()).isSameAs(3);
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams).size()).isSameAs(5);
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :a :a xx :a :a"), namedParams).size()).isSameAs(5);
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams).get(4).getSqlType()).isEqualTo(2);
|
||||
assertThat(NamedParameterUtils
|
||||
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c"), namedParams).get(2).getTypeName()).isEqualTo("SQL_TYPE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +124,7 @@ public class NamedParameterUtilsTests {
|
||||
String expectedSql = "select 'first name' from artists where id = ? and quote = 'exsqueeze me?'";
|
||||
String sql = "select 'first name' from artists where id = :id and quote = 'exsqueeze me?'";
|
||||
String newSql = NamedParameterUtils.substituteNamedParameters(sql, new MapSqlParameterSource());
|
||||
assertEquals(expectedSql, newSql);
|
||||
assertThat(newSql).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,41 +132,37 @@ public class NamedParameterUtilsTests {
|
||||
String expectedSql = "select 'first name' from artists where id = ? and quote = 'exsqueeze me?'";
|
||||
String sql = "select 'first name' from artists where id = :id and quote = 'exsqueeze me?'";
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(expectedSql, NamedParameterUtils.substituteNamedParameters(parsedSql, null));
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(parsedSql, null)).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-4789
|
||||
public void parseSqlContainingComments() {
|
||||
String sql1 = "/*+ HINT */ xxx /* comment ? */ :a yyyy :b :c :a zzzzz -- :xx XX\n";
|
||||
ParsedSql psql1 = NamedParameterUtils.parseSqlStatement(sql1);
|
||||
assertEquals("/*+ HINT */ xxx /* comment ? */ ? yyyy ? ? ? zzzzz -- :xx XX\n",
|
||||
NamedParameterUtils.substituteNamedParameters(psql1, null));
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(psql1, null)).isEqualTo("/*+ HINT */ xxx /* comment ? */ ? yyyy ? ? ? zzzzz -- :xx XX\n");
|
||||
MapSqlParameterSource paramMap = new MapSqlParameterSource();
|
||||
paramMap.addValue("a", "a");
|
||||
paramMap.addValue("b", "b");
|
||||
paramMap.addValue("c", "c");
|
||||
Object[] params = NamedParameterUtils.buildValueArray(psql1, paramMap, null);
|
||||
assertEquals(4, params.length);
|
||||
assertEquals("a", params[0]);
|
||||
assertEquals("b", params[1]);
|
||||
assertEquals("c", params[2]);
|
||||
assertEquals("a", params[3]);
|
||||
assertThat(params.length).isEqualTo(4);
|
||||
assertThat(params[0]).isEqualTo("a");
|
||||
assertThat(params[1]).isEqualTo("b");
|
||||
assertThat(params[2]).isEqualTo("c");
|
||||
assertThat(params[3]).isEqualTo("a");
|
||||
|
||||
String sql2 = "/*+ HINT */ xxx /* comment ? */ :a yyyy :b :c :a zzzzz -- :xx XX";
|
||||
ParsedSql psql2 = NamedParameterUtils.parseSqlStatement(sql2);
|
||||
assertEquals("/*+ HINT */ xxx /* comment ? */ ? yyyy ? ? ? zzzzz -- :xx XX",
|
||||
NamedParameterUtils.substituteNamedParameters(psql2, null));
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(psql2, null)).isEqualTo("/*+ HINT */ xxx /* comment ? */ ? yyyy ? ? ? zzzzz -- :xx XX");
|
||||
|
||||
String sql3 = "/*+ HINT */ xxx /* comment ? */ :a yyyy :b :c :a zzzzz /* :xx XX*";
|
||||
ParsedSql psql3 = NamedParameterUtils.parseSqlStatement(sql3);
|
||||
assertEquals("/*+ HINT */ xxx /* comment ? */ ? yyyy ? ? ? zzzzz /* :xx XX*",
|
||||
NamedParameterUtils.substituteNamedParameters(psql3, null));
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(psql3, null)).isEqualTo("/*+ HINT */ xxx /* comment ? */ ? yyyy ? ? ? zzzzz /* :xx XX*");
|
||||
|
||||
String sql4 = "/*+ HINT */ xxx /* comment :a ? */ :a yyyy :b :c :a zzzzz /* :xx XX*";
|
||||
ParsedSql psql4 = NamedParameterUtils.parseSqlStatement(sql4);
|
||||
Map<String, String> parameters = Collections.singletonMap("a", "0");
|
||||
assertEquals("/*+ HINT */ xxx /* comment :a ? */ ? yyyy ? ? ? zzzzz /* :xx XX*",
|
||||
NamedParameterUtils.substituteNamedParameters(psql4, new MapSqlParameterSource(parameters)));
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(psql4, new MapSqlParameterSource(parameters))).isEqualTo("/*+ HINT */ xxx /* comment :a ? */ ? yyyy ? ? ? zzzzz /* :xx XX*");
|
||||
}
|
||||
|
||||
@Test // SPR-4612
|
||||
@@ -176,7 +170,7 @@ public class NamedParameterUtilsTests {
|
||||
String expectedSql = "select 'first name' from artists where id = ? and birth_date=?::timestamp";
|
||||
String sql = "select 'first name' from artists where id = :id and birth_date=:birthDate::timestamp";
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(expectedSql, NamedParameterUtils.substituteNamedParameters(parsedSql, null));
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(parsedSql, null)).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-13582
|
||||
@@ -184,8 +178,8 @@ public class NamedParameterUtilsTests {
|
||||
String expectedSql = "select 'first name' from artists where info->'stat'->'albums' = ?? ? and '[\"1\",\"2\",\"3\"]'::jsonb ?? '4'";
|
||||
String sql = "select 'first name' from artists where info->'stat'->'albums' = ?? :album and '[\"1\",\"2\",\"3\"]'::jsonb ?? '4'";
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(1, parsedSql.getTotalParameterCount());
|
||||
assertEquals(expectedSql, NamedParameterUtils.substituteNamedParameters(parsedSql, null));
|
||||
assertThat(parsedSql.getTotalParameterCount()).isEqualTo(1);
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(parsedSql, null)).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-15382
|
||||
@@ -194,8 +188,8 @@ public class NamedParameterUtilsTests {
|
||||
String sql = "select '[\"3\", \"11\"]'::jsonb ?| '{1,3,11,12,17}'::text[]";
|
||||
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(0, parsedSql.getTotalParameterCount());
|
||||
assertEquals(expectedSql, NamedParameterUtils.substituteNamedParameters(parsedSql, null));
|
||||
assertThat(parsedSql.getTotalParameterCount()).isEqualTo(0);
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(parsedSql, null)).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-15382
|
||||
@@ -204,8 +198,8 @@ public class NamedParameterUtilsTests {
|
||||
String sql = "select '[\"3\", \"11\"]'::jsonb ?& '{1,3,11,12,17}'::text[] AND :album = 'Back in Black'";
|
||||
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(1, parsedSql.getTotalParameterCount());
|
||||
assertEquals(expectedSql, NamedParameterUtils.substituteNamedParameters(parsedSql, null));
|
||||
assertThat(parsedSql.getTotalParameterCount()).isEqualTo(1);
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(parsedSql, null)).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-7476
|
||||
@@ -214,11 +208,11 @@ public class NamedParameterUtilsTests {
|
||||
String sql = "select '0\\:0' as a, foo from bar where baz < DATE(:p1 23\\:59\\:59) and baz = :p2";
|
||||
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(2, parsedSql.getParameterNames().size());
|
||||
assertEquals("p1", parsedSql.getParameterNames().get(0));
|
||||
assertEquals("p2", parsedSql.getParameterNames().get(1));
|
||||
assertThat(parsedSql.getParameterNames().size()).isEqualTo(2);
|
||||
assertThat(parsedSql.getParameterNames().get(0)).isEqualTo("p1");
|
||||
assertThat(parsedSql.getParameterNames().get(1)).isEqualTo("p2");
|
||||
String finalSql = NamedParameterUtils.substituteNamedParameters(parsedSql, null);
|
||||
assertEquals(expectedSql, finalSql);
|
||||
assertThat(finalSql).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-7476
|
||||
@@ -227,11 +221,11 @@ public class NamedParameterUtilsTests {
|
||||
String sql = "select foo from bar where baz = b:{p1}:{p2}z";
|
||||
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(2, parsedSql.getParameterNames().size());
|
||||
assertEquals("p1", parsedSql.getParameterNames().get(0));
|
||||
assertEquals("p2", parsedSql.getParameterNames().get(1));
|
||||
assertThat(parsedSql.getParameterNames().size()).isEqualTo(2);
|
||||
assertThat(parsedSql.getParameterNames().get(0)).isEqualTo("p1");
|
||||
assertThat(parsedSql.getParameterNames().get(1)).isEqualTo("p2");
|
||||
String finalSql = NamedParameterUtils.substituteNamedParameters(parsedSql, null);
|
||||
assertEquals(expectedSql, finalSql);
|
||||
assertThat(finalSql).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-7476
|
||||
@@ -239,17 +233,17 @@ public class NamedParameterUtilsTests {
|
||||
String expectedSql = "select foo from bar where baz = b:{}z";
|
||||
String sql = "select foo from bar where baz = b:{}z";
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(0, parsedSql.getParameterNames().size());
|
||||
assertThat(parsedSql.getParameterNames().size()).isEqualTo(0);
|
||||
String finalSql = NamedParameterUtils.substituteNamedParameters(parsedSql, null);
|
||||
assertEquals(expectedSql, finalSql);
|
||||
assertThat(finalSql).isEqualTo(expectedSql);
|
||||
|
||||
String expectedSql2 = "select foo from bar where baz = 'b:{p1}z'";
|
||||
String sql2 = "select foo from bar where baz = 'b:{p1}z'";
|
||||
|
||||
ParsedSql parsedSql2 = NamedParameterUtils.parseSqlStatement(sql2);
|
||||
assertEquals(0, parsedSql2.getParameterNames().size());
|
||||
assertThat(parsedSql2.getParameterNames().size()).isEqualTo(0);
|
||||
String finalSql2 = NamedParameterUtils.substituteNamedParameters(parsedSql2, null);
|
||||
assertEquals(expectedSql2, finalSql2);
|
||||
assertThat(finalSql2).isEqualTo(expectedSql2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,55 +252,55 @@ public class NamedParameterUtilsTests {
|
||||
String sql = "select foo from bar where baz = b:{p}z";
|
||||
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(1, parsedSql.getParameterNames().size());
|
||||
assertEquals("p", parsedSql.getParameterNames().get(0));
|
||||
assertThat(parsedSql.getParameterNames().size()).isEqualTo(1);
|
||||
assertThat(parsedSql.getParameterNames().get(0)).isEqualTo("p");
|
||||
String finalSql = NamedParameterUtils.substituteNamedParameters(parsedSql, null);
|
||||
assertEquals(expectedSql, finalSql);
|
||||
assertThat(finalSql).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-2544
|
||||
public void parseSqlStatementWithLogicalAnd() {
|
||||
String expectedSql = "xxx & yyyy";
|
||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(expectedSql);
|
||||
assertEquals(expectedSql, NamedParameterUtils.substituteNamedParameters(parsedSql, null));
|
||||
assertThat(NamedParameterUtils.substituteNamedParameters(parsedSql, null)).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-2544
|
||||
public void substituteNamedParametersWithLogicalAnd() {
|
||||
String expectedSql = "xxx & yyyy";
|
||||
String newSql = NamedParameterUtils.substituteNamedParameters(expectedSql, new MapSqlParameterSource());
|
||||
assertEquals(expectedSql, newSql);
|
||||
assertThat(newSql).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-3173
|
||||
public void variableAssignmentOperator() {
|
||||
String expectedSql = "x := 1";
|
||||
String newSql = NamedParameterUtils.substituteNamedParameters(expectedSql, new MapSqlParameterSource());
|
||||
assertEquals(expectedSql, newSql);
|
||||
assertThat(newSql).isEqualTo(expectedSql);
|
||||
}
|
||||
|
||||
@Test // SPR-8280
|
||||
public void parseSqlStatementWithQuotedSingleQuote() {
|
||||
String sql = "SELECT ':foo'':doo', :xxx FROM DUAL";
|
||||
ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(1, psql.getTotalParameterCount());
|
||||
assertEquals("xxx", psql.getParameterNames().get(0));
|
||||
assertThat(psql.getTotalParameterCount()).isEqualTo(1);
|
||||
assertThat(psql.getParameterNames().get(0)).isEqualTo("xxx");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSqlStatementWithQuotesAndCommentBefore() {
|
||||
String sql = "SELECT /*:doo*/':foo', :xxx FROM DUAL";
|
||||
ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertEquals(1, psql.getTotalParameterCount());
|
||||
assertEquals("xxx", psql.getParameterNames().get(0));
|
||||
assertThat(psql.getTotalParameterCount()).isEqualTo(1);
|
||||
assertThat(psql.getParameterNames().get(0)).isEqualTo("xxx");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSqlStatementWithQuotesAndCommentAfter() {
|
||||
String sql2 = "SELECT ':foo'/*:doo*/, :xxx FROM DUAL";
|
||||
ParsedSql psql2 = NamedParameterUtils.parseSqlStatement(sql2);
|
||||
assertEquals(1, psql2.getTotalParameterCount());
|
||||
assertEquals("xxx", psql2.getParameterNames().get(0));
|
||||
assertThat(psql2.getTotalParameterCount()).isEqualTo(1);
|
||||
assertThat(psql2.getParameterNames().get(0)).isEqualTo("xxx");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.core.metadata.CallMetaDataContext;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -94,16 +93,17 @@ public class CallMetaDataContextTests {
|
||||
context.processParameters(parameters);
|
||||
|
||||
Map<String, Object> inParameters = context.matchInParameterValuesWithCallParameters(parameterSource);
|
||||
assertEquals("Wrong number of matched in parameter values", 2, inParameters.size());
|
||||
assertTrue("in parameter value missing", inParameters.containsKey("id"));
|
||||
assertTrue("in out parameter value missing", inParameters.containsKey("name"));
|
||||
assertTrue("out parameter value matched", !inParameters.containsKey("customer_no"));
|
||||
assertThat(inParameters.size()).as("Wrong number of matched in parameter values").isEqualTo(2);
|
||||
assertThat(inParameters.containsKey("id")).as("in parameter value missing").isTrue();
|
||||
assertThat(inParameters.containsKey("name")).as("in out parameter value missing").isTrue();
|
||||
boolean condition = !inParameters.containsKey("customer_no");
|
||||
assertThat(condition).as("out parameter value matched").isTrue();
|
||||
|
||||
List<String> names = context.getOutParameterNames();
|
||||
assertEquals("Wrong number of out parameters", 2, names.size());
|
||||
assertThat(names.size()).as("Wrong number of out parameters").isEqualTo(2);
|
||||
|
||||
List<SqlParameter> callParameters = context.getCallParameters();
|
||||
assertEquals("Wrong number of call parameters", 3, callParameters.size());
|
||||
assertThat(callParameters.size()).as("Wrong number of call parameters").isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ import org.springframework.jdbc.core.SqlOutParameter;
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -110,7 +110,7 @@ public class SimpleJdbcCallTests {
|
||||
Number newId = adder.executeObject(Number.class, new MapSqlParameterSource().
|
||||
addValue("amount", 1103).
|
||||
addValue("custid", 3));
|
||||
assertEquals(4, newId.intValue());
|
||||
assertThat(newId.intValue()).isEqualTo(4);
|
||||
verifyAddInvoiceWithoutMetaData(false);
|
||||
verify(connection, atLeastOnce()).close();
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public class SimpleJdbcCallTests {
|
||||
new SqlParameter("custid", Types.INTEGER),
|
||||
new SqlOutParameter("newid", Types.INTEGER));
|
||||
Number newId = adder.executeObject(Number.class, 1103, 3);
|
||||
assertEquals(4, newId.intValue());
|
||||
assertThat(newId.intValue()).isEqualTo(4);
|
||||
verifyAddInvoiceWithoutMetaData(false);
|
||||
verify(connection, atLeastOnce()).close();
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public class SimpleJdbcCallTests {
|
||||
Number newId = adder.executeObject(Number.class, new MapSqlParameterSource()
|
||||
.addValue("amount", 1103)
|
||||
.addValue("custid", 3));
|
||||
assertEquals(4, newId.intValue());
|
||||
assertThat(newId.intValue()).isEqualTo(4);
|
||||
verifyAddInvoiceWithMetaData(false);
|
||||
verify(connection, atLeastOnce()).close();
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public class SimpleJdbcCallTests {
|
||||
initializeAddInvoiceWithMetaData(false);
|
||||
SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withProcedureName("add_invoice");
|
||||
Number newId = adder.executeObject(Number.class, 1103, 3);
|
||||
assertEquals(4, newId.intValue());
|
||||
assertThat(newId.intValue()).isEqualTo(4);
|
||||
verifyAddInvoiceWithMetaData(false);
|
||||
verify(connection, atLeastOnce()).close();
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class SimpleJdbcCallTests {
|
||||
Number newId = adder.executeFunction(Number.class, new MapSqlParameterSource()
|
||||
.addValue("amount", 1103)
|
||||
.addValue("custid", 3));
|
||||
assertEquals(4, newId.intValue());
|
||||
assertThat(newId.intValue()).isEqualTo(4);
|
||||
verifyAddInvoiceWithoutMetaData(true);
|
||||
verify(connection, atLeastOnce()).close();
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public class SimpleJdbcCallTests {
|
||||
new SqlParameter("amount", Types.INTEGER),
|
||||
new SqlParameter("custid", Types.INTEGER));
|
||||
Number newId = adder.executeFunction(Number.class, 1103, 3);
|
||||
assertEquals(4, newId.intValue());
|
||||
assertThat(newId.intValue()).isEqualTo(4);
|
||||
verifyAddInvoiceWithoutMetaData(true);
|
||||
verify(connection, atLeastOnce()).close();
|
||||
}
|
||||
@@ -188,7 +188,7 @@ public class SimpleJdbcCallTests {
|
||||
Number newId = adder.executeFunction(Number.class, new MapSqlParameterSource()
|
||||
.addValue("amount", 1103)
|
||||
.addValue("custid", 3));
|
||||
assertEquals(4, newId.intValue());
|
||||
assertThat(newId.intValue()).isEqualTo(4);
|
||||
verifyAddInvoiceWithMetaData(true);
|
||||
verify(connection, atLeastOnce()).close();
|
||||
|
||||
@@ -199,7 +199,7 @@ public class SimpleJdbcCallTests {
|
||||
initializeAddInvoiceWithMetaData(true);
|
||||
SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice");
|
||||
Number newId = adder.executeFunction(Number.class, 1103, 3);
|
||||
assertEquals(4, newId.intValue());
|
||||
assertThat(newId.intValue()).isEqualTo(4);
|
||||
verifyAddInvoiceWithMetaData(true);
|
||||
verify(connection, atLeastOnce()).close();
|
||||
|
||||
@@ -231,7 +231,7 @@ public class SimpleJdbcCallTests {
|
||||
|
||||
|
||||
private void verifyStatement(SimpleJdbcCall adder, String expected) {
|
||||
assertEquals("Incorrect call statement", expected, adder.getCallString());
|
||||
assertThat(adder.getCallString()).as("Incorrect call statement").isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void initializeAddInvoiceWithoutMetaData(boolean isFunction) throws SQLException {
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.jdbc.core.SqlParameterValue;
|
||||
import org.springframework.jdbc.core.metadata.TableMetaDataContext;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -106,13 +105,15 @@ public class TableMetaDataContextTests {
|
||||
|
||||
List<Object> values = context.matchInParameterValuesWithInsertColumns(map);
|
||||
|
||||
assertEquals("wrong number of parameters: ", 4, values.size());
|
||||
assertTrue("id not wrapped with type info", values.get(0) instanceof Number);
|
||||
assertTrue("name not wrapped with type info", values.get(1) instanceof String);
|
||||
assertTrue("date wrapped with type info",
|
||||
values.get(2) instanceof SqlParameterValue);
|
||||
assertTrue("version wrapped with type info",
|
||||
values.get(3) instanceof SqlParameterValue);
|
||||
assertThat(values.size()).as("wrong number of parameters: ").isEqualTo(4);
|
||||
boolean condition3 = values.get(0) instanceof Number;
|
||||
assertThat(condition3).as("id not wrapped with type info").isTrue();
|
||||
boolean condition2 = values.get(1) instanceof String;
|
||||
assertThat(condition2).as("name not wrapped with type info").isTrue();
|
||||
boolean condition1 = values.get(2) instanceof SqlParameterValue;
|
||||
assertThat(condition1).as("date wrapped with type info").isTrue();
|
||||
boolean condition = values.get(3) instanceof SqlParameterValue;
|
||||
assertThat(condition).as("version wrapped with type info").isTrue();
|
||||
verify(metaDataResultSet, atLeastOnce()).next();
|
||||
verify(columnsResultSet, atLeastOnce()).next();
|
||||
verify(metaDataResultSet).close();
|
||||
@@ -150,8 +151,8 @@ public class TableMetaDataContextTests {
|
||||
List<Object> values = context.matchInParameterValuesWithInsertColumns(map);
|
||||
String insertString = context.createInsertString(keyCols);
|
||||
|
||||
assertEquals("wrong number of parameters: ", 0, values.size());
|
||||
assertEquals("empty insert not generated correctly", "INSERT INTO customers () VALUES()", insertString);
|
||||
assertThat(values.size()).as("wrong number of parameters: ").isEqualTo(0);
|
||||
assertThat(insertString).as("empty insert not generated correctly").isEqualTo("INSERT INTO customers () VALUES()");
|
||||
verify(metaDataResultSet, atLeastOnce()).next();
|
||||
verify(columnsResultSet, atLeastOnce()).next();
|
||||
verify(metaDataResultSet).close();
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -58,9 +58,9 @@ public class JdbcBeanDefinitionReaderTests {
|
||||
JdbcBeanDefinitionReader reader = new JdbcBeanDefinitionReader(bf);
|
||||
reader.setDataSource(dataSource);
|
||||
reader.loadBeanDefinitions(sql);
|
||||
assertEquals("Incorrect number of bean definitions", 1, bf.getBeanDefinitionCount());
|
||||
assertThat(bf.getBeanDefinitionCount()).as("Incorrect number of bean definitions").isEqualTo(1);
|
||||
TestBean tb = (TestBean) bf.getBean("one");
|
||||
assertEquals("Age in TestBean was wrong.", 53, tb.getAge());
|
||||
assertThat(tb.getAge()).as("Age in TestBean was wrong.").isEqualTo(53);
|
||||
|
||||
verify(resultSet).close();
|
||||
verify(statement).close();
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -45,9 +45,9 @@ public class JdbcDaoSupportTests {
|
||||
};
|
||||
dao.setDataSource(ds);
|
||||
dao.afterPropertiesSet();
|
||||
assertEquals("Correct DataSource", ds, dao.getDataSource());
|
||||
assertEquals("Correct JdbcTemplate", ds, dao.getJdbcTemplate().getDataSource());
|
||||
assertEquals("initDao called", 1, test.size());
|
||||
assertThat(dao.getDataSource()).as("Correct DataSource").isEqualTo(ds);
|
||||
assertThat(dao.getJdbcTemplate().getDataSource()).as("Correct JdbcTemplate").isEqualTo(ds);
|
||||
assertThat(test.size()).as("initDao called").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,8 +62,8 @@ public class JdbcDaoSupportTests {
|
||||
};
|
||||
dao.setJdbcTemplate(template);
|
||||
dao.afterPropertiesSet();
|
||||
assertEquals("Correct JdbcTemplate", dao.getJdbcTemplate(), template);
|
||||
assertEquals("initDao called", 1, test.size());
|
||||
assertThat(template).as("Correct JdbcTemplate").isEqualTo(dao.getJdbcTemplate());
|
||||
assertThat(test.size()).as("initDao called").isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,9 +29,8 @@ import org.springframework.jdbc.LobRetrievalFailureException;
|
||||
import org.springframework.jdbc.support.lob.LobCreator;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -65,8 +64,8 @@ public class LobSupportTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertEquals(Integer.valueOf(3), psc.doInPreparedStatement(ps));
|
||||
assertTrue(svc.b);
|
||||
assertThat(psc.doInPreparedStatement(ps)).isEqualTo(Integer.valueOf(3));
|
||||
assertThat(svc.b).isTrue();
|
||||
verify(creator).close();
|
||||
verify(handler).getLobCreator();
|
||||
verify(ps).executeUpdate();
|
||||
|
||||
@@ -46,11 +46,8 @@ import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
@@ -83,12 +80,12 @@ public class DataSourceJtaTransactionTests {
|
||||
|
||||
@After
|
||||
public void verifyTransactionSynchronizationManagerState() {
|
||||
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
|
||||
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertNull(TransactionSynchronizationManager.getCurrentTransactionName());
|
||||
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
|
||||
assertNull(TransactionSynchronizationManager.getCurrentTransactionIsolationLevel());
|
||||
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
|
||||
assertThat(TransactionSynchronizationManager.getResourceMap().isEmpty()).isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();
|
||||
assertThat(TransactionSynchronizationManager.getCurrentTransactionName()).isNull();
|
||||
assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
|
||||
assertThat(TransactionSynchronizationManager.getCurrentTransactionIsolationLevel()).isNull();
|
||||
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,22 +110,25 @@ public class DataSourceJtaTransactionTests {
|
||||
|
||||
JtaTransactionManager ptm = new JtaTransactionManager(userTransaction);
|
||||
TransactionTemplate tt = new TransactionTemplate(ptm);
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
|
||||
boolean condition3 = !TransactionSynchronizationManager.hasResource(dataSource);
|
||||
assertThat(condition3).as("Hasn't thread connection").isTrue();
|
||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||
assertThat(condition2).as("JTA synchronizations not active").isTrue();
|
||||
|
||||
tt.execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertTrue("Is new transaction", status.isNewTransaction());
|
||||
boolean condition = !TransactionSynchronizationManager.hasResource(dataSource);
|
||||
assertThat(condition).as("Hasn't thread connection").isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).as("JTA synchronizations active").isTrue();
|
||||
assertThat(status.isNewTransaction()).as("Is new transaction").isTrue();
|
||||
|
||||
Connection c = DataSourceUtils.getConnection(dataSource);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dataSource)).as("Has thread connection").isTrue();
|
||||
DataSourceUtils.releaseConnection(c, dataSource);
|
||||
|
||||
c = DataSourceUtils.getConnection(dataSource);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dataSource)).as("Has thread connection").isTrue();
|
||||
DataSourceUtils.releaseConnection(c, dataSource);
|
||||
|
||||
if (rollback) {
|
||||
@@ -137,8 +137,10 @@ public class DataSourceJtaTransactionTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
|
||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(dataSource);
|
||||
assertThat(condition1).as("Hasn't thread connection").isTrue();
|
||||
boolean condition = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||
assertThat(condition).as("JTA synchronizations not active").isTrue();
|
||||
verify(userTransaction).begin();
|
||||
if (rollback) {
|
||||
verify(userTransaction).rollback();
|
||||
@@ -218,24 +220,27 @@ public class DataSourceJtaTransactionTests {
|
||||
JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
|
||||
final TransactionTemplate tt = new TransactionTemplate(ptm);
|
||||
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
|
||||
boolean condition3 = !TransactionSynchronizationManager.hasResource(dsToUse);
|
||||
assertThat(condition3).as("Hasn't thread connection").isTrue();
|
||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||
assertThat(condition2).as("JTA synchronizations not active").isTrue();
|
||||
|
||||
tt.execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertTrue("Is new transaction", status.isNewTransaction());
|
||||
boolean condition = !TransactionSynchronizationManager.hasResource(dsToUse);
|
||||
assertThat(condition).as("Hasn't thread connection").isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).as("JTA synchronizations active").isTrue();
|
||||
assertThat(status.isNewTransaction()).as("Is new transaction").isTrue();
|
||||
|
||||
Connection c = DataSourceUtils.getConnection(dsToUse);
|
||||
try {
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
c.isReadOnly();
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
|
||||
c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
if (!openOuterConnection) {
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
@@ -248,18 +253,19 @@ public class DataSourceJtaTransactionTests {
|
||||
tt.execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertTrue("Is new transaction", status.isNewTransaction());
|
||||
boolean condition = !TransactionSynchronizationManager.hasResource(dsToUse);
|
||||
assertThat(condition).as("Hasn't thread connection").isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).as("JTA synchronizations active").isTrue();
|
||||
assertThat(status.isNewTransaction()).as("Is new transaction").isTrue();
|
||||
|
||||
try {
|
||||
Connection c = DataSourceUtils.getConnection(dsToUse);
|
||||
c.isReadOnly();
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
|
||||
c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
@@ -278,12 +284,12 @@ public class DataSourceJtaTransactionTests {
|
||||
if (!openOuterConnection) {
|
||||
c = DataSourceUtils.getConnection(dsToUse);
|
||||
}
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
c.isReadOnly();
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
|
||||
c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
@@ -298,8 +304,10 @@ public class DataSourceJtaTransactionTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
|
||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(dsToUse);
|
||||
assertThat(condition1).as("Hasn't thread connection").isTrue();
|
||||
boolean condition = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||
assertThat(condition).as("JTA synchronizations not active").isTrue();
|
||||
verify(userTransaction, times(6)).begin();
|
||||
verify(transactionManager, times(5)).resume(transaction);
|
||||
if (rollback) {
|
||||
@@ -366,15 +374,15 @@ public class DataSourceJtaTransactionTests {
|
||||
tt.setPropagationBehavior(notSupported ?
|
||||
TransactionDefinition.PROPAGATION_NOT_SUPPORTED : TransactionDefinition.PROPAGATION_SUPPORTS);
|
||||
|
||||
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();
|
||||
tt.execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
|
||||
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
|
||||
assertSame(connection1, DataSourceUtils.getConnection(dataSource));
|
||||
assertSame(connection1, DataSourceUtils.getConnection(dataSource));
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
|
||||
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isFalse();
|
||||
assertThat(DataSourceUtils.getConnection(dataSource)).isSameAs(connection1);
|
||||
assertThat(DataSourceUtils.getConnection(dataSource)).isSameAs(connection1);
|
||||
|
||||
TransactionTemplate tt2 = new TransactionTemplate(ptm);
|
||||
tt2.setPropagationBehavior(requiresNew ?
|
||||
@@ -382,21 +390,21 @@ public class DataSourceJtaTransactionTests {
|
||||
tt2.execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
|
||||
assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
|
||||
assertSame(connection2, DataSourceUtils.getConnection(dataSource));
|
||||
assertSame(connection2, DataSourceUtils.getConnection(dataSource));
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
|
||||
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
|
||||
assertThat(DataSourceUtils.getConnection(dataSource)).isSameAs(connection2);
|
||||
assertThat(DataSourceUtils.getConnection(dataSource)).isSameAs(connection2);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
|
||||
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
|
||||
assertSame(connection1, DataSourceUtils.getConnection(dataSource));
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
|
||||
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isFalse();
|
||||
assertThat(DataSourceUtils.getConnection(dataSource)).isSameAs(connection1);
|
||||
}
|
||||
});
|
||||
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();
|
||||
verify(userTransaction).begin();
|
||||
verify(userTransaction).commit();
|
||||
if (notSupported) {
|
||||
@@ -472,26 +480,29 @@ public class DataSourceJtaTransactionTests {
|
||||
JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
|
||||
final TransactionTemplate tt = new TransactionTemplate(ptm);
|
||||
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
|
||||
boolean condition3 = !TransactionSynchronizationManager.hasResource(dsToUse);
|
||||
assertThat(condition3).as("Hasn't thread connection").isTrue();
|
||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||
assertThat(condition2).as("JTA synchronizations not active").isTrue();
|
||||
|
||||
assertThatExceptionOfType(TransactionException.class).isThrownBy(() ->
|
||||
tt.execute(new TransactionCallbackWithoutResult() {
|
||||
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertTrue("Is new transaction", status.isNewTransaction());
|
||||
boolean condition = !TransactionSynchronizationManager.hasResource(dsToUse);
|
||||
assertThat(condition).as("Hasn't thread connection").isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).as("JTA synchronizations active").isTrue();
|
||||
assertThat(status.isNewTransaction()).as("Is new transaction").isTrue();
|
||||
|
||||
Connection c = DataSourceUtils.getConnection(dsToUse);
|
||||
try {
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
c.isReadOnly();
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
|
||||
c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
if (!openOuterConnection) {
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
@@ -503,16 +514,17 @@ public class DataSourceJtaTransactionTests {
|
||||
tt.execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertTrue("Is new transaction", status.isNewTransaction());
|
||||
boolean condition = !TransactionSynchronizationManager.hasResource(dsToUse);
|
||||
assertThat(condition).as("Hasn't thread connection").isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).as("JTA synchronizations active").isTrue();
|
||||
assertThat(status.isNewTransaction()).as("Is new transaction").isTrue();
|
||||
|
||||
Connection c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
|
||||
c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
});
|
||||
@@ -530,8 +542,10 @@ public class DataSourceJtaTransactionTests {
|
||||
}
|
||||
}));
|
||||
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
|
||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(dsToUse);
|
||||
assertThat(condition1).as("Hasn't thread connection").isTrue();
|
||||
boolean condition = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||
assertThat(condition).as("JTA synchronizations not active").isTrue();
|
||||
|
||||
verify(userTransaction).begin();
|
||||
if (suspendException) {
|
||||
@@ -572,8 +586,10 @@ public class DataSourceJtaTransactionTests {
|
||||
}
|
||||
};
|
||||
TransactionTemplate tt = new TransactionTemplate(ptm);
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
|
||||
boolean condition2 = !TransactionSynchronizationManager.hasResource(dataSource);
|
||||
assertThat(condition2).as("Hasn't thread connection").isTrue();
|
||||
boolean condition1 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||
assertThat(condition1).as("JTA synchronizations not active").isTrue();
|
||||
|
||||
given(userTransaction.getStatus()).willReturn(Status.STATUS_ACTIVE);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -582,15 +598,16 @@ public class DataSourceJtaTransactionTests {
|
||||
tt.execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
|
||||
assertTrue("Is existing transaction", !status.isNewTransaction());
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).as("JTA synchronizations active").isTrue();
|
||||
boolean condition = !status.isNewTransaction();
|
||||
assertThat(condition).as("Is existing transaction").isTrue();
|
||||
|
||||
Connection c = DataSourceUtils.getConnection(dataSource);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dataSource)).as("Has thread connection").isTrue();
|
||||
DataSourceUtils.releaseConnection(c, dataSource);
|
||||
|
||||
c = DataSourceUtils.getConnection(dataSource);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dataSource)).as("Has thread connection").isTrue();
|
||||
if (releaseCon) {
|
||||
DataSourceUtils.releaseConnection(c, dataSource);
|
||||
}
|
||||
@@ -598,12 +615,14 @@ public class DataSourceJtaTransactionTests {
|
||||
});
|
||||
|
||||
if (!releaseCon) {
|
||||
assertTrue("Still has connection holder", TransactionSynchronizationManager.hasResource(dataSource));
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dataSource)).as("Still has connection holder").isTrue();
|
||||
}
|
||||
else {
|
||||
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dataSource));
|
||||
boolean condition = !TransactionSynchronizationManager.hasResource(dataSource);
|
||||
assertThat(condition).as("Hasn't thread connection").isTrue();
|
||||
}
|
||||
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
|
||||
boolean condition = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||
assertThat(condition).as("JTA synchronizations not active").isTrue();
|
||||
}
|
||||
verify(connection, times(3)).close();
|
||||
}
|
||||
@@ -630,8 +649,8 @@ public class DataSourceJtaTransactionTests {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
Connection c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertSame(connection, c);
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
assertThat(c).isSameAs(connection);
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
});
|
||||
@@ -642,8 +661,8 @@ public class DataSourceJtaTransactionTests {
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
Connection c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertSame(connection, c);
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
assertThat(c).isSameAs(connection);
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
});
|
||||
@@ -701,8 +720,8 @@ given( userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, St
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
Connection c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertSame(connection1, c);
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
assertThat(c).isSameAs(connection1);
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
});
|
||||
@@ -712,8 +731,8 @@ given( userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, St
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
|
||||
Connection c = DataSourceUtils.getConnection(dsToUse);
|
||||
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
|
||||
assertSame(connection2, c);
|
||||
assertThat(TransactionSynchronizationManager.hasResource(dsToUse)).as("Has thread connection").isTrue();
|
||||
assertThat(c).isSameAs(connection2);
|
||||
DataSourceUtils.releaseConnection(c, dsToUse);
|
||||
}
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,9 +21,8 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -42,9 +41,9 @@ public class DriverManagerDataSourceTests {
|
||||
class TestDriverManagerDataSource extends DriverManagerDataSource {
|
||||
@Override
|
||||
protected Connection getConnectionFromDriverManager(String url, Properties props) {
|
||||
assertEquals(jdbcUrl, url);
|
||||
assertEquals(uname, props.getProperty("user"));
|
||||
assertEquals(pwd, props.getProperty("password"));
|
||||
assertThat(url).isEqualTo(jdbcUrl);
|
||||
assertThat(props.getProperty("user")).isEqualTo(uname);
|
||||
assertThat(props.getProperty("password")).isEqualTo(pwd);
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
@@ -56,11 +55,11 @@ public class DriverManagerDataSourceTests {
|
||||
ds.setPassword(pwd);
|
||||
|
||||
Connection actualCon = ds.getConnection();
|
||||
assertTrue(actualCon == connection);
|
||||
assertThat(actualCon == connection).isTrue();
|
||||
|
||||
assertTrue(ds.getUrl().equals(jdbcUrl));
|
||||
assertTrue(ds.getPassword().equals(pwd));
|
||||
assertTrue(ds.getUsername().equals(uname));
|
||||
assertThat(ds.getUrl().equals(jdbcUrl)).isTrue();
|
||||
assertThat(ds.getPassword().equals(pwd)).isTrue();
|
||||
assertThat(ds.getUsername().equals(uname)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,11 +75,11 @@ public class DriverManagerDataSourceTests {
|
||||
class TestDriverManagerDataSource extends DriverManagerDataSource {
|
||||
@Override
|
||||
protected Connection getConnectionFromDriverManager(String url, Properties props) {
|
||||
assertEquals(jdbcUrl, url);
|
||||
assertEquals("uname", props.getProperty("user"));
|
||||
assertEquals("pwd", props.getProperty("password"));
|
||||
assertEquals("myValue", props.getProperty("myProp"));
|
||||
assertEquals("yourValue", props.getProperty("yourProp"));
|
||||
assertThat(url).isEqualTo(jdbcUrl);
|
||||
assertThat(props.getProperty("user")).isEqualTo("uname");
|
||||
assertThat(props.getProperty("password")).isEqualTo("pwd");
|
||||
assertThat(props.getProperty("myProp")).isEqualTo("myValue");
|
||||
assertThat(props.getProperty("yourProp")).isEqualTo("yourValue");
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
@@ -91,9 +90,9 @@ public class DriverManagerDataSourceTests {
|
||||
ds.setConnectionProperties(connProps);
|
||||
|
||||
Connection actualCon = ds.getConnection();
|
||||
assertTrue(actualCon == connection);
|
||||
assertThat(actualCon == connection).isTrue();
|
||||
|
||||
assertTrue(ds.getUrl().equals(jdbcUrl));
|
||||
assertThat(ds.getUrl().equals(jdbcUrl)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,11 +110,11 @@ public class DriverManagerDataSourceTests {
|
||||
class TestDriverManagerDataSource extends DriverManagerDataSource {
|
||||
@Override
|
||||
protected Connection getConnectionFromDriverManager(String url, Properties props) {
|
||||
assertEquals(jdbcUrl, url);
|
||||
assertEquals(uname, props.getProperty("user"));
|
||||
assertEquals(pwd, props.getProperty("password"));
|
||||
assertEquals("myValue", props.getProperty("myProp"));
|
||||
assertEquals("yourValue", props.getProperty("yourProp"));
|
||||
assertThat(url).isEqualTo(jdbcUrl);
|
||||
assertThat(props.getProperty("user")).isEqualTo(uname);
|
||||
assertThat(props.getProperty("password")).isEqualTo(pwd);
|
||||
assertThat(props.getProperty("myProp")).isEqualTo("myValue");
|
||||
assertThat(props.getProperty("yourProp")).isEqualTo("yourValue");
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
@@ -128,11 +127,11 @@ public class DriverManagerDataSourceTests {
|
||||
ds.setConnectionProperties(connProps);
|
||||
|
||||
Connection actualCon = ds.getConnection();
|
||||
assertTrue(actualCon == connection);
|
||||
assertThat(actualCon == connection).isTrue();
|
||||
|
||||
assertTrue(ds.getUrl().equals(jdbcUrl));
|
||||
assertTrue(ds.getPassword().equals(pwd));
|
||||
assertTrue(ds.getUsername().equals(uname));
|
||||
assertThat(ds.getUrl().equals(jdbcUrl)).isTrue();
|
||||
assertThat(ds.getPassword().equals(pwd)).isTrue();
|
||||
assertThat(ds.getUsername().equals(uname)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,7 +22,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||
adapter.setTargetDataSource(dataSource);
|
||||
adapter.setUsername("user");
|
||||
adapter.setPassword("pw");
|
||||
assertEquals(connection, adapter.getConnection());
|
||||
assertThat(adapter.getConnection()).isEqualTo(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,7 +52,7 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
||||
adapter.setTargetDataSource(dataSource);
|
||||
assertEquals(connection, adapter.getConnection());
|
||||
assertThat(adapter.getConnection()).isEqualTo(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,7 +66,7 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||
|
||||
adapter.setCredentialsForCurrentThread("user", "pw");
|
||||
try {
|
||||
assertEquals(connection, adapter.getConnection());
|
||||
assertThat(adapter.getConnection()).isEqualTo(connection);
|
||||
}
|
||||
finally {
|
||||
adapter.removeCredentialsFromCurrentThread();
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.init.CannotReadScriptException;
|
||||
import org.springframework.jdbc.datasource.init.ScriptStatementFailedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType.DERBY;
|
||||
import static org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType.H2;
|
||||
|
||||
@@ -205,7 +205,7 @@ public class EmbeddedDatabaseBuilderTests {
|
||||
}
|
||||
|
||||
private void assertNumRowsInTestTable(JdbcTemplate template, int count) {
|
||||
assertEquals(count, template.queryForObject("select count(*) from T_TEST", Integer.class).intValue());
|
||||
assertThat(template.queryForObject("select count(*) from T_TEST", Integer.class).intValue()).isEqualTo(count);
|
||||
}
|
||||
|
||||
private void assertDatabaseCreated(EmbeddedDatabase db) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
@@ -48,7 +48,7 @@ public class EmbeddedDatabaseFactoryBeanTests {
|
||||
bean.afterPropertiesSet();
|
||||
DataSource ds = bean.getObject();
|
||||
JdbcTemplate template = new JdbcTemplate(ds);
|
||||
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
|
||||
assertThat(template.queryForObject("select NAME from T_TEST", String.class)).isEqualTo("Keith");
|
||||
bean.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.jdbc.datasource.init.DatabasePopulator;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
@@ -37,7 +37,7 @@ public class EmbeddedDatabaseFactoryTests {
|
||||
StubDatabasePopulator populator = new StubDatabasePopulator();
|
||||
factory.setDatabasePopulator(populator);
|
||||
EmbeddedDatabase db = factory.getDatabase();
|
||||
assertTrue(populator.populateCalled);
|
||||
assertThat(populator.populateCalled).isTrue();
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -190,7 +189,7 @@ public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseIni
|
||||
}
|
||||
|
||||
private void assertTestDatabaseCreated(String name) {
|
||||
assertEquals(name, jdbcTemplate.queryForObject("select NAME from T_TEST", String.class));
|
||||
assertThat(jdbcTemplate.queryForObject("select NAME from T_TEST", String.class)).isEqualTo(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ResourceDatabasePopulator}.
|
||||
@@ -53,22 +53,22 @@ public class ResourceDatabasePopulatorTests {
|
||||
@Test
|
||||
public void constructWithResource() {
|
||||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1);
|
||||
assertEquals(1, databasePopulator.scripts.size());
|
||||
assertThat(databasePopulator.scripts.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructWithMultipleResources() {
|
||||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2);
|
||||
assertEquals(2, databasePopulator.scripts.size());
|
||||
assertThat(databasePopulator.scripts.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructWithMultipleResourcesAndThenAddScript() {
|
||||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2);
|
||||
assertEquals(2, databasePopulator.scripts.size());
|
||||
assertThat(databasePopulator.scripts.size()).isEqualTo(2);
|
||||
|
||||
databasePopulator.addScript(script3);
|
||||
assertEquals(3, databasePopulator.scripts.size());
|
||||
assertThat(databasePopulator.scripts.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,13 +102,13 @@ public class ResourceDatabasePopulatorTests {
|
||||
@Test
|
||||
public void setScriptsAndThenAddScript() {
|
||||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
|
||||
assertEquals(0, databasePopulator.scripts.size());
|
||||
assertThat(databasePopulator.scripts.size()).isEqualTo(0);
|
||||
|
||||
databasePopulator.setScripts(script1, script2);
|
||||
assertEquals(2, databasePopulator.scripts.size());
|
||||
assertThat(databasePopulator.scripts.size()).isEqualTo(2);
|
||||
|
||||
databasePopulator.addScript(script3);
|
||||
assertEquals(3, databasePopulator.scripts.size());
|
||||
assertThat(databasePopulator.scripts.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_STATEMENT_SEPARATOR;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.containsSqlScriptDelimiters;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.splitSqlScript;
|
||||
@@ -56,10 +54,10 @@ public class ScriptUtilsUnitTests {
|
||||
String script = rawStatement1 + delim + rawStatement2 + delim + rawStatement3 + delim;
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(script, delim, statements);
|
||||
assertEquals("wrong number of statements", 3, statements.size());
|
||||
assertEquals("statement 1 not split correctly", cleanedStatement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", cleanedStatement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", cleanedStatement3, statements.get(2));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(3);
|
||||
assertThat(statements.get(0)).as("statement 1 not split correctly").isEqualTo(cleanedStatement1);
|
||||
assertThat(statements.get(1)).as("statement 2 not split correctly").isEqualTo(cleanedStatement2);
|
||||
assertThat(statements.get(2)).as("statement 3 not split correctly").isEqualTo(cleanedStatement3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,10 +69,10 @@ public class ScriptUtilsUnitTests {
|
||||
String script = statement1 + delim + statement2 + delim + statement3 + delim;
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(script, delim, statements);
|
||||
assertEquals("wrong number of statements", 3, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(3);
|
||||
assertThat(statements.get(0)).as("statement 1 not split correctly").isEqualTo(statement1);
|
||||
assertThat(statements.get(1)).as("statement 2 not split correctly").isEqualTo(statement2);
|
||||
assertThat(statements.get(2)).as("statement 3 not split correctly").isEqualTo(statement3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,9 +83,8 @@ public class ScriptUtilsUnitTests {
|
||||
String script = statement1 + delim + statement2 + delim;
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(script, DEFAULT_STATEMENT_SEPARATOR, statements);
|
||||
assertEquals("wrong number of statements", 1, statements.size());
|
||||
assertEquals("script should have been 'stripped' but not actually 'split'", script.replace('\n', ' '),
|
||||
statements.get(0));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(1);
|
||||
assertThat(statements.get(0)).as("script should have been 'stripped' but not actually 'split'").isEqualTo(script.replace('\n', ' '));
|
||||
}
|
||||
|
||||
@Test // SPR-13218
|
||||
@@ -98,9 +95,9 @@ public class ScriptUtilsUnitTests {
|
||||
String script = statement1 + delim + statement2 + delim;
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(script, ';', statements);
|
||||
assertEquals("wrong number of statements", 2, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(2);
|
||||
assertThat(statements.get(0)).as("statement 1 not split correctly").isEqualTo(statement1);
|
||||
assertThat(statements.get(1)).as("statement 2 not split correctly").isEqualTo(statement2);
|
||||
}
|
||||
|
||||
@Test // SPR-11560
|
||||
@@ -112,9 +109,9 @@ public class ScriptUtilsUnitTests {
|
||||
String statement1 = "insert into T_TEST (NAME) values ('Keith')";
|
||||
String statement2 = "insert into T_TEST (NAME) values ('Dave')";
|
||||
|
||||
assertEquals("wrong number of statements", 2, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(2);
|
||||
assertThat(statements.get(0)).as("statement 1 not split correctly").isEqualTo(statement1);
|
||||
assertThat(statements.get(1)).as("statement 2 not split correctly").isEqualTo(statement2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,11 +126,11 @@ public class ScriptUtilsUnitTests {
|
||||
// Statement 4 addresses the error described in SPR-9982.
|
||||
String statement4 = "INSERT INTO persons( person_id , name) VALUES( 1 , 'Name' )";
|
||||
|
||||
assertEquals("wrong number of statements", 4, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
|
||||
assertEquals("statement 4 not split correctly", statement4, statements.get(3));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(4);
|
||||
assertThat(statements.get(0)).as("statement 1 not split correctly").isEqualTo(statement1);
|
||||
assertThat(statements.get(1)).as("statement 2 not split correctly").isEqualTo(statement2);
|
||||
assertThat(statements.get(2)).as("statement 3 not split correctly").isEqualTo(statement3);
|
||||
assertThat(statements.get(3)).as("statement 4 not split correctly").isEqualTo(statement4);
|
||||
}
|
||||
|
||||
@Test // SPR-10330
|
||||
@@ -146,10 +143,10 @@ public class ScriptUtilsUnitTests {
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) values (2, '2013-06-08', 1)";
|
||||
|
||||
assertEquals("wrong number of statements", 3, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(3);
|
||||
assertThat(statements.get(0)).as("statement 1 not split correctly").isEqualTo(statement1);
|
||||
assertThat(statements.get(1)).as("statement 2 not split correctly").isEqualTo(statement2);
|
||||
assertThat(statements.get(2)).as("statement 3 not split correctly").isEqualTo(statement3);
|
||||
}
|
||||
|
||||
@Test // SPR-9531
|
||||
@@ -161,9 +158,9 @@ public class ScriptUtilsUnitTests {
|
||||
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')";
|
||||
String statement2 = "INSERT INTO users(first_name, last_name) VALUES( 'Sam' , 'Brannen' )";
|
||||
|
||||
assertEquals("wrong number of statements", 2, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(2);
|
||||
assertThat(statements.get(0)).as("statement 1 not split correctly").isEqualTo(statement1);
|
||||
assertThat(statements.get(1)).as("statement 2 not split correctly").isEqualTo(statement2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,25 +172,25 @@ public class ScriptUtilsUnitTests {
|
||||
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')";
|
||||
String statement2 = "INSERT INTO users(first_name, last_name) VALUES( 'Sam' , 'Brannen' )";
|
||||
|
||||
assertEquals("wrong number of statements", 2, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertThat(statements.size()).as("wrong number of statements").isEqualTo(2);
|
||||
assertThat(statements.get(0)).as("statement 1 not split correctly").isEqualTo(statement1);
|
||||
assertThat(statements.get(1)).as("statement 2 not split correctly").isEqualTo(statement2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsDelimiters() {
|
||||
assertFalse(containsSqlScriptDelimiters("select 1\n select ';'", ";"));
|
||||
assertTrue(containsSqlScriptDelimiters("select 1; select 2", ";"));
|
||||
assertThat(containsSqlScriptDelimiters("select 1\n select ';'", ";")).isFalse();
|
||||
assertThat(containsSqlScriptDelimiters("select 1; select 2", ";")).isTrue();
|
||||
|
||||
assertFalse(containsSqlScriptDelimiters("select 1; select '\\n\n';", "\n"));
|
||||
assertTrue(containsSqlScriptDelimiters("select 1\n select 2", "\n"));
|
||||
assertThat(containsSqlScriptDelimiters("select 1; select '\\n\n';", "\n")).isFalse();
|
||||
assertThat(containsSqlScriptDelimiters("select 1\n select 2", "\n")).isTrue();
|
||||
|
||||
assertFalse(containsSqlScriptDelimiters("select 1\n select 2", "\n\n"));
|
||||
assertTrue(containsSqlScriptDelimiters("select 1\n\n select 2", "\n\n"));
|
||||
assertThat(containsSqlScriptDelimiters("select 1\n select 2", "\n\n")).isFalse();
|
||||
assertThat(containsSqlScriptDelimiters("select 1\n\n select 2", "\n\n")).isTrue();
|
||||
|
||||
// MySQL style escapes '\\'
|
||||
assertFalse(containsSqlScriptDelimiters("insert into users(first_name, last_name)\nvalues('a\\\\', 'b;')", ";"));
|
||||
assertTrue(containsSqlScriptDelimiters("insert into users(first_name, last_name)\nvalues('Charles', 'd\\'Artagnan'); select 1;", ";"));
|
||||
assertThat(containsSqlScriptDelimiters("insert into users(first_name, last_name)\nvalues('a\\\\', 'b;')", ";")).isFalse();
|
||||
assertThat(containsSqlScriptDelimiters("insert into users(first_name, last_name)\nvalues('Charles', 'd\\'Artagnan'); select 1;", ";")).isTrue();
|
||||
}
|
||||
|
||||
private String readScript(String path) throws Exception {
|
||||
|
||||
@@ -23,10 +23,9 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -50,9 +49,9 @@ public class BeanFactoryDataSourceLookupTests {
|
||||
BeanFactoryDataSourceLookup lookup = new BeanFactoryDataSourceLookup();
|
||||
lookup.setBeanFactory(beanFactory);
|
||||
DataSource dataSource = lookup.getDataSource(DATASOURCE_BEAN_NAME);
|
||||
assertNotNull("A DataSourceLookup implementation must *never* return null from " +
|
||||
"getDataSource(): this one obviously (and incorrectly) is", dataSource);
|
||||
assertSame(expectedDataSource, dataSource);
|
||||
assertThat(dataSource).as("A DataSourceLookup implementation must *never* return null from " +
|
||||
"getDataSource(): this one obviously (and incorrectly) is").isNotNull();
|
||||
assertThat(dataSource).isSameAs(expectedDataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,10 +21,8 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
@@ -40,13 +38,13 @@ public class JndiDataSourceLookupTests {
|
||||
JndiDataSourceLookup lookup = new JndiDataSourceLookup() {
|
||||
@Override
|
||||
protected <T> T lookup(String jndiName, Class<T> requiredType) {
|
||||
assertEquals(DATA_SOURCE_NAME, jndiName);
|
||||
assertThat(jndiName).isEqualTo(DATA_SOURCE_NAME);
|
||||
return requiredType.cast(expectedDataSource);
|
||||
}
|
||||
};
|
||||
DataSource dataSource = lookup.getDataSource(DATA_SOURCE_NAME);
|
||||
assertNotNull("A DataSourceLookup implementation must *never* return null from getDataSource(): this one obviously (and incorrectly) is", dataSource);
|
||||
assertSame(expectedDataSource, dataSource);
|
||||
assertThat(dataSource).as("A DataSourceLookup implementation must *never* return null from getDataSource(): this one obviously (and incorrectly) is").isNotNull();
|
||||
assertThat(dataSource).isSameAs(expectedDataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +52,7 @@ public class JndiDataSourceLookupTests {
|
||||
JndiDataSourceLookup lookup = new JndiDataSourceLookup() {
|
||||
@Override
|
||||
protected <T> T lookup(String jndiName, Class<T> requiredType) throws NamingException {
|
||||
assertEquals(DATA_SOURCE_NAME, jndiName);
|
||||
assertThat(jndiName).isEqualTo(DATA_SOURCE_NAME);
|
||||
throw new NamingException();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,9 +22,8 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
@@ -53,8 +52,8 @@ public class MapDataSourceLookupTests {
|
||||
MapDataSourceLookup lookup = new MapDataSourceLookup();
|
||||
lookup.setDataSources(dataSources);
|
||||
DataSource dataSource = lookup.getDataSource(DATA_SOURCE_NAME);
|
||||
assertNotNull("A DataSourceLookup implementation must *never* return null from getDataSource(): this one obviously (and incorrectly) is", dataSource);
|
||||
assertSame(expectedDataSource, dataSource);
|
||||
assertThat(dataSource).as("A DataSourceLookup implementation must *never* return null from getDataSource(): this one obviously (and incorrectly) is").isNotNull();
|
||||
assertThat(dataSource).isSameAs(expectedDataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,8 +65,8 @@ public class MapDataSourceLookupTests {
|
||||
lookup.setDataSources(dataSources);
|
||||
lookup.setDataSources(null); // must be idempotent (i.e. the following lookup must still work);
|
||||
DataSource dataSource = lookup.getDataSource(DATA_SOURCE_NAME);
|
||||
assertNotNull("A DataSourceLookup implementation must *never* return null from getDataSource(): this one obviously (and incorrectly) is", dataSource);
|
||||
assertSame(expectedDataSource, dataSource);
|
||||
assertThat(dataSource).as("A DataSourceLookup implementation must *never* return null from getDataSource(): this one obviously (and incorrectly) is").isNotNull();
|
||||
assertThat(dataSource).isSameAs(expectedDataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,8 +79,8 @@ public class MapDataSourceLookupTests {
|
||||
lookup.setDataSources(dataSources);
|
||||
lookup.addDataSource(DATA_SOURCE_NAME, expectedDataSource); // must override existing entry
|
||||
DataSource dataSource = lookup.getDataSource(DATA_SOURCE_NAME);
|
||||
assertNotNull("A DataSourceLookup implementation must *never* return null from getDataSource(): this one obviously (and incorrectly) is", dataSource);
|
||||
assertSame(expectedDataSource, dataSource);
|
||||
assertThat(dataSource).as("A DataSourceLookup implementation must *never* return null from getDataSource(): this one obviously (and incorrectly) is").isNotNull();
|
||||
assertThat(dataSource).isSameAs(expectedDataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -76,33 +75,33 @@ public class BatchSqlUpdateTests {
|
||||
update.update(ids[1]);
|
||||
|
||||
if (flushThroughBatchSize) {
|
||||
assertEquals(0, update.getQueueCount());
|
||||
assertEquals(2, update.getRowsAffected().length);
|
||||
assertThat(update.getQueueCount()).isEqualTo(0);
|
||||
assertThat(update.getRowsAffected().length).isEqualTo(2);
|
||||
}
|
||||
else {
|
||||
assertEquals(2, update.getQueueCount());
|
||||
assertEquals(0, update.getRowsAffected().length);
|
||||
assertThat(update.getQueueCount()).isEqualTo(2);
|
||||
assertThat(update.getRowsAffected().length).isEqualTo(0);
|
||||
}
|
||||
|
||||
int[] actualRowsAffected = update.flush();
|
||||
assertEquals(0, update.getQueueCount());
|
||||
assertThat(update.getQueueCount()).isEqualTo(0);
|
||||
|
||||
if (flushThroughBatchSize) {
|
||||
assertTrue("flush did not execute updates", actualRowsAffected.length == 0);
|
||||
assertThat(actualRowsAffected.length == 0).as("flush did not execute updates").isTrue();
|
||||
}
|
||||
else {
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
}
|
||||
|
||||
actualRowsAffected = update.getRowsAffected();
|
||||
assertTrue("executed 2 updates", actualRowsAffected.length == 2);
|
||||
assertEquals(rowsAffected[0], actualRowsAffected[0]);
|
||||
assertEquals(rowsAffected[1], actualRowsAffected[1]);
|
||||
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue();
|
||||
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]);
|
||||
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]);
|
||||
|
||||
update.reset();
|
||||
assertEquals(0, update.getRowsAffected().length);
|
||||
assertThat(update.getRowsAffected().length).isEqualTo(0);
|
||||
|
||||
verify(preparedStatement).setObject(1, ids[0], Types.INTEGER);
|
||||
verify(preparedStatement).setObject(1, ids[1], Types.INTEGER);
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.Customer;
|
||||
import org.springframework.jdbc.datasource.TestDataSourceWrapper;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -109,10 +109,10 @@ public class GenericSqlQueryTests {
|
||||
Object[] params = new Object[] {1, "UK"};
|
||||
queryResults = query.execute(params);
|
||||
}
|
||||
assertTrue("Customer was returned correctly", queryResults.size() == 1);
|
||||
assertThat(queryResults.size() == 1).as("Customer was returned correctly").isTrue();
|
||||
Customer cust = (Customer) queryResults.get(0);
|
||||
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
|
||||
assertThat(cust.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(cust.getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
|
||||
verify(resultSet).close();
|
||||
verify(preparedStatement).setObject(1, 1, Types.INTEGER);
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.datasource.TestDataSourceWrapper;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -64,7 +64,7 @@ public class GenericStoredProcedureTests {
|
||||
in.put("custid", 3);
|
||||
Map<String, Object> out = adder.execute(in);
|
||||
Integer id = (Integer) out.get("newid");
|
||||
assertEquals(4, id.intValue());
|
||||
assertThat(id.intValue()).isEqualTo(4);
|
||||
|
||||
verify(callableStatement).setObject(1, 1106, Types.INTEGER);
|
||||
verify(callableStatement).setObject(2, 3, Types.INTEGER);
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.jdbc.core.SqlOutParameter;
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Trevor Cook
|
||||
@@ -132,9 +132,9 @@ public class RdbmsOperationTests {
|
||||
operation.setFetchSize(10);
|
||||
operation.setMaxRows(20);
|
||||
JdbcTemplate jt = operation.getJdbcTemplate();
|
||||
assertEquals(ds, jt.getDataSource());
|
||||
assertEquals(10, jt.getFetchSize());
|
||||
assertEquals(20, jt.getMaxRows());
|
||||
assertThat(jt.getDataSource()).isEqualTo(ds);
|
||||
assertThat(jt.getFetchSize()).isEqualTo(10);
|
||||
assertThat(jt.getMaxRows()).isEqualTo(20);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,7 +156,7 @@ public class RdbmsOperationTests {
|
||||
new SqlParameter("two", Types.NUMERIC)});
|
||||
operation.afterPropertiesSet();
|
||||
operation.validateParameters(new Object[] { 1, "2" });
|
||||
assertEquals(2, operation.getDeclaredParameters().size());
|
||||
assertThat(operation.getDeclaredParameters().size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,8 +41,6 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -112,8 +110,8 @@ public class SqlQueryTests {
|
||||
@Override
|
||||
protected Integer mapRow(ResultSet rs, int rownum, @Nullable Object[] params, @Nullable Map<? ,?> context)
|
||||
throws SQLException {
|
||||
assertTrue("params were null", params == null);
|
||||
assertTrue("context was null", context == null);
|
||||
assertThat(params == null).as("params were null").isTrue();
|
||||
assertThat(context == null).as("context was null").isTrue();
|
||||
return rs.getInt(1);
|
||||
}
|
||||
};
|
||||
@@ -222,8 +220,8 @@ public class SqlQueryTests {
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
Customer cust = query.findCustomer(1, 1);
|
||||
|
||||
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
|
||||
assertThat(cust.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(cust.getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.NUMERIC);
|
||||
verify(connection).prepareStatement(SELECT_ID_WHERE);
|
||||
@@ -262,9 +260,8 @@ public class SqlQueryTests {
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
Customer cust = query.findCustomer("rod");
|
||||
|
||||
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly",
|
||||
cust.getForename().equals("rod"));
|
||||
assertThat(cust.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(cust.getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(preparedStatement).setString(1, "rod");
|
||||
verify(connection).prepareStatement(SELECT_ID_FORENAME_WHERE);
|
||||
verify(resultSet).close();
|
||||
@@ -309,11 +306,11 @@ public class SqlQueryTests {
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
|
||||
Customer cust1 = query.findCustomer(1, "rod");
|
||||
assertTrue("Found customer", cust1 != null);
|
||||
assertTrue("Customer id was assigned correctly", cust1.getId() == 1);
|
||||
assertThat(cust1 != null).as("Found customer").isTrue();
|
||||
assertThat(cust1.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
|
||||
Customer cust2 = query.findCustomer(1, "Roger");
|
||||
assertTrue("No customer found", cust2 == null);
|
||||
assertThat(cust2 == null).as("No customer found").isTrue();
|
||||
|
||||
verify(preparedStatement).setObject(1, 1, Types.INTEGER);
|
||||
verify(preparedStatement).setString(2, "rod");
|
||||
@@ -389,7 +386,7 @@ public class SqlQueryTests {
|
||||
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
List<Customer> list = query.execute(1, 1);
|
||||
assertTrue("2 results in list", list.size() == 2);
|
||||
assertThat(list.size() == 2).as("2 results in list").isTrue();
|
||||
assertThat(list.get(0).getForename()).isEqualTo("rod");
|
||||
assertThat(list.get(1).getForename()).isEqualTo("dave");
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
@@ -425,7 +422,7 @@ public class SqlQueryTests {
|
||||
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
List<Customer> list = query.execute("one");
|
||||
assertTrue("2 results in list", list.size() == 2);
|
||||
assertThat(list.size() == 2).as("2 results in list").isTrue();
|
||||
assertThat(list.get(0).getForename()).isEqualTo("rod");
|
||||
assertThat(list.get(1).getForename()).isEqualTo("dave");
|
||||
verify(preparedStatement).setString(1, "one");
|
||||
@@ -469,8 +466,8 @@ public class SqlQueryTests {
|
||||
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
Customer cust = query.findCustomer(1);
|
||||
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
|
||||
assertThat(cust.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(cust.getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(resultSet).close();
|
||||
verify(preparedStatement).close();
|
||||
@@ -565,8 +562,8 @@ public class SqlQueryTests {
|
||||
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
Customer cust = query.findCustomer(1, "UK");
|
||||
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
|
||||
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
|
||||
assertThat(cust.getId() == 1).as("Customer id was assigned correctly").isTrue();
|
||||
assertThat(cust.getForename().equals("rod")).as("Customer forename was assigned correctly").isTrue();
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setString(2, "UK");
|
||||
verify(resultSet).close();
|
||||
@@ -614,11 +611,11 @@ public class SqlQueryTests {
|
||||
ids.add(2);
|
||||
List<Customer> cust = query.findCustomers(ids);
|
||||
|
||||
assertEquals("We got two customers back", 2, cust.size());
|
||||
assertEquals("First customer id was assigned correctly", cust.get(0).getId(), 1);
|
||||
assertEquals("First customer forename was assigned correctly", cust.get(0).getForename(), "rod");
|
||||
assertEquals("Second customer id was assigned correctly", cust.get(1).getId(), 2);
|
||||
assertEquals("Second customer forename was assigned correctly", cust.get(1).getForename(), "juergen");
|
||||
assertThat(cust.size()).as("We got two customers back").isEqualTo(2);
|
||||
assertThat(1).as("First customer id was assigned correctly").isEqualTo(cust.get(0).getId());
|
||||
assertThat("rod").as("First customer forename was assigned correctly").isEqualTo(cust.get(0).getForename());
|
||||
assertThat(2).as("Second customer id was assigned correctly").isEqualTo(cust.get(1).getId());
|
||||
assertThat("juergen").as("Second customer forename was assigned correctly").isEqualTo(cust.get(1).getForename());
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 2, Types.NUMERIC);
|
||||
verify(resultSet).close();
|
||||
@@ -663,11 +660,11 @@ public class SqlQueryTests {
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
List<Customer> cust = query.findCustomers(1);
|
||||
|
||||
assertEquals("We got two customers back", 2, cust.size());
|
||||
assertEquals("First customer id was assigned correctly", cust.get(0).getId(), 1);
|
||||
assertEquals("First customer forename was assigned correctly", cust.get(0).getForename(), "rod");
|
||||
assertEquals("Second customer id was assigned correctly", cust.get(1).getId(), 2);
|
||||
assertEquals("Second customer forename was assigned correctly", cust.get(1).getForename(), "juergen");
|
||||
assertThat(cust.size()).as("We got two customers back").isEqualTo(2);
|
||||
assertThat(1).as("First customer id was assigned correctly").isEqualTo(cust.get(0).getId());
|
||||
assertThat("rod").as("First customer forename was assigned correctly").isEqualTo(cust.get(0).getForename());
|
||||
assertThat(2).as("Second customer id was assigned correctly").isEqualTo(cust.get(1).getId());
|
||||
assertThat("juergen").as("Second customer forename was assigned correctly").isEqualTo(cust.get(1).getForename());
|
||||
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.NUMERIC);
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.jdbc.support.KeyHolder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -105,7 +105,7 @@ public class SqlUpdateTests {
|
||||
Updater pc = new Updater();
|
||||
int rowsAffected = pc.run();
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,7 +116,7 @@ public class SqlUpdateTests {
|
||||
IntUpdater pc = new IntUpdater();
|
||||
int rowsAffected = pc.run(1);
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public class SqlUpdateTests {
|
||||
IntIntUpdater pc = new IntIntUpdater();
|
||||
int rowsAffected = pc.run(1, 1);
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.NUMERIC);
|
||||
}
|
||||
@@ -173,7 +173,7 @@ public class SqlUpdateTests {
|
||||
|
||||
NamedParameterUpdater pc = new NamedParameterUpdater();
|
||||
int rowsAffected = pc.run(1, 1);
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.DECIMAL);
|
||||
}
|
||||
@@ -186,7 +186,7 @@ public class SqlUpdateTests {
|
||||
StringUpdater pc = new StringUpdater();
|
||||
int rowsAffected = pc.run("rod");
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
verify(preparedStatement).setString(1, "rod");
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class SqlUpdateTests {
|
||||
MixedUpdater pc = new MixedUpdater();
|
||||
int rowsAffected = pc.run(1, 1, "rod", true);
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.NUMERIC, 2);
|
||||
verify(preparedStatement).setString(3, "rod");
|
||||
@@ -222,9 +222,9 @@ public class SqlUpdateTests {
|
||||
KeyHolder generatedKeyHolder = new GeneratedKeyHolder();
|
||||
int rowsAffected = pc.run("rod", generatedKeyHolder);
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertEquals(1, generatedKeyHolder.getKeyList().size());
|
||||
assertEquals(11, generatedKeyHolder.getKey().intValue());
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
assertThat(generatedKeyHolder.getKeyList().size()).isEqualTo(1);
|
||||
assertThat(generatedKeyHolder.getKey().intValue()).isEqualTo(11);
|
||||
verify(preparedStatement).setString(1, "rod");
|
||||
verify(resultSet).close();
|
||||
}
|
||||
@@ -237,7 +237,7 @@ public class SqlUpdateTests {
|
||||
|
||||
int rowsAffected = pc.run(1, 1, "rod", true);
|
||||
|
||||
assertEquals(1, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(1);
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setString(3, "rod");
|
||||
@@ -252,7 +252,7 @@ public class SqlUpdateTests {
|
||||
MaxRowsUpdater pc = new MaxRowsUpdater();
|
||||
|
||||
int rowsAffected = pc.run();
|
||||
assertEquals(3, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -263,7 +263,7 @@ public class SqlUpdateTests {
|
||||
MaxRowsUpdater pc = new MaxRowsUpdater();
|
||||
int rowsAffected = pc.run();
|
||||
|
||||
assertEquals(5, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -285,7 +285,7 @@ public class SqlUpdateTests {
|
||||
RequiredRowsUpdater pc = new RequiredRowsUpdater();
|
||||
int rowsAffected = pc.run();
|
||||
|
||||
assertEquals(3, rowsAffected);
|
||||
assertThat(rowsAffected).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -50,9 +50,8 @@ import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.startsWith;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -107,14 +106,14 @@ public class StoredProcedureTests {
|
||||
private void testAddInvoice(final int amount, final int custid) throws Exception {
|
||||
AddInvoice adder = new AddInvoice(dataSource);
|
||||
int id = adder.execute(amount, custid);
|
||||
assertEquals(4, id);
|
||||
assertThat(id).isEqualTo(4);
|
||||
}
|
||||
|
||||
private void testAddInvoiceUsingObjectArray(final int amount, final int custid)
|
||||
throws Exception {
|
||||
AddInvoiceUsingObjectArray adder = new AddInvoiceUsingObjectArray(dataSource);
|
||||
int id = adder.execute(amount, custid);
|
||||
assertEquals(5, id);
|
||||
assertThat(id).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,8 +194,8 @@ public class StoredProcedureTests {
|
||||
t.setExceptionTranslator(new SQLStateSQLExceptionTranslator());
|
||||
StoredProcedureConfiguredViaJdbcTemplate sp = new StoredProcedureConfiguredViaJdbcTemplate(t);
|
||||
|
||||
assertEquals(5, sp.execute(11));
|
||||
assertEquals(1, t.calls);
|
||||
assertThat(sp.execute(11)).isEqualTo(5);
|
||||
assertThat(t.calls).isEqualTo(1);
|
||||
|
||||
verify(callableStatement).setObject(1, 11, Types.INTEGER);
|
||||
verify(callableStatement).registerOutParameter(2, Types.INTEGER);
|
||||
@@ -215,7 +214,7 @@ public class StoredProcedureTests {
|
||||
JdbcTemplate t = new JdbcTemplate();
|
||||
t.setDataSource(dataSource);
|
||||
StoredProcedureConfiguredViaJdbcTemplate sp = new StoredProcedureConfiguredViaJdbcTemplate(t);
|
||||
assertEquals(4, sp.execute(1106));
|
||||
assertThat(sp.execute(1106)).isEqualTo(4);
|
||||
verify(callableStatement).setObject(1, 1106, Types.INTEGER);
|
||||
verify(callableStatement).registerOutParameter(2, Types.INTEGER);
|
||||
}
|
||||
@@ -270,7 +269,7 @@ public class StoredProcedureTests {
|
||||
).willReturn(callableStatement);
|
||||
StoredProcedureWithResultSet sproc = new StoredProcedureWithResultSet(dataSource);
|
||||
sproc.execute();
|
||||
assertEquals(2, sproc.getCount());
|
||||
assertThat(sproc.getCount()).isEqualTo(2);
|
||||
verify(resultSet).close();
|
||||
}
|
||||
|
||||
@@ -290,9 +289,9 @@ public class StoredProcedureTests {
|
||||
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(dataSource);
|
||||
Map<String, Object> res = sproc.execute();
|
||||
List<String> rs = (List<String>) res.get("rs");
|
||||
assertEquals(2, rs.size());
|
||||
assertEquals("Foo", rs.get(0));
|
||||
assertEquals("Bar", rs.get(1));
|
||||
assertThat(rs.size()).isEqualTo(2);
|
||||
assertThat(rs.get(0)).isEqualTo("Foo");
|
||||
assertThat(rs.get(1)).isEqualTo("Bar");
|
||||
verify(resultSet).close();
|
||||
}
|
||||
|
||||
@@ -325,23 +324,24 @@ public class StoredProcedureTests {
|
||||
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(dataSource);
|
||||
Map<String, Object> res = sproc.execute();
|
||||
|
||||
assertEquals("incorrect number of returns", 3, res.size());
|
||||
assertThat(res.size()).as("incorrect number of returns").isEqualTo(3);
|
||||
|
||||
List<String> rs1 = (List<String>) res.get("rs");
|
||||
assertEquals(2, rs1.size());
|
||||
assertEquals("Foo", rs1.get(0));
|
||||
assertEquals("Bar", rs1.get(1));
|
||||
assertThat(rs1.size()).isEqualTo(2);
|
||||
assertThat(rs1.get(0)).isEqualTo("Foo");
|
||||
assertThat(rs1.get(1)).isEqualTo("Bar");
|
||||
|
||||
List<Object> rs2 = (List<Object>) res.get("#result-set-2");
|
||||
assertEquals(1, rs2.size());
|
||||
assertThat(rs2.size()).isEqualTo(1);
|
||||
Object o2 = rs2.get(0);
|
||||
assertTrue("wron type returned for result set 2", o2 instanceof Map);
|
||||
boolean condition = o2 instanceof Map;
|
||||
assertThat(condition).as("wron type returned for result set 2").isTrue();
|
||||
Map<String, String> m2 = (Map<String, String>) o2;
|
||||
assertEquals("Spam", m2.get("spam"));
|
||||
assertEquals("Eggs", m2.get("eggs"));
|
||||
assertThat(m2.get("spam")).isEqualTo("Spam");
|
||||
assertThat(m2.get("eggs")).isEqualTo("Eggs");
|
||||
|
||||
Number n = (Number) res.get("#update-count-1");
|
||||
assertEquals("wrong update count", 0, n.intValue());
|
||||
assertThat(n.intValue()).as("wrong update count").isEqualTo(0);
|
||||
verify(resultSet1).close();
|
||||
verify(resultSet2).close();
|
||||
}
|
||||
@@ -357,7 +357,7 @@ public class StoredProcedureTests {
|
||||
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(
|
||||
jdbcTemplate);
|
||||
Map<String, Object> res = sproc.execute();
|
||||
assertEquals("incorrect number of returns", 0, res.size());
|
||||
assertThat(res.size()).as("incorrect number of returns").isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,11 +380,11 @@ public class StoredProcedureTests {
|
||||
jdbcTemplate);
|
||||
Map<String, Object> res = sproc.execute();
|
||||
|
||||
assertEquals("incorrect number of returns", 1, res.size());
|
||||
assertThat(res.size()).as("incorrect number of returns").isEqualTo(1);
|
||||
List<String> rs1 = (List<String>) res.get("rs");
|
||||
assertEquals(2, rs1.size());
|
||||
assertEquals("Foo", rs1.get(0));
|
||||
assertEquals("Bar", rs1.get(1));
|
||||
assertThat(rs1.size()).isEqualTo(2);
|
||||
assertThat(rs1.get(0)).isEqualTo("Foo");
|
||||
assertThat(rs1.get(1)).isEqualTo("Bar");
|
||||
verify(resultSet).close();
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ public class StoredProcedureTests {
|
||||
|
||||
ParameterMapperStoredProcedure pmsp = new ParameterMapperStoredProcedure(dataSource);
|
||||
Map<String, Object> out = pmsp.executeTest();
|
||||
assertEquals("OK", out.get("out"));
|
||||
assertThat(out.get("out")).isEqualTo("OK");
|
||||
|
||||
verify(callableStatement).setString(eq(1), startsWith("Mock for Connection"));
|
||||
verify(callableStatement).registerOutParameter(2, Types.VARCHAR);
|
||||
@@ -415,7 +415,7 @@ public class StoredProcedureTests {
|
||||
|
||||
SqlTypeValueStoredProcedure stvsp = new SqlTypeValueStoredProcedure(dataSource);
|
||||
Map<String, Object> out = stvsp.executeTest(testVal);
|
||||
assertEquals("OK", out.get("out"));
|
||||
assertThat(out.get("out")).isEqualTo("OK");
|
||||
verify(callableStatement).setObject(1, testVal, Types.ARRAY);
|
||||
verify(callableStatement).registerOutParameter(2, Types.VARCHAR);
|
||||
}
|
||||
@@ -429,7 +429,7 @@ public class StoredProcedureTests {
|
||||
).willReturn(callableStatement);
|
||||
NumericWithScaleStoredProcedure nwssp = new NumericWithScaleStoredProcedure(dataSource);
|
||||
Map<String, Object> out = nwssp.executeTest();
|
||||
assertEquals(new BigDecimal("12345.6789"), out.get("out"));
|
||||
assertThat(out.get("out")).isEqualTo(new BigDecimal("12345.6789"));
|
||||
verify(callableStatement).registerOutParameter(1, Types.DECIMAL, 4);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,7 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for custom {@link SQLExceptionTranslator}.
|
||||
@@ -47,17 +45,15 @@ public class CustomSQLExceptionTranslatorRegistrarTests {
|
||||
sext.setSqlErrorCodes(codes);
|
||||
|
||||
DataAccessException exFor4200 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 42000));
|
||||
assertNotNull("Should have been translated", exFor4200);
|
||||
assertTrue("Should have been instance of BadSqlGrammarException",
|
||||
BadSqlGrammarException.class.isAssignableFrom(exFor4200.getClass()));
|
||||
assertThat(exFor4200).as("Should have been translated").isNotNull();
|
||||
assertThat(BadSqlGrammarException.class.isAssignableFrom(exFor4200.getClass())).as("Should have been instance of BadSqlGrammarException").isTrue();
|
||||
|
||||
DataAccessException exFor2 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 2));
|
||||
assertNotNull("Should have been translated", exFor2);
|
||||
assertTrue("Should have been instance of TransientDataAccessResourceException",
|
||||
TransientDataAccessResourceException.class.isAssignableFrom(exFor2.getClass()));
|
||||
assertThat(exFor2).as("Should have been translated").isNotNull();
|
||||
assertThat(TransientDataAccessResourceException.class.isAssignableFrom(exFor2.getClass())).as("Should have been instance of TransientDataAccessResourceException").isTrue();
|
||||
|
||||
DataAccessException exFor3 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 3));
|
||||
assertNull("Should not have been translated", exFor3);
|
||||
assertThat(exFor3).as("Should not have been translated").isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -65,8 +65,8 @@ public class DataFieldMaxValueIncrementerTests {
|
||||
incrementer.setPaddingLength(2);
|
||||
incrementer.afterPropertiesSet();
|
||||
|
||||
assertEquals(10, incrementer.nextLongValue());
|
||||
assertEquals("12", incrementer.nextStringValue());
|
||||
assertThat(incrementer.nextLongValue()).isEqualTo(10);
|
||||
assertThat(incrementer.nextStringValue()).isEqualTo("12");
|
||||
|
||||
verify(resultSet, times(2)).close();
|
||||
verify(statement, times(2)).close();
|
||||
@@ -89,11 +89,11 @@ public class DataFieldMaxValueIncrementerTests {
|
||||
incrementer.setPaddingLength(3);
|
||||
incrementer.afterPropertiesSet();
|
||||
|
||||
assertEquals(0, incrementer.nextIntValue());
|
||||
assertEquals(1, incrementer.nextLongValue());
|
||||
assertEquals("002", incrementer.nextStringValue());
|
||||
assertEquals(3, incrementer.nextIntValue());
|
||||
assertEquals(4, incrementer.nextLongValue());
|
||||
assertThat(incrementer.nextIntValue()).isEqualTo(0);
|
||||
assertThat(incrementer.nextLongValue()).isEqualTo(1);
|
||||
assertThat(incrementer.nextStringValue()).isEqualTo("002");
|
||||
assertThat(incrementer.nextIntValue()).isEqualTo(3);
|
||||
assertThat(incrementer.nextLongValue()).isEqualTo(4);
|
||||
|
||||
verify(statement, times(6)).executeUpdate("insert into myseq values(null)");
|
||||
verify(statement).executeUpdate("delete from myseq where seq < 2");
|
||||
@@ -120,11 +120,11 @@ public class DataFieldMaxValueIncrementerTests {
|
||||
incrementer.setDeleteSpecificValues(true);
|
||||
incrementer.afterPropertiesSet();
|
||||
|
||||
assertEquals(0, incrementer.nextIntValue());
|
||||
assertEquals(1, incrementer.nextLongValue());
|
||||
assertEquals("002", incrementer.nextStringValue());
|
||||
assertEquals(3, incrementer.nextIntValue());
|
||||
assertEquals(4, incrementer.nextLongValue());
|
||||
assertThat(incrementer.nextIntValue()).isEqualTo(0);
|
||||
assertThat(incrementer.nextLongValue()).isEqualTo(1);
|
||||
assertThat(incrementer.nextStringValue()).isEqualTo("002");
|
||||
assertThat(incrementer.nextIntValue()).isEqualTo(3);
|
||||
assertThat(incrementer.nextLongValue()).isEqualTo(4);
|
||||
|
||||
verify(statement, times(6)).executeUpdate("insert into myseq values(null)");
|
||||
verify(statement).executeUpdate("delete from myseq where seq in (-1, 0, 1)");
|
||||
@@ -150,10 +150,10 @@ public class DataFieldMaxValueIncrementerTests {
|
||||
incrementer.setPaddingLength(1);
|
||||
incrementer.afterPropertiesSet();
|
||||
|
||||
assertEquals(1, incrementer.nextIntValue());
|
||||
assertEquals(2, incrementer.nextLongValue());
|
||||
assertEquals("3", incrementer.nextStringValue());
|
||||
assertEquals(4, incrementer.nextLongValue());
|
||||
assertThat(incrementer.nextIntValue()).isEqualTo(1);
|
||||
assertThat(incrementer.nextLongValue()).isEqualTo(2);
|
||||
assertThat(incrementer.nextStringValue()).isEqualTo("3");
|
||||
assertThat(incrementer.nextLongValue()).isEqualTo(4);
|
||||
|
||||
verify(statement, times(2)).executeUpdate("update myseq set seq = last_insert_id(seq + 2)");
|
||||
verify(resultSet, times(2)).close();
|
||||
@@ -175,8 +175,8 @@ public class DataFieldMaxValueIncrementerTests {
|
||||
incrementer.setPaddingLength(2);
|
||||
incrementer.afterPropertiesSet();
|
||||
|
||||
assertEquals(10, incrementer.nextLongValue());
|
||||
assertEquals("12", incrementer.nextStringValue());
|
||||
assertThat(incrementer.nextLongValue()).isEqualTo(10);
|
||||
assertThat(incrementer.nextStringValue()).isEqualTo("12");
|
||||
|
||||
verify(resultSet, times(2)).close();
|
||||
verify(statement, times(2)).close();
|
||||
@@ -197,8 +197,8 @@ public class DataFieldMaxValueIncrementerTests {
|
||||
incrementer.setPaddingLength(5);
|
||||
incrementer.afterPropertiesSet();
|
||||
|
||||
assertEquals("00010", incrementer.nextStringValue());
|
||||
assertEquals(12, incrementer.nextIntValue());
|
||||
assertThat(incrementer.nextStringValue()).isEqualTo("00010");
|
||||
assertThat(incrementer.nextIntValue()).isEqualTo(12);
|
||||
|
||||
verify(resultSet, times(2)).close();
|
||||
verify(statement, times(2)).close();
|
||||
|
||||
@@ -20,8 +20,7 @@ import java.sql.Types;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JdbcUtils}.
|
||||
@@ -33,27 +32,27 @@ public class JdbcUtilsTests {
|
||||
|
||||
@Test
|
||||
public void commonDatabaseName() {
|
||||
assertEquals("Oracle", JdbcUtils.commonDatabaseName("Oracle"));
|
||||
assertEquals("DB2", JdbcUtils.commonDatabaseName("DB2-for-Spring"));
|
||||
assertEquals("Sybase", JdbcUtils.commonDatabaseName("Sybase SQL Server"));
|
||||
assertEquals("Sybase", JdbcUtils.commonDatabaseName("Adaptive Server Enterprise"));
|
||||
assertEquals("MySQL", JdbcUtils.commonDatabaseName("MySQL"));
|
||||
assertThat(JdbcUtils.commonDatabaseName("Oracle")).isEqualTo("Oracle");
|
||||
assertThat(JdbcUtils.commonDatabaseName("DB2-for-Spring")).isEqualTo("DB2");
|
||||
assertThat(JdbcUtils.commonDatabaseName("Sybase SQL Server")).isEqualTo("Sybase");
|
||||
assertThat(JdbcUtils.commonDatabaseName("Adaptive Server Enterprise")).isEqualTo("Sybase");
|
||||
assertThat(JdbcUtils.commonDatabaseName("MySQL")).isEqualTo("MySQL");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveTypeName() {
|
||||
assertEquals("VARCHAR", JdbcUtils.resolveTypeName(Types.VARCHAR));
|
||||
assertEquals("NUMERIC", JdbcUtils.resolveTypeName(Types.NUMERIC));
|
||||
assertEquals("INTEGER", JdbcUtils.resolveTypeName(Types.INTEGER));
|
||||
assertNull(JdbcUtils.resolveTypeName(JdbcUtils.TYPE_UNKNOWN));
|
||||
assertThat(JdbcUtils.resolveTypeName(Types.VARCHAR)).isEqualTo("VARCHAR");
|
||||
assertThat(JdbcUtils.resolveTypeName(Types.NUMERIC)).isEqualTo("NUMERIC");
|
||||
assertThat(JdbcUtils.resolveTypeName(Types.INTEGER)).isEqualTo("INTEGER");
|
||||
assertThat(JdbcUtils.resolveTypeName(JdbcUtils.TYPE_UNKNOWN)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertUnderscoreNameToPropertyName() {
|
||||
assertEquals("myName", JdbcUtils.convertUnderscoreNameToPropertyName("MY_NAME"));
|
||||
assertEquals("yourName", JdbcUtils.convertUnderscoreNameToPropertyName("yOUR_nAME"));
|
||||
assertEquals("AName", JdbcUtils.convertUnderscoreNameToPropertyName("a_name"));
|
||||
assertEquals("someoneElsesName", JdbcUtils.convertUnderscoreNameToPropertyName("someone_elses_name"));
|
||||
assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("MY_NAME")).isEqualTo("myName");
|
||||
assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("yOUR_nAME")).isEqualTo("yourName");
|
||||
assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("a_name")).isEqualTo("AName");
|
||||
assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("someone_elses_name")).isEqualTo("someoneElsesName");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link KeyHolder} and {@link GeneratedKeyHolder}.
|
||||
@@ -48,7 +48,7 @@ public class KeyHolderTests {
|
||||
public void singleKey() {
|
||||
kh.getKeyList().addAll(singletonList(singletonMap("key", 1)));
|
||||
|
||||
assertEquals("single key should be returned", 1, kh.getKey().intValue());
|
||||
assertThat(kh.getKey().intValue()).as("single key should be returned").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +77,7 @@ public class KeyHolderTests {
|
||||
}};
|
||||
kh.getKeyList().addAll(singletonList(m));
|
||||
|
||||
assertEquals("two keys should be in the map", 2, kh.getKeys().size());
|
||||
assertThat(kh.getKeys().size()).as("two keys should be in the map").isEqualTo(2);
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
|
||||
kh.getKey())
|
||||
.withMessageStartingWith("The getKey method should only be used when a single key is returned.");
|
||||
@@ -91,7 +91,7 @@ public class KeyHolderTests {
|
||||
}};
|
||||
kh.getKeyList().addAll(asList(m, m));
|
||||
|
||||
assertEquals("two rows should be in the list", 2, kh.getKeyList().size());
|
||||
assertThat(kh.getKeyList().size()).as("two rows should be in the list").isEqualTo(2);
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
|
||||
kh.getKeys())
|
||||
.withMessageStartingWith("The getKeys method should only be used when keys for a single row are returned.");
|
||||
|
||||
@@ -33,9 +33,8 @@ import org.springframework.jdbc.BadSqlGrammarException;
|
||||
import org.springframework.jdbc.InvalidResultSetAccessException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -63,13 +62,13 @@ public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||
|
||||
SQLException badSqlEx = new SQLException("", "", 1);
|
||||
BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", badSqlEx);
|
||||
assertEquals("SQL", bsgex.getSql());
|
||||
assertEquals(badSqlEx, bsgex.getSQLException());
|
||||
assertThat(bsgex.getSql()).isEqualTo("SQL");
|
||||
assertThat((Object) bsgex.getSQLException()).isEqualTo(badSqlEx);
|
||||
|
||||
SQLException invResEx = new SQLException("", "", 4);
|
||||
InvalidResultSetAccessException irsex = (InvalidResultSetAccessException) sext.translate("task", "SQL", invResEx);
|
||||
assertEquals("SQL", irsex.getSql());
|
||||
assertEquals(invResEx, irsex.getSQLException());
|
||||
assertThat(irsex.getSql()).isEqualTo("SQL");
|
||||
assertThat((Object) irsex.getSQLException()).isEqualTo(invResEx);
|
||||
|
||||
checkTranslation(sext, 5, DataAccessResourceFailureException.class);
|
||||
checkTranslation(sext, 6, DataIntegrityViolationException.class);
|
||||
@@ -80,22 +79,21 @@ public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||
|
||||
SQLException dupKeyEx = new SQLException("", "", 10);
|
||||
DataAccessException dksex = sext.translate("task", "SQL", dupKeyEx);
|
||||
assertTrue("Not instance of DataIntegrityViolationException",
|
||||
DataIntegrityViolationException.class.isAssignableFrom(dksex.getClass()));
|
||||
assertThat(DataIntegrityViolationException.class.isAssignableFrom(dksex.getClass())).as("Not instance of DataIntegrityViolationException").isTrue();
|
||||
|
||||
// Test fallback. We assume that no database will ever return this error code,
|
||||
// but 07xxx will be bad grammar picked up by the fallback SQLState translator
|
||||
SQLException sex = new SQLException("", "07xxx", 666666666);
|
||||
BadSqlGrammarException bsgex2 = (BadSqlGrammarException) sext.translate("task", "SQL2", sex);
|
||||
assertEquals("SQL2", bsgex2.getSql());
|
||||
assertEquals(sex, bsgex2.getSQLException());
|
||||
assertThat(bsgex2.getSql()).isEqualTo("SQL2");
|
||||
assertThat((Object) bsgex2.getSQLException()).isEqualTo(sex);
|
||||
}
|
||||
|
||||
private void checkTranslation(SQLExceptionTranslator sext, int errorCode, Class<?> exClass) {
|
||||
SQLException sex = new SQLException("", "", errorCode);
|
||||
DataAccessException ex = sext.translate("", "", sex);
|
||||
assertTrue(exClass.isInstance(ex));
|
||||
assertTrue(ex.getCause() == sex);
|
||||
assertThat(exClass.isInstance(ex)).isTrue();
|
||||
assertThat(ex.getCause() == sex).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,8 +104,8 @@ public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||
BatchUpdateException batchUpdateEx = new BatchUpdateException();
|
||||
batchUpdateEx.setNextException(badSqlEx);
|
||||
BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", batchUpdateEx);
|
||||
assertEquals("SQL", bsgex.getSql());
|
||||
assertEquals(badSqlEx, bsgex.getSQLException());
|
||||
assertThat(bsgex.getSql()).isEqualTo("SQL");
|
||||
assertThat((Object) bsgex.getSQLException()).isEqualTo(badSqlEx);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,7 +115,7 @@ public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||
SQLException dataAccessEx = new SQLException("", "", 5);
|
||||
DataTruncation dataTruncation = new DataTruncation(1, true, true, 1, 1, dataAccessEx);
|
||||
DataAccessResourceFailureException daex = (DataAccessResourceFailureException) sext.translate("task", "SQL", dataTruncation);
|
||||
assertEquals(dataTruncation, daex.getCause());
|
||||
assertThat(daex.getCause()).isEqualTo(dataTruncation);
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@@ -134,17 +132,17 @@ public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||
@Override
|
||||
@Nullable
|
||||
protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlex) {
|
||||
assertEquals(TASK, task);
|
||||
assertEquals(SQL, sql);
|
||||
assertThat(task).isEqualTo(TASK);
|
||||
assertThat(sql).isEqualTo(SQL);
|
||||
return (sqlex == badSqlEx) ? customDex : null;
|
||||
}
|
||||
};
|
||||
sext.setSqlErrorCodes(ERROR_CODES);
|
||||
|
||||
// Shouldn't custom translate this
|
||||
assertEquals(customDex, sext.translate(TASK, SQL, badSqlEx));
|
||||
assertThat(sext.translate(TASK, SQL, badSqlEx)).isEqualTo(customDex);
|
||||
DataIntegrityViolationException diex = (DataIntegrityViolationException) sext.translate(TASK, SQL, intVioEx);
|
||||
assertEquals(intVioEx, diex.getCause());
|
||||
assertThat(diex.getCause()).isEqualTo(intVioEx);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,13 +163,13 @@ public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||
|
||||
// Should custom translate this
|
||||
SQLException badSqlEx = new SQLException("", "", 1);
|
||||
assertEquals(CustomErrorCodeException.class, sext.translate(TASK, SQL, badSqlEx).getClass());
|
||||
assertEquals(badSqlEx, sext.translate(TASK, SQL, badSqlEx).getCause());
|
||||
assertThat(sext.translate(TASK, SQL, badSqlEx).getClass()).isEqualTo(CustomErrorCodeException.class);
|
||||
assertThat(sext.translate(TASK, SQL, badSqlEx).getCause()).isEqualTo(badSqlEx);
|
||||
|
||||
// Shouldn't custom translate this
|
||||
SQLException invResEx = new SQLException("", "", 3);
|
||||
DataIntegrityViolationException diex = (DataIntegrityViolationException) sext.translate(TASK, SQL, invResEx);
|
||||
assertEquals(invResEx, diex.getCause());
|
||||
assertThat(diex.getCause()).isEqualTo(invResEx);
|
||||
|
||||
// Shouldn't custom translate this - invalid class
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
|
||||
@@ -28,10 +28,6 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -51,8 +47,8 @@ public class SQLErrorCodesFactoryTests {
|
||||
@Test
|
||||
public void testDefaultInstanceWithNoSuchDatabase() {
|
||||
SQLErrorCodes sec = SQLErrorCodesFactory.getInstance().getErrorCodes("xx");
|
||||
assertTrue(sec.getBadSqlGrammarCodes().length == 0);
|
||||
assertTrue(sec.getDataIntegrityViolationCodes().length == 0);
|
||||
assertThat(sec.getBadSqlGrammarCodes().length == 0).isTrue();
|
||||
assertThat(sec.getDataIntegrityViolationCodes().length == 0).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,80 +61,80 @@ public class SQLErrorCodesFactoryTests {
|
||||
}
|
||||
|
||||
private void assertIsOracle(SQLErrorCodes sec) {
|
||||
assertTrue(sec.getBadSqlGrammarCodes().length > 0);
|
||||
assertTrue(sec.getDataIntegrityViolationCodes().length > 0);
|
||||
assertThat(sec.getBadSqlGrammarCodes().length > 0).isTrue();
|
||||
assertThat(sec.getDataIntegrityViolationCodes().length > 0).isTrue();
|
||||
// These had better be a Bad SQL Grammar code
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "942") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "6550") >= 0);
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "942") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "6550") >= 0).isTrue();
|
||||
// This had better NOT be
|
||||
assertFalse(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "9xx42") >= 0);
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "9xx42") >= 0).isFalse();
|
||||
}
|
||||
|
||||
private void assertIsSQLServer(SQLErrorCodes sec) {
|
||||
assertThat(sec.getDatabaseProductName()).isEqualTo("Microsoft SQL Server");
|
||||
|
||||
assertTrue(sec.getBadSqlGrammarCodes().length > 0);
|
||||
assertThat(sec.getBadSqlGrammarCodes().length > 0).isTrue();
|
||||
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "156") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "170") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "207") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "208") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "209") >= 0);
|
||||
assertFalse(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "9xx42") >= 0);
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "156") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "170") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "207") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "208") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "209") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "9xx42") >= 0).isFalse();
|
||||
|
||||
assertTrue(sec.getPermissionDeniedCodes().length > 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getPermissionDeniedCodes(), "229") >= 0);
|
||||
assertThat(sec.getPermissionDeniedCodes().length > 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getPermissionDeniedCodes(), "229") >= 0).isTrue();
|
||||
|
||||
assertTrue(sec.getDuplicateKeyCodes().length > 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "2601") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "2627") >= 0);
|
||||
assertThat(sec.getDuplicateKeyCodes().length > 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "2601") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "2627") >= 0).isTrue();
|
||||
|
||||
assertTrue(sec.getDataIntegrityViolationCodes().length > 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "544") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "8114") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "8115") >= 0);
|
||||
assertThat(sec.getDataIntegrityViolationCodes().length > 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "544") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "8114") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "8115") >= 0).isTrue();
|
||||
|
||||
assertTrue(sec.getDataAccessResourceFailureCodes().length > 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDataAccessResourceFailureCodes(), "4060") >= 0);
|
||||
assertThat(sec.getDataAccessResourceFailureCodes().length > 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDataAccessResourceFailureCodes(), "4060") >= 0).isTrue();
|
||||
|
||||
assertTrue(sec.getCannotAcquireLockCodes().length > 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getCannotAcquireLockCodes(), "1222") >= 0);
|
||||
assertThat(sec.getCannotAcquireLockCodes().length > 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getCannotAcquireLockCodes(), "1222") >= 0).isTrue();
|
||||
|
||||
assertTrue(sec.getDeadlockLoserCodes().length > 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDeadlockLoserCodes(), "1205") >= 0);
|
||||
assertThat(sec.getDeadlockLoserCodes().length > 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDeadlockLoserCodes(), "1205") >= 0).isTrue();
|
||||
}
|
||||
|
||||
private void assertIsHsql(SQLErrorCodes sec) {
|
||||
assertTrue(sec.getBadSqlGrammarCodes().length > 0);
|
||||
assertTrue(sec.getDataIntegrityViolationCodes().length > 0);
|
||||
assertThat(sec.getBadSqlGrammarCodes().length > 0).isTrue();
|
||||
assertThat(sec.getDataIntegrityViolationCodes().length > 0).isTrue();
|
||||
// This had better be a Bad SQL Grammar code
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-22") >= 0);
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-22") >= 0).isTrue();
|
||||
// This had better NOT be
|
||||
assertFalse(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-9") >= 0);
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-9") >= 0).isFalse();
|
||||
}
|
||||
|
||||
private void assertIsDB2(SQLErrorCodes sec) {
|
||||
assertTrue(sec.getBadSqlGrammarCodes().length > 0);
|
||||
assertTrue(sec.getDataIntegrityViolationCodes().length > 0);
|
||||
assertThat(sec.getBadSqlGrammarCodes().length > 0).isTrue();
|
||||
assertThat(sec.getDataIntegrityViolationCodes().length > 0).isTrue();
|
||||
|
||||
assertFalse(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "942") >= 0);
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "942") >= 0).isFalse();
|
||||
// This had better NOT be
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-204") >= 0);
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-204") >= 0).isTrue();
|
||||
}
|
||||
|
||||
private void assertIsHana(SQLErrorCodes sec) {
|
||||
assertTrue(sec.getBadSqlGrammarCodes().length > 0);
|
||||
assertTrue(sec.getDataIntegrityViolationCodes().length > 0);
|
||||
assertThat(sec.getBadSqlGrammarCodes().length > 0).isTrue();
|
||||
assertThat(sec.getDataIntegrityViolationCodes().length > 0).isTrue();
|
||||
|
||||
assertTrue(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "368") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getPermissionDeniedCodes(), "10") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "301") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "461") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDataAccessResourceFailureCodes(), "-813") >=0);
|
||||
assertTrue(Arrays.binarySearch(sec.getInvalidResultSetAccessCodes(), "582") >=0);
|
||||
assertTrue(Arrays.binarySearch(sec.getCannotAcquireLockCodes(), "131") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getCannotSerializeTransactionCodes(), "138") >= 0);
|
||||
assertTrue(Arrays.binarySearch(sec.getDeadlockLoserCodes(), "133") >= 0);
|
||||
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "368") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getPermissionDeniedCodes(), "10") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "301") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "461") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDataAccessResourceFailureCodes(), "-813") >=0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getInvalidResultSetAccessCodes(), "582") >=0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getCannotAcquireLockCodes(), "131") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getCannotSerializeTransactionCodes(), "138") >= 0).isTrue();
|
||||
assertThat(Arrays.binarySearch(sec.getDeadlockLoserCodes(), "133") >= 0).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@@ -150,13 +146,13 @@ public class SQLErrorCodesFactoryTests {
|
||||
protected Resource loadResource(String path) {
|
||||
++lookups;
|
||||
if (lookups == 1) {
|
||||
assertEquals(SQLErrorCodesFactory.SQL_ERROR_CODE_DEFAULT_PATH, path);
|
||||
assertThat(path).isEqualTo(SQLErrorCodesFactory.SQL_ERROR_CODE_DEFAULT_PATH);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
// Should have only one more lookup
|
||||
assertEquals(2, lookups);
|
||||
assertEquals(SQLErrorCodesFactory.SQL_ERROR_CODE_OVERRIDE_PATH, path);
|
||||
assertThat(lookups).isEqualTo(2);
|
||||
assertThat(path).isEqualTo(SQLErrorCodesFactory.SQL_ERROR_CODE_OVERRIDE_PATH);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -164,8 +160,8 @@ public class SQLErrorCodesFactoryTests {
|
||||
|
||||
// Should have failed to load without error
|
||||
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory();
|
||||
assertTrue(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length == 0);
|
||||
assertTrue(sf.getErrorCodes("Oracle").getDataIntegrityViolationCodes().length == 0);
|
||||
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length == 0).isTrue();
|
||||
assertThat(sf.getErrorCodes("Oracle").getDataIntegrityViolationCodes().length == 0).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,10 +181,10 @@ public class SQLErrorCodesFactoryTests {
|
||||
|
||||
// Should have loaded without error
|
||||
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory();
|
||||
assertTrue(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length == 0);
|
||||
assertEquals(2, sf.getErrorCodes("Oracle").getBadSqlGrammarCodes().length);
|
||||
assertEquals("1", sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()[0]);
|
||||
assertEquals("2", sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()[1]);
|
||||
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length == 0).isTrue();
|
||||
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes().length).isEqualTo(2);
|
||||
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()[0]).isEqualTo("1");
|
||||
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()[1]).isEqualTo("2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -206,8 +202,8 @@ public class SQLErrorCodesFactoryTests {
|
||||
|
||||
// Should have failed to load without error
|
||||
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory();
|
||||
assertTrue(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length == 0);
|
||||
assertEquals(0, sf.getErrorCodes("Oracle").getBadSqlGrammarCodes().length);
|
||||
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length == 0).isTrue();
|
||||
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes().length).isEqualTo(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,11 +223,11 @@ public class SQLErrorCodesFactoryTests {
|
||||
|
||||
// Should have loaded without error
|
||||
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory();
|
||||
assertEquals(1, sf.getErrorCodes("Oracle").getCustomTranslations().length);
|
||||
assertThat(sf.getErrorCodes("Oracle").getCustomTranslations().length).isEqualTo(1);
|
||||
CustomSQLErrorCodesTranslation translation =
|
||||
sf.getErrorCodes("Oracle").getCustomTranslations()[0];
|
||||
assertEquals(CustomErrorCodeException.class, translation.getExceptionClass());
|
||||
assertEquals(1, translation.getErrorCodes().length);
|
||||
assertThat(translation.getExceptionClass()).isEqualTo(CustomErrorCodeException.class);
|
||||
assertThat(translation.getErrorCodes().length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -259,8 +255,8 @@ public class SQLErrorCodesFactoryTests {
|
||||
|
||||
private void assertIsEmpty(SQLErrorCodes sec) {
|
||||
// Codes should be empty
|
||||
assertEquals(0, sec.getBadSqlGrammarCodes().length);
|
||||
assertEquals(0, sec.getDataIntegrityViolationCodes().length);
|
||||
assertThat(sec.getBadSqlGrammarCodes().length).isEqualTo(0);
|
||||
assertThat(sec.getDataIntegrityViolationCodes().length).isEqualTo(0);
|
||||
}
|
||||
|
||||
private SQLErrorCodes getErrorCodesFromDataSource(String productName, SQLErrorCodesFactory factory) throws Exception {
|
||||
@@ -285,7 +281,7 @@ public class SQLErrorCodesFactoryTests {
|
||||
|
||||
|
||||
SQLErrorCodes sec2 = secf.getErrorCodes(dataSource);
|
||||
assertSame("Cached per DataSource", sec2, sec);
|
||||
assertThat(sec).as("Cached per DataSource").isSameAs(sec2);
|
||||
|
||||
verify(connection).close();
|
||||
return sec;
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit tests for custom SQLException translation.
|
||||
@@ -50,7 +49,7 @@ public class SQLExceptionCustomTranslatorTests {
|
||||
public void badSqlGrammarException() {
|
||||
SQLException badSqlGrammarExceptionEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 1);
|
||||
DataAccessException dae = sext.translate("task", "SQL", badSqlGrammarExceptionEx);
|
||||
assertEquals(badSqlGrammarExceptionEx, dae.getCause());
|
||||
assertThat(dae.getCause()).isEqualTo(badSqlGrammarExceptionEx);
|
||||
assertThat(dae).isInstanceOf(BadSqlGrammarException.class);
|
||||
}
|
||||
|
||||
@@ -58,7 +57,7 @@ public class SQLExceptionCustomTranslatorTests {
|
||||
public void dataAccessResourceException() {
|
||||
SQLException dataAccessResourceEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 2);
|
||||
DataAccessException dae = sext.translate("task", "SQL", dataAccessResourceEx);
|
||||
assertEquals(dataAccessResourceEx, dae.getCause());
|
||||
assertThat(dae.getCause()).isEqualTo(dataAccessResourceEx);
|
||||
assertThat(dae).isInstanceOf(TransientDataAccessResourceException.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.dao.RecoverableDataAccessException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
@@ -50,62 +50,62 @@ public class SQLExceptionSubclassTranslatorTests {
|
||||
|
||||
SQLException dataIntegrityViolationEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 0);
|
||||
DataIntegrityViolationException divex = (DataIntegrityViolationException) sext.translate("task", "SQL", dataIntegrityViolationEx);
|
||||
assertEquals(dataIntegrityViolationEx, divex.getCause());
|
||||
assertThat(divex.getCause()).isEqualTo(dataIntegrityViolationEx);
|
||||
|
||||
SQLException featureNotSupEx = SQLExceptionSubclassFactory.newSQLFeatureNotSupportedException("", "", 0);
|
||||
InvalidDataAccessApiUsageException idaex = (InvalidDataAccessApiUsageException) sext.translate("task", "SQL", featureNotSupEx);
|
||||
assertEquals(featureNotSupEx, idaex.getCause());
|
||||
assertThat(idaex.getCause()).isEqualTo(featureNotSupEx);
|
||||
|
||||
SQLException dataIntegrityViolationEx2 = SQLExceptionSubclassFactory.newSQLIntegrityConstraintViolationException("", "", 0);
|
||||
DataIntegrityViolationException divex2 = (DataIntegrityViolationException) sext.translate("task", "SQL", dataIntegrityViolationEx2);
|
||||
assertEquals(dataIntegrityViolationEx2, divex2.getCause());
|
||||
assertThat(divex2.getCause()).isEqualTo(dataIntegrityViolationEx2);
|
||||
|
||||
SQLException permissionDeniedEx = SQLExceptionSubclassFactory.newSQLInvalidAuthorizationSpecException("", "", 0);
|
||||
PermissionDeniedDataAccessException pdaex = (PermissionDeniedDataAccessException) sext.translate("task", "SQL", permissionDeniedEx);
|
||||
assertEquals(permissionDeniedEx, pdaex.getCause());
|
||||
assertThat(pdaex.getCause()).isEqualTo(permissionDeniedEx);
|
||||
|
||||
SQLException dataAccessResourceEx = SQLExceptionSubclassFactory.newSQLNonTransientConnectionException("", "", 0);
|
||||
DataAccessResourceFailureException darex = (DataAccessResourceFailureException) sext.translate("task", "SQL", dataAccessResourceEx);
|
||||
assertEquals(dataAccessResourceEx, darex.getCause());
|
||||
assertThat(darex.getCause()).isEqualTo(dataAccessResourceEx);
|
||||
|
||||
SQLException badSqlEx2 = SQLExceptionSubclassFactory.newSQLSyntaxErrorException("", "", 0);
|
||||
BadSqlGrammarException bsgex2 = (BadSqlGrammarException) sext.translate("task", "SQL2", badSqlEx2);
|
||||
assertEquals("SQL2", bsgex2.getSql());
|
||||
assertEquals(badSqlEx2, bsgex2.getSQLException());
|
||||
assertThat(bsgex2.getSql()).isEqualTo("SQL2");
|
||||
assertThat((Object) bsgex2.getSQLException()).isEqualTo(badSqlEx2);
|
||||
|
||||
SQLException tranRollbackEx = SQLExceptionSubclassFactory.newSQLTransactionRollbackException("", "", 0);
|
||||
ConcurrencyFailureException cfex = (ConcurrencyFailureException) sext.translate("task", "SQL", tranRollbackEx);
|
||||
assertEquals(tranRollbackEx, cfex.getCause());
|
||||
assertThat(cfex.getCause()).isEqualTo(tranRollbackEx);
|
||||
|
||||
SQLException transientConnEx = SQLExceptionSubclassFactory.newSQLTransientConnectionException("", "", 0);
|
||||
TransientDataAccessResourceException tdarex = (TransientDataAccessResourceException) sext.translate("task", "SQL", transientConnEx);
|
||||
assertEquals(transientConnEx, tdarex.getCause());
|
||||
assertThat(tdarex.getCause()).isEqualTo(transientConnEx);
|
||||
|
||||
SQLException transientConnEx2 = SQLExceptionSubclassFactory.newSQLTimeoutException("", "", 0);
|
||||
QueryTimeoutException tdarex2 = (QueryTimeoutException) sext.translate("task", "SQL", transientConnEx2);
|
||||
assertEquals(transientConnEx2, tdarex2.getCause());
|
||||
assertThat(tdarex2.getCause()).isEqualTo(transientConnEx2);
|
||||
|
||||
SQLException recoverableEx = SQLExceptionSubclassFactory.newSQLRecoverableException("", "", 0);
|
||||
RecoverableDataAccessException rdaex2 = (RecoverableDataAccessException) sext.translate("task", "SQL", recoverableEx);
|
||||
assertEquals(recoverableEx, rdaex2.getCause());
|
||||
assertThat(rdaex2.getCause()).isEqualTo(recoverableEx);
|
||||
|
||||
// Test classic error code translation. We should move there next if the exception we pass in is not one
|
||||
// of the new sub-classes.
|
||||
SQLException sexEct = new SQLException("", "", 1);
|
||||
BadSqlGrammarException bsgEct = (BadSqlGrammarException) sext.translate("task", "SQL-ECT", sexEct);
|
||||
assertEquals("SQL-ECT", bsgEct.getSql());
|
||||
assertEquals(sexEct, bsgEct.getSQLException());
|
||||
assertThat(bsgEct.getSql()).isEqualTo("SQL-ECT");
|
||||
assertThat((Object) bsgEct.getSQLException()).isEqualTo(sexEct);
|
||||
|
||||
// Test fallback. We assume that no database will ever return this error code,
|
||||
// but 07xxx will be bad grammar picked up by the fallback SQLState translator
|
||||
SQLException sexFbt = new SQLException("", "07xxx", 666666666);
|
||||
BadSqlGrammarException bsgFbt = (BadSqlGrammarException) sext.translate("task", "SQL-FBT", sexFbt);
|
||||
assertEquals("SQL-FBT", bsgFbt.getSql());
|
||||
assertEquals(sexFbt, bsgFbt.getSQLException());
|
||||
assertThat(bsgFbt.getSql()).isEqualTo("SQL-FBT");
|
||||
assertThat((Object) bsgFbt.getSQLException()).isEqualTo(sexFbt);
|
||||
// and 08xxx will be data resource failure (non-transient) picked up by the fallback SQLState translator
|
||||
SQLException sexFbt2 = new SQLException("", "08xxx", 666666666);
|
||||
DataAccessResourceFailureException darfFbt = (DataAccessResourceFailureException) sext.translate("task", "SQL-FBT2", sexFbt2);
|
||||
assertEquals(sexFbt2, darfFbt.getCause());
|
||||
assertThat(darfFbt.getCause()).isEqualTo(sexFbt2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
import org.springframework.jdbc.UncategorizedSQLException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -46,8 +46,8 @@ public class SQLStateExceptionTranslatorTests {
|
||||
}
|
||||
catch (BadSqlGrammarException ex) {
|
||||
// OK
|
||||
assertTrue("SQL is correct", sql.equals(ex.getSql()));
|
||||
assertTrue("Exception matches", sex.equals(ex.getSQLException()));
|
||||
assertThat(sql.equals(ex.getSql())).as("SQL is correct").isTrue();
|
||||
assertThat(sex.equals(ex.getSQLException())).as("Exception matches").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ public class SQLStateExceptionTranslatorTests {
|
||||
}
|
||||
catch (UncategorizedSQLException ex) {
|
||||
// OK
|
||||
assertTrue("SQL is correct", sql.equals(ex.getSql()));
|
||||
assertTrue("Exception matches", sex.equals(ex.getSQLException()));
|
||||
assertThat(sql.equals(ex.getSql())).as("SQL is correct").isTrue();
|
||||
assertThat(sex.equals(ex.getSQLException())).as("Exception matches").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ public class SQLStateExceptionTranslatorTests {
|
||||
}
|
||||
catch (UncategorizedSQLException ex) {
|
||||
// OK
|
||||
assertTrue("SQL is correct", sql.equals(ex.getSql()));
|
||||
assertTrue("Exception matches", sex.equals(ex.getSQLException()));
|
||||
assertThat(sql.equals(ex.getSql())).as("SQL is correct").isTrue();
|
||||
assertThat(sex.equals(ex.getSQLException())).as("Exception matches").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,8 @@ import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
import org.springframework.jdbc.UncategorizedSQLException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
@@ -88,10 +86,10 @@ public class SQLStateSQLExceptionTranslatorTests {
|
||||
SQLException ex = new SQLException(REASON, sqlState);
|
||||
SQLExceptionTranslator translator = new SQLStateSQLExceptionTranslator();
|
||||
DataAccessException dax = translator.translate(TASK, SQL, ex);
|
||||
assertNotNull("Translation must *never* result in a null DataAccessException being returned.", dax);
|
||||
assertEquals("Wrong DataAccessException type returned as the result of the translation", dataAccessExceptionType, dax.getClass());
|
||||
assertNotNull("The original SQLException must be preserved in the translated DataAccessException", dax.getCause());
|
||||
assertSame("The exact same original SQLException must be preserved in the translated DataAccessException", ex, dax.getCause());
|
||||
assertThat(dax).as("Translation must *never* result in a null DataAccessException being returned.").isNotNull();
|
||||
assertThat(dax.getClass()).as("Wrong DataAccessException type returned as the result of the translation").isEqualTo(dataAccessExceptionType);
|
||||
assertThat(dax.getCause()).as("The original SQLException must be preserved in the translated DataAccessException").isNotNull();
|
||||
assertThat(dax.getCause()).as("The exact same original SQLException must be preserved in the translated DataAccessException").isSameAs(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user