我无法更改需要测试的方法的签名。测试代码如下所示
Parser test = new Parser(props);
ArrayList<HDocument> list = new ArrayList<HDocument>();
test.parse("/users/mac/test.xml", list);
System.out.println("Size of list: "+list.size());
assertEquals(5, list.size());
parse
方法签名如下
public void parse(String filename, Collection<HDocument> docs)
parse 方法运行良好,但是当我运行测试器时,列表大小始终为 0。我无法更改 parse 方法签名。我该怎么做?
这是解析器类,
class Parser{
private Collection<HDocument> docs;
public void parse(String filename, Collection<HDocument> docs) {
docs = new ArrayList<HDocument>();
Collection<HDocument> docsFromXml = new ArrayList<HDocument>();
Handler hl = new Handler();
try {
docsFromXml = hl.getDocs(filename);
} catch (Exception e) {
e.printStackTrace();
}
docs = docsFromXml;
System.out.println("Size:"
+ docs.size()); // This prints the size correctly
}
}
}