-
-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for full method signatures in ForbiddenMethodCall (#3505)
- Loading branch information
1 parent
12ff439
commit c5f65a9
Showing
5 changed files
with
223 additions
and
10 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
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
57 changes: 57 additions & 0 deletions
57
detekt-psi-utils/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/MethodSignatureSpec.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,57 @@ | ||
package io.gitlab.arturbosch.detekt.rules | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.style.specification.describe | ||
|
||
class MethodSignatureSpec : Spek({ | ||
describe("extractMethodNameAndParams") { | ||
listOf( | ||
TestCase( | ||
testDescription = "should return method name and null params list in case of simplifies signature", | ||
methodSignature = "java.time.LocalDate.now", | ||
expectedMethodName = "java.time.LocalDate.now", | ||
expectedParams = null | ||
), | ||
TestCase( | ||
testDescription = "should return method name and empty params list for full signature parameterless method", | ||
methodSignature = "java.time.LocalDate.now()", | ||
expectedMethodName = "java.time.LocalDate.now", | ||
expectedParams = emptyList() | ||
), | ||
TestCase( | ||
testDescription = "should return method name and params list for full signature method with single param", | ||
methodSignature = "java.time.LocalDate.now(java.time.Clock)", | ||
expectedMethodName = "java.time.LocalDate.now", | ||
expectedParams = listOf("java.time.Clock") | ||
), | ||
TestCase( | ||
testDescription = "should return method name and params list for full signature method with multiple params", | ||
methodSignature = "java.time.LocalDate.of(kotlin.Int, kotlin.Int, kotlin.Int)", | ||
expectedMethodName = "java.time.LocalDate.of", | ||
expectedParams = listOf("kotlin.Int", "kotlin.Int", "kotlin.Int") | ||
), | ||
TestCase( | ||
testDescription = "should return method name and params list for full signature method with multiple params " + | ||
"where method name has spaces and special characters", | ||
methodSignature = "io.gitlab.arturbosch.detekt.SomeClass.`some , method`(kotlin.String)", | ||
expectedMethodName = "io.gitlab.arturbosch.detekt.SomeClass.some , method", | ||
expectedParams = listOf("kotlin.String") | ||
) | ||
).forEach { testCase -> | ||
it(testCase.testDescription) { | ||
val (methodName, params) = extractMethodNameAndParams(testCase.methodSignature) | ||
|
||
assertThat(methodName).isEqualTo(testCase.expectedMethodName) | ||
assertThat(params).isEqualTo(testCase.expectedParams) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
private class TestCase( | ||
val testDescription: String, | ||
val methodSignature: String, | ||
val expectedMethodName: String, | ||
val expectedParams: List<String>? | ||
) |
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
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