Reputation: 11
This is a part of my class, I want to test:
public class PrefPanel extends Composite {
private static PrefPanelUiBinder uiBinder = GWT.create(PrefPanelUiBinder.class);
interface PrefPanelUiBinder extends UiBinder<Widget, PrefPanel> {}
public PrefPanel(GlobalParams globalParams) {
initWidget(uiBinder.createAndBindUi(this));
String url = URL.encode(globalParams.getBaseUrl() + "book.html");
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
try {
Request response = builder.sendRequest(jsonString, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
displayError("Error");
}
@Override
public void onResponseReceived(Request request, Response response) {
updateBookList(response.getText());
}
});
} catch (RequestException e) {
displayError("Error");
}
Here is a part of my test class:
@RunWith(GwtMockitoTestRunner.class)
public class PositionServiceTest {
@Mock RequestBuilder builder;
@Mock GlobalParams globalParams;
@Mock URL url;
private PrefPanel prefPanel;
@Before
public void setup() {
GwtMockito.useProviderForType(RequestBuilder.class, new FakeProvider() {
@Override
public Object getFake(Class aclass) {
return builder;
}
});
when(globalParams.getBaseUrl()).thenReturn("http://localhost/");
prefPanel = new PrefPanel(globalParams);
...
When I start to debug I get an error message: - url cannot be empty - java.lang.IllegalArgumentException - at com.google.gwt.http.client.StringValidator.throwlfEmptyOrNull(StringValidator.java:52) - ...
The error occurs on the line where I create the RequestBuilder (new RequestBuilder). I have no idea how to create a new instance of RequestBuilder. Could you give me a clue?
I have heard that gwtmockit can't handle constructors. Is there a way to avoid the new RequestBuilder? Do I have to use powermockito?
Upvotes: 1
Views: 342