From b67f6da532cb6afd073bfed644fce979dc6211ac Mon Sep 17 00:00:00 2001 From: Benjamin Winterberg Date: Wed, 24 Feb 2016 13:05:10 +0100 Subject: [PATCH] Make more methods chainable --- .../kotlin/com/winterbe/expekt/ExpectAny.kt | 12 +++++++---- .../com/winterbe/expekt/ExpectBoolean.kt | 19 ++++++++++++++++++ .../com/winterbe/expekt/ExpectCollection.kt | 19 ++++++++++++++++++ .../com/winterbe/expekt/ExpectComparable.kt | 20 +++++++++++++++++++ .../kotlin/com/winterbe/expekt/ExpectMap.kt | 20 +++++++++++++++++++ .../com/winterbe/expekt/ExpectString.kt | 20 +++++++++++++++++++ 6 files changed, 106 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/winterbe/expekt/ExpectAny.kt b/src/main/kotlin/com/winterbe/expekt/ExpectAny.kt index 5a4f541..792177f 100644 --- a/src/main/kotlin/com/winterbe/expekt/ExpectAny.kt +++ b/src/main/kotlin/com/winterbe/expekt/ExpectAny.kt @@ -34,28 +34,32 @@ open class ExpectAny(protected val subject: T?, protected val flavor: Flavor) return this } - fun instanceof(type: Class) { + open fun instanceof(type: Class): ExpectAny { words.add("instanceof") words.add(type.toString()) verify { type.isInstance(subject) } + return this } - fun identity(other: T?) { + open fun identity(other: T?): ExpectAny { words.add("identity") words.add(other.toString()) verify { subject === other } + return this } - fun equal(other: T?) { + open fun equal(other: T?): ExpectAny { words.add("equal") words.add(other.toString()) verify { subject == other } + return this } - fun satisfy(predicate: (a: T) -> Boolean) { + open fun satisfy(predicate: (a: T) -> Boolean): ExpectAny { words.add("satisfy") words.add("predicate") verify { predicate(subject!!) } + return this } protected fun verify(rule: () -> Boolean) { diff --git a/src/main/kotlin/com/winterbe/expekt/ExpectBoolean.kt b/src/main/kotlin/com/winterbe/expekt/ExpectBoolean.kt index de08d30..44ee29a 100644 --- a/src/main/kotlin/com/winterbe/expekt/ExpectBoolean.kt +++ b/src/main/kotlin/com/winterbe/expekt/ExpectBoolean.kt @@ -105,4 +105,23 @@ class ExpectBoolean(subject: Boolean?, flavor: Flavor) : ExpectAny(subj return this } + override fun instanceof(type: Class): ExpectBoolean { + super.instanceof(type) + return this + } + + override fun identity(other: Boolean?): ExpectBoolean { + super.identity(other) + return this + } + + override fun equal(other: Boolean?): ExpectBoolean { + super.equal(other) + return this + } + + override fun satisfy(predicate: (Boolean) -> Boolean): ExpectBoolean { + super.satisfy(predicate) + return this + } } \ No newline at end of file diff --git a/src/main/kotlin/com/winterbe/expekt/ExpectCollection.kt b/src/main/kotlin/com/winterbe/expekt/ExpectCollection.kt index 1083dd5..bbf4efe 100644 --- a/src/main/kotlin/com/winterbe/expekt/ExpectCollection.kt +++ b/src/main/kotlin/com/winterbe/expekt/ExpectCollection.kt @@ -181,4 +181,23 @@ class ExpectCollection(subject: Collection?, flavor: Flavor): ExpectAny> instanceof(type: Class): ExpectCollection { + super.instanceof(type) + return this + } + + override fun identity(other: Collection?): ExpectCollection { + super.identity(other) + return this + } + + override fun equal(other: Collection?): ExpectCollection { + super.equal(other) + return this + } + + override fun satisfy(predicate: (Collection) -> Boolean): ExpectCollection { + super.satisfy(predicate) + return this + } } \ No newline at end of file diff --git a/src/main/kotlin/com/winterbe/expekt/ExpectComparable.kt b/src/main/kotlin/com/winterbe/expekt/ExpectComparable.kt index e60a845..5ff9029 100644 --- a/src/main/kotlin/com/winterbe/expekt/ExpectComparable.kt +++ b/src/main/kotlin/com/winterbe/expekt/ExpectComparable.kt @@ -130,4 +130,24 @@ open class ExpectComparable>(subject: T?, flavor: Flavor) : Exp super.`null` return this } + + override fun instanceof(type: Class): ExpectComparable { + super.instanceof(type) + return this + } + + override fun identity(other: T?): ExpectComparable { + super.identity(other) + return this + } + + override fun equal(other: T?): ExpectComparable { + super.equal(other) + return this + } + + override fun satisfy(predicate: (T) -> Boolean): ExpectComparable { + super.satisfy(predicate) + return this + } } \ No newline at end of file diff --git a/src/main/kotlin/com/winterbe/expekt/ExpectMap.kt b/src/main/kotlin/com/winterbe/expekt/ExpectMap.kt index f844a8f..62e5b44 100644 --- a/src/main/kotlin/com/winterbe/expekt/ExpectMap.kt +++ b/src/main/kotlin/com/winterbe/expekt/ExpectMap.kt @@ -213,4 +213,24 @@ class ExpectMap(subject: Map?, flavor: Flavor): ExpectAny> super.`null` return this } + + override fun > instanceof(type: Class): ExpectMap { + super.instanceof(type) + return this + } + + override fun identity(other: Map?): ExpectMap { + super.identity(other) + return this + } + + override fun equal(other: Map?): ExpectMap { + super.equal(other) + return this + } + + override fun satisfy(predicate: (Map) -> Boolean): ExpectMap { + super.satisfy(predicate) + return this + } } \ No newline at end of file diff --git a/src/main/kotlin/com/winterbe/expekt/ExpectString.kt b/src/main/kotlin/com/winterbe/expekt/ExpectString.kt index bcda4e0..782c7a1 100644 --- a/src/main/kotlin/com/winterbe/expekt/ExpectString.kt +++ b/src/main/kotlin/com/winterbe/expekt/ExpectString.kt @@ -170,4 +170,24 @@ class ExpectString(subject: String?, flavor: Flavor) : ExpectComparable( super.below(other) return this } + + override fun instanceof(type: Class): ExpectString { + super.instanceof(type) + return this + } + + override fun identity(other: String?): ExpectString { + super.identity(other) + return this + } + + override fun equal(other: String?): ExpectString { + super.equal(other) + return this + } + + override fun satisfy(predicate: (String) -> Boolean): ExpectString { + super.satisfy(predicate) + return this + } } \ No newline at end of file