Skip to content

Commit

Permalink
Fix exception on annotation traversal when target is not present (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioarfaria committed Mar 28, 2022
1 parent 5eed679 commit a2e0f2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/slack/eithernet/Annotations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private fun <A : Any> Array<out Annotation>.nextAnnotations(type: Class<A>): Pai
if (type.isInstance(next)) {
@Suppress("UNCHECKED_CAST")
resultType = next as A
} else {
} else if (nextIndex < nextAnnotations.size) {
nextAnnotations[nextIndex] = next
nextIndex++
}
Expand Down
20 changes: 18 additions & 2 deletions src/test/kotlin/com/slack/eithernet/ResultTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ResultTypeTest {
}

@Test
fun errorType() {
fun errorType_present() {
val annotations = Array<Annotation>(4) {
ResultTypeTest::class.java.getAnnotation(SampleAnnotation::class.java)
}
Expand All @@ -74,7 +74,15 @@ class ResultTypeTest {
}

@Test
fun statusCode() {
fun errorType_absent() {
val annotations = Array<Annotation>(4) {
ResultTypeTest::class.java.getAnnotation(SampleAnnotation::class.java)
}
assertThat(annotations.errorType()).isNull()
}

@Test
fun statusCode_present() {
val annotations = Array<Annotation>(4) {
ResultTypeTest::class.java.getAnnotation(SampleAnnotation::class.java)
}
Expand All @@ -85,6 +93,14 @@ class ResultTypeTest {
assertThat(statusCode).isSameInstanceAs(statusCodeAnnotation)
}

@Test
fun statusCode_absent() {
val annotations = Array<Annotation>(4) {
ResultTypeTest::class.java.getAnnotation(SampleAnnotation::class.java)
}
assertThat(annotations.statusCode()).isNull()
}

private class A

private class B
Expand Down

0 comments on commit a2e0f2d

Please sign in to comment.