funbee / mockito

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

Can't mock toString() #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
public class ToStringTest {

    @Test
    public void shouldBeAbleToMockToString() {
        ThingAsAString thing = Mockito.mock(ThingAsAString.class);
        Mockito.stub(thing.toString()).toReturn("Wibble");

        assertEquals("Wibble", thing.toString());
    }

    private static interface ThingAsAString {
        public String toString();
    }
}

(Found by Tom and Candace at TWU)

Original issue reported on code.google.com by featheredwings@gmail.com on 13 Mar 2008 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by iczechowski@gmail.com on 13 Mar 2008 at 11:09

GoogleCodeExporter commented 9 years ago
Hi TWU!

Mockito doesn't allow to mock toString(), hashCode() and equals() to make sure 
mock
behaves correctly (for example, prints nicely in verification error messages). 
It's
written in limitations on main page.

On the other hand, there is no strong reason why we shouldn't just allow mocking
toString()... We will look at it.

Original comment by szcze...@gmail.com on 14 Mar 2008 at 2:01

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 16 Mar 2008 at 2:24

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 16 Mar 2008 at 3:11

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 16 Mar 2008 at 3:23

GoogleCodeExporter commented 9 years ago
fixed in 1.3

Original comment by szcze...@gmail.com on 13 Apr 2008 at 8:57

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 19 Apr 2009 at 7:40