Last active
August 14, 2016 17:38
-
-
Save davelnewton/92b768d9925baa683e6323a4fd9f82cd to your computer and use it in GitHub Desktop.
Refactored
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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