All implements ExecutableWithNamespace { protected Set<Map.Entry<String, JsonElement>> parseStoreToImagesMap(String storeName) throws IOException, InterruptedException { GHMyself myself = dockerfileGitHubUtil.getMyself(); String login = myself.getLogin(); GHRepository store = dockerfileGitHubUtil.getRepo(Paths.get(login, storeName).toString()); GHContent storeContent = dockerfileGitHubUtil.tryRetrievingContent(store, Constants.STORE_JSON_FILE, store.getDefaultBranch()); if (storeContent == null) { return Collections.emptySet(); } JsonElement json; try (InputStream stream = storeContent.read(); InputStreamReader streamR = new InputStreamReader(stream)) { try { json = JsonParser.parseReader(streamR); } catch (JsonParseException e) { log.warn("Not a JSON format store."); return Collections.emptySet(); } } JsonElement imagesJson = json.getAsJsonObject().get("images"); return imagesJson.getAsJsonObject().entrySet(); }  @Override void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil);  }
@Test public void testParseStoreToImagesMap() throws Exception { DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); when(dockerfileGitHubUtil.getMyself()).thenReturn(mock(GHMyself.class)); when(dockerfileGitHubUtil.getRepo(anyString())).thenReturn(mock(GHRepository.class)); GHContent mockContent = mock(GHContent.class); ClassLoader classloader = Thread.currentThread().getContextClassLoader(); when(mockContent.read()).thenReturn(classloader.getResourceAsStream("image-store-sample.json")); when(dockerfileGitHubUtil.tryRetrievingContent(any(GHRepository.class), anyString(), anyString())).thenReturn(mockContent); All all = new All(); all.loadDockerfileGithubUtil(dockerfileGitHubUtil); Set<Map.Entry<String, JsonElement>> imageSet = all.parseStoreToImagesMap("testStore"); assertNotNull(imageSet); }