Skip to content
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 @@ -56,7 +56,7 @@ class ViolationsUtil {

@JvmStatic
fun printSummary(resultMap: Map<Rule, List<RuleResult>>, output: StyledTextOutput) {
val maxRuleNameLength = resultMap.keys.maxOf { it.ruleName().length }
val maxRuleNameLength = resultMap.keys.maxOfOrNull { it.ruleName().length } ?: 1
resultMap.forEach { (rule, results) ->
val failures = results.filter { it.status() != RuleResultStatus.PASS }
if (failures.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.netflix.nebula.archrules.gradle

import com.tngtech.archunit.lang.Priority
import org.assertj.core.api.Assertions.assertThat
import org.gradle.internal.logging.text.StyledTextOutput
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wish this was public :(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

import org.junit.jupiter.api.Test

internal class ViolationsUtilTest {

@Test
fun `test printSummary`() {
val output = MockStyledTextOutput()
val rule = Rule("RuleClass", "RuleName", "description", Priority.MEDIUM)
val results = listOf(RuleResult(rule, "message", RuleResultStatus.PASS))
ViolationsUtil.printSummary(mapOf(rule to results), output)
assertThat(output.getOutput()).contains("RuleName MEDIUM (No failures)")
}

@Test
fun `test printSummary empty results`() {
val output = MockStyledTextOutput()
ViolationsUtil.printSummary(mapOf(), output)
assertThat(output.getOutput()).isEmpty()
}
}

class MockStyledTextOutput : StyledTextOutput {
private val output: StringBuilder = StringBuilder()
fun getOutput(): String = output.toString()
override fun append(c: Char): StyledTextOutput {
output.append(c)
return this
}

override fun append(csq: CharSequence?): StyledTextOutput {
output.append(csq)
return this
}

override fun append(
csq: CharSequence?,
start: Int,
end: Int
): StyledTextOutput {
output.append(csq)
return this
}

override fun style(style: StyledTextOutput.Style?): StyledTextOutput {
return this
}

override fun withStyle(style: StyledTextOutput.Style?): StyledTextOutput {
return this
}

override fun text(text: Any?): StyledTextOutput {
output.append(text)
return this
}

override fun println(text: Any): StyledTextOutput {
output.append(text).append("\n")
return this
}

override fun format(
pattern: String?,
vararg args: Any?
): StyledTextOutput {
output.append(pattern?.format(*args))
return this
}

override fun formatln(
pattern: String?,
vararg args: Any?
): StyledTextOutput {
output.append(pattern?.format(*args)).append("\n")
return this
}

override fun println(): StyledTextOutput {
output.append("\n")
return this
}

override fun exception(throwable: Throwable?): StyledTextOutput {
TODO("Not yet implemented")
}

}