I am new to junit, and am trying a program from Martin Fowler's book Refactoring, pp. 92-94. I have added the BufferedReader following the example on p.454 of HeadFirstJava.
I have reached the point where I have only three compile errors. They are:
cannot find symbol variable reader (lines 29, 39)
inconvertible types line 39
(these lines are identified with comments in the listing below.)
I have tried everthing I can think of without success.
Can anyone tell me what is wrong?
I am a beginner, but am leery of posting this on the beginner forum for fear of dire consequences.
Besides it doesn't seem very beginner to me.
/****************************************************************************************/
import junit.framework.*;
import java.io.*;
class FileReaderTester extends TestCase
{
public static void main (String[] args)
{
junit.textui.TestRunner.run(suite());
}
public FileReaderTester(String name)
{
super(name);
}
protected void setUp()
{
try {
FileReader filereader = new FileReader("data.txt");
BufferedReader reader = new BufferedReader(fileReader);
} catch (FileNotFoundException e) {
throw new RuntimeException("unable to open test file");
}
}
protected void tearDown()
{
try {
reader.close(); // line 29
} catch (IOException e) {
throw new RuntimeException("error on closing test file");
}
}
public void testRead() throws IOException
{
char ch = '&';
for (int i=0; i<4; i++)
ch = (char) reader.read(); // line 39
assert('d' == ch);
}
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTest(new FileReaderTester("testRead"));
return suite;
}
}