Hot questions for Using Mockito in gwt


I'm learning GwtMockito but having trouble getting consistent verify() method results in one of my tests.

I'm trying to test the correct GwtEvents are being fired by my application. So I've mocked the Event Bus like this in my @Before method:

eventBus = mock(HandlerManager.class);

This test passes as expected:

// Passes as expected

I wanted to force the test to fail just to know it was running correctly. So I changed it to this and it still passes:

// Expected this to fail, but it passes

This seems contradictory to me. So I removed the first test:

// Fails as expected

Finally I added an unrelated event that should cause it to fail

// Expected to fail, but passes
verify(eventBus).fireEvent(any(ModelCreatedEvent.class));  // This event is not used at all by the class that I'm testing. It's not possible for it to be fired.

I'm not finding any documentation that explains what's going on. Both ErrorOccurredEvent and ModelCreatedEvent extend GwtEvent, and have been verified in manual testing. Am I testing my EventBus incorrectly? If so, what is a better way to go about it?


I've done some additional experimenting. It appears to be an issue I'm having with the Mockito matcher. When I get the test to fail the exception reports the method signature as eventBus.fireEvent(<any>) so it doesn't appear to be taking into account the different classes I'm passing into the any method. Not sure what to do about this yet, but including it here for anyone else researching this problem.


The method you're looking for is isA, instead of any.


I'm doing a project with gwt at the moment. I have to test a presenter using Eclipse Luna, JUnit and Mockito and have problems doing anything.

After I failed with mockito I discovered GwtMockito and tried that. I used this example to get started: Github GwtMockito example

My Test class looks like this:

public class GamePresenterTest {

@GwtMock private GameServiceAsync gameService;
@GwtMock private LobbyPresenter lobbyPresenter;
@GwtMock private EventBus eventBus;
@GwtMock private Display gameView;
@GwtMock private User user;
@GwtMock private Player player;
@GwtMock private ClickEvent event;

private GamePresenter presenter;
private String username = "name";
private String gameTitle = "title";

public void setUp() {
    System.out.println("TODO: set up");

public void testActionTableClicked() {
    System.out.println("TODO: add test");

When I run it I get this

java.lang.NoClassDefFoundError: javassist/NotFoundException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(
at java.lang.Class.getConstructor0(
at java.lang.Class.getConstructor(
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(
at org.junit.internal.requests.ClassRequest.getRunner(
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
Caused by: java.lang.ClassNotFoundException: javassist.NotFoundException
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
        ... 18 more

When I remove the @RunWith(GwtMockitoTestRunner.class) I get another message that tells me I should use initMocks, but I don't how to do that, too. Without @RunWith(GwtMockitoTestRunner.class) and the @GwtMock stuff everything works fine of course.

I hope someone can help, because my project ends in a few weeks.


Looks like you need javassist-<version>.jar. Add it to your classpath and it should work