### Question:
XmiWriter { public static final void writeDocument(final Model model, final ModelIndex mapper, final OutputStream outstream) { final XMLOutputFactory xof = XMLOutputFactory.newInstance(); try { final XMLStreamWriter xsw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(outstream, "UTF-8")); xsw.writeStartDocument("UTF-8", "1.0"); try { XmiWriter.writeXMI(model, mapper, xsw); } finally { xsw.writeEndDocument(); } xsw.flush(); } catch (final XMLStreamException e) { throw new XmiRuntimeException(e); } }  static final void writeDocument(final Model model, final ModelIndex mapper, final OutputStream outstream); static final void writeDocument(final Model model, final ModelIndex mapper, final String fileName); static final void writeDocument(final Model model, final ModelIndex mapper, final File file);  }### Answer:
@Test public void testWriteDocumentOutputStream() throws Exception { OutputStream os = new ByteArrayOutputStream(); OutputStream mockOutputStream = spy(os); XmiWriter.writeDocument(model, modelIndex, mockOutputStream); String output = mockOutputStream.toString(); assertTrue(output.contains(MODEL_ID.toString())); assertTrue(output.contains(MODEL_NAME)); assertTrue(output.contains(PACKAGE_ID.toString())); assertTrue(output.contains(PACKAGE_NAME)); assertTrue(output.contains(TAGGEDVALUE_VALUE)); assertTrue(output.contains(TAGDEFINITION_ID.toString())); assertTrue(output.contains(TAGDEFINITION_NAME)); assertTrue(output.contains("lower=\"0\"")); assertTrue(output.contains("upper=\"1\"")); assertFalse(output.contains("upper=\"-1\"")); assertTrue(output.contains(DATATYPE_ID.toString())); assertTrue(output.contains(DATATYPE_NAME)); assertTrue(output.contains(ATTRIBUTE_ID.toString())); assertTrue(output.contains(ATTRIBUTE_NAME)); assertTrue(output.contains(CLASSTYPE_ID.toString())); assertTrue(output.contains(CLASSTYPE_NAME)); assertTrue(output.contains(ENUMLITERALA_ID.toString())); assertTrue(output.contains(ENUMLITERALA_NAME)); assertTrue(output.contains(ENUMTYPE_ID.toString())); assertTrue(output.contains(ENUMTYPE_NAME)); assertTrue(output.contains(ASSOCIATIONEND_PARENT_ID.toString())); assertTrue(output.contains(ASSOCIATIONEND_PARENT_NAME)); assertTrue(output.contains(GENERALIZATION_ID.toString())); assertTrue(output.contains(GENERALIZATION_NAME)); }
@Test public void testWriteDocumentFile() { File file = new File("unittest-writedocumentfile.xmi"); assertFalse(file.exists()); XmiWriter.writeDocument(model, modelIndex, file); assertTrue(file.exists()); file.deleteOnExit(); }
@Test public void testWriteDocumentString() { String filename = "unittest-writedocumentstring.xmi"; File file = new File(filename); assertFalse(file.exists()); XmiWriter.writeDocument(model, modelIndex, filename); assertTrue(file.exists()); file.deleteOnExit(); }