reformats & optimize imports
This commit is contained in:
parent
9325f26b24
commit
43b920cc8a
|
@ -3,7 +3,6 @@ package com.baeldung.jtademo;
|
|||
import org.hsqldb.jdbc.pool.JDBCXADataSource;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.jta.bitronix.BitronixXADataSourceWrapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
|
@ -26,7 +25,8 @@ public class AuditService {
|
|||
|
||||
public TransferLog lastTransferLog() {
|
||||
return jdbcTemplate.query("select FROM_ACCOUNT,TO_ACCOUNT,AMOUNT from AUDIT_LOG order by ID desc", (ResultSetExtractor<TransferLog>) (rs) -> {
|
||||
if(!rs.next()) return null;
|
||||
if (!rs.next())
|
||||
return null;
|
||||
return new TransferLog(rs.getString(1), rs.getString(2), BigDecimal.valueOf(rs.getDouble(3)));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
|
|
|
@ -25,7 +25,7 @@ public class TellerService {
|
|||
bankAccountService.transfer(fromAccontId, toAccountId, amount);
|
||||
auditService.log(fromAccontId, toAccountId, amount);
|
||||
BigDecimal balance = bankAccountService.balanceOf(fromAccontId);
|
||||
if(balance.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
if (balance.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new RuntimeException("Insufficient fund.");
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class TellerService {
|
|||
bankAccountService.transfer(fromAccontId, toAccountId, amount);
|
||||
auditService.log(fromAccontId, toAccountId, amount);
|
||||
BigDecimal balance = bankAccountService.balanceOf(fromAccontId);
|
||||
if(balance.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
if (balance.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
userTransaction.rollback();
|
||||
throw new RuntimeException("Insufficient fund.");
|
||||
} else {
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package com.baeldung.jtademo.services;
|
||||
|
||||
import com.baeldung.jtademo.dto.TransferLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||
import org.springframework.jdbc.datasource.init.ScriptUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
@ -43,5 +40,4 @@ public class TestHelper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
package com.baeldung.jtademo;
|
||||
|
||||
import com.baeldung.jtademo.dto.TransferLog;
|
||||
import com.baeldung.jtademo.services.*;
|
||||
import com.baeldung.jtademo.services.AuditService;
|
||||
import com.baeldung.jtademo.services.BankAccountService;
|
||||
import com.baeldung.jtademo.services.TellerService;
|
||||
import com.baeldung.jtademo.services.TestHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = JtaDemoApplication.class)
|
||||
public class JtaDemoUnitTest {
|
||||
|
|
Loading…
Reference in New Issue