### Question:
StreamHelper { ByteArrayOutputStream getOrCreateStream() { ByteArrayOutputStream baos = streams.get(); if (baos == null) { baos = new ByteArrayOutputStream(); streams.set(baos); } else { baos.reset(); } return baos; } StreamHelper();   }### Answer:
@Test public void getOrCreateStream() { StreamHelper helper = new StreamHelper(); ByteArrayOutputStream o1 = helper.getOrCreateStream(); ByteArrayOutputStream o2 = helper.getOrCreateStream(); Assertions.assertSame(o1, o2); }
@Test public void streamIsResetBeforeNextUse() { StreamHelper helper = new StreamHelper(); ByteArrayOutputStream out = helper.getOrCreateStream(); out.write(42); Assertions.assertEquals(1, out.size()); helper.getOrCreateStream(); Assertions.assertEquals(0, out.size()); }