Unit testing with third party APIs

64 views
Skip to first unread message

vivek poddar

unread,
Mar 3, 2016, 3:32:33 AM3/3/16
to Clean Code Discussion
Hi Guys,

Hope everyone is doing good. Lately I have been busy with adjusting myself to Java world. I am writing an application which doesn't have any persistence and it just communicates with third party APIs.

I have put an detailed discussion here: 

Although it may not be directly related with clean coding but I hope I can get some good guidance here.

Thanks,

Norbert Nemes

unread,
Mar 3, 2016, 8:12:23 AM3/3/16
to Clean Code Discussion
I would have all that ugliness in one class: the API gateway.
It would have nicely named methods like fetchWhatever with a nice lambda returning the object(s) you are looking for and an error (but not your custom api errors). It would probably have a sendWhatever method in the same patrern. This way your app has no idea what API its using to communicate, and as such, it is unaffected by changes to it. As an added bonus, if the version of the API classes change, you would only have to modify one class: the gateway. The gateway would be composed of 2 parts: one that serialized your object into a request, and an API manager that sends it. This latter one would contain the API gunk, and would be simple enough not to need testing.
Reply all
Reply to author
Forward
0 new messages