You can refactor the onResponseReceived callback as a method in your top level class and expose it package private.
-- Then you target it directly in a unittest, mocking both request and response objects.
On Fri, Sep 23, 2016 at 8:46 AM Jonathan Cook <jpcook04@gmail.com> wrote:
Hello,--
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 {
expRequestBuilder.sendRequest(null, new RequestCallback() {
@Override
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 insideonResponseReceived
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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment