Last active
January 13, 2020 18:10
-
-
Save glureau-betclic/5dcfb9ef398f419e2f9a288b81d15e16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.betclic.test | |
import org.junit.After | |
import org.junit.Before | |
interface Rule { | |
fun onBefore() {} | |
fun onAfter() {} | |
} | |
open class CompositeRules(vararg val rules: Rule) { | |
@Before | |
fun compositeSetup() { | |
rules.forEach { it.onBefore() } | |
} | |
@After | |
fun compositeTearDown() { | |
rules.reversed().forEach { it.onAfter() } | |
} | |
inline fun <reified T : Rule> getRule() = rules.first { it is T } as T | |
} | |
// --- Example of test class | |
class MySuperTest : CompositeRules(RxRule(), MockRule(), WhateverRule()) { | |
@Test | |
fun myTest() {...} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment