I am in the process of writing jUnit tests for my application and I am wondering how I can test the following class:
public class PdfBottomCheckView extends AbstractPdfView {
@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
HttpServletRequest request, HttpServletResponse response) throws Exception {
MyObjet1 object1 = (MyObject1) model.get("object1");
MyObject2 object2= (MyObject2) model.get("object2");
HelperClass helper= new HelpClass(getMessageSourceAccessor(), getServletContext());
helper.writeLogo(document);
helper.writeFooter(document, writer);
document.add(help.generate开发者_JAVA技巧Output(object1, object2, 105, new int[]{55,20,30}, helper.getNormalFont())); }
}
There is a complete example of how I implemented this with spring here
I found another website that shows you can compare byte[] to test pdf output. That article is here (Scroll down to the heading 'Producing the Correct Binary Output')
I am getting an error running the test on the helper line. How can I mock or pass valid values for the Helper Class? I am using Spring 3.0.5, jUnit 4, and Mockito 1.8.5.
Thanks
Create a factory class that produces helpers. Pass the factory class in as a constructor arg for your PdfBottomCheckView. Them mock your factory in your test and from there you can generate a mock helper class.
If you aren't using Mockito use that.
精彩评论