GHRepository#listLanguages returns correct Map type

This is a less than perfect solution, but it is sufficient to solve the current issue
without risking further side-effects.

Fixes #1103
This commit is contained in:
Liam Newman
2021-04-16 14:18:49 -07:00
parent adf054ba5d
commit 684560ef67
2 changed files with 14 additions and 2 deletions

View File

@@ -578,7 +578,15 @@ public class GHRepository extends GHObject {
* the io exception
*/
public Map<String, Long> listLanguages() throws IOException {
return root.createRequest().withUrlPath(getApiTailUrl("languages")).fetch(HashMap.class);
HashMap<String, Long> result = new HashMap<>();
root.createRequest().withUrlPath(getApiTailUrl("languages")).fetch(HashMap.class).forEach((key, value) -> {
Long addValue = -1L;
if (value instanceof Integer) {
addValue = Long.valueOf((Integer) value);
}
result.put(key.toString(), addValue);
});
return result;
}
/**

View File

@@ -14,6 +14,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.hamcrest.Matchers.*;
@@ -396,7 +397,10 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
public void listLanguages() throws IOException {
GHRepository r = gitHub.getRepository("hub4j/github-api");
String mainLanguage = r.getLanguage();
assertTrue(r.listLanguages().containsKey(mainLanguage));
assertThat(mainLanguage, equalTo("Java"));
Map<String, Long> languages = r.listLanguages();
assertTrue(languages.containsKey(mainLanguage));
assertThat(languages.get("Java"), greaterThan(100000L));
}
@Test