Mocking Apache HTTPClient using Mockito

后端 未结 5 810
走了就别回头了
走了就别回头了 2020-12-25 11:24

I\'m trying to mock Apache HttpClient Interface in order to mock one of its methods mentioned below to return a stubbed JSON object in response.

HttpResponse         


        
5条回答
  •  悲&欢浪女
    2020-12-25 12:04

    You can look at HttpClientMock, I wrote it for internal project but later decided to open source. It allows you to define mock behavior with fluent API and later verify a number of made calls. Example:

    HttpClientMock httpClientMock = new 
    HttpClientMock("http://localhost:8080");
    httpClientMock.onGet("/login?user=john").doReturnJSON("{permission:1}");
    
    httpClientMock.verify().get("/login?user=john").called();
    

提交回复
热议问题