Skip to content

Instantly share code, notes, and snippets.

@davelnewton
Last active August 14, 2016 17:38
Show Gist options
  • Save davelnewton/92b768d9925baa683e6323a4fd9f82cd to your computer and use it in GitHub Desktop.
Save davelnewton/92b768d9925baa683e6323a4fd9f82cd to your computer and use it in GitHub Desktop.
Refactored
public static String createId() {
// Test by mocking `checkConfigs()` and make
// sure `generateRandomId()` is called
if (!checkConfigs()) {
return generateRandomId();
}
HttpURLConnection connection = accessProv();
try {
// Test in two ways:
// 1. Mocking `checkSiteResponse` and make
// sure `generateId(connection)` is called
// 2. Mocking `checkSiteResponse`, throw
// the exception, and make sure `null`
// is returned. Alternatively also check
// that code in the `catch` is run.
if (checkSiteResponse(connection)) {
return generateId(connection);
}
} catch (IOException e) {
LOG.error("IOException");
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment