TagGroupApiClient { @NonNull Response<Void> updateTags(@NonNull String identifier, @NonNull TagGroupsMutation mutation) throws RequestException { URL url = runtimeConfig.getUrlConfig() .deviceUrl() .appendEncodedPath(path) .build(); JsonMap payload = JsonMap.newBuilder() .putAll(mutation.toJsonValue().optMap()) .put(AUDIENCE_KEY, JsonMap.newBuilder() .put(audienceKey, identifier) .build()) .build(); Logger.verbose("Updating tag groups with path: %s, payload: %s", path, payload); Response<Void> response = requestFactory.createRequest("POST", url) .setCredentials(runtimeConfig.getConfigOptions().appKey, runtimeConfig.getConfigOptions().appSecret) .setRequestBody(payload) .setAirshipJsonAcceptsHeader() .execute(); logTagGroupResponseIssues(response); return response; } @VisibleForTesting  TagGroupApiClient(@NonNull AirshipRuntimeConfig runtimeConfig,
                      @NonNull RequestFactory requestFactory,
                      @NonNull String audienceKey,
                      @NonNull String path); static TagGroupApiClient namedUserClient(AirshipRuntimeConfig runtimeConfig); static TagGroupApiClient channelClient(AirshipRuntimeConfig runtimeConfig);  }
@Test public void testUpload() throws JsonException, RequestException { TagGroupApiClient client = new TagGroupApiClient(runtimeConfig, requestFactory, "some-audience", "some-path"); Response<Void> response = client.updateTags("identifier", mutation); assertEquals(testRequest.response, response); assertEquals("https: assertEquals("POST", testRequest.getRequestMethod()); JsonMap expectedBody = JsonMap.newBuilder() .put("audience", JsonMap.newBuilder() .put("some-audience", "identifier") .build()) .putAll(mutation.toJsonValue().optMap()) .build(); JsonValue requestBody = JsonValue.parseString(testRequest.getRequestBody()); assertEquals(expectedBody.toJsonValue(), requestBody); }