@Test
public void testPostUserDomain() {

    ZMSClient client = createClient(systemAdminUser);
    ZMSRDLGeneratedClient c = Mockito.mock(ZMSRDLGeneratedClient.class);
    client.setZMSRDLGeneratedClient(c);
    UserDomain ud = new UserDomain().setDescription("domain desc").setOrg("org:test").setEnabled(true)
            .setAuditEnabled(false).setAccount("user.test").setYpmId(10).setName("testuser")
            .setTemplates(new DomainTemplateList().setTemplateNames(Collections.singletonList("template")));
    try {
        Mockito.when(c.postUserDomain("domain1", AUDIT_REF, ud)).thenThrow(new NullPointerException());
        client.postUserDomain("domain1", AUDIT_REF, ud);
        fail();
    } catch (ResourceException ex) {
        assertTrue(true);
    }
    try {
        Mockito.when(c.postUserDomain("domain2", AUDIT_REF, ud)).thenThrow(new ResourceException(400));
        client.postUserDomain("domain2", AUDIT_REF, ud);
        fail();
    } catch (ResourceException ex) {
        assertTrue(true);
    }
}