Skip to content

Commit

Permalink
test: clean API constructor test and CLI tests + deprecate other tests (
Browse files Browse the repository at this point in the history
#1061)

Based on @kalaspuffar’s work on #828

- use the locale object as the `Messages` lookup key to work around
  test failing when the messages created with the US default locale
  were retrieved when looking up the English locale
- add test dependency to `com.googlecode.json-simple:json-simple` for
  easy JSON parsing
- minor cleanup of `AbstractEpubCheckTest`
- cleanup `api_Test` to `ApiConstructosTest`
- consolidate CLI tests from `CLITest` and `command_line_Test` to a new
  `CommandLineTest` test class
- rename class `com.adobe.epubcheck.test.common` to `CommonTestRunner`
- add dreprecation annotation to the following test classes, pending
  refactoring:
  - CommonTestRunner
  - JsonCompare
  - Epub20CheckTest
  - Epub20CheckExpandedTest
  - Epub30CheckTest
  - Epub30CheckExpandedTest
  - LocalizationTest
  - NavCheckerTest
  - OCFCheckerTest
  - OCFFilenameCheckerTest
  - OCFMockPackage
  - MetadataSetTest
  - OPFCheckerTest
  - OPFCheckerTestChecks
  - OPSCheckerTest
  - OverlayCheckerTest
  - StressTest
  - MessageDictionary_LocalizationTest
  - OutputDifferenceListener
  - OverriddenMessageDictionaryTest
  - TestRunListener
  - UtilMessage_LocalizationTest
  - css_Test
  - debug
  - dtBook_Test
  - encryption_Test
  - message_coverage
  - opf_Test
  - package_Test
  - script_Test
  - single_file_Test
  - toc_Test
  - xhtml_Test
  - ExtraReportTest
  - OPFPeekerTest
  - PathUtilTest
  - ValidationReport
  - PrefixParsingTest
  - PropertyTest
  - VocabTest
  • Loading branch information
rdeltour authored Jul 19, 2019
1 parent e11dc21 commit 1ffe227
Show file tree
Hide file tree
Showing 84 changed files with 1,207 additions and 919 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/adobe/epubcheck/util/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Messages
{

private static final String BUNDLE_NAME = "com.adobe.epubcheck.util.messages";
private static final Table<String, String, Messages> messageTable = HashBasedTable.create();
private static final Table<String, Locale, Messages> messageTable = HashBasedTable.create();

private ResourceBundle bundle;
private Locale locale;
Expand Down Expand Up @@ -86,9 +86,8 @@ public static Messages getInstance(Locale locale, Class<?> cls)
locale = (locale == null) ? Locale.getDefault() : locale;

String bundleKey = (cls==null)? BUNDLE_NAME : getBundleName(cls);
String localeKey = locale.getLanguage();
if (messageTable.contains(bundleKey, localeKey)) {
instance = messageTable.get(bundleKey, localeKey);
if (messageTable.contains(bundleKey, locale)) {
instance = messageTable.get(bundleKey, locale);
}
else
{
Expand All @@ -97,7 +96,7 @@ public static Messages getInstance(Locale locale, Class<?> cls)
if (instance == null)
{
instance = new Messages(locale, bundleKey);
messageTable.put(bundleKey, localeKey, instance);
messageTable.put(bundleKey, locale, instance);
}
}
}
Expand Down
18 changes: 6 additions & 12 deletions src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.LinkedList;
import java.util.List;

import com.adobe.epubcheck.api.*;
import com.adobe.epubcheck.util.*;
import org.junit.Before;

Expand All @@ -47,14 +48,12 @@

public abstract class AbstractEpubCheckTest
{

private String basepath;
List<MessageId> expectedWarnings = new LinkedList<MessageId>();
List<MessageId> expectedErrors = new LinkedList<MessageId>();
List<MessageId> expectedFatals = new LinkedList<MessageId>();
List<MessageId> expectedInfos = new LinkedList<MessageId>();
List<MessageId> expectedUsages = new LinkedList<MessageId>();

protected List<MessageId> expectedWarnings = new LinkedList<MessageId>();
protected List<MessageId> expectedErrors = new LinkedList<MessageId>();
protected List<MessageId> expectedFatals = new LinkedList<MessageId>();
protected List<MessageId> expectedInfos = new LinkedList<MessageId>();
protected List<MessageId> expectedUsages = new LinkedList<MessageId>();

protected AbstractEpubCheckTest(String basepath)
{
Expand Down Expand Up @@ -86,11 +85,6 @@ public void testValidateDocument(String fileName, String resultFile)
testValidateDocument(fileName, resultFile, null, false, false);
}

public void testValidateDocument(String fileName, String resultFile, boolean usage, boolean verbose)
{
testValidateDocument(fileName, resultFile, EPUBProfile.DEFAULT, usage, verbose);
}

public void testValidateDocument(String fileName, String resultFile, EPUBProfile profile, boolean usage,
boolean verbose)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.adobe.epubcheck.test;
package com.adobe.epubcheck.api;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -15,12 +15,13 @@

import com.adobe.epubcheck.api.EpubCheck;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.test.CommonTestRunner;
import com.adobe.epubcheck.util.WriterReportImpl;

/**
* Test the various constructors for the EpubCheck Object.
*/
public class api_Test
public class ApiConstructorsTest
{

private Locale defaultLocale;
Expand All @@ -38,44 +39,63 @@ public void after() throws Exception
Locale.setDefault(defaultLocale);
}


/**
* Checking if the standard API constructor can take an epub and validate it.
*
* @throws Exception
*/
@Test
public void EpubCheck1_Test() throws Exception
public void StandardConstructorTest() throws Exception
{
File epub = getTestEpub();
EpubCheck check = new EpubCheck(epub);
Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate());
Assert.assertEquals("The file should have no errors.", 0, check.doValidate());
}

/**
* Checking if we can apply a PrintWriter to the constructor and get the expected output written
* to the supplied PrintWriter.
*
* @throws Exception
*/
@Test
public void EpubCheck_PrintWriter_Test() throws Exception
public void PrintWriterConstructorTest() throws Exception
{
try {
File epub = getTestEpub();
URL expectedUrl = common.class.getResource("api");
URL expectedUrl = this.getClass().getResource("");
String outputPath = new File(expectedUrl.toURI()).getAbsolutePath();

File actualResults = new File(outputPath + "/PrintWriter_Actual.txt");
File expectedResults = new File(outputPath + "/PrintWriter_Expected.txt");
FileOutputStream outputStream = new FileOutputStream(actualResults);
PrintWriter out = new PrintWriter(outputStream);
EpubCheck check = new EpubCheck(epub, out);
Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate());
Assert.assertEquals("The file should have no errors.", 0, check.doValidate());
out.flush();
outputStream.close();
out.close();
Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists());
Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists());
common.compareText(expectedResults, actualResults);
CommonTestRunner.compareText(expectedResults, actualResults);
} catch (URISyntaxException e) {
throw new IllegalStateException("Cannot find test file", e);
}
}

/**
* Checking if we can stream a epub to the constructor and use a Report object to
* summarize the output.
*
* @throws Exception
*/
@Test
public void EpubCheck_InputStream_Test() throws Exception
public void InputStreamConstructorTest() throws Exception
{
try {
File epub = getTestEpub();
URL expectedUrl = common.class.getResource("api");
URL expectedUrl = this.getClass().getResource("");
String outputPath = new File(expectedUrl.toURI()).getAbsolutePath();
File actualResults = new File(outputPath + "/InputStream_Actual.txt");
File expectedResults = new File(outputPath + "/InputStream_Expected.txt");
Expand All @@ -85,23 +105,24 @@ public void EpubCheck_InputStream_Test() throws Exception
FileInputStream epubStream = new FileInputStream(epub);
Report report = new WriterReportImpl(out, "Testing 123");
EpubCheck check = new EpubCheck(epubStream, report, epub.getPath());
Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate());
Assert.assertEquals("The file should have generated errors.", 0, check.doValidate());
out.flush();
outputStream.close();
out.close();
epubStream.close();
Assert.assertEquals("Errors reported", 0, report.getErrorCount());
Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists());
Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists());
common.compareText(expectedResults, actualResults);
CommonTestRunner.compareText(expectedResults, actualResults);
} catch (URISyntaxException e) {
throw new IllegalStateException("Cannot find test file", e);
}
}

private File getTestEpub()
private File getTestEpub() throws Exception
{
try {
URL inputUrl = common.class.getResource("../../../../30/epub/invalid/font_no_fallback.epub");
URL inputUrl = this.getClass().getResource("../../../../minimal-epub/30/minimal-epub-30.epub");
String inputPath = new File(inputUrl.toURI()).getAbsolutePath();
File epub = new File(inputPath);
Assert.assertTrue("Couldn't find resource: " + inputPath, epub.exists());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.adobe.epubcheck.messages.MessageId;

@Deprecated
public class Epub20CheckExpandedTest extends AbstractEpubCheckTest
{

Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.adobe.epubcheck.messages.MessageId;

@Deprecated
public class Epub20CheckTest extends AbstractEpubCheckTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.adobe.epubcheck.messages.MessageId;

@Deprecated
public class Epub30CheckExpandedTest extends AbstractEpubCheckTest
{

Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.adobe.epubcheck.messages.MessageId;

@Deprecated
public class Epub30CheckTest extends AbstractEpubCheckTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.adobe.epubcheck.messages.Message;
import com.adobe.epubcheck.util.FeatureEnum;

@Deprecated
public class LocalizationTest
{

Expand Down
Loading

0 comments on commit 1ffe227

Please sign in to comment.