@@ -22,7 +22,7 @@ test_that("java_valid_versions_fast uses file cache when session cache absent",
2222 )
2323
2424 # Write a valid cache file
25- jsonlite :: write_json(c( " 8" , " 11" , " 17" , " 21" , " 42" ) , cache_file )
25+ writeLines( ' [ "8", "11", "17", "21", "42"] ' , cache_file )
2626
2727 result <- java_valid_versions_fast()
2828
@@ -60,7 +60,7 @@ test_that("java_valid_versions_fast fallback on stale cache file", {
6060 )
6161
6262 # Write a cache file and make it old
63- jsonlite :: write_json(c( " 8" , " 11" , " 17" , " 21" , " old" ) , cache_file )
63+ writeLines( ' [ "8", "11", "17", "21", "old"] ' , cache_file )
6464 Sys.setFileTime(cache_file , Sys.time() - 25 * 60 * 60 ) # 25 hours ago
6565
6666 result <- java_valid_versions_fast()
@@ -109,7 +109,7 @@ test_that("java_valid_versions uses file cache when session cache expired", {
109109 )
110110
111111 # Write a valid cache file
112- jsonlite :: write_json(c( " 8" , " 11" , " 17" , " 21" , " file_cached" ) , cache_file )
112+ writeLines( ' [ "8", "11", "17", "21", "file_cached"] ' , cache_file )
113113
114114 result <- java_valid_versions(
115115 distribution = " Corretto" ,
@@ -160,7 +160,7 @@ test_that("java_valid_versions fetches from network when file cache expired", {
160160 )
161161
162162 # Write a cache file and make it old
163- jsonlite :: write_json(c( " 8" , " 11" , " 17" , " 21" , " stale" ) , cache_file )
163+ writeLines( ' [ "8", "11", "17", "21", "stale"] ' , cache_file )
164164 Sys.setFileTime(cache_file , Sys.time() - 25 * 60 * 60 ) # 25 hours ago
165165
166166 result <- java_valid_versions(force = FALSE )
@@ -178,19 +178,35 @@ test_that("java_valid_versions saves results to session and file cache", {
178178 cache_path <- withr :: local_tempdir()
179179
180180 withr :: local_options(
181- rJavaEnv.valid_versions_cache = NULL ,
182- rJavaEnv.valid_versions_timestamp = NULL ,
181+ rJavaEnv.valid_versions_cache_list = NULL ,
182+ rJavaEnv.valid_versions_timestamp_list = NULL ,
183183 rJavaEnv.cache_path = cache_path
184184 )
185185
186+ # Use fixed params via defaults or explicit if needed, but here defaults are fine
187+ # provided we know what key they generate.
188+ # By default: distribution="Corretto", platform=platform_detect()$os, arch=platform_detect()$arch
189+
186190 result <- java_valid_versions(force = TRUE )
187191
188- # Session cache should be populated
189- expect_equal(getOption( " rJavaEnv.valid_versions_cache " ), result )
190- expect_false(is.null(getOption( " rJavaEnv.valid_versions_timestamp " )) )
192+ plat <- platform_detect( quiet = TRUE ) $ os
193+ arch <- platform_detect( quiet = TRUE ) $ arch
194+ cache_key <- sprintf( " Corretto_%s_%s " , plat , arch )
191195
192- # File cache should be created
193- expect_true(file.exists(file.path(cache_path , " valid_versions.json" )))
196+ # Session cache check
197+ cache_list <- getOption(" rJavaEnv.valid_versions_cache_list" )
198+ ts_list <- getOption(" rJavaEnv.valid_versions_timestamp_list" )
199+
200+ expect_false(is.null(cache_list [[cache_key ]]))
201+ expect_equal(cache_list [[cache_key ]], result )
202+ expect_false(is.null(ts_list [[cache_key ]]))
203+
204+ # File cache check
205+ expected_file <- file.path(
206+ cache_path ,
207+ sprintf(" valid_versions_%s.json" , cache_key )
208+ )
209+ expect_true(file.exists(expected_file ))
194210})
195211
196212# Test java_valid_major_versions_corretto with explicit platform/arch
0 commit comments