java - How to unitest a method that produces an InputStream as a result? -


i have method produces inputstream, after processing bytes. correct design point of view. however, how can unit test method returns inputstream - valid assertions can made? (check size, transform file/bytes , check if file valid? else?)

in similar situations, i've read input stream byte array , tested results match expected.

inputstream inputstream = methodundertest(knownvalue1, knownvalue2, ...);  byte[] data = ioutils.tobytearray(inputstream); // apache commons io assertarrayequals(expecteddata, data); 

if method under test requires input data input stream, give bytearrayinputstream, reading byte array of known value.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -