1

I have a get method that takes 3 inputs and that needs to be mocked-

  1. Request - okhttp3.Request
  2. JSONUnmarshaler - Generic java object
  3. GSON - com.google.gson.Gson

    when(this.okhttpclient.get(any(Request.class), any(JSONUnmarshaler.class), any(Gson.class)).thenReturn(response);

I was able to mock the Request and GSON object but not sure how to mock the JSONUnmarshaler object. It is a Java generics object and here is the interface definition for it.

public interface JSONUnmarshaler<T> {
       T fromJSON(Gson gson, JsonElement json);
    }

Response type:-

List<Course> course_list = new ArrayList<Course>();
course_list.add(new Course());
UdemyResponse<List<Course>> response = new UdemyResponse<List<Course>>(200,"teststring","raw_data",course_list);
user1050619
  • 19,822
  • 85
  • 237
  • 413

0 Answers0