diff --git a/app/src/androidTest/java/com/orgzly/android/repos/DataRepositoryTest.java b/app/src/androidTest/java/com/orgzly/android/repos/DataRepositoryTest.java index c60ce8673..3db2b9425 100644 --- a/app/src/androidTest/java/com/orgzly/android/repos/DataRepositoryTest.java +++ b/app/src/androidTest/java/com/orgzly/android/repos/DataRepositoryTest.java @@ -70,7 +70,7 @@ public void testLoadRook() throws IOException { assertEquals("remote-book-1", book.getBook().getName()); assertEquals("/remote-book-1.org", book.getSyncedTo().getUri().getPath()); - assertEquals("remote-book-1", BookName.getInstance(context, book.getSyncedTo()).getName()); + assertEquals("remote-book-1", BookName.fromRook(book.getSyncedTo()).getName()); assertEquals("0abcdef", book.getSyncedTo().getRevision()); assertEquals(1400067156000L, book.getSyncedTo().getMtime()); assertEquals(repo.getUrl(), vrook.getRepoUri().toString()); diff --git a/app/src/androidTest/java/com/orgzly/android/repos/DirectoryRepoTest.java b/app/src/androidTest/java/com/orgzly/android/repos/DirectoryRepoTest.java index c790d473c..cf0e02fc6 100644 --- a/app/src/androidTest/java/com/orgzly/android/repos/DirectoryRepoTest.java +++ b/app/src/androidTest/java/com/orgzly/android/repos/DirectoryRepoTest.java @@ -62,8 +62,8 @@ public void testStoringFile() throws IOException { List books = repo.getBooks(); assertEquals(1, books.size()); - assertEquals("booky", BookName.getInstance(context, books.get(0)).getName()); - assertEquals("booky.org", BookName.getInstance(context, books.get(0)).getFileName()); + assertEquals("booky", BookName.fromRook(books.get(0)).getName()); + assertEquals("booky.org", BookName.fromRook(books.get(0)).getFileName()); assertEquals(repoUriString, books.get(0).getRepoUri().toString()); assertEquals(repoUriString + "/booky.org", books.get(0).getUri().toString()); } @@ -79,8 +79,8 @@ public void testExtension() throws IOException { List books = repo.getBooks(); assertEquals(1, books.size()); - assertEquals("03", BookName.getInstance(context, books.get(0)).getName()); - assertEquals("03.org", BookName.getInstance(context, books.get(0)).getFileName()); + assertEquals("03", BookName.fromRook(books.get(0)).getName()); + assertEquals("03.org", BookName.fromRook(books.get(0)).getFileName()); assertEquals(13, books.get(0).getRepoId()); assertEquals(repoUriString, books.get(0).getRepoUri().toString()); assertEquals(repoUriString + "/03.org", books.get(0).getUri().toString()); @@ -103,7 +103,7 @@ public void testGetBooksRespectsIgnoreRules() throws IOException { List books = repo.getBooks(); assertEquals(1, books.size()); - assertEquals("file2", BookName.getInstance(context, books.get(0)).getName()); + assertEquals("file2", BookName.fromRook(books.get(0)).getName()); assertEquals(repoUriString + "/file2.org", books.get(0).getUri().toString()); } diff --git a/app/src/androidTest/java/com/orgzly/android/repos/LocalDbRepoTest.java b/app/src/androidTest/java/com/orgzly/android/repos/LocalDbRepoTest.java index 7438e8955..dd54e3c02 100644 --- a/app/src/androidTest/java/com/orgzly/android/repos/LocalDbRepoTest.java +++ b/app/src/androidTest/java/com/orgzly/android/repos/LocalDbRepoTest.java @@ -38,7 +38,7 @@ public void testGetBooksFromAllRepos() throws IOException { VersionedRook vrook = books.get(0); - assertEquals("mock-book", BookName.getInstance(context, vrook).getName()); + assertEquals("mock-book", BookName.fromRook(vrook).getName()); assertEquals("mock://repo-a", vrook.getRepoUri().toString()); assertEquals("mock://repo-a/mock-book.org", vrook.getUri().toString()); assertEquals("rev1", vrook.getRevision()); @@ -67,7 +67,7 @@ public void testStoringBook() throws IOException { assertEquals(1, books.size()); VersionedRook vrook = books.get(0); - assertEquals("local-book-1", BookName.getInstance(context, vrook).getName()); + assertEquals("local-book-1", BookName.fromRook(vrook).getName()); assertEquals("mock://repo-a", vrook.getRepoUri().toString()); assertTrue(vrook.getMtime() >= now); } diff --git a/app/src/androidTest/java/com/orgzly/android/repos/SyncTest.java b/app/src/androidTest/java/com/orgzly/android/repos/SyncTest.java index 0d8cf71ae..ecdfd8c11 100644 --- a/app/src/androidTest/java/com/orgzly/android/repos/SyncTest.java +++ b/app/src/androidTest/java/com/orgzly/android/repos/SyncTest.java @@ -1,18 +1,10 @@ package com.orgzly.android.repos; -import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.longClick; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static com.orgzly.android.espresso.util.EspressoUtils.contextualToolbarOverflowMenu; import static com.orgzly.android.espresso.util.EspressoUtils.onBook; -import static com.orgzly.android.espresso.util.EspressoUtils.onSnackbar; -import static com.orgzly.android.espresso.util.EspressoUtils.sync; import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.endsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -25,8 +17,6 @@ import android.net.Uri; import android.os.Build; -import androidx.test.core.app.ActivityScenario; - import com.orgzly.R; import com.orgzly.android.BookFormat; import com.orgzly.android.BookName; @@ -38,7 +28,6 @@ import com.orgzly.android.db.entity.Repo; import com.orgzly.android.sync.BookNamesake; import com.orgzly.android.sync.BookSyncStatus; -import com.orgzly.android.ui.main.MainActivity; import com.orgzly.android.util.EncodingDetect; import com.orgzly.android.util.MiscUtils; @@ -420,7 +409,7 @@ public void testMockFileRename() throws IOException { vrooks = repo.getBooks(); assertEquals(1, vrooks.size()); - assertEquals("Booky", BookName.getInstance(context, vrooks.get(0)).getName()); + assertEquals("Booky", BookName.fromRook(vrooks.get(0)).getName()); long mtime = vrooks.get(0).getMtime(); String rev = vrooks.get(0).getRevision(); @@ -434,7 +423,7 @@ public void testMockFileRename() throws IOException { vrooks = repo.getBooks(); assertEquals(1, vrooks.size()); - assertEquals("BookyRenamed", BookName.getInstance(context, vrooks.get(0)).getName()); + assertEquals("BookyRenamed", BookName.fromRook(vrooks.get(0)).getName()); assertEquals("mock://repo-a/BookyRenamed.org", vrooks.get(0).getUri().toString()); assertTrue(mtime < vrooks.get(0).getMtime()); assertNotSame(rev, vrooks.get(0).getRevision()); @@ -464,7 +453,7 @@ public void testDirectoryFileRename() throws IOException { assertEquals(1, repo.getBooks().size()); assertEquals(repo.getUri() + "/notebook-renamed.org", repo.getBooks().get(0).getUri().toString()); - assertEquals("notebook-renamed.org", BookName.getInstance(context, repo.getBooks().get(0)).getFileName()); + assertEquals("notebook-renamed.org", BookName.fromRook(repo.getBooks().get(0)).getFileName()); LocalStorage.deleteRecursive(new File(repoDir)); } diff --git a/app/src/main/java/com/orgzly/android/BookName.java b/app/src/main/java/com/orgzly/android/BookName.java index 87c29c3eb..e2cf421af 100644 --- a/app/src/main/java/com/orgzly/android/BookName.java +++ b/app/src/main/java/com/orgzly/android/BookName.java @@ -78,8 +78,8 @@ public static String getFileName(Uri repoUri, Uri fileUri) { } } - public static BookName getInstance(Context context, Rook rook) { - return fromFileName(getFileName(context, rook.getUri())); + public static BookName fromRook(Rook rook) { + return fromFileName(getFileName(rook.getRepoUri(), rook.getUri())); } public static boolean isSupportedFormatFileName(String fileName) {