Skip to content

Commit

Permalink
Merge pull request #14 from UnasZole/fixUnitTests
Browse files Browse the repository at this point in the history
Fix unit tests to be fully portable
  • Loading branch information
tuomas2 committed Jan 18, 2024
2 parents 929fd54 + 7e47409 commit 8743b57
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
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")
}
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);
}

0 comments on commit 8743b57

Please sign in to comment.