10000 Migrate ComplexInterface test cases to JSR223 by schalkms · Pull Request #1830 · detekt/detekt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate ComplexInterface test cases to JSR223 #1830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ enum class Case(val file: String) {
MemberNameEqualsClassNamePositive("/cases/MemberNameEqualsClassNamePositive.kt"),
OverloadedMethods("/cases/OverloadedMethods.kt"),
ComplexClass("/cases/ComplexClass.kt"),
ComplexInterfaceNegative("/cases/ComplexInterfaceNegative.kt"),
ComplexInterfacePositive("/cases/ComplexInterfacePositive.kt"),
NestedClasses("/cases/NestedClasses.kt"),
NoClasses("/cases/NoClasses.kt"),
UnreachableCode("/cases/UnreachableCode.kt"),
Expand Down
10000
Original file line number Diff line number Diff line change
@@ -1,32 +1,117 @@
package io.gitlab.arturbosch.detekt.rules.complexity

import io.gitlab.arturbosch.detekt.rules.Case
import io.gitlab.arturbosch.detekt.test.TestConfig
import io.gitlab.arturbosch.detekt.test.lint
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.assertj.core.api.Assertions.assertThat
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe

class ComplexInterfaceSpec : Spek({

val subject by memoized { ComplexInterface(threshold = THRESHOLD) }
val config = TestConfig(mapOf(ComplexInterface.INCLUDE_STATIC_DECLARATIONS to "true"))

describe("ComplexInterface rule") {
describe("ComplexInterface rule positives") {

val path = Case.ComplexInterfacePositive.path()
context("interface members") {
val code = """
interface I {
fun f1()
fun f2()
val i1: Int
fun fImpl() {}
}
"""

it("reports interfaces which member size exceeds the threshold") {
assertThat(subject.lint(path)).hasSize(2)
it("reports complex interface") {
assertThat(subject.compileAndLint(code)).hasSize(1)
}

it("reports complex interface with includeStaticDeclarations config") {
val rule = ComplexInterface(config, threshold = THRESHOLD)
assertThat(rule.compileAndLint(code)).hasSize(1)
}
}

context("nested interface members") {
val code = """
class I {
interface Nested {
fun f1()
fun f2()
val i1: Int
fun fImpl() {}
}
}
"""

it("reports complex interface") {
assertThat(subject.compileAndLint(code)).hasSize(1)
}

it("reports complex interface with includeStaticDeclarations config") {
val rule = ComplexInterface(config, threshold = THRESHOLD)
assertThat(rule.compileAndLint(code)).hasSize(1)
}
}

context("interface with static declarations") {
val code = """
interface I {
fun f1()
companion object {
fun sf() = 0
const val c = 0
val v = 0
}
}
"""

it("does not report static declarations per default") {
assertThat(subject.compileAndLint(code)).isEmpty()
}

it("reports complex interface with includeStaticDeclarations config") {
val rule = ComplexInterface(config, threshold = THRESHOLD)
assertThat(rule.compileAndLint(code)).hasSize(1)
}
}
}

describe("ComplexInterface rule negatives") {

it("does not report a simple interface ") {
val code = """
interface I {
fun f()
fun fImpl() {
val x = 0 // should not report
}

val i: Int
// a comment shouldn't be detected
}
"""
assertThat(subject.compileAndLint(code)).isEmpty()
}

it("does not report a simple interface with a companion object") {
val code = """
interface I {
fun f()

it("reports interfaces which member size exceeds the threshold including static declarations") {
val config = TestConfig(mapOf(ComplexInterface.INCLUDE_STATIC_DECLARATIONS to "true"))
val rule = ComplexInterface(config, threshold = THRESHOLD)
assertThat(rule.lint(path)).hasSize(3)
companion object {
fun sf() = 0
const val c = 0
}
}
"""
assertThat(subject.compileAndLint(code)).isEmpty()
}

it("does not report interfaces which member size is under the threshold") {
assertThat(subject.lint(Case.ComplexInterfaceNegative.path())).hasSize(0)
it("does not report an empty interface") {
val code = "interface Empty"
assertThat(subject.compileAndLint(code)).isEmpty()
}
}
})
Expand Down
24 changes: 0 additions & 24 deletions detekt-rules/src/test/resources/cases/ComplexInterfaceNegative.kt

This file was deleted.

33 changes: 0 additions & 33 deletions detekt-rules/src/test/resources/cases/ComplexInterfacePositive.kt

This file was deleted.

0