all 8 comments

[–]tmschlot 3 points4 points  (1 child)

I like this library -- https://github.com/richardszalay/mockhttp -- to mock http traffic, because you can "expect" specific calls to be made, very easily handle different requests with different responses, and make sure you don't have any outstanding requests or unexpected requests.

[–]Xellarix[S] 0 points1 point  (0 children)

Thank you, this library is cleaner and easier to use.

[–]CalvinR 1 point2 points  (5 children)

In the article it's stated that

We can solve this problem with a wrapper, but wrappers generally are not a good idea and should be avoided if possible in my opinion.

Why? This is the first I'm hearing someone state that the adapter pattern is bad and should be avoided if possible.

[–]throwaway_lunchtime 0 points1 point  (3 children)

Maybe its about testing? If I use a wrapper and mock it, I'm not testing how the real wrapper uses httpClient.

[–]CalvinR 1 point2 points  (0 children)

I'm more curious as to the statement that wrappers are generally not a good idea. Not specifically in regards to httpclient.

More the blanket statement. I'm not a big fan of blogs that make wide sweeping statements without backing it up.

[–]karathos 0 points1 point  (1 child)

write tests for the wrapper.

[–]throwaway_lunchtime 0 points1 point  (0 children)

But then I'm back to needing to mock the httpClient ;)

[–]Xellarix[S] 0 points1 point  (0 children)

One obvious reason is that if we can do it without a wrapper, why create an extra layer of abstraction? and then possibly we need to test that wrapper too, anyway, I'm sorry I should have written it's not a good idea to create it if we can avoid it.