Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't mock toString() #4

Closed
GoogleCodeExporter opened this issue Jun 25, 2015 · 7 comments
Closed

Can't mock toString() #4

GoogleCodeExporter opened this issue Jun 25, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: Priority-Low
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

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

@GoogleCodeExporter
Copy link
Author

fixed in 1.3

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: Milestone-Pre1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant