Skip to content

Commit

Permalink
No context is needed to get a BookName when we have a Rook
Browse files Browse the repository at this point in the history
  • Loading branch information
amberin committed Aug 21, 2024
1 parent 76cc77b commit 120fa64
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public void testStoringFile() throws IOException {
List<VersionedRook> 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());
}
Expand All @@ -79,8 +79,8 @@ public void testExtension() throws IOException {
List<VersionedRook> 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());
Expand All @@ -103,7 +103,7 @@ public void testGetBooksRespectsIgnoreRules() throws IOException {
List<VersionedRook> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
Expand Down
17 changes: 3 additions & 14 deletions app/src/androidTest/java/com/orgzly/android/repos/SyncTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/orgzly/android/BookName.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 120fa64

Please sign in to comment.