From a108073f3122899dd8dcbdd49ebaa9606bbc8a69 Mon Sep 17 00:00:00 2001 From: Aleksei Tiurin Date: Sun, 17 Mar 2024 22:47:24 +0200 Subject: [PATCH] Fix assertion error exception (#62) --- gradle.properties | 2 +- .../atiurin/sampleapp/framework/utils/AssertUtils.kt | 2 +- .../sampleapp/tests/espresso/RecyclerViewTest.kt | 10 ++++++++++ .../com/atiurin/ultron/core/config/UltronConfig.kt | 6 ++++-- .../ultron/exceptions/UltronOperationException.kt | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9b94afd7..93bb472e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ kotlin.code.style=official android.useAndroidX=true GROUP=com.atiurin POM_ARTIFACT_ID=ultron -VERSION_NAME=2.3.4 +VERSION_NAME=2.3.5 POM_NAME=ultron diff --git a/sample-app/src/androidTest/java/com/atiurin/sampleapp/framework/utils/AssertUtils.kt b/sample-app/src/androidTest/java/com/atiurin/sampleapp/framework/utils/AssertUtils.kt index a1ebe2c3..4eaa1d18 100644 --- a/sample-app/src/androidTest/java/com/atiurin/sampleapp/framework/utils/AssertUtils.kt +++ b/sample-app/src/androidTest/java/com/atiurin/sampleapp/framework/utils/AssertUtils.kt @@ -32,7 +32,7 @@ object AssertUtils { Assert.assertTrue(System.currentTimeMillis() - startTime <= time) } - fun assertExecTimeBetween(minTime: Long, maxTime: Long,block: () -> Unit){ + fun assertExecTimeBetween(minTime: Long, maxTime: Long, block: () -> Unit) { val startTime = System.currentTimeMillis() try { block() diff --git a/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/espresso/RecyclerViewTest.kt b/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/espresso/RecyclerViewTest.kt index d5721e63..46f5fd7e 100644 --- a/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/espresso/RecyclerViewTest.kt +++ b/sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/espresso/RecyclerViewTest.kt @@ -125,6 +125,16 @@ class RecyclerViewTest : BaseTest() { } } + @Test + fun item_notExist_executionTime() { + val timeout = 5_000L + AssertUtils.assertExecTimeMoreThen(timeout){ + AssertUtils.assertException { + runCatching { page.recycler.withTimeout(timeout).item(withText("Not existed item")).isDisplayed() } + } + } + } + @Test @SetUp(CUSTOM_TIMEOUT) @TearDown(CUSTOM_TIMEOUT) diff --git a/ultron/src/main/java/com/atiurin/ultron/core/config/UltronConfig.kt b/ultron/src/main/java/com/atiurin/ultron/core/config/UltronConfig.kt index 70caf212..bdd3da97 100644 --- a/ultron/src/main/java/com/atiurin/ultron/core/config/UltronConfig.kt +++ b/ultron/src/main/java/com/atiurin/ultron/core/config/UltronConfig.kt @@ -144,7 +144,8 @@ object UltronConfig { UltronAssertionException::class.java, PerformException::class.java, NoMatchingViewException::class.java, - AmbiguousViewMatcherException::class.java + AmbiguousViewMatcherException::class.java, + UltronOperationException::class.java ) val resultHandler: (EspressoOperationResult) -> Unit = { resultAnalyzer.analyze(it) @@ -158,10 +159,11 @@ object UltronConfig { UltronWrapperException::class.java, UltronException::class.java, UltronAssertionException::class.java, + UltronOperationException::class.java, PerformException::class.java, NoMatchingViewException::class.java, AssertionFailedError::class.java, - AmbiguousViewMatcherException::class.java + AmbiguousViewMatcherException::class.java, ) val resultHandler: (EspressoOperationResult) -> Unit = { resultAnalyzer.analyze(it) diff --git a/ultron/src/main/java/com/atiurin/ultron/exceptions/UltronOperationException.kt b/ultron/src/main/java/com/atiurin/ultron/exceptions/UltronOperationException.kt index 909b2db1..4c6b493f 100644 --- a/ultron/src/main/java/com/atiurin/ultron/exceptions/UltronOperationException.kt +++ b/ultron/src/main/java/com/atiurin/ultron/exceptions/UltronOperationException.kt @@ -2,7 +2,7 @@ package com.atiurin.ultron.exceptions import android.annotation.SuppressLint -class UltronOperationException : AssertionError { +class UltronOperationException : RuntimeException { constructor(message: String) : super(message) @SuppressLint("NewApi") constructor(message: String, cause: Throwable) : super(message, cause)