alorma
12/02/2020, 3:54 PMIntent
for android:
inline fun <reified T : Parcelable> Assertion.Builder<Intent>.hasParams(
paramsName: String,
noinline block: Assertion.Builder<T>.() -> Unit = {},
): Assertion.Builder<Intent> {
return assert("has params %s", expected = paramsName) {
val params = it.extras?.getParcelable<T>(paramsName)
if (params != null) {
expectThat(params).isA<T>().and(block)
} else {
fail()
}
}
}
When I use this extension, whatever check I put on following lines are marked ass successfull, but those should fail:
@Test
fun testHasParamsSuccess() {
val intent = Intent(getApplicationContext(), SelectCountryActivity::class.java)
.putExtra("param1", TestClass(id = "ABCD"))
expectThat(intent)
.hasParams<TestClass>("param1") { get { id }.isEqualTo("ABCD") }
.assertThat("Simple") { false } // Here assertThat { false } must fail
}
What I'm doing wrong with the hasParams
extension?robfletcher
12/02/2020, 4:05 PMexpectThat
inside — that creates an entire new assertion chain rather than contributing to the one you’re working on. Gimme a sec & I’ll see if I can work out the correct implementationrobfletcher
12/02/2020, 4:06 PMhasParams
assertion as
get { extras.getParcelable<T>(paramsName) }.isNotNull().isA<T>().and(block)
alorma
12/02/2020, 4:07 PMreturn this
at the end?robfletcher
12/02/2020, 4:08 PMrobfletcher
12/02/2020, 4:09 PMalorma
12/02/2020, 4:10 PMrobfletcher
12/02/2020, 4:10 PMalorma
12/02/2020, 4:11 PMrobfletcher
12/02/2020, 4:18 PMalorma
12/03/2020, 7:20 AMrobfletcher
12/03/2020, 3:25 PMalorma
12/03/2020, 3:27 PMalorma
12/03/2020, 3:27 PMstrik-android
could be a good additionrobfletcher
12/03/2020, 3:28 PMrobfletcher
12/03/2020, 3:28 PMrobfletcher
12/03/2020, 3:29 PMstrikt-arrow
and strikt-gradle
modules were community contributions, tho.alorma
12/03/2020, 9:50 PM