Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests to be fully portable #14

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ tasks.withType<JavaCompile>() {
options.encoding = "UTF-8"
}

tasks.withType<Test>() {
// Enforce en-US locale, as many unit tests are locale-dependant.
systemProperty("user.language", "en")
systemProperty("user.country", "US")
}

group = "org.crosswire"
version = "2.3"

Expand All @@ -28,11 +34,8 @@ dependencies {
// implementation("org.apache.lucene:lucene-analyzers-common:x")

//implementation("org.slf4j:slf4j-api:1.7.6")
if(project.hasProperty("tests")) {
implementation("org.slf4j:slf4j-api:1.7.6")
} else {
implementation("de.psdev.slf4j-android-logger:slf4j-android-logger:1.0.5")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using in Android app (AndBible) we need this logger implementation.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide PR for AndBible how to use this if we make this change?

Copy link
Author

@UnasZole UnasZole Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'm not familiar with android development (I'm a very experienced Java developer, but only for backend applications, not frontends so far) so I'm not equipped to run tests on and-bible. (I could take time to try it later on, though).

But the change is very simple : you can just add the dependency directly in this list : https://github.com/AndBible/and-bible/blob/develop/app/build.gradle.kts#L335
This should be enough :-)

}
implementation("org.slf4j:slf4j-api:1.7.6")
testImplementation("org.slf4j:slf4j-simple:1.7.6")
testImplementation("junit:junit:4.13")
}

Expand Down
21 changes: 12 additions & 9 deletions src/test/java/org/crosswire/jsword/book/BooksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -134,6 +135,7 @@ public void testGetDataPassage() throws Exception {
public void testBookList() throws Exception {
//part of the pre-requisites
AbstractPassageBook esv = (AbstractPassageBook) Books.installed().getBook("ESV2011");
Assume.assumeTrue("ESV2011 is installed", esv != null);
Assert.assertTrue(esv.getBibleBooks().contains(BibleBook.ACTS));
}

Expand All @@ -147,17 +149,18 @@ public void testBookList() throws Exception {
@Test
public void testLinkedVersesNotDuplicated() throws Exception {
Book turNTB = Books.installed().getBook("TurNTB");
if (turNTB != null) {
// Eph 2:4,5 are merged/linked in TurNTB
Key eph245 = VerseRangeFactory.fromString(Versifications.instance().getVersification("KJV"), "Eph 2:4-5");
BookData bookData = new BookData(turNTB, eph245);
final Element osisFragment = bookData.getOsisFragment();

final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
String xml = xmlOutputter.outputString(osisFragment);
Assume.assumeTrue("TurNTB is installed", turNTB != null);

Assert.assertTrue("Probable duplicate text", xml.length() < 300);
}
// Eph 2:4,5 are merged/linked in TurNTB
Key eph245 = VerseRangeFactory.fromString(Versifications.instance().getVersification("KJV"), "Eph 2:4-5");
BookData bookData = new BookData(turNTB, eph245);
final Element osisFragment = bookData.getOsisFragment();

final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
String xml = xmlOutputter.outputString(osisFragment);

Assert.assertTrue("Probable duplicate text", xml.length() < 300);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -270,9 +271,8 @@ public void testBackendGenevaCommentsZ() throws Exception {
public void testBackendStrongsGreekRawLd() throws Exception {
String version = "StrongsGreek";
String reference = "G3588";
String assertion = "3588 ho ho, including the feminine";

backendTest(version, reference, assertion);
backendTest(version, reference, "3588", "ho");
}

/**
Expand Down Expand Up @@ -331,9 +331,7 @@ public void testBackendOt1Nt2Devotional() throws Exception {
private String backendTest(String version, String reference, String... assertion) throws NoSuchKeyException, BookException {
final Book currentBook = Books.installed().getBook(version);

if (currentBook == null) {
return null;
}
Assume.assumeTrue("Book " + version + " is installed", currentBook != null);

return backendTest(currentBook, currentBook.getKey(reference), assertion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import org.crosswire.jsword.book.BookException;
import org.crosswire.jsword.passage.NoSuchKeyException;
import org.crosswire.jsword.versification.BookName;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.*;

/**
* Test of functionality for use with DWR. This test assumes, at a minimum, that
Expand All @@ -42,6 +39,10 @@ public class DwrBridgeMissingAssetsTest {
@Before
public void setUp() {
BookName.setFullBookName(true);

Assume.assumeTrue("KJV must be installed", BookInstaller.getInstalledBook("KJV") != null);
Assume.assumeTrue("StrongsHebrew must be installed", BookInstaller.getInstalledBook("StrongsHebrew") != null);
Assume.assumeTrue("StrongsGreek must be installed", BookInstaller.getInstalledBook("StrongsGreek") != null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void testInstallBook() {
private BookInstaller underTest;
private Books installedBooks;

private static final String[] BOOKS = new String[]{"KJV", "ESV2011"};
/**
* All books referenced in these unit tests that can be retrieved from the Crosswire repository.
* Currently missing : ESV2011, MHCC, ot1nt2
* Tests that reference a currently missing book are automatically skipped unless the book was installed externally.
*/
private static final String[] BOOKS = new String[]{"KJV", "StrongsHebrew", "StrongsGreek", "Josephus", "Nave", "Geneva", "TurNTB"};
private static final Logger LOGGER = LoggerFactory.getLogger(BookPreRequisitesTest.class);
}
Loading