Skip to content
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

Add test for BaselineHandler #2462

Merged
merged 3 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.gitlab.arturbosch.detekt.cli.baseline
import org.xml.sax.Attributes
import org.xml.sax.helpers.DefaultHandler

class BaselineHandler : DefaultHandler() {
internal class BaselineHandler : DefaultHandler() {

private var current: String? = null
private var content: String = ""
Expand All @@ -27,7 +27,8 @@ class BaselineHandler : DefaultHandler() {

override fun endElement(uri: String, localName: String, qName: String) {
when (qName) {
ID -> if (content.isNotBlank()) {
ID -> {
check(content.isNotBlank())
when (current) {
BLACKLIST -> blackIds.add(content)
WHITELIST -> whiteIds.add(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package io.gitlab.arturbosch.detekt.cli.baseline

import io.gitlab.arturbosch.detekt.test.resource
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatIllegalStateException
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.nio.file.Files
import java.nio.file.Paths
import java.time.Instant

class BaselineFormatSpec : Spek({

Expand All @@ -26,10 +26,15 @@ class BaselineFormatSpec : Spek({
assertThat(whitelist.ids).anySatisfy { it.startsWith("FeatureEnvy") }
}

it("throws on an invalid baseline file") {
it("throws on an invalid baseline file extension") {
val path = Paths.get(resource("/invalid-smell-baseline.txt"))
assertThatThrownBy { BaselineFormat().read(path) }.isInstanceOf(InvalidBaselineState::class.java)
}

it("throws on an invalid baseline ID declaration") {
val path = Paths.get(resource("/invalid-smell-baseline.xml"))
assertThatIllegalStateException().isThrownBy { BaselineFormat().read(path) }
}
}

context("writes a baseline file") {
Expand Down
6 changes: 6 additions & 0 deletions detekt-cli/src/test/resources/invalid-smell-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<SmellBaseline>
<Blacklist>
<ID></ID>
</Blacklist>
</SmellBaseline>