This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disabled autoCorrect for subconfigs too (#110)
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
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
64 changes: 64 additions & 0 deletions
64
src/test/kotlin/io/gitlab/arturbosch/detekt/sonar/foundation/NoAutoCorrectConfigTest.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,64 @@ | ||
package io.gitlab.arturbosch.detekt.sonar.foundation | ||
|
||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.api.YamlConfig | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.style.specification.describe | ||
import java.io.* | ||
import java.net.URL | ||
import org.assertj.core.api.Assertions.assertThat | ||
|
||
class NoAutoCorrectConfigTest : Spek({ | ||
describe("a configuration") { | ||
|
||
context("with autoCorrect on 1st level") { | ||
val config = NoAutoCorrectConfig( | ||
createConfig(""" | ||
autoCorrect: true | ||
""".trimIndent()) | ||
) | ||
|
||
it("should be false") { | ||
assertThat(config.valueOrDefault("autoCorrect", true)).isEqualTo(false) | ||
} | ||
} | ||
|
||
context("with autoCorrect on 2d level") { | ||
val config = NoAutoCorrectConfig( | ||
createConfig(""" | ||
secondLevel: | ||
autoCorrect: true | ||
""".trimIndent()) | ||
) | ||
|
||
it("should be false") { | ||
val secondLevelConfig = config.subConfig("secondLevel") | ||
assertThat(secondLevelConfig.valueOrDefault("autoCorrect", true)).isEqualTo(false) | ||
} | ||
} | ||
|
||
context("with autoCorrect on 3rd level") { | ||
val config = NoAutoCorrectConfig( | ||
createConfig(""" | ||
secondLevel: | ||
thirdLevel: | ||
autoCorrect: true | ||
""".trimIndent()) | ||
) | ||
|
||
it("should be false") { | ||
val thirdLevelConfig = config.subConfig("secondLevel").subConfig("thirdLevel") | ||
assertThat(thirdLevelConfig.valueOrDefault("autoCorrect", true)).isEqualTo(false) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
private fun createConfig(yamlInput: String): Config { | ||
val yamlInputStream = ByteArrayInputStream(yamlInput.toByteArray(Charsets.UTF_8)) | ||
val url = mockk<URL>() | ||
every { url.openStream() } returns yamlInputStream | ||
return YamlConfig.loadResource(url) | ||
} |