NamedUserApiClient { @NonNull Response<Void> associate(@NonNull String id, @NonNull String channelId) throws RequestException { URL url = runtimeConfig.getUrlConfig() .deviceUrl() .appendEncodedPath(ASSOCIATE_PATH) .build(); JsonMap payload = JsonMap.newBuilder() .put(CHANNEL_KEY, channelId) .put(DEVICE_TYPE_KEY, getDeviceType()) .put(NAMED_USER_ID_KEY, id) .build(); return requestFactory.createRequest() .setOperation("POST", url) .setCredentials(runtimeConfig.getConfigOptions().appKey, runtimeConfig.getConfigOptions().appSecret) .setRequestBody(payload) .setAirshipJsonAcceptsHeader() .execute(); } NamedUserApiClient(@NonNull AirshipRuntimeConfig runtimeConfig); @VisibleForTesting  NamedUserApiClient(@NonNull AirshipRuntimeConfig runtimeConfig, @NonNull RequestFactory requestFactory);   }
@Test public void testAssociateSucceeds() throws RequestException, JsonException { testRequest.responseStatus = 200; Response<Void> response = client.associate(fakeNamedUserId, fakeChannelId); JsonMap expected = JsonMap.newBuilder() .put("device_type", "android") .put("named_user_id", fakeNamedUserId) .put("channel_id", fakeChannelId) .build(); assertEquals(200, response.getStatus()); assertEquals("POST", testRequest.getRequestMethod()); assertEquals("https: assertEquals(expected, JsonValue.parseString(testRequest.getRequestBody())); }
@Test(expected = RequestException.class) public void testNullUrlAssociate() throws RequestException { runtimeConfig.setUrlConfig(AirshipUrlConfig.newBuilder().build()); client.associate(fakeNamedUserId, fakeChannelId); }