0

I'm trying to set a mock expectation in a test in Scala. The mock is on the Hibernate Query object. It has the method:

List list() throws HibernateException;

The List is not parameterised.

When I try to mock this I can't get the types right. E.g.

when(query.list).thenReturn(new ArrayList)
when(query.list).thenReturn(new ArrayList[Any])
// and other variations

Report:

overloaded method value thenReturn with alternatives: 
(java.util.List[?0],<repeated...>[java.util.List[?0]])org.mockito.stubbing.OngoingStubbing[java.util.List[?0]] <and> 
(java.util.List[?0])org.mockito.stubbing.OngoingStubbing[java.util.List[?0]] 
cannot be applied to (java.util.ArrayList[java.lang.Object])

What should my Scala mock expectation look like?

1
  • 1
    From memory you should write: when(query.list.asInstanceOf[ArrayList[Any]]).thenReturn(new ArrayList[Any]) but I can't check it right now so I'm not proposing this as an answer. Commented Nov 15, 2012 at 4:45

1 Answer 1

2

You can use an asInstanceOf cast and write:

when(query.list.asInstanceOf[ArrayList[Any]]).thenReturn(new ArrayList[Any])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.