@Test void fetchMetadata() throws URISyntaxException { List<Path> paths = new ArrayList<>(4); paths.add(Paths.get(ClassLoader.getSystemResource("com/webauthn4j/metadata/JsonMetadataItem_fido2.json").toURI())); paths.add(Paths.get(ClassLoader.getSystemResource("com/webauthn4j/metadata/JsonMetadataItem_u2f.json").toURI())); paths.add(Paths.get(ClassLoader.getSystemResource("com/webauthn4j/metadata/JsonMetadataItem_uaf.json").toURI())); JsonFileMetadataStatementsProvider provider = new JsonFileMetadataStatementsProvider(objectConverter, paths); Map<AAGUID, Set<MetadataStatement>> itemMapInFirstCall = provider.provide(); readMetadataItem(itemMapInFirstCall); Map<AAGUID, Set<MetadataStatement>> itemMap = provider.provide(); readMetadataItem(itemMap); assertThat(itemMap).isSameAs(itemMapInFirstCall); }
@Override public Map<AAGUID, Set<MetadataStatement>> provide() { if (cachedMetadataItems == null) { cachedMetadataItems = paths.stream() .map(this::readJsonFile) .distinct() .collect(Collectors.groupingBy(this::extractAAGUID)) .entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> new HashSet<>(entry.getValue()))); } return cachedMetadataItems; }
JsonFileMetadataStatementsProvider implements MetadataStatementsProvider { @Override public Map<AAGUID, Set<MetadataStatement>> provide() { if (cachedMetadataItems == null) { cachedMetadataItems = paths.stream() .map(this::readJsonFile) .distinct() .collect(Collectors.groupingBy(this::extractAAGUID)) .entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> new HashSet<>(entry.getValue()))); } return cachedMetadataItems; } }
JsonFileMetadataStatementsProvider implements MetadataStatementsProvider { @Override public Map<AAGUID, Set<MetadataStatement>> provide() { if (cachedMetadataItems == null) { cachedMetadataItems = paths.stream() .map(this::readJsonFile) .distinct() .collect(Collectors.groupingBy(this::extractAAGUID)) .entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> new HashSet<>(entry.getValue()))); } return cachedMetadataItems; } JsonFileMetadataStatementsProvider(ObjectConverter objectConverter, List<Path> paths); }
JsonFileMetadataStatementsProvider implements MetadataStatementsProvider { @Override public Map<AAGUID, Set<MetadataStatement>> provide() { if (cachedMetadataItems == null) { cachedMetadataItems = paths.stream() .map(this::readJsonFile) .distinct() .collect(Collectors.groupingBy(this::extractAAGUID)) .entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> new HashSet<>(entry.getValue()))); } return cachedMetadataItems; } JsonFileMetadataStatementsProvider(ObjectConverter objectConverter, List<Path> paths); @Override Map<AAGUID, Set<MetadataStatement>> provide(); }
JsonFileMetadataStatementsProvider implements MetadataStatementsProvider { @Override public Map<AAGUID, Set<MetadataStatement>> provide() { if (cachedMetadataItems == null) { cachedMetadataItems = paths.stream() .map(this::readJsonFile) .distinct() .collect(Collectors.groupingBy(this::extractAAGUID)) .entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> new HashSet<>(entry.getValue()))); } return cachedMetadataItems; } JsonFileMetadataStatementsProvider(ObjectConverter objectConverter, List<Path> paths); @Override Map<AAGUID, Set<MetadataStatement>> provide();  }