Skip to content

Commit 9b185a2

Browse files
committed
stuff
1 parent 7a4ae23 commit 9b185a2

4 files changed

Lines changed: 32 additions & 25 deletions

File tree

app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ android {
3131
defaultConfig {
3232
applicationId "at.tomtasche.reader"
3333
minSdkVersion 23
34-
compileSdkVersion 34
3534
targetSdkVersion 34
3635

3736
testApplicationId "at.tomtasche.reader.test"

app/src/androidTest/java/at/tomtasche/reader/test/MainActivityTests.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ public class MainActivityTests {
6161

6262
// Yes, this is ActivityTestRule instead of ActivityScenario, because ActivityScenario does not actually work.
6363
// Issue ID may or may not be added later.
64+
// Launch activity manually to ensure complete restart between tests
6465
@Rule
65-
public ActivityTestRule<MainActivity> mainActivityActivityTestRule = new ActivityTestRule<>(MainActivity.class);
66+
public ActivityTestRule<MainActivity> mainActivityActivityTestRule = new ActivityTestRule<>(MainActivity.class, false, false);
6667

6768
@Before
6869
public void setUp() {
69-
MainActivity mainActivity = mainActivityActivityTestRule.getActivity();
70+
// Launch a fresh activity for each test
71+
MainActivity mainActivity = mainActivityActivityTestRule.launchActivity(null);
7072

7173
m_idlingResource = mainActivity.getOpenFileIdlingResource();
7274
IdlingRegistry.getInstance().register(m_idlingResource);
@@ -91,8 +93,14 @@ public void tearDown() {
9193
IdlingRegistry.getInstance().unregister(m_idlingResource);
9294
}
9395

94-
// Ensure activity is finished to reset state between tests
95-
mainActivityActivityTestRule.getActivity().finish();
96+
// Finish and wait for activity to be destroyed
97+
MainActivity activity = mainActivityActivityTestRule.getActivity();
98+
if (activity != null) {
99+
mainActivityActivityTestRule.finishActivity();
100+
101+
// Use Instrumentation to wait until activity is destroyed
102+
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
103+
}
96104
}
97105

98106
private static void copy(InputStream src, File dst) throws IOException {
@@ -135,7 +143,7 @@ public static void cleanupTestFiles() {
135143
}
136144

137145
@Test
138-
public void testODT() {
146+
public void testXODT() {
139147
File testFile = s_testFiles.get("test.odt");
140148
Assert.assertNotNull(testFile);
141149
Context appCtx = InstrumentationRegistry.getInstrumentation().getTargetContext();
@@ -149,21 +157,21 @@ public void testODT() {
149157
);
150158

151159
onView(allOf(withId(R.id.menu_open), withContentDescription("Open document"), isDisplayed()))
152-
.perform(click());
160+
.perform(click());
153161

154162
// The menu item could be either Documents or Files.
155163
onView(allOf(withId(android.R.id.text1), anyOf(withText("Documents"), withText("Files")), isDisplayed()))
156164
.perform(click());
157165

158166
// next onView will be blocked until m_idlingResource is idle.
159167
onView(allOf(withId(R.id.menu_edit), withContentDescription("Edit document"), isEnabled()))
160-
.withFailureHandler((error, viewMatcher) -> {
161-
// fails on small screens, try again with overflow menu
162-
onView(allOf(withContentDescription("More options"), isDisplayed())).perform(click());
168+
.withFailureHandler((error, viewMatcher) -> {
169+
// fails on small screens, try again with overflow menu
170+
onView(allOf(withContentDescription("More options"), isDisplayed())).perform(click());
163171

164-
onView(allOf(withId(R.id.menu_edit), withContentDescription("Edit document"), isDisplayed()))
165-
.perform(click());
166-
});
172+
onView(allOf(withId(R.id.menu_edit), withContentDescription("Edit document"), isDisplayed()))
173+
.perform(click());
174+
});
167175
}
168176

169177
@Test
@@ -203,19 +211,19 @@ public void testPDF() {
203211
public void testPasswordProtectedODT() {
204212
File testFile = s_testFiles.get("password-test.odt");
205213
Assert.assertNotNull(testFile);
206-
214+
207215
// Check if the file exists and is readable
208216
Assert.assertTrue("Password test file does not exist: " + testFile.getAbsolutePath(), testFile.exists());
209217
Assert.assertTrue("Password test file is not readable: " + testFile.getAbsolutePath(), testFile.canRead());
210-
218+
211219
// Log file info for debugging CI issues
212220
Log.d("MainActivityTests", "Password test file path: " + testFile.getAbsolutePath());
213221
Log.d("MainActivityTests", "Password test file size: " + testFile.length());
214222
Log.d("MainActivityTests", "All test files: " + s_testFiles.keySet());
215-
223+
216224
// Double-check we're using the right file
217225
Assert.assertEquals("password-test.odt file size mismatch", 12671L, testFile.length());
218-
226+
219227
Context appCtx = InstrumentationRegistry.getInstrumentation().getTargetContext();
220228
Uri testFileUri = FileProvider.getUriForFile(appCtx, appCtx.getPackageName() + ".provider", testFile);
221229
Intents.intending(hasAction(Intent.ACTION_OPEN_DOCUMENT)).respondWith(
@@ -227,7 +235,7 @@ public void testPasswordProtectedODT() {
227235
);
228236

229237
onView(allOf(withId(R.id.menu_open), withContentDescription("Open document"), isDisplayed()))
230-
.perform(click());
238+
.perform(click());
231239

232240
onView(allOf(withId(android.R.id.text1), anyOf(withText("Documents"), withText("Files")), isDisplayed()))
233241
.perform(click());
@@ -256,11 +264,11 @@ public void testPasswordProtectedODT() {
256264

257265
// Check if edit button becomes available (indicating successful load)
258266
onView(allOf(withId(R.id.menu_edit), withContentDescription("Edit document"), isEnabled()))
259-
.withFailureHandler((error, viewMatcher) -> {
260-
onView(allOf(withContentDescription("More options"), isDisplayed())).perform(click());
267+
.withFailureHandler((error, viewMatcher) -> {
268+
onView(allOf(withContentDescription("More options"), isDisplayed())).perform(click());
261269

262-
onView(allOf(withId(R.id.menu_edit), withContentDescription("Edit document"), isDisplayed()))
263-
.perform(click());
264-
});
270+
onView(allOf(withId(R.id.menu_edit), withContentDescription("Edit document"), isDisplayed()))
271+
.perform(click());
272+
});
265273
}
266274
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'com.android.application' version '8.5.2' apply false
2+
id 'com.android.application' version '8.9.2' apply false
33
id 'com.google.gms.google-services'version '4.4.2' apply false
44
id 'com.google.firebase.crashlytics' version '3.0.2' apply false
55
id 'app.opendocument.conanandroidgradleplugin' version '0.9.6' apply false

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)