Skip to content

Commit

Permalink
test: 캐시 테스트마다 비우기 구현
Browse files Browse the repository at this point in the history
Co-Authored-By: jinwoo22 <[email protected]>
  • Loading branch information
shin-jisong and JINU-CHANG committed Nov 21, 2024
1 parent 8861132 commit 7fa872b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;

Expand All @@ -27,10 +29,25 @@ public abstract class IntegrationTestSupport {
@Autowired
UserRepository userRepository;

@Autowired
private CacheManager cacheManager;

@BeforeEach
void init() {
UserFixture.init(userRepository);
QuestionFixture.init(categoryRepository, questionRepository);
CustomChecklistFixture.init();
clearCaches();
}

void clearCaches() {
if (cacheManager != null) {
cacheManager.getCacheNames().forEach(name -> {
Cache cache = cacheManager.getCache(name);
if (cache != null) {
cache.clear();
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

class JpaAuditingTest extends IntegrationTestSupport {
class JpaAuditingTest extends IntegrationTestSupport {

@Autowired
private TestRepository testRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ void readArticles() {
@Test
void deleteArticle() {
// given
articleRepository.save(ArticleFixture.ARTICLE());
Article article = articleRepository.save(ArticleFixture.ARTICLE());

// when
articleService.deleteArticle(ArticleFixture.ARTICLE().getId());
articleService.deleteArticle(article.getId());

//then
assertThatThrownBy(() -> articleService.readArticle(ArticleFixture.ARTICLE().getId()))
assertThatThrownBy(() -> articleService.readArticle(article.getId()))
.isInstanceOf(BangggoodException.class)
.hasMessage(ExceptionCode.ARTICLE_NOT_FOUND.getMessage());
}
Expand Down

0 comments on commit 7fa872b

Please sign in to comment.