RequestBuilder { public <T> ResponseBuilder<T> withTargetClass(Class<T> clazz) { Assert.notNull(clazz, "Target Class token"); assertFinishState(); ResponseBuilder<T> builder = new ResponseBuilder<T>(requestQueue, configuration, httpContent, clazz); markFinishState(); return builder; } RequestBuilder(RequestQueue requestQueue, VolleyerConfiguration configuration, String url, HttpMethod method); @SuppressWarnings("unchecked") B addHeader(String key, String value); ResponseBuilder<T> withTargetClass(Class<T> clazz); ResponseBuilder<String> withListener(Listener<String> listener); ResponseBuilder<String> withErrorListener(ErrorListener errorListener); Request<Void> execute();  }
@Test public void afterRequestMethodShouldReturnAnActualInstance() { String url = "test"; HttpMethod method = HttpMethod.GET; VolleyerConfiguration configuration = DefaultVolleyerConfigurationFactory.create(); TestPurposeRequestBuilder builder = new TestPurposeRequestBuilder(requestQueue, configuration, url, method); ResponseBuilder<String> responseBuilder = builder.withTargetClass(String.class); assertNotNull(responseBuilder); }
@Test(expected = NullPointerException.class) public void withTargetClassMethodShouldThrowNpeWhenTargetClassIsNull() { String key = "testKey"; String value = "testValue"; String url = "test"; HttpMethod method = HttpMethod.GET; VolleyerConfiguration configuration = DefaultVolleyerConfigurationFactory.create(); TestPurposeRequestBuilder builder = new TestPurposeRequestBuilder(requestQueue, configuration, url, method); Class<?> clazz = null; builder.withTargetClass(clazz); }
@Test public void withTargetClassMethodShouldReturnAnActualInstanceWhenTargetClassIsNotNull() { String key = "testKey"; String value = "testValue"; String url = "test"; HttpMethod method = HttpMethod.GET; VolleyerConfiguration configuration = DefaultVolleyerConfigurationFactory.create(); TestPurposeRequestBuilder builder = new TestPurposeRequestBuilder(requestQueue, configuration, url, method); Class<String> clazz = String.class; ResponseBuilder<String> responseBuilder = builder.withTargetClass(clazz); assertNotNull(responseBuilder); }
@Test(expected = IllegalStateException.class) public void withTargetClassMethodShouldThrowIllegalStateExceptionWhenSetTargetClassMethodIsCalledAgain() { String url = "test"; HttpMethod method = HttpMethod.GET; VolleyerConfiguration configuration = DefaultVolleyerConfigurationFactory.create(); TestPurposeRequestBuilder builder = new TestPurposeRequestBuilder(requestQueue, configuration, url, method); Class<String> clazz = String.class; builder.withTargetClass(clazz); builder.withTargetClass(clazz); }