Replace anonymous types with lambda expressions or method references

This commit is contained in:
Mahmoud Ben Hassine
2023-07-04 18:49:31 +02:00
parent 07154909a1
commit 96f8d6bd35
34 changed files with 405 additions and 695 deletions

View File

@@ -34,12 +34,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.orm.hibernate5.HibernateJdbcException;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
@@ -123,17 +121,8 @@ class HibernateFailureJobFunctionalTests {
*/
protected void validatePreConditions() {
ensureState();
creditsBeforeUpdate = new TransactionTemplate(transactionManager).execute(new TransactionCallback<>() {
@Override
public List<BigDecimal> doInTransaction(TransactionStatus status) {
return jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper<>() {
@Override
public BigDecimal mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getBigDecimal(CREDIT_COLUMN);
}
});
}
});
creditsBeforeUpdate = new TransactionTemplate(transactionManager)
.execute(status -> jdbcTemplate.query(ALL_CUSTOMERS, (rs, rowNum) -> rs.getBigDecimal(CREDIT_COLUMN)));
}
/*
@@ -141,16 +130,12 @@ class HibernateFailureJobFunctionalTests {
* customer table and reading the expected defaults.
*/
private void ensureState() {
new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus status) {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "CUSTOMER");
for (String customer : customers) {
jdbcTemplate.update(customer);
}
return null;
new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
JdbcTestUtils.deleteFromTables(jdbcTemplate, "CUSTOMER");
for (String customer : customers) {
jdbcTemplate.update(customer);
}
return null;
});
}
@@ -160,25 +145,22 @@ class HibernateFailureJobFunctionalTests {
protected void validatePostConditions() {
final List<BigDecimal> matches = new ArrayList<>();
new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus status) {
jdbcTemplate.query(ALL_CUSTOMERS, new RowCallbackHandler() {
private int i = 0;
new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
jdbcTemplate.query(ALL_CUSTOMERS, new RowCallbackHandler() {
private int i = 0;
@Override
public void processRow(ResultSet rs) throws SQLException {
final BigDecimal creditBeforeUpdate = creditsBeforeUpdate.get(i++);
final BigDecimal expectedCredit = creditBeforeUpdate.add(CREDIT_INCREASE);
if (expectedCredit.equals(rs.getBigDecimal(CREDIT_COLUMN))) {
matches.add(rs.getBigDecimal(ID_COLUMN));
}
@Override
public void processRow(ResultSet rs) throws SQLException {
final BigDecimal creditBeforeUpdate = creditsBeforeUpdate.get(i++);
final BigDecimal expectedCredit = creditBeforeUpdate.add(CREDIT_INCREASE);
if (expectedCredit.equals(rs.getBigDecimal(CREDIT_COLUMN))) {
matches.add(rs.getBigDecimal(ID_COLUMN));
}
}
});
});
return null;
}
return null;
});
assertEquals((creditsBeforeUpdate.size() - 1), matches.size());

View File

@@ -39,7 +39,7 @@ class JobExecutionNotificationPublisherTests {
void testRepeatOperationsOpenUsed() {
final List<Notification> list = new ArrayList<>();
publisher.setNotificationPublisher(notification -> list.add(notification));
publisher.setNotificationPublisher(list::add);
publisher.onApplicationEvent(new SimpleMessageApplicationEvent(this, "foo"));
assertEquals(1, list.size());