diff --git a/app/src/main/java/com/techcourse/service/TxUserService.java b/app/src/main/java/com/techcourse/service/TxUserService.java index 3c018a592a..4bc2d4021d 100644 --- a/app/src/main/java/com/techcourse/service/TxUserService.java +++ b/app/src/main/java/com/techcourse/service/TxUserService.java @@ -1,33 +1,30 @@ package com.techcourse.service; -import com.techcourse.dao.UserDao; -import com.techcourse.dao.UserHistoryDao; import com.techcourse.domain.User; -import com.techcourse.domain.UserHistory; import org.springframework.transaction.support.TransactionTemplate; public class TxUserService implements UserService { - private final UserService userService; + private final AppUserService appUserService; private final TransactionTemplate transactionTemplate; - public TxUserService(final UserService userService, final TransactionTemplate transactionTemplate) { - this.userService = userService; + public TxUserService(final AppUserService appUserService, final TransactionTemplate transactionTemplate) { + this.appUserService = appUserService; this.transactionTemplate = transactionTemplate; } @Override public User findById(final long id) { - return userService.findById(id); + return appUserService.findById(id); } @Override public void insert(final User user) { - transactionTemplate.execute(connection -> userService.insert(user)); + transactionTemplate.execute(connection -> appUserService.insert(user)); } @Override public void changePassword(final long id, final String newPassword, final String createBy) { - transactionTemplate.execute(connection -> userService.changePassword(id, newPassword, createBy)); + transactionTemplate.execute(connection -> appUserService.changePassword(id, newPassword, createBy)); } } diff --git a/app/src/test/java/com/techcourse/service/TxUserServiceTest.java b/app/src/test/java/com/techcourse/service/TxUserServiceTest.java index 29e86f88ca..138b3db602 100644 --- a/app/src/test/java/com/techcourse/service/TxUserServiceTest.java +++ b/app/src/test/java/com/techcourse/service/TxUserServiceTest.java @@ -6,7 +6,6 @@ import com.techcourse.domain.User; import com.techcourse.support.jdbc.init.DatabasePopulatorUtils; import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.JdbcTemplate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.transaction.support.TransactionTemplate; @@ -16,7 +15,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; @@ -24,7 +22,7 @@ class TxUserServiceTest { private DataSource dataSource; private UserDao userDao; - private UserService userService; + private AppUserService appUserService; private TransactionTemplate transactionTemplate; @BeforeEach @@ -32,7 +30,7 @@ void setUp() { this.dataSource = DataSourceConfig.getInstance(); this.userDao = new UserDao(dataSource); UserHistoryDao userHistoryDao = new UserHistoryDao(dataSource); - this.userService = new AppUserService(userDao, userHistoryDao); + this.appUserService = new AppUserService(userDao, userHistoryDao); this.transactionTemplate = new TransactionTemplate(dataSource); DatabasePopulatorUtils.execute(DataSourceConfig.getInstance()); @@ -42,11 +40,11 @@ void setUp() { @Test void testChangePassword() { - final var txUserService = new TxUserService(userService, transactionTemplate); + final var txUserService = new TxUserService(appUserService, transactionTemplate); final var newPassword = "qqqqq"; final var createBy = "gugu"; - userService.changePassword(1L, newPassword, createBy); + appUserService.changePassword(1L, newPassword, createBy); final var actual = txUserService.findById(1L);