All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rapatao.projects.ruleset.engine.cases.OnFailureCases.kt Maven / Gradle / Ivy

Go to download

Simple yet powerful rules engine that offers the flexibility of using the built-in engine and creating a custom one.

The newest version!
package com.rapatao.projects.ruleset.engine.cases

import com.rapatao.projects.ruleset.engine.types.Expression
import com.rapatao.projects.ruleset.engine.types.OnFailure
import com.rapatao.projects.ruleset.engine.types.builder.extensions.equalsTo
import org.junit.jupiter.params.provider.Arguments

object OnFailureCases {

    fun cases(): List = anyMatchCases() + allMatchCases() + noneMatchCases()

    @Suppress("MagicNumber")
    private fun anyMatchCases(): List = listOf(
        Arguments.of(
            Expression(
                anyMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            true,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.THROW,
                anyMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            true,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.FALSE,
                anyMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            false,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.TRUE,
                anyMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            true,
            false,
        ),
    )

    @Suppress("MagicNumber")
    private fun allMatchCases(): List = listOf(
        Arguments.of(
            Expression(
                allMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            true,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.THROW,
                allMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            true,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.FALSE,
                allMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            false,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.TRUE,
                allMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            true,
            false,
        ),
    )

    @Suppress("MagicNumber")
    private fun noneMatchCases(): List = listOf(
        Arguments.of(
            Expression(
                noneMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            true,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.THROW,
                noneMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            true,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.FALSE,
                noneMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            false,
            false,
        ),
        Arguments.of(
            Expression(
                onFailure = OnFailure.TRUE,
                noneMatch = listOf(
                    "item.non.existing.field" equalsTo 10,
                )
            ),
            true,
            false,
        ),
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy