PreValidationRule { override fun perform(purchaseData: PurchaseData): ResultAction { val subscriber = purchaseData.subscriptionType val productType = purchaseData.productType return when (subscriber buying productType) { PlusUser buying Plus, GoldUser buying Gold, GoldUser buying Plus -> Interrupt else -> Proceed() } } } internal infix fun UserSubscriptionType.buying(productType: ProductType) = this to productType @RunWith(Parameterized::class) class CheckPurchaseConsistencyRuleTest(. . .) { . . . companion object { @Parameterized.Parameters(name = "{index}: {0} buying {1} should {2}") @JvmStatic fun data() = listOf( testCase(NonSubscriber, buyingProduct = Plus, expectedAction = Proceed()), testCase(NonSubscriber, buyingProduct = Gold, expectedAction = Proceed()), testCase(NonSubscriber, buyingProduct = Boost, expectedAction = Proceed()), testCase(NonSubscriber, buyingProduct = SuperLike, expectedAction = Proceed()) testCase(NonSubscriber, buyingProduct = TopPicks, expectedAction = Proceed()), testCase(PlusUser, buyingProduct = Plus, expectedAction = Interrupt), testCase(PlusUser, buyingProduct = Gold, expectedAction = Proceed()), testCase(PlusUser, buyingProduct = Boost, expectedAction = Proceed()), testCase(PlusUser, buyingProduct = SuperLike, expectedAction = Proceed()), testCase(PlusUser, buyingProduct = TopPicks, expectedAction = Proceed()), testCase(GoldUser, buyingProduct = Plus, expectedAction = Interrupt), testCase(GoldUser, buyingProduct = Gold, expectedAction = Interrupt), testCase(GoldUser, buyingProduct = Boost, expectedAction = Proceed()), testCase(GoldUser, buyingProduct = SuperLike, expectedAction = Proceed()), testCase(GoldUser, buyingProduct = TopPicks, expectedAction = Proceed()) ) }