1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.fit; |
34 |
| |
35 |
| import java.io.*; |
36 |
| import java.util.*; |
37 |
| |
38 |
| import junit.framework.*; |
39 |
| |
40 |
| import fit.*; |
41 |
| |
42 |
| public class FitTest extends TestCase { |
43 |
| private File inFile; |
44 |
| private File outFile; |
45 |
| |
46 |
| private Fixture fixture; |
47 |
| private String input; |
48 |
| private PrintWriter output; |
49 |
| |
50 |
77
| public FitTest(String name, File inDir, File outDir) {
|
51 |
77
| super(name);
|
52 |
| |
53 |
77
| inFile = new File(inDir, name);
|
54 |
77
| outFile = new File(outDir, name);
|
55 |
| } |
56 |
| |
57 |
77
| protected void setUp() throws Exception {
|
58 |
77
| super.setUp();
|
59 |
| |
60 |
77
| fixture = new Fixture();
|
61 |
77
| fixture.summary.put("input file", inFile.getAbsolutePath());
|
62 |
77
| fixture.summary.put("input update", new Date(inFile.lastModified()));
|
63 |
77
| fixture.summary.put("output file", outFile.getAbsolutePath());
|
64 |
| |
65 |
77
| input = read(inFile);
|
66 |
| |
67 |
77
| output = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
|
68 |
| } |
69 |
| |
70 |
77
| protected void tearDown() throws Exception {
|
71 |
77
| try {
|
72 |
77
| output.close();
|
73 |
| } finally { |
74 |
77
| super.tearDown();
|
75 |
| } |
76 |
| } |
77 |
| |
78 |
77
| protected void runTest() throws Throwable {
|
79 |
77
| Parse tables;
|
80 |
| |
81 |
77
| if (input.indexOf("<wiki>") >= 0) {
|
82 |
0
| tables = new Parse(input, new String[]{"wiki", "table", "tr", "td"});
|
83 |
0
| fixture.doTables(tables.parts);
|
84 |
| } else { |
85 |
77
| tables = new Parse(input, new String[]{"table", "tr", "td"});
|
86 |
77
| fixture.doTables(tables);
|
87 |
| } |
88 |
77
| tables.print(output);
|
89 |
| |
90 |
77
| assertEquals("count wrongs(" + fixture.counts.wrong + ") + exceptions(" + fixture.counts.exceptions + ")", 0, fixture.counts.wrong + fixture.counts.exceptions);
|
91 |
| } |
92 |
| |
93 |
77
| private String read(File input) throws IOException {
|
94 |
77
| char chars[] = new char[(int) (input.length())];
|
95 |
77
| FileReader in = new FileReader(input);
|
96 |
77
| in.read(chars);
|
97 |
77
| in.close();
|
98 |
77
| return new String(chars);
|
99 |
| } |
100 |
| } |