Introduce TestBookmark.

This commit is contained in:
Matthieu Gautier 2023-06-14 15:07:38 +02:00
parent 83a6429565
commit 52cc2e48a8
3 changed files with 50 additions and 6 deletions

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2022 Matthieu Gautier <mgautier@kymeria.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.kiwix.test.libkiwix;
import org.kiwix.libkiwix.Bookmark;
public class TestBookmark
{
private Bookmark inner;
public Bookmark inner() { return inner; }
public TestBookmark() { inner = new Bookmark(); }
public TestBookmark(Bookmark _inner) { inner = _inner; }
public void setBookId(String bookId) { inner.setBookId(bookId); }
public void setBookTitle(String bookTitle) { inner.setBookTitle(bookTitle); }
public void setUrl(String url) { inner.setUrl(url); }
public void setTitle(String title) { inner.setTitle(title); }
public void setLanguage(String language) { inner.setLanguage(language); }
public void setDate(String date) { inner.setDate(date); }
public String getBookId() { return inner.getBookId(); }
public String getBookTitle() { return inner.getBookTitle(); }
public String getUrl() { return inner.getUrl(); }
public String getTitle() { return inner.getTitle(); }
public String getLanguage() { return inner.getLanguage(); }
public String getDate() { return inner.getDate(); }
}

View File

@ -21,11 +21,11 @@ package org.kiwix.test.libkiwix;
import org.kiwix.libkiwix.Library; import org.kiwix.libkiwix.Library;
import org.kiwix.test.libzim.TestArchive; import org.kiwix.test.libzim.TestArchive;
import org.kiwix.test.libkiwix.TestBookmark;
import org.kiwix.libzim.Searcher; import org.kiwix.libzim.Searcher;
import org.kiwix.libkiwix.Filter; import org.kiwix.libkiwix.Filter;
import org.kiwix.libkiwix.Book;
import org.kiwix.libkiwix.JNIKiwixException; import org.kiwix.libkiwix.JNIKiwixException;
import org.kiwix.libkiwix.Bookmark; import java.util.stream.Stream;
public class TestLibrary public class TestLibrary
{ {
@ -56,7 +56,7 @@ public class TestLibrary
public String[] getBooksCreators() { return inner.getBooksCreators(); } public String[] getBooksCreators() { return inner.getBooksCreators(); }
public String[] getBooksPublishers() { return inner.getBooksPublishers(); } public String[] getBooksPublishers() { return inner.getBooksPublishers(); }
public void addBookmark(Bookmark bookmark) { inner.addBookmark(bookmark); } public void addBookmark(TestBookmark bookmark) { inner.addBookmark(bookmark.inner()); }
public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); } public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); }
public Bookmark[] getBookmarks(boolean onlyValidBookmarks) { return inner.getBookmarks(onlyValidBookmarks); } public TestBookmark[] getBookmarks(boolean onlyValidBookmarks) { return Stream.of(inner.getBookmarks(onlyValidBookmarks)).map(b -> new TestBookmark(b)).toArray(TestBookmark[]::new); }
} }

View File

@ -154,7 +154,7 @@ public class test {
TestBook book = new TestBook(); TestBook book = new TestBook();
book.update(archive); book.update(archive);
lib.addBook(book); lib.addBook(book);
Bookmark bookmark = new Bookmark(); TestBookmark bookmark = new TestBookmark();
bookmark.setBookId(book.getId()); bookmark.setBookId(book.getId());
bookmark.setTitle(book.getTitle()); bookmark.setTitle(book.getTitle());
bookmark.setUrl(book.getUrl()); bookmark.setUrl(book.getUrl());
@ -163,7 +163,7 @@ public class test {
bookmark.setBookTitle(book.getName()); bookmark.setBookTitle(book.getName());
// add bookmark to library // add bookmark to library
lib.addBookmark(bookmark); lib.addBookmark(bookmark);
Bookmark[] bookmarkArray = lib.getBookmarks(true); TestBookmark[] bookmarkArray = lib.getBookmarks(true);
assertEquals(1, bookmarkArray.length); assertEquals(1, bookmarkArray.length);
bookmark = bookmarkArray[0]; bookmark = bookmarkArray[0];
// test saved bookmark // test saved bookmark