mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
add isNoneOf and isNotIn to scala api
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -9,4 +9,5 @@ node_modules
|
|||||||
*.hprof
|
*.hprof
|
||||||
.history
|
.history
|
||||||
.bloop
|
.bloop
|
||||||
.metals
|
.metals
|
||||||
|
.vscode
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import kotlin.reflect.KProperty1
|
|||||||
class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
|
class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
|
||||||
fun1<Int, Int>(Expect<Int>::toBe),
|
fun1<Int, Int>(Expect<Int>::toBe),
|
||||||
fun1<DataClass, DataClass>(Expect<DataClass>::toBe),
|
fun1<DataClass, DataClass>(Expect<DataClass>::toBe),
|
||||||
fun1<Int?, Int?>(Expect<Int?>::toBe),
|
fun1<Int?, Int?>(Expect<Int?>::toBe).withNullableSuffix(),
|
||||||
fun1<DataClass?, DataClass?>(Expect<DataClass?>::toBe),
|
fun1<DataClass?, DataClass?>(Expect<DataClass?>::toBe).withNullableSuffix(),
|
||||||
fun1(Expect<Int>::notToBe),
|
fun1(Expect<Int>::notToBe),
|
||||||
fun1(Expect<DataClass>::notToBe),
|
fun1(Expect<DataClass>::notToBe),
|
||||||
fun1(Expect<Int?>::notToBe).withNullableSuffix(),
|
fun1(Expect<Int?>::notToBe).withNullableSuffix(),
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import kotlin.reflect.KFunction2
|
|||||||
class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
|
class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
|
||||||
fun1<Int, Int>(Expect<Int>::toBe),
|
fun1<Int, Int>(Expect<Int>::toBe),
|
||||||
fun1<DataClass, DataClass>(Expect<DataClass>::toBe),
|
fun1<DataClass, DataClass>(Expect<DataClass>::toBe),
|
||||||
fun1<Int?, Int?>(Expect<Int?>::toBe),
|
fun1<Int?, Int?>(Expect<Int?>::toBe).withNullableSuffix(),
|
||||||
fun1<DataClass?, DataClass?>(Expect<DataClass?>::toBe),
|
fun1<DataClass?, DataClass?>(Expect<DataClass?>::toBe).withNullableSuffix(),
|
||||||
fun1(Expect<Int>::notToBe),
|
fun1(Expect<Int>::notToBe),
|
||||||
fun1(Expect<DataClass>::notToBe),
|
fun1(Expect<DataClass>::notToBe),
|
||||||
fun1(Expect<Int?>::notToBe).withNullableSuffix(),
|
fun1(Expect<Int?>::notToBe).withNullableSuffix(),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
description = 'A fluent assertion function API in en_GB with a focus on code completion for Scala.'
|
description = 'A fluent assertion function API in en_GB with a focus on code completion for Scala.'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api atriumKotlinDep('domain-builders')
|
api atriumKotlinDep('logic')
|
||||||
|
|
||||||
testImplementation atriumKotlinDep('specs')
|
testImplementation atriumKotlinDep('specs')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package ch.tutteli.atrium.api.fluent.en_GB.scala
|
|||||||
import ch.tutteli.atrium.assertions.Assertion
|
import ch.tutteli.atrium.assertions.Assertion
|
||||||
import ch.tutteli.atrium.creating.Expect
|
import ch.tutteli.atrium.creating.Expect
|
||||||
import ch.tutteli.atrium.domain.builders.creating.AnyAssertionsBuilder
|
import ch.tutteli.atrium.domain.builders.creating.AnyAssertionsBuilder
|
||||||
|
import ch.tutteli.atrium.logic.impl.DefaultAnyAssertions
|
||||||
|
import ch.tutteli.atrium.creating.AssertionContainer
|
||||||
|
|
||||||
class AnyAssertions[T](expect: Expect[T]) {
|
class AnyAssertions[T](expect: Expect[T]) {
|
||||||
@inline private def anyAssertions: AnyAssertionsBuilder = ExpectImpl.getAny
|
@inline private def anyAssertions: AnyAssertionsBuilder = ExpectImpl.getAny
|
||||||
@@ -35,6 +37,17 @@ class AnyAssertions[T](expect: Expect[T]) {
|
|||||||
val and: Expect[T] = expect
|
val and: Expect[T] = expect
|
||||||
def and(assertionCreator: Expect[T] => Unit): Expect[T] = expect.addAssertionsCreatedBy(assertionCreator)
|
def and(assertionCreator: Expect[T] => Unit): Expect[T] = expect.addAssertionsCreatedBy(assertionCreator)
|
||||||
|
|
||||||
|
def isNoneOf(expected: T, otherValues: T*): Expect[T] = {
|
||||||
|
isNotIn(expected +: otherValues)
|
||||||
|
}
|
||||||
|
|
||||||
|
def isNotIn(iterable: Iterable[T]): Expect[T] = {
|
||||||
|
import scala.jdk.CollectionConverters._
|
||||||
|
expect.addAssertion(new DefaultAnyAssertions().isNotIn(expect.asInstanceOf[AssertionContainer[T]], iterable.asJava))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@inline private def addAssertion(f: AnyAssertionsBuilder => Assertion): Expect[T] =
|
@inline private def addAssertion(f: AnyAssertionsBuilder => Assertion): Expect[T] =
|
||||||
expect.addAssertion(f(anyAssertions))
|
expect.addAssertion(f(anyAssertions))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,25 +2,35 @@ package ch.tutteli.atrium.api.fluent.en_GB.scala
|
|||||||
|
|
||||||
import TestUtils._
|
import TestUtils._
|
||||||
import AnyAssertionsSpec._
|
import AnyAssertionsSpec._
|
||||||
|
import ch.tutteli.atrium.creating.Expect
|
||||||
|
|
||||||
class AnyAssertionsSpec
|
class AnyAssertionsSpec
|
||||||
extends ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
|
extends ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
|
||||||
toBe,
|
toBe,
|
||||||
toBe,
|
toBe,
|
||||||
toBe,
|
toBe.withNullableSuffix(),
|
||||||
toBe,
|
toBe.withNullableSuffix(),
|
||||||
notToBe,
|
|
||||||
notToBe,
|
|
||||||
notToBe,
|
notToBe,
|
||||||
notToBe,
|
notToBe,
|
||||||
|
notToBe.withNullableSuffix(),
|
||||||
|
notToBe.withNullableSuffix(),
|
||||||
isSameAs,
|
isSameAs,
|
||||||
isSameAs,
|
isSameAs,
|
||||||
isSameAs,
|
isSameAs.withNullableSuffix(),
|
||||||
isSameAs,
|
isSameAs.withNullableSuffix(),
|
||||||
isNotSameAs,
|
|
||||||
isNotSameAs,
|
|
||||||
isNotSameAs,
|
isNotSameAs,
|
||||||
isNotSameAs,
|
isNotSameAs,
|
||||||
|
isNotSameAs.withNullableSuffix(),
|
||||||
|
isNotSameAs.withNullableSuffix(),
|
||||||
|
isNoneOf,
|
||||||
|
isNoneOf,
|
||||||
|
isNoneOf.withNullableSuffix(),
|
||||||
|
isNoneOf.withNullableSuffix(),
|
||||||
|
isNotIn,
|
||||||
|
isNotIn,
|
||||||
|
isNotIn.withNullableSuffix(),
|
||||||
|
isNotIn.withNullableSuffix(),
|
||||||
|
|
||||||
fun0("toBe", _.toBe(null)),
|
fun0("toBe", _.toBe(null)),
|
||||||
fun1("toBeNullIfNullGivenElse", _.toBeNullIfNullGivenElse(_)),
|
fun1("toBeNullIfNullGivenElse", _.toBeNullIfNullGivenElse(_)),
|
||||||
new kotlin.Pair("isA (feature)", _.isA()),
|
new kotlin.Pair("isA (feature)", _.isA()),
|
||||||
@@ -33,13 +43,22 @@ class AnyAssertionsSpec
|
|||||||
fun1("notToBeNull", _.notToBeNull(_)),
|
fun1("notToBeNull", _.notToBeNull(_)),
|
||||||
fun0("and (feature)", _.and),
|
fun0("and (feature)", _.and),
|
||||||
fun1("and", _.and(_)),
|
fun1("and", _.and(_)),
|
||||||
|
"⚬ ",
|
||||||
"[Atrium] "
|
"[Atrium] "
|
||||||
)
|
)
|
||||||
|
|
||||||
//noinspection TypeAnnotation
|
//noinspection TypeAnnotation
|
||||||
object AnyAssertionsSpec {
|
object AnyAssertionsSpec {
|
||||||
|
import scala.jdk.CollectionConverters._
|
||||||
|
|
||||||
def toBe[T]: Fun1[T, T] = fun1("toBe", _.toBe(_))
|
def toBe[T]: Fun1[T, T] = fun1("toBe", _.toBe(_))
|
||||||
def notToBe[T]: Fun1[T, T] = fun1("notToBe", _.notToBe(_))
|
def notToBe[T]: Fun1[T, T] = fun1("notToBe", _.notToBe(_))
|
||||||
def isSameAs[T]: Fun1[T, T] = fun1("isSameAs", _.isSameAs(_))
|
def isSameAs[T]: Fun1[T, T] = fun1("isSameAs", _.isSameAs(_))
|
||||||
def isNotSameAs[T]: Fun1[T, T] = fun1("isNotSameAs", _.isNotSameAs(_))
|
def isNotSameAs[T]: Fun1[T, T] = fun1("isNotSameAs", _.isNotSameAs(_))
|
||||||
|
def isNoneOf[T]: Fun2[T, T, Array[T]] = fun2("isNoneOf", (e: Expect[T], t: T, arr: Array[T]) => e.isNoneOf(t, arr.toIndexedSeq: _*))
|
||||||
|
def isNotIn[T]: Fun1[T, java.lang.Iterable[T]] = fun1("isNotIn", (e: Expect[T], i: java.lang.Iterable[T]) => e.isNotIn(i.asScala))
|
||||||
|
|
||||||
|
implicit class RxKotlinPair[T](pair: kotlin.Pair[String, T]) {
|
||||||
|
def withNullableSuffix() = new kotlin.Pair(pair.getFirst+" (nullable)", pair.getSecond)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user