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