diff --git a/src/main/java/com/uid2/shared/store/reader/RotatingSiteStore.java b/src/main/java/com/uid2/shared/store/reader/RotatingSiteStore.java index 124efa2a..0c523032 100644 --- a/src/main/java/com/uid2/shared/store/reader/RotatingSiteStore.java +++ b/src/main/java/com/uid2/shared/store/reader/RotatingSiteStore.java @@ -14,7 +14,6 @@ public class RotatingSiteStore implements ISiteStore, StoreReader> { - public static final String SITES_METADATA_PATH = "sites_metadata_path"; private final ScopedStoreReader> reader; public RotatingSiteStore(DownloadCloudStorage fileStreamProvider, StoreScope scope) { @@ -36,7 +35,8 @@ public Collection getAll() { @Override public Site getSite(int siteId) { - return reader.getSnapshot().get(siteId); + final var snapshot = reader.getSnapshot(); + return snapshot != null ? snapshot.get(siteId) : null; } public JsonObject getMetadata() throws Exception { diff --git a/src/test/java/com/uid2/shared/store/RotatingSiteStoreTest.java b/src/test/java/com/uid2/shared/store/RotatingSiteStoreTest.java index 90a7b709..54a554de 100644 --- a/src/test/java/com/uid2/shared/store/RotatingSiteStoreTest.java +++ b/src/test/java/com/uid2/shared/store/RotatingSiteStoreTest.java @@ -17,8 +17,7 @@ import java.util.List; import static com.uid2.shared.TestUtilites.makeInputStream; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; public class RotatingSiteStoreTest { @@ -97,4 +96,10 @@ public void loadContentMultipleSites() throws Exception { assertTrue(siteStore.getAllSites().contains(s3)); assertTrue(siteStore.getAllSites().contains(s4)); } + + @Test + public void getSiteReturnsNullBeforeLoadContentIsCalled() { //eg, loadContent() is never called for Private Operators as they don't currently require site data + final var site = siteStore.getSite(1); + assertNull(site); + } }