### Question:
BulkDocumentWriter { public void write(Collection<?> objects, boolean allOrNothing, OutputStream out) { try { JsonGenerator jg = objectMapper.getFactory().createGenerator(out, JsonEncoding.UTF8); jg.writeStartObject(); if (allOrNothing) { jg.writeBooleanField("all_or_nothing", true); } jg.writeArrayFieldStart("docs"); for (Object o : objects) { jg.writeObject(o); } jg.writeEndArray(); jg.writeEndObject(); jg.flush(); jg.close(); } catch (Exception e) { throw Exceptions.propagate(e); } finally { IOUtils.closeQuietly(out); } } BulkDocumentWriter(ObjectMapper om); void write(Collection<?> objects, boolean allOrNothing, OutputStream out); InputStream createInputStreamWrapper(boolean allOrNothing, InputStream in);  }### Answer:
@Test public void testWrite() throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bw.write(objects, false, bos); JsonNode root = mapper.readTree(bos.toString("UTF-8")); assertThatObjectsAreWritten(root); }
@Test public void testWriteAllOrNothing() throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bw.write(objects, true, bos); JsonNode root = mapper.readTree(bos.toString("UTF-8")); assertTrue(root.get("all_or_nothing").booleanValue()); assertThatObjectsAreWritten(root); }