X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Ftest%2FTestBase.java;h=dbc6952a6e03c1a2db2a244175b83655cf9c1a75;hb=6e234797ebb6bf2ba83e6e36d95c84cd176091db;hp=1da6b48a6a2f7451bb13425bb4a9d4125665f1bc;hpb=1aaa6ba3686a5a14f2957b6b8d02ffc0903f6832;p=gofetch.git
diff --git a/src/be/nikiroo/gofetch/test/TestBase.java b/src/be/nikiroo/gofetch/test/TestBase.java
index 1da6b48..dbc6952 100644
--- a/src/be/nikiroo/gofetch/test/TestBase.java
+++ b/src/be/nikiroo/gofetch/test/TestBase.java
@@ -13,26 +13,42 @@ import be.nikiroo.gofetch.output.Gopher;
import be.nikiroo.gofetch.output.Html;
import be.nikiroo.gofetch.output.Output;
import be.nikiroo.gofetch.support.BasicSupport;
+import be.nikiroo.utils.Cache;
+import be.nikiroo.utils.Downloader;
import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.test.TestCase;
-import be.nikiroo.utils.test.TestLauncher;
/**
* Base class for {@link BasicSupport}s testing.
*
* It will use the paths:
*
- * - test/XXX/source: the html source files
- * - test/XXX/expected: the expected output
- * - test/XXX/actual: the actual output of the last test
+ * - test/???/source: the html source files
+ * - test/???/expected: the expected output
+ * - test/???/actual: the actual output of the last test
*
*
* @author niki
*/
-abstract class TestBase extends TestLauncher {
+abstract class TestBase extends TestCase {
+ private BasicSupport support;
+ private Cache cache;
+ private Downloader downloader;
+
public TestBase(BasicSupport support, String[] args) {
- super(support.getType().toString(), args);
- addTest(support);
+ super(support.getType().toString());
+ this.support = support;
+ try {
+ cache = new Cache(new File("test/source/" + support.getType()), -1,
+ -1);
+ downloader = new Downloader("gofetch", cache);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected InputStream download(URL url) throws IOException {
+ return downloader.open(url);
}
static protected InputStream doOpen(BasicSupport support,
@@ -48,35 +64,30 @@ abstract class TestBase extends TestLauncher {
}
- private void addTest(final BasicSupport support) {
- addTest(new TestCase("Processing example data") {
- @Override
- public void test() throws Exception {
- File expected = new File("test/expected/" + support.getType());
- File actual = new File("test/result/" + support.getType());
+ @Override
+ public void test() throws Exception {
+ File expected = new File("test/expected/" + support.getType());
+ File actual = new File("test/result/" + support.getType());
- IOUtils.deltree(actual);
- expected.mkdirs();
- actual.mkdirs();
+ IOUtils.deltree(actual);
+ expected.mkdirs();
+ actual.mkdirs();
- Output gopher = new Gopher(support.getType(), "", "", 70);
- Output html = new Html(support.getType(), "", "", 80);
+ Output gopher = new Gopher(support.getType(), "", "", 70);
+ Output html = new Html(support.getType(), "", "", 80);
- for (Story story : support.list()) {
- support.fetch(story);
- IOUtils.writeSmallFile(new File(actual, story.getId()
- + ".header"), gopher.exportHeader(story));
- IOUtils.writeSmallFile(
- new File(actual, story.getId() + ""),
- gopher.export(story));
- IOUtils.writeSmallFile(new File(actual, story.getId()
- + ".header.html"), html.exportHeader(story));
- IOUtils.writeSmallFile(new File(actual, story.getId()
- + ".html"), html.export(story));
- }
+ for (Story story : support.list()) {
+ support.fetch(story);
+ IOUtils.writeSmallFile(new File(actual, story.getId() + ".header"),
+ gopher.exportHeader(story));
+ IOUtils.writeSmallFile(new File(actual, story.getId() + ""),
+ gopher.export(story));
+ IOUtils.writeSmallFile(new File(actual, story.getId()
+ + ".header.html"), html.exportHeader(story));
+ IOUtils.writeSmallFile(new File(actual, story.getId() + ".html"),
+ html.export(story));
+ }
- assertEquals(expected, actual);
- }
- });
+ assertEquals(expected, actual);
}
}