1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.source;
16
17 import static java.nio.charset.StandardCharsets.ISO_8859_1;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.util.List;
22
23 import org.apache.commons.io.FileUtils;
24
25
26
27
28
29
30 public final class TestCaseCreator {
31
32
33
34
35
36
37
38 public static void main(final String[] args) throws IOException {
39 if (args.length == 0) {
40 System.out.println("HTML file location is not provided");
41 return;
42 }
43
44 final File file = new File(args[0]);
45 if (!file.exists()) {
46 System.out.println("File does not exist " + file.getAbsolutePath());
47 }
48
49 System.out.println(" /**");
50 System.out.println(" * @throws Exception if an error occurs");
51 System.out.println(" */");
52 System.out.println(" @Test");
53 System.out.println(" @Alerts()");
54 System.out.println(" public void test() throws Exception {");
55
56 final List<String> lines = FileUtils.readLines(file, ISO_8859_1);
57 for (int i = 0; i < lines.size(); i++) {
58 final String line = lines.get(i);
59 if (i == 0) {
60 System.out.println(" final String html = \"" + line.replace("\"", "\\\"") + "\\n\"");
61 }
62 else {
63 System.out.print(" + \"" + line.replace("\"", "\\\"") + "\\n\"");
64 if (i == lines.size() - 1) {
65 System.out.print(";");
66 }
67 System.out.println();
68 }
69 }
70 System.out.println(" loadPageWithAlerts2(html);");
71 System.out.println(" }");
72 }
73
74 private TestCaseCreator() {
75 }
76 }