add isNoneOf and isNotIn to scala api

This commit is contained in:
Robert Stoll
2020-08-25 23:22:26 +02:00
parent 7029cc6985
commit 94f32506ad
6 changed files with 47 additions and 14 deletions

3
.gitignore vendored
View File

@@ -9,4 +9,5 @@ node_modules
*.hprof
.history
.bloop
.metals
.metals
.vscode

View File

@@ -12,8 +12,8 @@ import kotlin.reflect.KProperty1
class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
fun1<Int, Int>(Expect<Int>::toBe),
fun1<DataClass, DataClass>(Expect<DataClass>::toBe),
fun1<Int?, Int?>(Expect<Int?>::toBe),
fun1<DataClass?, DataClass?>(Expect<DataClass?>::toBe),
fun1<Int?, Int?>(Expect<Int?>::toBe).withNullableSuffix(),
fun1<DataClass?, DataClass?>(Expect<DataClass?>::toBe).withNullableSuffix(),
fun1(Expect<Int>::notToBe),
fun1(Expect<DataClass>::notToBe),
fun1(Expect<Int?>::notToBe).withNullableSuffix(),

View File

@@ -12,8 +12,8 @@ import kotlin.reflect.KFunction2
class AnyAssertionsSpec : ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
fun1<Int, Int>(Expect<Int>::toBe),
fun1<DataClass, DataClass>(Expect<DataClass>::toBe),
fun1<Int?, Int?>(Expect<Int?>::toBe),
fun1<DataClass?, DataClass?>(Expect<DataClass?>::toBe),
fun1<Int?, Int?>(Expect<Int?>::toBe).withNullableSuffix(),
fun1<DataClass?, DataClass?>(Expect<DataClass?>::toBe).withNullableSuffix(),
fun1(Expect<Int>::notToBe),
fun1(Expect<DataClass>::notToBe),
fun1(Expect<Int?>::notToBe).withNullableSuffix(),

View File

@@ -1,7 +1,7 @@
description = 'A fluent assertion function API in en_GB with a focus on code completion for Scala.'
dependencies {
api atriumKotlinDep('domain-builders')
api atriumKotlinDep('logic')
testImplementation atriumKotlinDep('specs')
}

View File

@@ -3,6 +3,8 @@ package ch.tutteli.atrium.api.fluent.en_GB.scala
import ch.tutteli.atrium.assertions.Assertion
import ch.tutteli.atrium.creating.Expect
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]) {
@inline private def anyAssertions: AnyAssertionsBuilder = ExpectImpl.getAny
@@ -35,6 +37,17 @@ class AnyAssertions[T](expect: Expect[T]) {
val and: Expect[T] = expect
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] =
expect.addAssertion(f(anyAssertions))
}

View File

@@ -2,25 +2,35 @@ package ch.tutteli.atrium.api.fluent.en_GB.scala
import TestUtils._
import AnyAssertionsSpec._
import ch.tutteli.atrium.creating.Expect
class AnyAssertionsSpec
extends ch.tutteli.atrium.specs.integration.AnyAssertionsSpec(
toBe,
toBe,
toBe,
toBe,
notToBe,
notToBe,
toBe.withNullableSuffix(),
toBe.withNullableSuffix(),
notToBe,
notToBe,
notToBe.withNullableSuffix(),
notToBe.withNullableSuffix(),
isSameAs,
isSameAs,
isSameAs,
isSameAs,
isNotSameAs,
isNotSameAs,
isSameAs.withNullableSuffix(),
isSameAs.withNullableSuffix(),
isNotSameAs,
isNotSameAs,
isNotSameAs.withNullableSuffix(),
isNotSameAs.withNullableSuffix(),
isNoneOf,
isNoneOf,
isNoneOf.withNullableSuffix(),
isNoneOf.withNullableSuffix(),
isNotIn,
isNotIn,
isNotIn.withNullableSuffix(),
isNotIn.withNullableSuffix(),
fun0("toBe", _.toBe(null)),
fun1("toBeNullIfNullGivenElse", _.toBeNullIfNullGivenElse(_)),
new kotlin.Pair("isA (feature)", _.isA()),
@@ -33,13 +43,22 @@ class AnyAssertionsSpec
fun1("notToBeNull", _.notToBeNull(_)),
fun0("and (feature)", _.and),
fun1("and", _.and(_)),
"⚬ ",
"[Atrium] "
)
//noinspection TypeAnnotation
object AnyAssertionsSpec {
import scala.jdk.CollectionConverters._
def toBe[T]: Fun1[T, T] = fun1("toBe", _.toBe(_))
def notToBe[T]: Fun1[T, T] = fun1("notToBe", _.notToBe(_))
def isSameAs[T]: Fun1[T, T] = fun1("isSameAs", _.isSameAs(_))
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)
}
}