@Test public void testFindContactNegative() { try { client.findContact("admin", "badid"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
public Contact findContact(String username, String id) { try { Entry entry = service. path("contacts"). path(username). path(id). accept(ENTRY_MEDIA_TYPE). header(AUTHENTICATION_HEADER, authentication). get(Entry.class); return Contact.fromEntry(entry); } catch (UniformInterfaceException e) { if (e.getResponse().getStatus() == 401) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 403) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 404) { throw new IllegalArgumentException("Username '" + username + "' and/or contact id '" + id + "' does not exist", e); } else { throw e; } } }
ContactsClient { public Contact findContact(String username, String id) { try { Entry entry = service. path("contacts"). path(username). path(id). accept(ENTRY_MEDIA_TYPE). header(AUTHENTICATION_HEADER, authentication). get(Entry.class); return Contact.fromEntry(entry); } catch (UniformInterfaceException e) { if (e.getResponse().getStatus() == 401) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 403) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 404) { throw new IllegalArgumentException("Username '" + username + "' and/or contact id '" + id + "' does not exist", e); } else { throw e; } } } }
ContactsClient { public Contact findContact(String username, String id) { try { Entry entry = service. path("contacts"). path(username). path(id). accept(ENTRY_MEDIA_TYPE). header(AUTHENTICATION_HEADER, authentication). get(Entry.class); return Contact.fromEntry(entry); } catch (UniformInterfaceException e) { if (e.getResponse().getStatus() == 401) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 403) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 404) { throw new IllegalArgumentException("Username '" + username + "' and/or contact id '" + id + "' does not exist", e); } else { throw e; } } } ContactsClient(String uri, String username, String password); }
ContactsClient { public Contact findContact(String username, String id) { try { Entry entry = service. path("contacts"). path(username). path(id). accept(ENTRY_MEDIA_TYPE). header(AUTHENTICATION_HEADER, authentication). get(Entry.class); return Contact.fromEntry(entry); } catch (UniformInterfaceException e) { if (e.getResponse().getStatus() == 401) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 403) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 404) { throw new IllegalArgumentException("Username '" + username + "' and/or contact id '" + id + "' does not exist", e); } else { throw e; } } } ContactsClient(String uri, String username, String password); String createContact(String username, Contact contact); void deleteContact(String username, String id); Contact findContact(String username, String id); List<Contact> findContacts(String username); void updateContact(String username, Contact contact); boolean doesUserExist(String username); String createUser(User user); void deleteUser(String username); User findUser(String username); List<User> findUsers(); void updateUser(User user); String encodeCredentialsBasic(String username, String password); static void main(String[] args); }
ContactsClient { public Contact findContact(String username, String id) { try { Entry entry = service. path("contacts"). path(username). path(id). accept(ENTRY_MEDIA_TYPE). header(AUTHENTICATION_HEADER, authentication). get(Entry.class); return Contact.fromEntry(entry); } catch (UniformInterfaceException e) { if (e.getResponse().getStatus() == 401) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 403) { throw new IllegalStateException(e); } else if (e.getResponse().getStatus() == 404) { throw new IllegalArgumentException("Username '" + username + "' and/or contact id '" + id + "' does not exist", e); } else { throw e; } } } ContactsClient(String uri, String username, String password); String createContact(String username, Contact contact); void deleteContact(String username, String id); Contact findContact(String username, String id); List<Contact> findContacts(String username); void updateContact(String username, Contact contact); boolean doesUserExist(String username); String createUser(User user); void deleteUser(String username); User findUser(String username); List<User> findUsers(); void updateUser(User user); String encodeCredentialsBasic(String username, String password); static void main(String[] args); static final URI BASE_URI; }