X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Ftest%2FTestBase.java;h=65074ca7b577f9de79ca384225f863a75acbe239;hb=299a08f325f3de71e191b17b16a120d1714e3d7c;hp=e8bfde089785b1ce73408430aa5c4a850320f169;hpb=a71d4075a8591b0655277b1a0e606ee48d228869;p=gofetch.git
diff --git a/src/be/nikiroo/gofetch/test/TestBase.java b/src/be/nikiroo/gofetch/test/TestBase.java
index e8bfde0..65074ca 100644
--- a/src/be/nikiroo/gofetch/test/TestBase.java
+++ b/src/be/nikiroo/gofetch/test/TestBase.java
@@ -15,55 +15,64 @@ import be.nikiroo.gofetch.output.Output;
import be.nikiroo.gofetch.support.BasicSupport;
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
+ *
*
* @author niki
*/
-abstract class TestBase extends TestLauncher {
+abstract class TestBase extends TestCase {
+ private BasicSupport support;
+
public TestBase(BasicSupport support, String[] args) {
- super(support.getType().toString(), args);
- addTest(support);
+ super(support.getType().toString());
+ this.support = support;
}
- static protected InputStream doOpen(Map map, URL url)
- throws IOException {
+ static protected InputStream doOpen(BasicSupport support,
+ Map map, URL url) throws IOException {
File file = map.get(url);
if (file == null) {
throw new FileNotFoundException("Test file not found for URL: "
+ url);
}
- return new FileInputStream(file);
+ return new FileInputStream("test/source/" + support.getType() + "/"
+ + file);
}
- 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();
- 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()) {
- 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);
}
}