Introduce lambdaError instead of using TODO, to handle error when a lambda is invoked and it should not.

This commit is contained in:
Benoit Marty 2024-05-23 09:12:40 +02:00
parent 955b4308ce
commit 4fc3c6f889
21 changed files with 77 additions and 33 deletions

View file

@ -16,26 +16,28 @@
package io.element.android.tests.testutils
import io.element.android.tests.testutils.lambda.lambdaError
class EnsureNeverCalled : () -> Unit {
override fun invoke() {
throw AssertionError("Should not be called")
lambdaError()
}
}
class EnsureNeverCalledWithParam<T> : (T) -> Unit {
override fun invoke(p1: T) {
throw AssertionError("Should not be called and is called with $p1")
lambdaError("Should not be called and is called with $p1")
}
}
class EnsureNeverCalledWithParamAndResult<T, R> : (T) -> R {
override fun invoke(p1: T): R {
throw AssertionError("Should not be called and is called with $p1")
lambdaError("Should not be called and is called with $p1")
}
}
class EnsureNeverCalledWithTwoParams<T, U> : (T, U) -> Unit {
override fun invoke(p1: T, p2: U) {
throw AssertionError("Should not be called and is called with $p1 and $p2")
lambdaError("Should not be called and is called with $p1 and $p2")
}
}

View file

@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.tests.testutils.lambda
fun lambdaError(
message: String = "This lambda should never be called."
): Nothing {
throw AssertionError(message)
}

View file

@ -26,7 +26,7 @@ abstract class LambdaRecorder internal constructor(
internal fun onInvoke(vararg params: Any?) {
if (assertNoInvocation) {
throw AssertionError("This lambda should never be called.")
lambdaError()
}
parametersSequence.add(params.toList())
}