Skip to content

Commit

Permalink
refactor: tx userservice 의 필드는 appuserservice로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
shb03323 committed Oct 11, 2023
1 parent 407ef4d commit e1b576b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
15 changes: 6 additions & 9 deletions app/src/main/java/com/techcourse/service/TxUserService.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
10 changes: 4 additions & 6 deletions app/src/test/java/com/techcourse/service/TxUserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,23 +15,22 @@
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;

class TxUserServiceTest {

private DataSource dataSource;
private UserDao userDao;
private UserService userService;
private AppUserService appUserService;
private TransactionTemplate transactionTemplate;

@BeforeEach
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());
Expand All @@ -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);

Expand Down

0 comments on commit e1b576b

Please sign in to comment.