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

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -