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
public class LooperDependent { | |
static final Handler HANDLER = | |
new Handler(Looper.getMainLooper()) { | |
@Override | |
public void handleMessage(Message msg) { | |
throw new AssertionError("Unknown handler message received: " + msg.what); | |
} | |
}; | |
public void someMethodToVerify() {} | |
} |
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
sandbox.runOnMainThread(() -> { | |
ClassLoader priorContextClassLoader = Thread.currentThread().getContextClassLoader(); | |
Thread.currentThread().setContextClassLoader(sandbox.getRobolectricClassLoader()); | |
Class bootstrappedTestClass = | |
sandbox.bootstrappedClass(getTestClass().getJavaClass()); | |
HelperTestRunner helperTestRunner = getHelperTestRunner(bootstrappedTestClass); | |
helperTestRunner.frameworkMethod = method; | |
final Method bootstrappedMethod; |
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
abstract val destination: Int | |
inline fun <reified F : Fragment> onFragment(crossinline block: F.() -> Unit) { | |
val intent = Intent( | |
ApplicationProvider.getApplicationContext<Application>(), | |
MainActivity::class.java | |
).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK } | |
val scenario = ActivityScenario.launch<MainActivity>(intent) | |
scenario.onActivity { | |
Shadows.shadowOf(Looper.getMainLooper()).idle() |
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
inline fun <reified F : Fragment, reified A : AppCompatActivity> launchInActivity( | |
crossinline fragmentFactory: () -> F, | |
state: Lifecycle.State = Lifecycle.State.RESUMED, | |
layoutId: Int = android.R.id.content, | |
isTestOnlyActivity: Boolean = false | |
) : ActivityScenario<A> { | |
//Manually register test only Activity since manifest merging is broken for test resources https://github.com/robolectric/robolectric/issues/4725 | |
if(isTestOnlyActivity) { | |
val appContext = ApplicationProvider.getApplicationContext<Application>() |
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
class TimerFlow { | |
@ExperimentalCoroutinesApi | |
suspend fun timer( | |
pollingDelay: Long, | |
coroutineDispatcher: CoroutineDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher() | |
) = flow { | |
while (true) { | |
delay(pollingDelay) | |
emit(Unit) | |
} |
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
class TestFragmentTest: RobolectricTest() { | |
@Test | |
fun `test adapter dsl`() { | |
val scenario = launchFragmentInContainer<TestFragment>() | |
scenario.onFragment { | |
val recyclerView = it.requireView().findViewById<RecyclerView>(R.id.recycler) | |
val headerViewHolder = | |
recyclerView.findViewHolderForLayoutPosition(0) ?: throw IllegalStateException() |
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
private val adapter by adapter() |
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
fun TestFragment.adapter() = adapter<Model> { | |
val TYPE_HEADER = 1 | |
val TYPE_CONTENT = 2 | |
onCreateViewHolder { parent, viewType -> | |
when (viewType) { | |
TYPE_HEADER -> holder<HeaderBinding, Header>(parent, R.layout.header, BR.header) { | |
onBind { binding, header -> |
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
private val adapter by adapter<ComicCellBinding, ComicModel>(BR.comicModel, R.layout.comic_cell){binding, model-> //do something} |
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
private val adapter by adapter<ComicModel>(BR.comicModel, R.layout.comic_cell){model-> //do something on click} |
NewerOlder