### Question:
InputControlRestApi { @NotNull public List<InputControlState> requestInputControlsStates(@NotNull String reportUri, @NotNull List<ReportParameter> parameters, boolean freshData) throws HttpException, IOException { Utils.checkNotNull(reportUri, "Report URI should not be null"); Utils.checkNotNull(parameters, "Parameters should not be null"); Map<String, Set<String>> params = ReportParamsMapper.INSTANCE.toMap(parameters); String ids = Utils.joinString(";", params.keySet()); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("reports") .addPaths(reportUri) .addPath("inputControls") .addPath(ids) .addPath("values") .build() .resolve(mNetworkClient.getBaseUrl()) .newBuilder() .addQueryParameter("freshData", String.valueOf(freshData)) .build(); RequestBody jsonRequestBody = mNetworkClient.createJsonRequestBody(params); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .post(jsonRequestBody) .url(url) .build(); Response response = mNetworkClient.makeCall(request); if (response.code() == 204) { return Collections.emptyList(); } InputControlStateCollection inputControlStateCollection = mNetworkClient.deserializeJson(response, InputControlStateCollection.class); return Collections.unmodifiableList(inputControlStateCollection.get()); } InputControlRestApi(NetworkClient networkClient); @NotNull List<InputControl> requestInputControls(@NotNull String reportUri,
                                                   @Nullable Set<String> controlIds,
                                                   boolean excludeState); @NotNull List<InputControlState> requestInputControlsInitialStates(@NotNull String reportUri,
                                                                     boolean freshData); @NotNull List<InputControlState> requestInputControlsStates(@NotNull String reportUri,
                                                              @NotNull List<ReportParameter> parameters,
                                                              boolean freshData);  }### Answer:
@Test public void requestInputControlsStatesShouldNotAllowNullReportUri() throws Exception { mExpectedException.expect(NullPointerException.class); mExpectedException.expectMessage("Report URI should not be null"); restApiUnderTest.requestInputControlsStates(null, Collections.<ReportParameter>emptyList(), true); }
@Test public void requestInputControlsStatesShouldNotAllowNullControlParams() throws Exception { mExpectedException.expect(NullPointerException.class); mExpectedException.expectMessage("Parameters should not be null"); restApiUnderTest.requestInputControlsStates("any_id", null, true); }
@Test public void requestInputControlsStatesShouldThrowRestErrorFor500() throws Exception { mExpectedException.expect(HttpException.class); mWebMockRule.enqueue(MockResponseFactory.create500()); restApiUnderTest.requestInputControlsStates("any_id", Collections.<ReportParameter>emptyList(), true); }
@Test public void apiShouldProvideFreshStatesForInputControls() throws Exception { List<ReportParameter> parameters = Collections.singletonList( new ReportParameter("sales_fact_ALL__store_sales_2013_1", Collections.singleton("19"))); MockResponse mockResponse = MockResponseFactory.create200() .setBody(icsStates.asString()); mWebMockRule.enqueue(mockResponse); Collection<InputControlState> states = restApiUnderTest.requestInputControlsStates("/my/uri", parameters, true); assertThat(states, Matchers.is(not(Matchers.empty()))); RecordedRequest request = mWebMockRule.get().takeRequest(); assertThat(request, containsHeader("Accept", "application/json; charset=UTF-8")); assertThat(request, hasPath("/rest_v2/reports/my/uri/inputControls/sales_fact_ALL__store_sales_2013_1/values?freshData=true")); assertThat(request, wasMethod("POST")); }
@Test public void list_input_control_states_returns_empty_collection_on_204() throws Exception { mWebMockRule.enqueue(MockResponseFactory.create204()); List<InputControlState> expected = restApiUnderTest.requestInputControlsStates("/my/uri", Collections.<ReportParameter>emptyList(), false); assertThat(expected, Matchers.is(Matchers.empty())); }