-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'improved_offset_display'
- Loading branch information
Showing
8 changed files
with
339 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/androidTest/java/de/blau/android/imageryoffset/SaveResumeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package de.blau.android.imageryoffset; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import android.app.Instrumentation; | ||
import android.app.Instrumentation.ActivityMonitor; | ||
import android.content.Context; | ||
import androidx.lifecycle.Lifecycle.State; | ||
import androidx.test.core.app.ActivityScenario; | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.uiautomator.UiDevice; | ||
import androidx.test.uiautomator.UiObject2; | ||
import de.blau.android.App; | ||
import de.blau.android.Logic; | ||
import de.blau.android.Main; | ||
import de.blau.android.Map; | ||
import de.blau.android.MockTileServer; | ||
import de.blau.android.R; | ||
import de.blau.android.TestUtils; | ||
import de.blau.android.exception.OsmException; | ||
import de.blau.android.layer.LayerDialogTest; | ||
import de.blau.android.osm.BoundingBox; | ||
import de.blau.android.prefs.AdvancedPrefDatabase; | ||
import de.blau.android.prefs.Preferences; | ||
import de.blau.android.util.GeoMath; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
|
||
/** | ||
* 1st attempts at testing lifecycle related aspects | ||
* | ||
* @author simon | ||
* | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class SaveResumeTest { | ||
|
||
Context context = null; | ||
AdvancedPrefDatabase prefDB = null; | ||
Main main = null; | ||
UiDevice device = null; | ||
Map map = null; | ||
Logic logic = null; | ||
MockWebServer tileServer = null; | ||
ActivityScenario<Main> scenario = null; | ||
|
||
@Rule | ||
public ActivityScenarioRule<Main> activityScenarioRule = new ActivityScenarioRule<>(Main.class); | ||
|
||
/** | ||
* Pre-test setup | ||
*/ | ||
@Before | ||
public void setup() { | ||
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); | ||
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); | ||
context = instrumentation.getTargetContext(); | ||
ActivityMonitor monitor = instrumentation.addMonitor(Main.class.getName(), null, false); | ||
scenario = ActivityScenario.launch(Main.class); | ||
main = (Main) instrumentation.waitForMonitorWithTimeout(monitor, 30000); | ||
instrumentation.removeMonitor(monitor); | ||
Preferences prefs = new Preferences(context); | ||
|
||
tileServer = MockTileServer.setupTileServer(main, "ersatz_background.mbt", true); | ||
|
||
map = main.getMap(); | ||
map.setPrefs(main, prefs); | ||
logic = App.getLogic(); | ||
logic.setPrefs(prefs); | ||
TestUtils.resetOffsets(main.getMap()); | ||
TestUtils.grantPermissons(device); | ||
TestUtils.dismissStartUpDialogs(device, main); | ||
TestUtils.stopEasyEdit(main); | ||
TestUtils.zoomToNullIsland(logic, map); | ||
main.invalidateOptionsMenu(); // to be sure that the menu entry is actually shown | ||
} | ||
|
||
/** | ||
* Post-test teardown | ||
*/ | ||
@After | ||
public void teardown() { | ||
try { | ||
tileServer.close(); | ||
} catch (IOException e) { | ||
// ignore | ||
} | ||
|
||
scenario.moveToState(State.DESTROYED); | ||
} | ||
|
||
/** | ||
* Start the alignment mode then recreate | ||
*/ | ||
@Test | ||
public void startResumeMode() { | ||
TestUtils.zoomToLevel(device, main, 18); | ||
try { | ||
BoundingBox bbox = GeoMath.createBoundingBoxForCoordinates(47.390339D, 8.38782D, 50D); | ||
App.getLogic().getViewBox().setBorders(map, bbox); | ||
map.setViewBox(App.getLogic().getViewBox()); | ||
map.invalidate(); | ||
try { | ||
Thread.sleep(5000); // NOSONAR | ||
} catch (InterruptedException e) { | ||
} | ||
main.invalidateOptionsMenu(); | ||
} catch (OsmException e) { | ||
fail(e.getMessage()); | ||
} | ||
UiObject2 menuButton = TestUtils.getLayerButton(device, "Vespucci Test", LayerDialogTest.MENU_BUTTON); | ||
menuButton.click(); | ||
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.menu_layers_background_align), true, false)); | ||
assertTrue(TestUtils.findText(device, false, main.getString(R.string.menu_tools_background_align))); | ||
scenario.recreate(); | ||
assertTrue(TestUtils.findText(device, false, main.getString(R.string.menu_tools_background_align), 10000)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.