Skip to content

Commit

Permalink
Make more methods chainable
Browse files Browse the repository at this point in the history
  • Loading branch information
winterbe committed Feb 24, 2016
1 parent 273eca6 commit b67f6da
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/kotlin/com/winterbe/expekt/ExpectAny.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,32 @@ open class ExpectAny<T>(protected val subject: T?, protected val flavor: Flavor)
return this
}

fun <S: T> instanceof(type: Class<S>) {
open fun <S: T> instanceof(type: Class<S>): ExpectAny<T> {
words.add("instanceof")
words.add(type.toString())
verify { type.isInstance(subject) }
return this
}

fun identity(other: T?) {
open fun identity(other: T?): ExpectAny<T> {
words.add("identity")
words.add(other.toString())
verify { subject === other }
return this
}

fun equal(other: T?) {
open fun equal(other: T?): ExpectAny<T> {
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<T> {
words.add("satisfy")
words.add("predicate")
verify { predicate(subject!!) }
return this
}

protected fun verify(rule: () -> Boolean) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/kotlin/com/winterbe/expekt/ExpectBoolean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,23 @@ class ExpectBoolean(subject: Boolean?, flavor: Flavor) : ExpectAny<Boolean>(subj
return this
}

override fun <S : Boolean> instanceof(type: Class<S>): 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
}
}
19 changes: 19 additions & 0 deletions src/main/kotlin/com/winterbe/expekt/ExpectCollection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,23 @@ class ExpectCollection<T>(subject: Collection<T>?, flavor: Flavor): ExpectAny<Co
return this
}

override fun <S : Collection<T>> instanceof(type: Class<S>): ExpectCollection<T> {
super.instanceof(type)
return this
}

override fun identity(other: Collection<T>?): ExpectCollection<T> {
super.identity(other)
return this
}

override fun equal(other: Collection<T>?): ExpectCollection<T> {
super.equal(other)
return this
}

override fun satisfy(predicate: (Collection<T>) -> Boolean): ExpectCollection<T> {
super.satisfy(predicate)
return this
}
}
20 changes: 20 additions & 0 deletions src/main/kotlin/com/winterbe/expekt/ExpectComparable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,24 @@ open class ExpectComparable<T: Comparable<T>>(subject: T?, flavor: Flavor) : Exp
super.`null`
return this
}

override fun <S : T> instanceof(type: Class<S>): ExpectComparable<T> {
super.instanceof(type)
return this
}

override fun identity(other: T?): ExpectComparable<T> {
super.identity(other)
return this
}

override fun equal(other: T?): ExpectComparable<T> {
super.equal(other)
return this
}

override fun satisfy(predicate: (T) -> Boolean): ExpectComparable<T> {
super.satisfy(predicate)
return this
}
}
20 changes: 20 additions & 0 deletions src/main/kotlin/com/winterbe/expekt/ExpectMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,24 @@ class ExpectMap<K, V>(subject: Map<K, V>?, flavor: Flavor): ExpectAny<Map<K, V>>
super.`null`
return this
}

override fun <S : Map<K, V>> instanceof(type: Class<S>): ExpectMap<K, V> {
super.instanceof(type)
return this
}

override fun identity(other: Map<K, V>?): ExpectMap<K, V> {
super.identity(other)
return this
}

override fun equal(other: Map<K, V>?): ExpectMap<K, V> {
super.equal(other)
return this
}

override fun satisfy(predicate: (Map<K, V>) -> Boolean): ExpectMap<K, V> {
super.satisfy(predicate)
return this
}
}
20 changes: 20 additions & 0 deletions src/main/kotlin/com/winterbe/expekt/ExpectString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,24 @@ class ExpectString(subject: String?, flavor: Flavor) : ExpectComparable<String>(
super.below(other)
return this
}

override fun <S : String> instanceof(type: Class<S>): 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
}
}

0 comments on commit b67f6da

Please sign in to comment.