### Question:
SettingsProtocol { public Document encodeResponse(User user) throws FactoryConfigurationError { Preconditions.checkNotNull(user); Preconditions.checkArgument(!Strings.isNullOrEmpty(user.getEmail())); Document ret = DOMUtils.createDoc(null, "Settings"); Element root = ret.getDocumentElement(); DOMUtils.createElementAndText(root, "Status", SETTINGS_SUCCESS); Element deviceInformaton = DOMUtils.createElement(root, "DeviceInformaton"); DOMUtils.createElementAndText(deviceInformaton, "Status", SETTINGS_SUCCESS); Element userInformaton = DOMUtils.createElement(root, "UserInformation"); DOMUtils.createElementAndText(userInformaton, "Status", SETTINGS_SUCCESS); Element getUserInformaton = DOMUtils.createElement(userInformaton, "Get"); Element addressesUserInformaton = DOMUtils.createElement(getUserInformaton, "EmailAddresses"); DOMUtils.createElementAndText(addressesUserInformaton, "SmtpAddress", user.getEmail()); return ret; }  Document encodeResponse(User user);  }### Answer:
@Test public void testResponseWithUser() throws TransformerException { User user = User.Factory.create().createUser("domain\\userId", "useremail@domain", "user"); String responseAsText = new StringBuilder() .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") .append("<Settings>") .append("<Status>1</Status>") .append("<DeviceInformaton><Status>1</Status></DeviceInformaton>") .append("<UserInformation><Status>1</Status>") .append("<Get><EmailAddresses>") .append("<SmtpAddress>") .append(user.getEmail()) .append("</SmtpAddress>") .append("</EmailAddresses></Get>") .append("</UserInformation>") .append("</Settings>").toString(); Document response = new SettingsProtocol().encodeResponse(user); assertThat(DOMUtils.serialize(response)).isEqualTo(responseAsText); }
@Test(expected=NullPointerException.class) public void testResponseWithNullUser() { User user = null; new SettingsProtocol().encodeResponse(user); }
@Test(expected=IllegalArgumentException.class) public void testResponseWithNullUserEmail() { User user = User.Factory.create().createUser("userId", null, "user"); new SettingsProtocol().encodeResponse(user); }
@Test(expected=IllegalArgumentException.class) public void testResponseWithEmptyUserEmail() { User user = User.Factory.create().createUser("userId", "", "user"); new SettingsProtocol().encodeResponse(user); }