AssociationStore { @NonNull public static Set<String> read(@NonNull Context context, @NonNull AssociationMap map) { Set<String> initial = read(context); if (initial == null) { Set<String> associations = map.associations().map(Association::getAbbreviation).collect(Collectors.toSet()); replace(context, associations); return associations; } else { return initial; } } private  AssociationStore(); @NonNull static Set<String> read(@NonNull Context context, @NonNull AssociationMap map); @Nullable static Set<String> read(@NonNull Context context); static void blacklist(@NonNull Context context, @NonNull String abbreviation); static void whitelist(@NonNull Context context, @NonNull String abbreviation); static void replace(@NonNull Context context, @NonNull Set<String> whitelist); static final String PREF_WHITELIST; }
@Test public void readingWithoutDataReturnsNull() { assertNull(AssociationStore.read(context)); }
@Test public void readWithData() { List<Association> associations = Utils.generate(Association.class, 2).collect(Collectors.toList()); MemoryAssociationMap map = new MemoryAssociationMap(associations); Set<String> result = AssociationStore.read(context, map); assertTrue(result.containsAll(associations.stream().map(Association::getAbbreviation).collect(Collectors.toSet()))); result = AssociationStore.read(context); assertNotNull(result); assertTrue(result.containsAll(associations.stream().map(Association::getAbbreviation).collect(Collectors.toSet()))); }