### Question:
XmlFieldWriter extends XmlFieldTransformer implements AtlasFieldWriter { @Override public void write(AtlasInternalSession session) throws AtlasException { Field targetField = session.head().getTargetField(); if (targetField == null) { throw new AtlasException(new IllegalArgumentException("Argument 'field' cannot be null")); } if (LOG.isDebugEnabled()) { LOG.debug("Now processing field path={} type={} value={}", targetField.getPath(), targetField.getFieldType(), targetField.getValue()); } XmlPath path = new XmlPath(targetField.getPath()); XmlSegmentContext lastSegment = path.getLastSegment(); Element parentNode = null; XmlSegmentContext parentSegment = null; for (XmlSegmentContext segment : path.getXmlSegments(false)) { if (LOG.isDebugEnabled()) { LOG.debug("Now processing segment: {}", segment); LOG.debug("Parent element is currently: {}", xmlHelper.writeDocumentToString(true, parentNode)); } if (parentNode == null) { parentNode = document.getDocumentElement(); if (parentNode == null) { if (LOG.isDebugEnabled()) { LOG.debug("Creating root element with name: {}", segment.getName()); } Element rootNode = createElement(segment); addNamespacesToElement(rootNode, namespaces); document.appendChild(rootNode); parentNode = rootNode; } else if (!(parentNode.getNodeName().equals(segment.getQName()))) { throw new AtlasException(String.format( "Root element name '%s' does not match expected name '%s' from path: %s", parentNode.getNodeName(), segment.getName(), targetField.getPath())); } parentSegment = segment; } else { if (LOG.isDebugEnabled()) { if (segment.equals(lastSegment)) { LOG.debug("Now processing field value segment: {}", segment); } else { LOG.debug("Now processing parent segment: {}", segment); } } if (segment.equals(lastSegment) && targetField.getValue() == null) { break; } if (!segment.isAttribute()) { Element childNode = getChildNode(parentNode, parentSegment, segment); if (childNode == null) { childNode = createParentNode(parentNode, parentSegment, segment); } if (childNode == null) { return; } parentNode = childNode; parentSegment = segment; } if (segment.equals(lastSegment)) { writeValue(parentNode, segment, targetField); } } } } XmlFieldWriter();  XmlFieldWriter(ClassLoader classLoader, Map<String, String> namespaces, String seedDocument); @Override void write(AtlasInternalSession session); Document getDocument(); boolean isEnableElementNamespaces(); void setEnableElementNamespaces(boolean enableElementNamespaces); boolean isEnableAttributeNamespaces(); void setEnableAttributeNamespaces(boolean enableAttributeNamespaces); boolean isIgnoreMissingNamespaces(); void setIgnoreMissingNamespaces(boolean ignoreMissingNamespaces);  }### Answer:
@Test(expected = AtlasException.class) public void testThrowExceptionOnNullXmlField() throws Exception { createWriter(); XmlField field = null; AtlasInternalSession session = mock(AtlasInternalSession.class); when(session.head()).thenReturn(mock(Head.class)); when(session.head().getSourceField()).thenReturn(mock(Field.class)); when(session.head().getTargetField()).thenReturn(field); writer.write(session); }