Skip to content

Commit

Permalink
🐛 : correct potential NPE on 404
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit authored and cdubuisson committed Apr 9, 2020
1 parent c0e1fe0 commit be05718
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class AbstractRegistryApi<K: SourceRepository>(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be05718

Please sign in to comment.