Last active
August 29, 2015 14:05
-
-
Save klimeryk/46f0562772e4a990b08a to your computer and use it in GitHub Desktop.
Using gwtmockito's AsyncAnswers (http://klimer.eu/2014/08/28/testing-asynchronous-gwt-rpc-services/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AnyAsyncCallback<T> extends ArgumentMatcher<AsyncCallback<T>> { | |
public AnyAsyncCallback() { | |
} | |
@Override | |
public boolean matches(Object argument) { | |
return argument instanceof AsyncCallback; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected static <T> AsyncCallback<T> anyAsyncCallback(Class<T> clazz) { | |
return Matchers.argThat(new AnyAsyncCallback<T>()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doAnswer(returnSuccess(somePojoInstance)).when(service).login(eq(login), eq(password), anyAsyncCallback(SomPojo.class)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface LoginServiceAsync { | |
void login(String login, String password, AsyncCallback<SomePojo> callback); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doAnswer(AsyncAnswers.returnFailure(new LoginException("Unknown user"))).when(service).login(eq(login), eq(password), Matchers.<AsyncCallback<SomePojo>>.any()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doAnswer(AsyncAnswers.returnSuccess(somePojoInstance)).when(service).login(eq(login), eq(password), Matchers.<AsyncCallback<SomePojo>>.any()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment