Skip to content

Instantly share code, notes, and snippets.

@glureau-betclic
Last active January 13, 2020 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glureau-betclic/5dcfb9ef398f419e2f9a288b81d15e16 to your computer and use it in GitHub Desktop.
Save glureau-betclic/5dcfb9ef398f419e2f9a288b81d15e16 to your computer and use it in GitHub Desktop.
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