Skip to content

Commit 3cc7e22

Browse files
committed
clear cache before each test
1 parent 604b17a commit 3cc7e22

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

server/src/test/java/org/eclipse/openvsx/cache/CacheServiceTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import org.eclipse.openvsx.security.IdPrincipal;
2323
import org.eclipse.openvsx.util.TempFile;
2424
import org.eclipse.openvsx.util.TimeUtil;
25+
import org.junit.jupiter.api.BeforeEach;
2526
import org.junit.jupiter.api.Test;
2627
import org.springframework.beans.factory.annotation.Autowired;
2728
import org.springframework.boot.test.context.SpringBootTest;
29+
import org.springframework.cache.Cache;
2830
import org.springframework.cache.CacheManager;
2931
import org.springframework.mock.web.MockHttpServletRequest;
3032
import org.springframework.security.authentication.TestingAuthenticationToken;
@@ -39,8 +41,11 @@
3941
import java.time.LocalDateTime;
4042
import java.util.Collections;
4143
import java.util.List;
44+
import java.util.Objects;
45+
import java.util.stream.Stream;
4246

4347
import static org.eclipse.openvsx.cache.CacheService.CACHE_EXTENSION_JSON;
48+
import static org.eclipse.openvsx.cache.CacheService.CACHE_AVERAGE_REVIEW_RATING;
4449
import static org.eclipse.openvsx.entities.FileResource.DOWNLOAD;
4550
import static org.eclipse.openvsx.entities.FileResource.STORAGE_LOCAL;
4651
import static org.junit.jupiter.api.Assertions.*;
@@ -70,6 +75,14 @@ class CacheServiceTest {
7075
@Autowired
7176
RepositoryService repositories;
7277

78+
@BeforeEach
79+
void beforeEach() {
80+
Stream.of(CACHE_EXTENSION_JSON, CACHE_AVERAGE_REVIEW_RATING)
81+
.map(name -> cache.getCache(name))
82+
.filter(Objects::nonNull)
83+
.forEach(Cache::clear);
84+
}
85+
7386
@Test
7487
@Transactional
7588
void testGetExtension() throws IOException {
@@ -287,8 +300,6 @@ void testAverageReviewRating() throws IOException {
287300
var user = insertAdmin();
288301
try (var tempFile = insertExtensionVersion()) {
289302
// no reviews in database
290-
var reviews = repositories.findAllReviews(tempFile.getResource().getExtension().getExtension());
291-
assertTrue(reviews.isEmpty());
292303
assertEquals(0L, repositories.getAverageReviewRating());
293304

294305
var extVersion = tempFile.getResource().getExtension();
@@ -303,7 +314,7 @@ void testAverageReviewRating() throws IOException {
303314
// returns cached value
304315
assertEquals(0L, repositories.getAverageReviewRating());
305316

306-
cache.getCache(CacheService.CACHE_AVERAGE_REVIEW_RATING).clear();
317+
cache.getCache(CACHE_AVERAGE_REVIEW_RATING).clear();
307318

308319
// returns new value from database
309320
assertEquals(3L, repositories.getAverageReviewRating());

0 commit comments

Comments
 (0)