Migrate Hamcrest assertions to AssertJ
Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ and add checkstyle rules to ensure they don't return. See gh-23022
This commit is contained in:
@@ -36,11 +36,8 @@ import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||
import org.springframework.tests.Assume;
|
||||
import org.springframework.tests.TestGroup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.DEFAULT_DATABASE_NAME;
|
||||
@@ -184,8 +181,8 @@ public class JdbcNamespaceIntegrationTests {
|
||||
private void assertBeanPropertyValueOf(String propertyName, String expected, DefaultListableBeanFactory factory) {
|
||||
BeanDefinition bean = factory.getBeanDefinition(expected);
|
||||
PropertyValue value = bean.getPropertyValues().getPropertyValue(propertyName);
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value.getValue().toString(), is(expected));
|
||||
assertThat(value).isNotNull();
|
||||
assertThat(value.getValue().toString()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void assertNumRowsInTestTable(JdbcTemplate template, int count) {
|
||||
@@ -204,7 +201,7 @@ public class JdbcNamespaceIntegrationTests {
|
||||
assertNumRowsInTestTable(new JdbcTemplate(dataSource), count);
|
||||
assertTrue(dataSource instanceof AbstractDriverBasedDataSource);
|
||||
AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource;
|
||||
assertThat(adbDataSource.getUrl(), containsString(dataSourceName));
|
||||
assertThat(adbDataSource.getUrl()).contains(dataSourceName);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -52,10 +52,8 @@ import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
@@ -440,7 +438,7 @@ public class JdbcTemplateTests {
|
||||
template.batchUpdate(sql);
|
||||
}
|
||||
catch (UncategorizedSQLException ex) {
|
||||
assertThat(ex.getSql(), equalTo("B; D"));
|
||||
assertThat(ex.getSql()).isEqualTo("B; D");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1069,7 +1067,7 @@ public class JdbcTemplateTests {
|
||||
Map<String, Object> out = this.template.call(
|
||||
conn -> conn.prepareCall("my query"), Collections.singletonList(new SqlOutParameter("a", 12)));
|
||||
|
||||
assertThat(out, instanceOf(LinkedCaseInsensitiveMap.class));
|
||||
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"));
|
||||
verify(this.callableStatement).close();
|
||||
|
||||
@@ -19,13 +19,12 @@ package org.springframework.jdbc.core.namedparam;
|
||||
import java.sql.Types;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
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.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -94,35 +93,32 @@ public class BeanPropertySqlParameterSourceTests {
|
||||
@Test
|
||||
public void toStringShowsParameterDetails() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
||||
assertThat(source.toString(), Matchers.allOf(
|
||||
Matchers.startsWith("BeanPropertySqlParameterSource {"),
|
||||
Matchers.endsWith("}"),
|
||||
Matchers.containsString("name=tb (type:VARCHAR)"),
|
||||
Matchers.containsString("age=99 (type:INTEGER)")
|
||||
));
|
||||
assertThat(source.toString())
|
||||
.startsWith("BeanPropertySqlParameterSource {")
|
||||
.contains("name=tb (type:VARCHAR)")
|
||||
.contains("age=99 (type:INTEGER)")
|
||||
.endsWith("}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringShowsCustomSqlType() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
||||
source.registerSqlType("name", Integer.MAX_VALUE);
|
||||
assertThat(source.toString(), Matchers.allOf(
|
||||
Matchers.startsWith("BeanPropertySqlParameterSource {"),
|
||||
Matchers.endsWith("}"),
|
||||
Matchers.containsString("name=tb (type:" + Integer.MAX_VALUE + ")"),
|
||||
Matchers.containsString("age=99 (type:INTEGER)")
|
||||
));
|
||||
assertThat(source.toString())
|
||||
.startsWith("BeanPropertySqlParameterSource {")
|
||||
.contains("name=tb (type:" + Integer.MAX_VALUE + ")")
|
||||
.contains("age=99 (type:INTEGER)")
|
||||
.endsWith("}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringDoesNotShowTypeUnknown() {
|
||||
BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99));
|
||||
assertThat(source.toString(), Matchers.allOf(
|
||||
Matchers.startsWith("BeanPropertySqlParameterSource {"),
|
||||
Matchers.endsWith("}"),
|
||||
Matchers.containsString("beanFactory=null"),
|
||||
Matchers.not(Matchers.containsString("beanFactory=null (type:"))
|
||||
));
|
||||
assertThat(source.toString())
|
||||
.startsWith("BeanPropertySqlParameterSource {")
|
||||
.contains("beanFactory=null")
|
||||
.doesNotContain("beanFactory=null (type:")
|
||||
.endsWith("}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,9 +32,8 @@ import org.mockito.MockitoAnnotations;
|
||||
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.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -113,7 +112,7 @@ public class SqlLobValueTests {
|
||||
verify(creator).setClobAsAsciiStream(eq(preparedStatement), eq(1), inputStreamCaptor.capture(), eq(3));
|
||||
byte[] bytes = new byte[3];
|
||||
inputStreamCaptor.getValue().read(bytes);
|
||||
assertThat(bytes, equalTo(testContent));
|
||||
assertThat(bytes).isEqualTo(testContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,8 +23,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
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;
|
||||
@@ -44,7 +43,7 @@ public class DelegatingDataSourceTests {
|
||||
public void shouldDelegateGetConnection() throws Exception {
|
||||
Connection connection = mock(Connection.class);
|
||||
given(delegate.getConnection()).willReturn(connection);
|
||||
assertThat(dataSource.getConnection(), is(connection));
|
||||
assertThat(dataSource.getConnection()).isEqualTo(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,14 +52,14 @@ public class DelegatingDataSourceTests {
|
||||
String username = "username";
|
||||
String password = "password";
|
||||
given(delegate.getConnection(username, password)).willReturn(connection);
|
||||
assertThat(dataSource.getConnection(username, password), is(connection));
|
||||
assertThat(dataSource.getConnection(username, password)).isEqualTo(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDelegateGetLogWriter() throws Exception {
|
||||
PrintWriter writer = new PrintWriter(new ByteArrayOutputStream());
|
||||
given(delegate.getLogWriter()).willReturn(writer);
|
||||
assertThat(dataSource.getLogWriter(), is(writer));
|
||||
assertThat(dataSource.getLogWriter()).isEqualTo(writer);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,7 +73,7 @@ public class DelegatingDataSourceTests {
|
||||
public void shouldDelegateGetLoginTimeout() throws Exception {
|
||||
int timeout = 123;
|
||||
given(delegate.getLoginTimeout()).willReturn(timeout);
|
||||
assertThat(dataSource.getLoginTimeout(), is(timeout));
|
||||
assertThat(dataSource.getLoginTimeout()).isEqualTo(timeout);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,26 +87,25 @@ public class DelegatingDataSourceTests {
|
||||
public void shouldDelegateUnwrapWithoutImplementing() throws Exception {
|
||||
ExampleWrapper wrapper = mock(ExampleWrapper.class);
|
||||
given(delegate.unwrap(ExampleWrapper.class)).willReturn(wrapper);
|
||||
assertThat(dataSource.unwrap(ExampleWrapper.class), is(wrapper));
|
||||
assertThat(dataSource.unwrap(ExampleWrapper.class)).isEqualTo(wrapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDelegateUnwrapImplementing() throws Exception {
|
||||
dataSource = new DelegatingDataSourceWithWrapper();
|
||||
assertThat(dataSource.unwrap(ExampleWrapper.class),
|
||||
is((ExampleWrapper) dataSource));
|
||||
assertThat(dataSource.unwrap(ExampleWrapper.class)).isSameAs(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDelegateIsWrapperForWithoutImplementing() throws Exception {
|
||||
given(delegate.isWrapperFor(ExampleWrapper.class)).willReturn(true);
|
||||
assertThat(dataSource.isWrapperFor(ExampleWrapper.class), is(true));
|
||||
assertThat(dataSource.isWrapperFor(ExampleWrapper.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDelegateIsWrapperForImplementing() throws Exception {
|
||||
dataSource = new DelegatingDataSourceWithWrapper();
|
||||
assertThat(dataSource.isWrapperFor(ExampleWrapper.class), is(true));
|
||||
assertThat(dataSource.isWrapperFor(ExampleWrapper.class)).isTrue();
|
||||
}
|
||||
|
||||
public static interface ExampleWrapper {
|
||||
|
||||
@@ -27,8 +27,9 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Abstract base class for integration tests involving database initialization.
|
||||
@@ -76,9 +77,9 @@ public abstract class AbstractDatabaseInitializationTests {
|
||||
|
||||
void assertUsersDatabaseCreated(String... lastNames) {
|
||||
for (String lastName : lastNames) {
|
||||
assertThat("Did not find user with last name [" + lastName + "].",
|
||||
jdbcTemplate.queryForObject("select count(0) from users where last_name = ?", Integer.class, lastName),
|
||||
equalTo(1));
|
||||
String sql = "select count(0) from users where last_name = ?";
|
||||
Integer result = jdbcTemplate.queryForObject(sql, Integer.class, lastName);
|
||||
assertThat(result).as("user with last name [" + lastName + "]").isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
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;
|
||||
@@ -40,6 +39,10 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseInitializationTests {
|
||||
|
||||
private static final String COUNT_DAVE_SQL = "select COUNT(NAME) from T_TEST where NAME='Dave'";
|
||||
|
||||
private static final String COUNT_KEITH_SQL = "select COUNT(NAME) from T_TEST where NAME='Keith'";
|
||||
|
||||
protected final ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
|
||||
|
||||
|
||||
@@ -73,10 +76,8 @@ public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseIni
|
||||
databasePopulator.addScript(defaultSchema());
|
||||
databasePopulator.addScript(resource("db-test-data-multiple.sql"));
|
||||
DatabasePopulatorUtils.execute(databasePopulator, db);
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_KEITH_SQL, Integer.class)).isEqualTo(1);
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_DAVE_SQL, Integer.class)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,10 +86,8 @@ public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseIni
|
||||
databasePopulator.addScript(resource("db-test-data-endings.sql"));
|
||||
databasePopulator.setSeparator("@@");
|
||||
DatabasePopulatorUtils.execute(databasePopulator, db);
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_KEITH_SQL, Integer.class)).isEqualTo(1);
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_DAVE_SQL, Integer.class)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,10 +96,8 @@ public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseIni
|
||||
databasePopulator.addScript(resource("db-test-data-whitespace.sql"));
|
||||
databasePopulator.setSeparator("/\n");
|
||||
DatabasePopulatorUtils.execute(databasePopulator, db);
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_KEITH_SQL, Integer.class)).isEqualTo(1);
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_DAVE_SQL, Integer.class)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,10 +105,8 @@ public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseIni
|
||||
databasePopulator.addScript(defaultSchema());
|
||||
databasePopulator.addScript(resource("db-test-data-newline.sql"));
|
||||
DatabasePopulatorUtils.execute(databasePopulator, db);
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_KEITH_SQL, Integer.class)).isEqualTo(1);
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_DAVE_SQL, Integer.class)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,10 +115,8 @@ public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseIni
|
||||
databasePopulator.addScript(resource("db-test-data-multi-newline.sql"));
|
||||
databasePopulator.setSeparator("\n\n");
|
||||
DatabasePopulatorUtils.execute(databasePopulator, db);
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_KEITH_SQL, Integer.class)).isEqualTo(1);
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_DAVE_SQL, Integer.class)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,10 +159,8 @@ public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseIni
|
||||
databasePopulator.addScript(defaultSchema());
|
||||
databasePopulator.addScript(resource("db-test-data-select.sql"));
|
||||
DatabasePopulatorUtils.execute(databasePopulator, db);
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class),
|
||||
equalTo(1));
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_KEITH_SQL, Integer.class)).isEqualTo(1);
|
||||
assertThat(jdbcTemplate.queryForObject(COUNT_DAVE_SQL, Integer.class)).isEqualTo(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,8 +20,9 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -48,7 +49,7 @@ public class H2DatabasePopulatorTests extends AbstractDatabasePopulatorTests {
|
||||
databasePopulator.setSeparator("\n\n");
|
||||
DatabasePopulatorUtils.execute(databasePopulator, db);
|
||||
String sql = "select REVERSE(first_name) from users where last_name='Brannen'";
|
||||
assertThat(jdbcTemplate.queryForObject(sql, String.class), equalTo("maS"));
|
||||
assertThat(jdbcTemplate.queryForObject(sql, String.class)).isEqualTo("maS");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,10 +39,8 @@ import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -124,7 +122,7 @@ public class SqlQueryTests {
|
||||
query.compile();
|
||||
List<Integer> list = query.execute();
|
||||
|
||||
assertThat(list, is(equalTo(Arrays.asList(1))));
|
||||
assertThat(list).isEqualTo(Arrays.asList(1));
|
||||
verify(connection).prepareStatement(SELECT_ID);
|
||||
verify(resultSet).close();
|
||||
verify(preparedStatement).close();
|
||||
@@ -174,7 +172,7 @@ public class SqlQueryTests {
|
||||
StringQuery query = new StringQuery(dataSource, SELECT_FORENAME);
|
||||
query.setRowsExpected(3);
|
||||
String[] results = query.run();
|
||||
assertThat(results, is(equalTo(dbResults)));
|
||||
assertThat(results).isEqualTo(dbResults);
|
||||
verify(connection).prepareStatement(SELECT_FORENAME);
|
||||
verify(resultSet).close();
|
||||
verify(preparedStatement).close();
|
||||
@@ -186,7 +184,7 @@ public class SqlQueryTests {
|
||||
given(resultSet.next()).willReturn(false);
|
||||
StringQuery query = new StringQuery(dataSource, SELECT_FORENAME_EMPTY);
|
||||
String[] results = query.run();
|
||||
assertThat(results, is(equalTo(new String[0])));
|
||||
assertThat(results).isEqualTo(new String[0]);
|
||||
verify(connection).prepareStatement(SELECT_FORENAME_EMPTY);
|
||||
verify(resultSet).close();
|
||||
verify(preparedStatement).close();
|
||||
@@ -392,8 +390,8 @@ 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.get(0).getForename(), is("rod"));
|
||||
assertThat(list.get(1).getForename(), is("dave"));
|
||||
assertThat(list.get(0).getForename()).isEqualTo("rod");
|
||||
assertThat(list.get(1).getForename()).isEqualTo("dave");
|
||||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.NUMERIC);
|
||||
verify(connection).prepareStatement(SELECT_ID_WHERE);
|
||||
@@ -428,8 +426,8 @@ public class SqlQueryTests {
|
||||
CustomerQuery query = new CustomerQuery(dataSource);
|
||||
List<Customer> list = query.execute("one");
|
||||
assertTrue("2 results in list", list.size() == 2);
|
||||
assertThat(list.get(0).getForename(), is("rod"));
|
||||
assertThat(list.get(1).getForename(), is("dave"));
|
||||
assertThat(list.get(0).getForename()).isEqualTo("rod");
|
||||
assertThat(list.get(1).getForename()).isEqualTo("dave");
|
||||
verify(preparedStatement).setString(1, "one");
|
||||
verify(connection).prepareStatement(SELECT_ID_FORENAME_WHERE);
|
||||
verify(resultSet).close();
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.junit.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
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;
|
||||
@@ -76,7 +75,7 @@ public class SQLErrorCodesFactoryTests {
|
||||
}
|
||||
|
||||
private void assertIsSQLServer(SQLErrorCodes sec) {
|
||||
assertThat(sec.getDatabaseProductName(), equalTo("Microsoft SQL Server"));
|
||||
assertThat(sec.getDatabaseProductName()).isEqualTo("Microsoft SQL Server");
|
||||
|
||||
assertTrue(sec.getBadSqlGrammarCodes().length > 0);
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
@@ -52,7 +51,7 @@ public class SQLExceptionCustomTranslatorTests {
|
||||
SQLException badSqlGrammarExceptionEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 1);
|
||||
DataAccessException dae = sext.translate("task", "SQL", badSqlGrammarExceptionEx);
|
||||
assertEquals(badSqlGrammarExceptionEx, dae.getCause());
|
||||
assertThat(dae, instanceOf(BadSqlGrammarException.class));
|
||||
assertThat(dae).isInstanceOf(BadSqlGrammarException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +59,7 @@ public class SQLExceptionCustomTranslatorTests {
|
||||
SQLException dataAccessResourceEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 2);
|
||||
DataAccessException dae = sext.translate("task", "SQL", dataAccessResourceEx);
|
||||
assertEquals(dataAccessResourceEx, dae.getCause());
|
||||
assertThat(dae, instanceOf(TransientDataAccessResourceException.class));
|
||||
assertThat(dae).isInstanceOf(TransientDataAccessResourceException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user