-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
400f15d
commit b0ab4c1
Showing
2 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/DetektMessageCollectorSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.gitlab.arturbosch.detekt.core | ||
|
||
import io.mockk.Called | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.slot | ||
import io.mockk.verify | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.lifecycle.CachingMode | ||
import org.spekframework.spek2.style.specification.describe | ||
|
||
internal object DetektMessageCollectorSpec : Spek({ | ||
describe("DetektMessageCollector") { | ||
val debugPrinter: (() -> String) -> Unit by memoized(CachingMode.TEST) { | ||
mockk { | ||
every { this@mockk.invoke(any()) } returns Unit | ||
} | ||
} | ||
val warningPrinter: (String) -> Unit by memoized(CachingMode.TEST) { | ||
mockk { | ||
every { this@mockk.invoke(any()) } returns Unit | ||
} | ||
} | ||
val subject by memoized(CachingMode.TEST) { | ||
DetektMessageCollector( | ||
minSeverity = CompilerMessageSeverity.INFO, | ||
debugPrinter = debugPrinter, | ||
warningPrinter = warningPrinter, | ||
) | ||
} | ||
|
||
describe("message with min severity") { | ||
beforeEachTest { subject.report(CompilerMessageSeverity.INFO, "message", null) } | ||
|
||
it("prints the message") { | ||
val slot = slot<() -> String>() | ||
verify { debugPrinter.invoke(capture(slot)) } | ||
assertThat(slot.captured()).isEqualTo("info: message") | ||
} | ||
|
||
it("adds up to the message count") { | ||
subject.printIssuesCountIfAny() | ||
|
||
verify { | ||
warningPrinter( | ||
"The BindingContext was created with 1 issues. " + | ||
"Run detekt with --debug to see the error messages." | ||
) | ||
} | ||
} | ||
} | ||
describe("message with higher severity than the min severity") { | ||
beforeEachTest { subject.report(CompilerMessageSeverity.WARNING, "message", null) } | ||
|
||
it("prints the message") { | ||
val slot = slot<() -> String>() | ||
verify { debugPrinter.invoke(capture(slot)) } | ||
assertThat(slot.captured()).isEqualTo("warning: message") | ||
} | ||
|
||
it("adds up to the message count") { | ||
subject.printIssuesCountIfAny() | ||
|
||
verify { | ||
warningPrinter( | ||
"The BindingContext was created with 1 issues. " + | ||
"Run detekt with --debug to see the error messages." | ||
) | ||
} | ||
} | ||
} | ||
describe("message with lower severity than the min severity") { | ||
beforeEachTest { subject.report(CompilerMessageSeverity.LOGGING, "message", null) } | ||
|
||
it("ignores the message") { | ||
verify { debugPrinter wasNot Called } | ||
} | ||
|
||
it("doesn't add up to the message count") { | ||
subject.printIssuesCountIfAny() | ||
|
||
verify { warningPrinter wasNot Called } | ||
} | ||
} | ||
} | ||
}) |