Created
January 7, 2015 02:43
-
-
Save brunkb/3f5e22d11d8c0a9e2005 to your computer and use it in GitHub Desktop.
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
class PricingServiceFirstTry { | |
// these dependencies would normally be injected | |
AuthenticationProvider auth = new AuthenticationProvider() | |
InventorySystem inv = new InventorySystem() | |
String username = 'test' | |
String password = 'test' | |
def logError(String msg) { println msg } // simulated logger | |
def priceLookup(String clientId, String itemUUID) { | |
try { | |
def authenticatedUserToken = auth.authenticateUser(username, password) | |
if(!inv.open(authenticatedUserToken)) { | |
throw new RuntimeException('Connection open failed') | |
} else { | |
inv.pricingLookup(clientId, itemUUID) | |
} | |
} catch(any) { | |
logError("Something went wrong: ${any.message}".toString()) | |
throw any | |
} finally { | |
inv.close() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment