Skip to content

Commit

Permalink
Addressed review issues zalando#725
Browse files Browse the repository at this point in the history
  • Loading branch information
roxspring committed Jun 14, 2018
1 parent 5ae0037 commit 2ea220b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
4 changes: 2 additions & 2 deletions server/src/main/java/de/zalando/zally/rule/Context.kt
Expand Up @@ -53,8 +53,8 @@ class Context(openApi: OpenAPI, swagger: Swagger? = null) {
* @param pointer an existing pointer or null
* @return the new Violation
*/
fun violations(description: String, pointer: JsonPointer? = null): List<Violation> =
listOf(Violation(description, pointer as JsonPointer))
fun violations(description: String, pointer: JsonPointer?): List<Violation> =
listOf(violation(description, pointer))

/**
* Creates a Violation with a pointer to the OpenAPI or Swagger model node specified,
Expand Down
23 changes: 23 additions & 0 deletions server/src/test/java/de/zalando/zally/rule/ViolationAssert.kt
Expand Up @@ -4,25 +4,48 @@ import de.zalando.zally.rule.api.Violation
import org.assertj.core.api.AbstractAssert
import org.assertj.core.api.StringAssert

/**
* Assertions for Violation type
*/
class ViolationAssert(actual: Violation?) : AbstractAssert<ViolationAssert, Violation?>(actual, ViolationAssert::class.java) {

/**
* Check that the description equals some expected value
* @param description the expected value
* @return this ViolationAssert
*/
fun descriptionEqualTo(description: String): ViolationAssert {
description().isEqualTo(description)
return this
}

/**
* Check that the description matches some expected regex
* @param description the expected value
* @return this ViolationAssert
*/
fun descriptionMatches(description: String): ViolationAssert {
description().matches(description)
return this
}

private fun description() = StringAssert(actual?.description).`as`("description")

/**
* Check that the pointer equals some expected value
* @param pointer the expected value
* @return this ViolationAssert
*/
fun pointerEqualTo(pointer: String): ViolationAssert {
pointer().isEqualTo(pointer)
return this
}

/**
* Check that the pointer matches some expected regex
* @param pointer the expected value
* @return this ViolationAssert
*/
fun pointerMatches(pointer: String): ViolationAssert {
pointer().matches(pointer)
return this
Expand Down
28 changes: 20 additions & 8 deletions server/src/test/java/de/zalando/zally/rule/ViolationsAssert.kt
@@ -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
}
}
15 changes: 15 additions & 0 deletions server/src/test/java/de/zalando/zally/rule/ZallyAssertions.kt
Expand Up @@ -2,9 +2,24 @@ package de.zalando.zally.rule

import de.zalando.zally.rule.api.Violation

/**
* Assertions for Zally types
*/
class ZallyAssertions {
companion object {

/**
* Creates assertion around an actual value
* @param actual the value to assert about
* @return the object with assertion methods
*/
fun assertThat(actual: Violation?): ViolationAssert = ViolationAssert(actual)

/**
* Creates assertion around an actual value
* @param actual the value to assert about
* @return the object with assertion methods
*/
fun assertThat(actual: List<Violation>?): ViolationsAssert = ViolationsAssert(actual)
}
}
Expand Up @@ -4,6 +4,7 @@ import de.zalando.zally.rule.Context
import de.zalando.zally.rule.ZallyAssertions.Companion.assertThat
import org.junit.Test

@Suppress("StringLiteralDuplication")
class AvoidTrailingSlashesRuleTest {

private val rule = AvoidTrailingSlashesRule()
Expand Down

0 comments on commit 2ea220b

Please sign in to comment.