2222import org .eclipse .openvsx .security .IdPrincipal ;
2323import org .eclipse .openvsx .util .TempFile ;
2424import org .eclipse .openvsx .util .TimeUtil ;
25+ import org .junit .jupiter .api .BeforeEach ;
2526import org .junit .jupiter .api .Test ;
2627import org .springframework .beans .factory .annotation .Autowired ;
2728import org .springframework .boot .test .context .SpringBootTest ;
29+ import org .springframework .cache .Cache ;
2830import org .springframework .cache .CacheManager ;
2931import org .springframework .mock .web .MockHttpServletRequest ;
3032import org .springframework .security .authentication .TestingAuthenticationToken ;
3941import java .time .LocalDateTime ;
4042import java .util .Collections ;
4143import java .util .List ;
44+ import java .util .Objects ;
45+ import java .util .stream .Stream ;
4246
4347import static org .eclipse .openvsx .cache .CacheService .CACHE_EXTENSION_JSON ;
48+ import static org .eclipse .openvsx .cache .CacheService .CACHE_AVERAGE_REVIEW_RATING ;
4449import static org .eclipse .openvsx .entities .FileResource .DOWNLOAD ;
4550import static org .eclipse .openvsx .entities .FileResource .STORAGE_LOCAL ;
4651import 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