• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to test a method taking resultset as input parameter with junit

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
can any body give me idea...I have a java class with me which I want to do unit test.On that class there is a method which takes input parameter as a result set...I am unable to find the way how to test it.Here I am giving the code for that method


public void setBlobList(OracleResultSet results,String labelname)
throws SQLException,FileNotFoundException,IOException{

Properties props = archiveFolderPath("logrole.properties");
//For Windows
File file = new File(props.getProperty("archivefolder")+"\\"+labelname);
//For Linux
//File file = new File(props.getProperty("archivefolder")+"/"+labelname);
file.mkdirs();
while(results.next()) {
String docid=""+results.getInt("docid");
oracle.sql.BLOB blb = (oracle.sql.BLOB)results.getBLOB("doccontent");
InputStream io = blb.getBinaryStream();
byte[] data = new byte[blb.getBufferSize()];
io.read(data);
io.close();
//For Windows
File f=new File(props.getProperty("archivefolder")+"\\"+labelname+"\\"+results.getInt("docid")+"_"+results.getString("filename"));
//For Linux
//File f=new File(props.getProperty("archivefolder")+"/"+labelname+"/"+results.getInt("docid")+"_"+results.getString("filename"));
FileOutputStream fo=new FileOutputStream(f);
fo.write(data);
fo.close();
VTLArchiveBlob document = new VTLArchiveBlob(docid,f);
// add to document list
documentList.add(document);
}
}

welcome for suggestions
usha
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Usha,
Why are you passing an OracleResultSet instead of a ResultSet? If you can switch to ResultSet, it is an interface. Then you can pass a mock object in. Take a look at easyMock or jMock for a mock objects framework.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For JDBC, there are also already predefined mock objects at www.mockobjects.com
 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic