Couldn't you just do `expectThat(data).dataAsserti...
# strikt
r
Couldn't you just do
expectThat(data).dataAssertion()
e
I don’t think so. The entire assertion is:
Copy code
fun <D : Operation.Data> Result<ApolloResponse<D>, ApolloException>.assertIsSuccessful(
    dataAssertion: (Assertion.Builder<D>.() -> Unit)? = null
): D = expectThat(this)
    .and { get { isSuccess() }.isTrue() } // Result is a success
    .get { get() } // get the ApolloResponse<D>
    .and { get { errors }.isNull() } // ApolloResponse<D> does not have errors
    .get { data }.isNotNull() // ApolloResponse has data D
    .also { data -> dataAssertion?.invoke(data) } // custom assertion on data D
    .subject // return the data D held by ApolloResponse
r
It looks like you could replace
Copy code
.get { data }.isNotNull() // ApolloResponse has data D
    .also { data -> dataAssertion?.invoke(data) } // custom assertion on data D
with
Copy code
.get { data }.isNotNull().dataAssertion()
e
dataAssertion
is nullable, though. I suppose it could be non-nullable and default to always true
r
oh I see
e
it might work if the signature was
Copy code
dataAssertion: (Assertion.Builder<D>.() -> Unit) = { },
actually this
Copy code
dataAssertion: (Assertion.Builder<D>.() -> D) = { subject },
Copy code
fun <D : Operation.Data> Result<ApolloResponse<D>, ApolloException>.assertIsSuccessful(
    dataAssertion: (Assertion.Builder<D>.() -> Unit) = { },
): D = expectThat(this)
    .and { get { isSuccess() }.isTrue() }
    .get { get() }
    .and { get { errors }.isNull() }
    .get { data }.isNotNull()
    .and { dataAssertion() }
    .subject
this wouldn’t require any of the callers to change