diff --git a/src/main/java/io/codeka/gaia/registries/AbstractRegistryApi.kt b/src/main/java/io/codeka/gaia/registries/AbstractRegistryApi.kt index 0211ad50f..239e8d9f2 100644 --- a/src/main/java/io/codeka/gaia/registries/AbstractRegistryApi.kt +++ b/src/main/java/io/codeka/gaia/registries/AbstractRegistryApi.kt @@ -42,7 +42,7 @@ abstract class AbstractRegistryApi(val restTemplate: RestTe val token = user.oAuth2User?.token!! - return callWithAuth(url, token, registryListFileClass)!!.toList() + return callWithAuth(url, token, registryListFileClass)?.toList() ?: emptyList() } override fun getRepository(user: User, projectId: String): K { diff --git a/src/test/java/io/codeka/gaia/registries/github/GithubRegistryApiTest.kt b/src/test/java/io/codeka/gaia/registries/github/GithubRegistryApiTest.kt index 18732120c..dcbe50977 100644 --- a/src/test/java/io/codeka/gaia/registries/github/GithubRegistryApiTest.kt +++ b/src/test/java/io/codeka/gaia/registries/github/GithubRegistryApiTest.kt @@ -53,6 +53,23 @@ class GithubRegistryApiTest{ assertThat(repositories).containsExactly(sampleResult) } + @Test + fun `getRepositories() should return empty list in case of 404`() { + // given + server.expect(requestTo("https://api.github.com/user/repos?visibility=public")) + .andExpect(header("Authorization", "Bearer johnstoken")) + .andRespond(withStatus(HttpStatus.NOT_FOUND)) + + val john = User("john", null) + john.oAuth2User = OAuth2User("github", "johnstoken", null) + + // when + val repositories = githubRegistryApi.getRepositories(john) + + // then + assertThat(repositories).isEmpty() + } + @Test fun `getRepository() should call the repos github api`() { // given