Git Product home page Git Product logo

Comments (8)

felipecsl avatar felipecsl commented on July 30, 2024 1

The problem is not the @Before. It is actually more subtle than that... I was able to work around it. Closing since it looks like it is not an issue for anyone else

from otto.

holmes avatar holmes commented on July 30, 2024

Stacktrace?

We've mocked it using Mockito without any issues.

from otto.

felipecsl avatar felipecsl commented on July 30, 2024

I'm using mockito as well.
If I replace the Bus object with a plain Object object, it works fine.
Im doing verify(bus).register(listener) and the test fails since there were no interactions with that mock

from otto.

holmes avatar holmes commented on July 30, 2024

Are you sure you're actually using the mock in your class under test?

Feel free to show us your code
On Jun 18, 2013 11:54 AM, "Felipe Lima" [email protected] wrote:

I'm using mockito as well.
If I replace the Bus object with a plain Object object, it works fine.
Im doing verify(bus).register(listener) and the test fails since there
were no interactions with that mock


Reply to this email directly or view it on GitHubhttps://github.com//issues/87#issuecomment-19632700
.

from otto.

felipecsl avatar felipecsl commented on July 30, 2024

Test 1:

    @Test
    public void busMockTest() {
        Object listener = new Object();
        manager.register(listener);
        verify(bus).register(listener);
    }

Here is manager.register():

    // bus is a mock(Bus.class)
    public void register(Object listener) {
        bus.register(listener);
    }

Fails. Stack trace:

Wanted but not invoked:
bus.register(java.lang.Object@41a8dfb3);
-> at com.weheartit.manager.WeHeartItNotificationManagerTest.busMockTest(WeHeartItNotificationManagerTest.java:62)
Actually, there were zero interactions with this mock.

    at com.weheartit.manager.WeHeartItNotificationManagerTest.busMockTest(WeHeartItNotificationManagerTest.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at com.xtremelabs.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:292)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

from otto.

felipecsl avatar felipecsl commented on July 30, 2024

Test 2:

    @Test
    public void busMockTest() {
        Object listener = new Object();
        manager.register(listener);
        verify(bus).equals(listener);
    }
    // bus is a mock(Object.class)
    public void register(Object listener) {
        bus.equals(listener);
    }

This passes

from otto.

felipecsl avatar felipecsl commented on July 30, 2024

Ok there may be a problem where it only doens't work when I set up the mock in the @Before method.. Investigating

from otto.

naco-siren avatar naco-siren commented on July 30, 2024

I have the same issue.

from otto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.