java - Unit testing a method that writes serialized objects to a file -



java - Unit testing a method that writes serialized objects to a file -

i have static method writes serialized object. how can write junit tests see if works? here method...

public static void writetodisk(data data){ try{ fileinputstream fis = new fileinputstream(filename); objectinputstream in = new objectinputstream(fis); datalist = (datalist) in.readobject(); in.close(); } catch(exception e){ datalist = new datalist(); system.out.println("new file created!"); } datalist.insertdata(data); try{ fileoutputstream fos = new fileoutputstream(filename); objectoutputstream out = new objectoutputstream(fos); out.writeobject(datalist); out.close(); } catch(exception e){ e.printstacktrace(); } } }

start no file.

call method test data argument. read resulting file (pull info list needed) , compare original.

repeat new objects see if new info added successfully.

java unit-testing serialization junit

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -