Thursday, September 22, 2016

Mocking onResponseReceived response.getText()


I wanted to know if it could be possible to Mock out the response.getText() in a callback when using RequestBuilder. This way I can write tests to simulate the responses etc.

 RequestBuilder expRequestBuilder = new RequestBuilder(RequestBuilder.GET, encodedUrl);
try {
.sendRequest(null, new RequestCallback() {

public void onResponseReceived(final Request request, final Response response) {
if (response.getStatusCode() == Response.SC_OK) {
String json = response.getText();
//populate the map with the data we retrieve
JsArray<EntityLite> array = evalJsonGetData("(" + json + ")");
for (int i = 0; i < array.length(); i++) {
EntityLite entity = array.get(i);
String oid = entity.getValue(ExperimentEntityLite.EXPERIMENT_OID.getAttributeId());

The above shows the code which is inside a method inside a class. I thought maybe I could pass in the RequestBuilder as a mock but I don't think that will work as I want to exercise the code inside onResponseReceived

I didn't find examples unfortunately in the framework for this simple kind of testing.

Many thanks

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment