From 803f57cea46e1fbc0d26de36e9489257f045d2b1 Mon Sep 17 00:00:00 2001 From: Binnette Date: Mon, 25 Nov 2024 21:41:54 +0100 Subject: [PATCH] androidTest: fix all androidTests --- .../java/net/osmtracker/layouts/DeleteLayoutTest.java | 4 ++++ .../osmtracker/layouts/RepositorySettingsDialogTest.java | 4 ++++ .../java/net/osmtracker/activity/AvailableLayouts.java | 8 ++++++-- .../main/java/net/osmtracker/activity/ButtonsPresets.java | 5 ++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/net/osmtracker/layouts/DeleteLayoutTest.java b/app/src/androidTest/java/net/osmtracker/layouts/DeleteLayoutTest.java index 013721bf1..14df601c1 100644 --- a/app/src/androidTest/java/net/osmtracker/layouts/DeleteLayoutTest.java +++ b/app/src/androidTest/java/net/osmtracker/layouts/DeleteLayoutTest.java @@ -8,6 +8,7 @@ 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; @@ -20,6 +21,7 @@ import static androidx.test.espresso.action.ViewActions.longClick; import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist; import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static net.osmtracker.util.LogcatHelper.checkLogForMessage; import static net.osmtracker.util.TestUtils.checkToastIsShownWith; import static net.osmtracker.util.TestUtils.getLayoutsDirectory; import static net.osmtracker.util.TestUtils.getStringResource; @@ -73,6 +75,8 @@ public void layoutDeletionTest(){ deleteLayout(layoutName); + checkLogForMessage("TOAST", TestUtils.getStringResource(R.string.buttons_presets_successful_delete)); + // Check the informative Toast is shown checkToastIsShownWith(getStringResource(R.string.buttons_presets_successful_delete)); diff --git a/app/src/androidTest/java/net/osmtracker/layouts/RepositorySettingsDialogTest.java b/app/src/androidTest/java/net/osmtracker/layouts/RepositorySettingsDialogTest.java index 4fc9c8729..a93cd2dc3 100644 --- a/app/src/androidTest/java/net/osmtracker/layouts/RepositorySettingsDialogTest.java +++ b/app/src/androidTest/java/net/osmtracker/layouts/RepositorySettingsDialogTest.java @@ -7,6 +7,7 @@ import net.osmtracker.OSMTracker; import net.osmtracker.R; import net.osmtracker.activity.AvailableLayouts; +import net.osmtracker.util.TestUtils; import org.hamcrest.Matcher; import org.junit.Rule; @@ -23,6 +24,7 @@ import static androidx.test.espresso.matcher.ViewMatchers.isEnabled; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static net.osmtracker.util.LogcatHelper.checkLogForMessage; import static net.osmtracker.util.TestUtils.checkToastIsShownWith; import static net.osmtracker.util.TestUtils.getStringResource; import static org.hamcrest.core.IsNot.not; @@ -80,6 +82,8 @@ public void checkRepositoryValidity(String user, String repo, String branch, boo String expectedMessage = (isValid) ? getStringResource(R.string.github_repository_settings_valid_server) : getStringResource(R.string.github_repository_settings_invalid_server); + checkLogForMessage("TOAST", expectedMessage); + checkToastIsShownWith(expectedMessage); ViewAssertion expectedDialogState = (isValid) ? doesNotExist() : matches(isDisplayed()); diff --git a/app/src/main/java/net/osmtracker/activity/AvailableLayouts.java b/app/src/main/java/net/osmtracker/activity/AvailableLayouts.java index 20850b813..64a321e4b 100644 --- a/app/src/main/java/net/osmtracker/activity/AvailableLayouts.java +++ b/app/src/main/java/net/osmtracker/activity/AvailableLayouts.java @@ -247,7 +247,9 @@ public void onClick(DialogInterface dialog, int which) { protected void onPostExecute(Boolean result){ //validating the github repository if(result){ - Toast.makeText(AvailableLayouts.this, getResources().getString(R.string.github_repository_settings_valid_server), Toast.LENGTH_SHORT).show(); + String message = getResources().getString(R.string.github_repository_settings_valid_server); + Log.i("TOAST", message); + Toast.makeText(AvailableLayouts.this, message, Toast.LENGTH_SHORT).show(); //save the entered options into the shared preferences file editor.putString(OSMTracker.Preferences.KEY_GITHUB_USERNAME, repositoryCustomOptions[0]); editor.putString(OSMTracker.Preferences.KEY_REPOSITORY_NAME, repositoryCustomOptions[1]); @@ -257,7 +259,9 @@ protected void onPostExecute(Boolean result){ tmpSharedPref.edit().putBoolean("isCallBack", false).commit(); retrieveAvailableLayouts(); }else{ - Toast.makeText(AvailableLayouts.this, getResources().getString(R.string.github_repository_settings_invalid_server), Toast.LENGTH_SHORT).show(); + String message = getResources().getString(R.string.github_repository_settings_invalid_server); + Log.e("TOAST", message); + Toast.makeText(AvailableLayouts.this, message, Toast.LENGTH_SHORT).show(); tmpSharedPref.edit().putString(OSMTracker.Preferences.KEY_GITHUB_USERNAME, repositoryCustomOptions[0]).commit(); tmpSharedPref.edit().putString(OSMTracker.Preferences.KEY_REPOSITORY_NAME, repositoryCustomOptions[1]).commit(); tmpSharedPref.edit().putString(OSMTracker.Preferences.KEY_BRANCH_NAME, repositoryCustomOptions[2]).commit(); diff --git a/app/src/main/java/net/osmtracker/activity/ButtonsPresets.java b/app/src/main/java/net/osmtracker/activity/ButtonsPresets.java index ed6a9fb46..2d5f864dd 100644 --- a/app/src/main/java/net/osmtracker/activity/ButtonsPresets.java +++ b/app/src/main/java/net/osmtracker/activity/ButtonsPresets.java @@ -285,8 +285,11 @@ public void onClick(DialogInterface dialog, int which) { int messageToShowId = (successfulDeletion) ? R.string.buttons_presets_successful_delete : R.string.buttons_presets_unsuccessful_delete; + String message = getResources().getString(messageToShowId); - Toast.makeText(getApplicationContext(), getResources().getString(messageToShowId), Toast.LENGTH_SHORT).show(); + Log.println(successfulDeletion ? Log.INFO : Log.ERROR, "TOAST", message); + + Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); //reload the activity refreshActivity();