Skip to content

Commit

Permalink
Add hasSourceLocation assertion for FindingAssert
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Jun 5, 2022
1 parent 9146e4d commit da57cef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions detekt-test/api/detekt-test.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ public final class io/gitlab/arturbosch/detekt/test/FindingAssert : org/assertj/
public fun <init> (Lio/gitlab/arturbosch/detekt/api/Finding;)V
public final fun getActual ()Lio/gitlab/arturbosch/detekt/api/Finding;
public final fun hasMessage (Ljava/lang/String;)Lio/gitlab/arturbosch/detekt/test/FindingAssert;
public final fun hasSourceLocation (II)Lio/gitlab/arturbosch/detekt/test/FindingAssert;
}

public final class io/gitlab/arturbosch/detekt/test/FindingsAssert : org/assertj/core/api/AbstractListAssert {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ class FindingsAssert(actual: List<Finding>) :
}

class FindingAssert(val actual: Finding?) : AbstractAssert<FindingAssert, Finding>(actual, FindingAssert::class.java) {

fun hasSourceLocation(line: Int, column: Int) = apply {
val expectedLocation = SourceLocation(line, column)
val actualLocation = actual.location.source
if (actualLocation != expectedLocation) {
failWithMessage("Expected source location to be $expectedLocation but was $actualLocation")
}
}

fun hasMessage(expectedMessage: String) = apply {
if (expectedMessage.isNotBlank() && actual.message.isBlank()) {
failWithMessage("Expected message <$expectedMessage> but finding has no message")
Expand Down

0 comments on commit da57cef

Please sign in to comment.