dhamini-poornachandra / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

why spied object call real method? #336

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
    @Test
    public void spyTestOne() {
        Jack spyJack = spy(new Jack());
        when(spyJack.go()).thenReturn(1111);

        assertEquals(1111, (spyJack.go()));
    }

    class Jack {
        public int go() {
            System.out.println("I say go go go!!");
            return 0;
        }
    }

What is the expected output? What do you see instead?
the test has passed, but console print "I say go go go!!"
i think go() will do nothing, isn't it?

What version of the product are you using? On what operating system?
mockito 1.9RC 
win7 32bit

Please provide any additional information below.

Original issue reported on code.google.com by heip...@gmail.com on 24 Apr 2012 at 5:39

GoogleCodeExporter commented 8 years ago
i got it.

i should use 

doReturn(1111).when(spyJack).go();
  >>> instead of
when(spyJack.go()).thenReturn(1111);

but i think it's a trap, right?

Original comment by heip...@gmail.com on 24 Apr 2012 at 5:51

GoogleCodeExporter commented 8 years ago
Hi,

Exactly! But I'm afraid we cannot do much about it.
However this is documented in the Javadoc. But we made it more explicit for the 
next release on other javadoc places as well.

Hope that helps
Brice

Original comment by brice.du...@gmail.com on 24 Apr 2012 at 9:20

GoogleCodeExporter commented 8 years ago
OK, Thx a lot.

Original comment by heip...@gmail.com on 25 Apr 2012 at 1:34

GoogleCodeExporter commented 8 years ago
You are welcome, don't hesitate to use the mailing-list as well :)

Cheers,
Brice

Original comment by brice.du...@gmail.com on 25 Apr 2012 at 10:50