Skip to content

Commit

Permalink
Replace deprecated ActivityTestRule
Browse files Browse the repository at this point in the history
  • Loading branch information
Binnette committed Dec 4, 2024
1 parent a1db1c3 commit e05b24a
Showing 1 changed file with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,39 +10,54 @@
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 {

@Rule
public GrantPermissionRule storagePermission = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);

@Rule
public ActivityTestRule<ButtonsPresets> mRule = new ActivityTestRule(ButtonsPresets.class) {
@Override
protected void beforeActivityLaunched() {
//Makes sure that only the mock layout exists
public ActivityScenarioRule<ButtonsPresets> 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);
Expand All @@ -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
Expand All @@ -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));
}
}

0 comments on commit e05b24a

Please sign in to comment.