@Override
 public Response execute(Request request) throws IOException {
   List<Header> headers = request.getHeaders();
   List<retrofit.client.Header> modified = new ArrayList<Header>();
   for (int i = 0; i < headers.size(); i++) {
     retrofit.client.Header header = headers.get(i);
     if (!header.getName().equals("Content-Length")) {
       modified.add(header);
     }
   }
   return super.execute(
       new Request(request.getMethod(), request.getUrl(), modified, request.getBody()));
 }
  @Test
  public void shouldGetPlaylistsForCategory() throws Exception {
    final Type modelType = new TypeToken<PlaylistsPager>() {}.getType();
    final String body = TestUtils.readTestData("category-playlist.json");
    final PlaylistsPager fixture = mGson.fromJson(body, modelType);

    final Response response = TestUtils.getResponseFromModel(fixture, modelType);

    final String categoryId = "mood";
    final String country = "SE";
    final int offset = 1;
    final int limit = 2;

    when(mMockClient.execute(
            argThat(
                new ArgumentMatcher<Request>() {
                  @Override
                  public boolean matches(Object argument) {
                    String requestUrl = ((Request) argument).getUrl();
                    return requestUrl.contains(String.format("limit=%d", limit))
                        && requestUrl.contains(String.format("offset=%d", offset))
                        && requestUrl.contains(String.format("country=%s", country));
                  }
                })))
        .thenReturn(response);

    final Map<String, Object> options = new HashMap<String, Object>();
    options.put("country", country);
    options.put("offset", offset);
    options.put("limit", limit);

    final PlaylistsPager result = mSpotifyService.getPlaylistsForCategory(categoryId, options);
    this.compareJSONWithoutNulls(body, result);
  }
  @Test
  public void shouldGetPlaylistFollowersContains() throws IOException {
    final Type modelType = new TypeToken<List<Boolean>>() {}.getType();
    final String body = TestUtils.readTestData("playlist-followers-contains.json");
    final List<Boolean> fixture = mGson.fromJson(body, modelType);

    final Response response = TestUtils.getResponseFromModel(fixture, modelType);

    final String userIds = "thelinmichael,jmperezperez,kaees";

    when(mMockClient.execute(
            argThat(
                new ArgumentMatcher<Request>() {
                  @Override
                  public boolean matches(Object argument) {
                    try {
                      return ((Request) argument)
                          .getUrl()
                          .contains("ids=" + URLEncoder.encode(userIds, "UTF-8"));
                    } catch (UnsupportedEncodingException e) {
                      return false;
                    }
                  }
                })))
        .thenReturn(response);

    final String requestPlaylist = TestUtils.readTestData("playlist-response.json");
    final Playlist requestFixture = mGson.fromJson(requestPlaylist, Playlist.class);

    final Boolean[] result =
        mSpotifyService.areFollowingPlaylist(requestFixture.owner.id, requestFixture.id, userIds);
    this.compareJSONWithoutNulls(body, result);
  }
  @Test
  public void shouldCheckFollowingArtists() throws IOException {
    Type modelType = new TypeToken<List<Boolean>>() {}.getType();
    String body = TestUtils.readTestData("follow_is_following_artists.json");
    List<Boolean> fixture = mGson.fromJson(body, modelType);

    final String artistIds = "3mOsjj1MhocRVwOejIZlTi";

    Response response = TestUtils.getResponseFromModel(fixture, modelType);

    when(mMockClient.execute(
            argThat(
                new ArgumentMatcher<Request>() {
                  @Override
                  public boolean matches(Object argument) {
                    try {
                      return ((Request) argument).getUrl().contains("type=artist")
                          && ((Request) argument)
                              .getUrl()
                              .contains("ids=" + URLEncoder.encode(artistIds, "UTF-8"));
                    } catch (UnsupportedEncodingException e) {
                      return false;
                    }
                  }
                })))
        .thenReturn(response);

    Boolean[] result = mSpotifyService.isFollowingArtists(artistIds);
    this.compareJSONWithoutNulls(body, result);
  }
  @Test
  public void shouldGetFeaturedPlaylists() throws IOException {
    final String countryId = "SE";
    final String locale = "sv_SE";
    final int limit = 5;

    String body = TestUtils.readTestData("featured-playlists.json");
    FeaturedPlaylists fixture = mGson.fromJson(body, FeaturedPlaylists.class);

    Response response = TestUtils.getResponseFromModel(fixture, FeaturedPlaylists.class);

    when(mMockClient.execute(
            argThat(
                new ArgumentMatcher<Request>() {
                  @Override
                  public boolean matches(Object argument) {

                    try {
                      return ((Request) argument).getUrl().contains("limit=" + limit)
                          && ((Request) argument)
                              .getUrl()
                              .contains("country=" + URLEncoder.encode(countryId, "UTF-8"))
                          && ((Request) argument)
                              .getUrl()
                              .contains("locale=" + URLEncoder.encode(locale, "UTF-8"));
                    } catch (UnsupportedEncodingException e) {
                      return false;
                    }
                  }
                })))
        .thenReturn(response);

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put(SpotifyService.COUNTRY, countryId);
    map.put(SpotifyService.LOCALE, locale);
    map.put(SpotifyService.OFFSET, 0);
    map.put(SpotifyService.LIMIT, limit);

    FeaturedPlaylists featuredPlaylists = mSpotifyService.getFeaturedPlaylists(map);

    this.compareJSONWithoutNulls(body, featuredPlaylists);
  }