e8bfde089785b1ce73408430aa5c4a850320f169
1 package be
.nikiroo
.gofetch
.test
;
4 import java
.io
.FileInputStream
;
5 import java
.io
.FileNotFoundException
;
6 import java
.io
.IOException
;
7 import java
.io
.InputStream
;
11 import be
.nikiroo
.gofetch
.data
.Story
;
12 import be
.nikiroo
.gofetch
.output
.Gopher
;
13 import be
.nikiroo
.gofetch
.output
.Html
;
14 import be
.nikiroo
.gofetch
.output
.Output
;
15 import be
.nikiroo
.gofetch
.support
.BasicSupport
;
16 import be
.nikiroo
.utils
.IOUtils
;
17 import be
.nikiroo
.utils
.test
.TestCase
;
18 import be
.nikiroo
.utils
.test
.TestLauncher
;
21 * Base class for {@link BasicSupport}s testing.
25 abstract class TestBase
extends TestLauncher
{
26 public TestBase(BasicSupport support
, String
[] args
) {
27 super(support
.getType().toString(), args
);
31 static protected InputStream
doOpen(Map
<URL
, File
> map
, URL url
)
33 File file
= map
.get(url
);
35 throw new FileNotFoundException("Test file not found for URL: "
39 return new FileInputStream(file
);
43 private void addTest(final BasicSupport support
) {
44 addTest(new TestCase("Processing example data") {
46 public void test() throws Exception
{
47 File expected
= new File("test/expected/" + support
.getType());
48 File actual
= new File("test/result/" + support
.getType());
50 Output gopher
= new Gopher(support
.getType(), "", "", 70);
51 Output html
= new Html(support
.getType(), "", "", 80);
53 for (Story story
: support
.list()) {
54 IOUtils
.writeSmallFile(new File(actual
, story
.getId()
55 + ".header"), gopher
.exportHeader(story
));
56 IOUtils
.writeSmallFile(
57 new File(actual
, story
.getId() + ""),
58 gopher
.export(story
));
59 IOUtils
.writeSmallFile(new File(actual
, story
.getId()
60 + ".header.html"), html
.exportHeader(story
));
61 IOUtils
.writeSmallFile(new File(actual
, story
.getId()
62 + ".html"), html
.export(story
));
65 assertEquals(expected
, actual
);