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

Having problems returning a List from a Mock #587

Closed
ramses-gomez opened this issue Feb 19, 2019 · 2 comments
Closed

Having problems returning a List from a Mock #587

ramses-gomez opened this issue Feb 19, 2019 · 2 comments
Assignees

Comments

@ramses-gomez
Copy link

@ramses-gomez ramses-gomez commented Feb 19, 2019

Using version 1.45
I have this:

new Expectations {{ object.getList(); result = new ArrayList(); }}

But I'm getting the error: java.lang.IllegalArgumentException: java.util.List is not mockable

I know in version 1.45 you can not longer Mock Lists but this is not the case.

Any help?

@rliesenfeld
Copy link
Member

@rliesenfeld rliesenfeld commented Feb 19, 2019

Works fine for me:

   static class AClass { List<?> getList() { return null; }}

   @Test
   public void mockMethodWhichReturnsAList(@Mocked final AClass object) {
      new Expectations() {{ object.getList(); result = new ArrayList(); }};

      List<?> result = object.getList();

      assertTrue(result.isEmpty());
   }

@ramses-gomez
Copy link
Author

@ramses-gomez ramses-gomez commented Feb 20, 2019

sorry I thought that returning a List will do but it is a bit more complex:

`
interface IList extends List {}

static class ClassA {
    IList<?> getList() {
        return null;
    }
}

@Test
public void test(@Mocked ClassA classA) {
    new Expectations() {{
        classA.getList(); result=null;
    }};
}

`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants