From e05b24a67cd56b8b0f2b2c11b73d65f856a66566 Mon Sep 17 00:00:00 2001 From: Binnette Date: Wed, 4 Dec 2024 09:25:27 +0100 Subject: [PATCH] Replace deprecated ActivityTestRule --- .../osmtracker/layouts/DeleteLayoutTest.java | 59 +++++++++---------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/app/src/androidTest/java/net/osmtracker/layouts/DeleteLayoutTest.java b/app/src/androidTest/java/net/osmtracker/layouts/DeleteLayoutTest.java index 63fd0a46..85cb39df 100644 --- a/app/src/androidTest/java/net/osmtracker/layouts/DeleteLayoutTest.java +++ b/app/src/androidTest/java/net/osmtracker/layouts/DeleteLayoutTest.java @@ -1,21 +1,5 @@ package net.osmtracker.layouts; -import android.Manifest; -import androidx.test.rule.ActivityTestRule; -import androidx.test.rule.GrantPermissionRule; - -import net.osmtracker.R; -import net.osmtracker.activity.ButtonsPresets; -import net.osmtracker.activity.Preferences; -import net.osmtracker.util.CustomLayoutsUtils; -import net.osmtracker.util.TestUtils; - -import org.junit.Rule; -import org.junit.Test; - -import java.io.IOException; -import java.util.ArrayList; - import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.longClick; @@ -26,10 +10,26 @@ import static net.osmtracker.util.TestUtils.getStringResource; import static net.osmtracker.util.TestUtils.injectMockLayout; import static net.osmtracker.util.TestUtils.listFiles; +import static org.apache.commons.io.FileUtils.deleteDirectory; import static org.hamcrest.Matchers.equalToIgnoringCase; import static org.junit.Assert.assertFalse; -import static org.apache.commons.io.FileUtils.deleteDirectory; +import android.Manifest; + +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.rule.GrantPermissionRule; + +import net.osmtracker.R; +import net.osmtracker.activity.ButtonsPresets; +import net.osmtracker.activity.Preferences; +import net.osmtracker.util.CustomLayoutsUtils; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; public class DeleteLayoutTest { @@ -37,28 +37,27 @@ public class DeleteLayoutTest { public GrantPermissionRule storagePermission = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE); @Rule - public ActivityTestRule mRule = new ActivityTestRule(ButtonsPresets.class) { - @Override - protected void beforeActivityLaunched() { - //Makes sure that only the mock layout exists + public ActivityScenarioRule mRule = new ActivityScenarioRule<>(ButtonsPresets.class); + + private static String layoutName = "mock"; + private static String ISOLanguageCode = "es"; + + @Before + public void setup() { + // Makes sure that only the mock layout exists try { deleteDirectory(getLayoutsDirectory()); injectMockLayout(layoutName, ISOLanguageCode); - } catch (IOException e) { e.printStackTrace(); } } - }; - - private static String layoutName = "mock"; - private static String ISOLanguageCode = "es"; /** * Assumes being in the ButtonsPresets activity * Deletes the layout with the received name */ - private void deleteLayout(String layoutName){ + private void deleteLayout(String layoutName) { onView(withText(layoutName)).perform(longClick()); onView(withText(getStringResource(R.string.buttons_presets_context_menu_delete))).perform(click()); String textToMatch = getStringResource(R.string.buttons_presets_delete_positive_confirmation); @@ -73,8 +72,7 @@ private void deleteLayout(String layoutName){ * - The icons directory is deleted */ @Test - public void layoutDeletionTest(){ - + public void layoutDeletionTest() { deleteLayout(layoutName); // Check the informative Toast is shown @@ -91,7 +89,6 @@ public void layoutDeletionTest(){ assertFalse(filesAfterDeletion.contains(layoutFileName)); // Check the icons folder was deleted - assertFalse(filesAfterDeletion.contains(layoutName+ Preferences.ICONS_DIR_SUFFIX)); - + assertFalse(filesAfterDeletion.contains(layoutName + Preferences.ICONS_DIR_SUFFIX)); } }