Move ArrowAssertions to simplenotes-domain
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package be.simplenotes.domain.testutils
|
||||
|
||||
import arrow.core.Either
|
||||
import com.natpryce.hamkrest.MatchResult
|
||||
import com.natpryce.hamkrest.Matcher
|
||||
|
||||
fun isLeft() = object : Matcher<Either<*, *>> {
|
||||
override val description: String
|
||||
get() = "is Either.Left<>"
|
||||
|
||||
override fun invoke(actual: Either<*, *>) = when {
|
||||
actual.isLeft() -> MatchResult.Match
|
||||
else -> MatchResult.Mismatch("is Either.Right<>")
|
||||
}
|
||||
}
|
||||
|
||||
fun isRight() = object : Matcher<Either<*, *>> {
|
||||
override val description: String
|
||||
get() = "is Either.Right<>"
|
||||
|
||||
override fun invoke(actual: Either<*, *>) = when (actual) {
|
||||
is Either.Right -> MatchResult.Match
|
||||
is Either.Left -> {
|
||||
val valueA = actual.a
|
||||
MatchResult.Mismatch("is Either.Left<${if (valueA == null) "Null" else valueA::class.simpleName}>")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified A> isLeftOfType() = object : Matcher<Either<*, *>> {
|
||||
override val description: String
|
||||
get() = "is Either.Left<${A::class.qualifiedName}>"
|
||||
|
||||
override fun invoke(actual: Either<*, *>) = when (actual) {
|
||||
is Either.Right -> MatchResult.Mismatch("was Either.Right<>")
|
||||
is Either.Left -> {
|
||||
val valueA = actual.a
|
||||
if (valueA is A) MatchResult.Match
|
||||
else MatchResult.Mismatch("was Left<${if (valueA == null) "Null" else valueA::class.simpleName}>")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import be.simplenotes.domain.security.BcryptPasswordHash
|
||||
import be.simplenotes.domain.security.SimpleJwt
|
||||
import be.simplenotes.domain.usecases.repositories.UserRepository
|
||||
import be.simplenotes.config.JwtConfig
|
||||
import be.simplenotes.shared.testutils.assertions.isLeftOfType
|
||||
import be.simplenotes.shared.testutils.assertions.isRight
|
||||
import be.simplenotes.domain.testutils.isLeftOfType
|
||||
import be.simplenotes.domain.testutils.isRight
|
||||
import com.natpryce.hamkrest.assertion.assertThat
|
||||
import io.mockk.*
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@ package be.simplenotes.domain.usecases.users.register
|
||||
|
||||
import be.simplenotes.types.PersistedUser
|
||||
import be.simplenotes.domain.security.BcryptPasswordHash
|
||||
import be.simplenotes.domain.testutils.isLeftOfType
|
||||
import be.simplenotes.domain.testutils.isRight
|
||||
import be.simplenotes.domain.usecases.repositories.UserRepository
|
||||
import be.simplenotes.shared.testutils.assertions.isLeftOfType
|
||||
import be.simplenotes.shared.testutils.assertions.isRight
|
||||
import com.natpryce.hamkrest.assertion.assertThat
|
||||
import com.natpryce.hamkrest.equalTo
|
||||
import io.mockk.*
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package be.simplenotes.domain.validation
|
||||
|
||||
import be.simplenotes.domain.testutils.isLeftOfType
|
||||
import be.simplenotes.domain.testutils.isRight
|
||||
import be.simplenotes.domain.usecases.users.login.InvalidLoginForm
|
||||
import be.simplenotes.domain.usecases.users.login.LoginForm
|
||||
import be.simplenotes.domain.usecases.users.register.RegisterForm
|
||||
import be.simplenotes.shared.testutils.assertions.isLeftOfType
|
||||
import be.simplenotes.shared.testutils.assertions.isRight
|
||||
import com.natpryce.hamkrest.assertion.assertThat
|
||||
import org.junit.jupiter.api.Nested
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
|
||||
Reference in New Issue
Block a user