
20 CHAPTER 1 Writing a Program
Figure 1.16
The testSort2 method.
public void testSort2() throws IOException{
// write out a known value
StringSorter ss1=new StringSorter();
ss1.sort("in.txt","test2.out");
ArrayList l=new ArrayList();
l.add("one");
l.add("three");
l.add("two");
// then read it and compare
Reader in=new FileReader("test2.out");
StringSorter ss2=new StringSorter();
ss2.readFromStream(in);
assertEquals(l,ss2.lines);
}
Figure 1.17
The StringSorter-
CommandLine class,
which implements a com-
mand-line interface for
StringSorter
functionality.
import java.io.IOException;
public class StringSorterCommandLine {
public static void main(String args[]) throws IOException ...