### Question:
S3ConfigSource { public RemoteConfigCollection getRemoteConfig() { try { if (enabled) { return cache.get(objectKey); } } catch (ExecutionException | UncheckedExecutionException e) { LOG.warn("Unable to get {} from cache.", objectKey); } return RemoteConfigCollection.EMPTY_REMOTE_CONFIG_COLLECTION; } S3ConfigSource();  S3ConfigSource(SelfServiceConfig selfServiceConfig, AmazonS3 s3Client, ObjectMapper objectMapper); RemoteConfigCollection getRemoteConfig(); CacheLoader<String, RemoteConfigCollection> getCacheLoader();  }### Answer:
@Test public void getRemoteConfigReturnsRemoteConfigCollection() throws Exception { SelfServiceConfig selfServiceConfig = objectMapper.readValue(selfServiceConfigEnabledJson, SelfServiceConfig.class); when(s3Client.getObject(new GetObjectRequest(BUCKET_NAME, OBJECT_KEY))).thenReturn(s3Object); when(s3Object.getObjectContent()).thenReturn(getObjectStream("/remote-test-config.json")); when(s3Object.getObjectMetadata()).thenReturn(objectMetadata); when(objectMetadata.getLastModified()).thenReturn(new Date()); S3ConfigSource testSource = new S3ConfigSource(selfServiceConfig, s3Client, objectMapper); RemoteConfigCollection result = testSource.getRemoteConfig(); Map<String, RemoteMatchingServiceConfig> msConfigs = result.getMatchingServiceAdapters(); assertThat(msConfigs.size()).isEqualTo(3); assertThat(msConfigs.get("https: assertThat(msConfigs.get("https: assertThat(msConfigs.get("https: assertThat(msConfigs.get("https: Map<String, RemoteServiceProviderConfig> spConfigs = result.getServiceProviders(); assertThat(spConfigs.size()).isEqualTo(3); RemoteServiceProviderConfig spConfig2 = spConfigs.get("2"); assertThat(spConfig2.getName()).isEqualTo("Apple Registry VSP"); assertThat(spConfig2.getSignatureVerificationCertificates().size()).isEqualTo(1); assertThat(spConfig2.getSignatureVerificationCertificates().get(0)).contains(CERT_VSP_APPLE_SIGNING); RemoteServiceProviderConfig spConfig3 = spConfigs.get("3"); assertThat(spConfig3.getName()).isEqualTo("Banana Registry VSP"); assertThat(spConfig3.getSignatureVerificationCertificates().size()).isEqualTo(1); assertThat(spConfig3.getSignatureVerificationCertificates().get(0)).contains(CERT_VSP_BANANA_SIGNING); }
@Test public void getRemoteConfigReturnsEmptyRemoteConfigWhenSelfServiceDisabled() throws IOException { SelfServiceConfig selfServiceConfig = objectMapper.readValue(selfServiceConfigDisabledJson, SelfServiceConfig.class); S3ConfigSource testSource = new S3ConfigSource(selfServiceConfig, null, objectMapper); RemoteConfigCollection result = testSource.getRemoteConfig(); assertThat(result).isNotNull(); assertThat(result.getServiceProviders().size()).isEqualTo(0); assertThat(result.getMatchingServiceAdapters().size()).isEqualTo(0); assertThat(result.getConnectedServices().size()).isEqualTo(0); }
@Test public void getRemoteConfigReturnsCachedConfigWhenRepeatedlyCalled() throws IOException { SelfServiceConfig selfServiceConfig = objectMapper.readValue(selfServiceConfigEnabledJson, SelfServiceConfig.class); when(s3Client.getObject(new GetObjectRequest(BUCKET_NAME, OBJECT_KEY))).thenReturn(s3Object); when(s3Object.getObjectContent()).thenReturn(getObjectStream("/remote-test-config.json")); when(s3Object.getObjectMetadata()).thenReturn(objectMetadata); when(objectMetadata.getLastModified()).thenReturn(new Date()); S3ConfigSource testSource = new S3ConfigSource(selfServiceConfig, s3Client, objectMapper); RemoteConfigCollection result1 = testSource.getRemoteConfig(); RemoteConfigCollection result2 = testSource.getRemoteConfig(); verify(s3Object, times(1)).getObjectContent(); assertThat(result1 == result2); }