1
2
3
4 package org.melati.app.test;
5
6 import java.io.BufferedReader;
7 import java.io.File;
8 import java.io.FileInputStream;
9 import java.io.InputStreamReader;
10
11 import org.melati.app.ConfigApp;
12
13 import junit.framework.TestCase;
14
15
16
17
18
19 public class ConfigAppTest extends TestCase {
20
21
22
23
24 public ConfigAppTest(String name) {
25 super(name);
26 }
27
28
29
30
31
32 protected void setUp() throws Exception {
33 super.setUp();
34 }
35
36
37
38
39
40 protected void tearDown() throws Exception {
41 super.tearDown();
42 }
43
44
45
46
47 public void testRun() throws Exception {
48 String fileName = "t1.tmp";
49 String[] args = { "fred", "-o", fileName };
50 ConfigApp it = new ConfigApp();
51 it.run(args);
52 String output = "";
53 File fileIn = new File(fileName);
54 BufferedReader in = new BufferedReader(
55 new InputStreamReader(
56 new FileInputStream(fileIn)));
57 while (in.ready()) {
58 output += in.readLine();
59 output += "\n";
60 }
61 in.close();
62 fileIn.delete();
63 assertEquals("Hello World\nYour Method was:fred\n" , output);
64 assertEquals("nobody", it.getSysAdminName());
65 assertEquals("nobody@nobody.com", it.getSysAdminEmail());
66 }
67
68
69
70
71 public void testMain() throws Exception {
72 String fileName = "t1.tmp";
73 String[] args = { "fred", "-o", fileName };
74 ConfigApp.main(args);
75 String output = "";
76 File fileIn = new File(fileName);
77 BufferedReader in = new BufferedReader(
78 new InputStreamReader(
79 new FileInputStream(fileIn)));
80 while (in.ready()) {
81 output += in.readLine();
82 output += "\n";
83 }
84 in.close();
85 fileIn.delete();
86 assertEquals("Hello World\nYour Method was:fred\n" , output);
87 }
88
89 }