@Test
public void testWrite() throws Exception {

	DDMFormInstanceRecordXMLWriter ddmFormInstanceRecordXMLWriter = mock(
		DDMFormInstanceRecordXMLWriter.class);
	Map<String, String> ddmFormFieldsLabel = LinkedHashMapBuilder.put(
		"field1", "Field 1"
	).put(
		"field2", "Field 2"
	).put(
		"field3", "Field 3"
	).put(
		"field4", "Field 4"
	).build();
	List<Map<String, String>> ddmFormFieldValues =
		new ArrayList<Map<String, String>>() {
			{
				add(
					HashMapBuilder.put(
						"field1", "2"
					).put(
						"field2", "esta é uma 'string'"
					).put(
						"field3", "false"
					).put(
						"field4", "11.7"
					).build());
				add(
					HashMapBuilder.put(
						"field1", "1"
					).put(
						"field2", "esta é uma 'string'"
					).put(
						"field3", ""
					).put(
						"field4", "10"
					).build());
			}
		};
	DDMFormInstanceRecordWriterRequest.Builder builder =
		DDMFormInstanceRecordWriterRequest.Builder.newBuilder(
			ddmFormFieldsLabel, ddmFormFieldValues);
	Document document = mock(Document.class);
	when(
		_saxReader.createDocument()
	).thenReturn(
		document
	);
	Element rootElement = mock(Element.class);
	when(
		document.addElement("root")
	).thenReturn(
		rootElement
	);
	when(
		document.asXML()
	).thenReturn(
		StringPool.BLANK
	);
	Mockito.doNothing(
	).when(
		ddmFormInstanceRecordXMLWriter
	).addFieldElements(
		Matchers.any(Element.class), Matchers.anyMap(), Matchers.anyMap()
	);
	DDMFormInstanceRecordWriterRequest ddmFormInstanceRecordWriterRequest =
		builder.build();
	when(
		ddmFormInstanceRecordXMLWriter.write(
			ddmFormInstanceRecordWriterRequest)
	).thenCallRealMethod();
	ddmFormInstanceRecordXMLWriter.write(
		ddmFormInstanceRecordWriterRequest);
	InOrder inOrder = Mockito.inOrder(
		_saxReader, document, rootElement, ddmFormInstanceRecordXMLWriter);
	inOrder.verify(
		_saxReader, Mockito.times(1)
	).createDocument();
	inOrder.verify(
		document, Mockito.times(1)
	).addElement(
		"root"
	);
	inOrder.verify(
		rootElement, Mockito.times(1)
	).addElement(
		"fields"
	);
	inOrder.verify(
		ddmFormInstanceRecordXMLWriter, Mockito.times(1)
	).addFieldElements(
		Matchers.any(Element.class), Matchers.anyMap(), Matchers.anyMap()
	);
	inOrder.verify(
		rootElement, Mockito.times(1)
	).addElement(
		"fields"
	);
	inOrder.verify(
		ddmFormInstanceRecordXMLWriter, Mockito.times(1)
	).addFieldElements(
		Matchers.any(Element.class), Matchers.anyMap(), Matchers.anyMap()
	);
	inOrder.verify(
		document, Mockito.times(1)
	).asXML();
}