From ccfd5f8a0821e863d5c4d0a0aea670884110132b Mon Sep 17 00:00:00 2001 From: Corinna Kindlhofer Date: Thu, 15 Aug 2024 10:34:28 +0200 Subject: [PATCH] IDE-142 Move and rewrite testHtmlExtractorDialogNotFoundMessage --- .../ui/dialog/HtmlExtractorDialogTest.java | 13 +--- .../HtmlExtractorErrorHandlingTest.kt | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 catroid/src/test/java/org/catrobat/catroid/test/ui/regexassistant/HtmlExtractorErrorHandlingTest.kt diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/HtmlExtractorDialogTest.java b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/HtmlExtractorDialogTest.java index 3ea187c6999..fd97b684c4b 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/HtmlExtractorDialogTest.java +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/HtmlExtractorDialogTest.java @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -37,7 +37,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; -import static org.hamcrest.Matchers.not; import static org.catrobat.catroid.uiespresso.content.brick.utils.BrickDataInteractionWrapper.onBrickAtPosition; import static org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper.onFormulaEditor; @@ -45,7 +44,6 @@ import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.typeText; import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.withDecorView; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withHint; import static androidx.test.espresso.matcher.ViewMatchers.withId; @@ -93,15 +91,6 @@ public void testHtmlExtractorDialogCancelButton() { onView(withText(R.string.cancel)).check(matches(isDisplayed())); } - @Test - public void testHtmlExtractorDialogNotFoundMessage() { - onView(withHint(R.string.keyword_label)).perform(typeText("Not")); - onView(withHint(R.string.html_label)).perform(typeText("Found")); - onView(withText(R.string.ok)).perform(click()); - - onView(withText(R.string.formula_editor_function_regex_html_extractor_not_found)).inRoot(withDecorView(not(baseActivityTestRule.getActivity().getWindow().getDecorView()))).check(matches(isDisplayed())); - } - private void openHtmlExtractor() { String regularExpressionAssistant = "\t\t\t\t\t" + UiTestUtils.getResourcesString(R.string.formula_editor_function_regex_assistant); diff --git a/catroid/src/test/java/org/catrobat/catroid/test/ui/regexassistant/HtmlExtractorErrorHandlingTest.kt b/catroid/src/test/java/org/catrobat/catroid/test/ui/regexassistant/HtmlExtractorErrorHandlingTest.kt new file mode 100644 index 00000000000..66507d8d987 --- /dev/null +++ b/catroid/src/test/java/org/catrobat/catroid/test/ui/regexassistant/HtmlExtractorErrorHandlingTest.kt @@ -0,0 +1,62 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2024 The Catrobat Team + * () + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.catrobat.catroid.test.ui.regexassistant + +import android.app.Activity +import org.catrobat.catroid.R +import org.catrobat.catroid.utils.HtmlRegexExtractor +import org.catrobat.catroid.utils.ToastUtil +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentMatchers.eq +import org.mockito.Mockito.times +import org.powermock.api.mockito.PowerMockito.mockStatic +import org.powermock.api.mockito.PowerMockito.verifyStatic +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest(ToastUtil::class) +class HtmlExtractorErrorHandlingTest { + private lateinit var htmlExtractor: HtmlRegexExtractor + private lateinit var context: Activity + + @Before + fun setUp() { + context = Activity() + htmlExtractor = HtmlRegexExtractor(context) + } + + @Test + fun testHtmlExtractorDialogNotFoundMessage() { + mockStatic(ToastUtil::class.java) + htmlExtractor.searchKeyword("Not", "Found") + verifyStatic(ToastUtil::class.java, times(1)) + ToastUtil.showError( + eq(context), + eq(R.string.formula_editor_function_regex_html_extractor_not_found) + ) + } +}