我有一个类CollectionObject创建一个ArrayList.
public class CollectionObject {
private List collectionObject;
public CollectionObject() {
collectionObject = new ArrayList();
}
public List getCollectionObject() {
return collectionObject;
}
public void add(final String stringToWrite) throws VerifyException {
collectionObject.add(stringToWrite);
}
}
还有另一个类接受类CollectionObject并使用它将文件的内容写入类CollectionObject.
public class ReaderFileWriterObjectService {
private BufferedReader bufferedReader;
private CollectionObject collectionObject;
private String line;
public CollectionObject getCollectionObjectAfterWritingFromAFile(final File file)
throws VerifyException,IOException {
collectionObject = new CollectionObject();
bufferedReader = new BufferedReader(new FileReader(file));
while ((line = bufferedReader.readLine()) != null) {
collectionObject.add(line);
}
bufferedReader.close();
return collectionObject;
}
如何测试和模拟类ReaderFileWriterObjectService的方法?