forked from zalando/zally
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 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
28 changes: 20 additions & 8 deletions
28
server/src/test/java/de/zalando/zally/rule/ViolationsAssert.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 |
---|---|---|
@@ -1,40 +1,52 @@ | ||
package de.zalando.zally.rule | ||
|
||
import com.fasterxml.jackson.core.JsonPointer | ||
import de.zalando.zally.rule.api.Violation | ||
import org.assertj.core.api.AbstractListAssert | ||
import org.assertj.core.api.ListAssert | ||
import org.assertj.core.api.ObjectAssert | ||
|
||
/** | ||
* Assertions for List<Violation> type | ||
*/ | ||
class ViolationsAssert(violations: List<Violation>?) : AbstractListAssert<ViolationsAssert, List<Violation>, Violation, ObjectAssert<Violation>>(violations, ViolationsAssert::class.java) { | ||
|
||
override fun toAssert(value: Violation?, description: String?): ObjectAssert<Violation> { | ||
return ObjectAssert<Violation>(value).`as`(description) | ||
} | ||
|
||
/** | ||
* Check that all the descriptions equal the expected value | ||
* @param description the expected value | ||
* @return this ViolationsAssert | ||
*/ | ||
fun descriptionsAllEqualTo(description: String): ViolationsAssert { | ||
descriptions().containsOnly(description) | ||
return this | ||
} | ||
|
||
/** | ||
* Check that description sequence equals the expected description sequence | ||
* @param descriptions the expected value | ||
* @return this ViolationsAssert | ||
*/ | ||
fun descriptionsEqualTo(vararg descriptions: String): ViolationsAssert { | ||
descriptions().containsExactly(*descriptions) | ||
return this | ||
} | ||
|
||
fun descriptions(): ListAssert<String> { | ||
private fun descriptions(): ListAssert<String> { | ||
isNotNull | ||
return ListAssert(actual.map { it.description }).`as`("descriptions") | ||
} | ||
|
||
fun pointers(): ListAssert<JsonPointer?> { | ||
isNotNull | ||
return ListAssert(actual.map { it.pointer }).`as`("pointers") | ||
} | ||
|
||
/** | ||
* Check that pointers sequence equals the expected pointers sequence | ||
* @param pointers the expected value | ||
* @return this ViolationsAssert | ||
*/ | ||
fun pointersEqualTo(vararg pointers: String): ViolationsAssert { | ||
isNotNull | ||
ListAssert(actual.map { it.pointer!!.toString() }).`as`("pointers").containsExactly(*pointers) | ||
ListAssert(actual.map { it.pointer?.toString() }).`as`("pointers").containsExactly(*pointers) | ||
return this | ||
} | ||
} |
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