Skip to content

Commit

Permalink
test: UserHsitoryDao테스트 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
pilyang committed Sep 29, 2023
1 parent d006aef commit aa06740
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions app/src/test/java/com/techcourse/dao/UserHistoryDaoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.techcourse.dao;

import com.techcourse.config.DataSourceConfig;
import com.techcourse.domain.User;
import com.techcourse.domain.UserHistory;
import com.techcourse.support.jdbc.init.DatabasePopulatorUtils;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;

class UserHistoryDaoTest {

private UserHistoryDao userHistoryDao;
private JdbcTemplate jdbcTemplate;

@BeforeEach
void setup() {
DatabasePopulatorUtils.execute(DataSourceConfig.getInstance());

userHistoryDao = new UserHistoryDao(DataSourceConfig.getInstance());
jdbcTemplate = new JdbcTemplate(DataSourceConfig.getInstance());
}

@Test
void log() {
final User philip = new User(1L, "philip", "jaepil", "[email protected]");
final UserHistory userHistory = new UserHistory(philip, "sun-shot");

userHistoryDao.log(userHistory);

var selectSql = "select id, user_id, account, password, email, created_at, created_by from user_history where created_by = ?";
Optional<UserHistory> result = jdbcTemplate.queryForObject(selectSql,
resultSet -> new UserHistory(
resultSet.getLong("id"),
resultSet.getLong("user_id"),
resultSet.getString("account"),
resultSet.getString("password"),
resultSet.getString("email"),
resultSet.getString("created_by")
),
"sun-shot");

SoftAssertions.assertSoftly(softly -> {
softly.assertThat(result).isPresent();
softly.assertThat(result.get().getAccount()).isEqualTo("philip");
softly.assertThat(result.get().getCreateBy()).isEqualTo("sun-shot");
});
}

}

0 comments on commit aa06740

Please sign in to comment.