-1

We have following code structure in our code

namedParamJdbcTemplate.query(buildMyQuery(request),new MapSqlParameterSource(),myresultSetExtractor);

and

namedParamJdbcTemplate.query(buildMyQuery(request),new BeanPropertySqlParameterSource(mybean),myresultSetExtractor);

How can I expect these method calls without using isA matcher?

Assume that I am passing mybean and myresultSetExtractor in request for the methods in which above code lies.

Arun Rahul
  • 565
  • 1
  • 7
  • 24
  • Could you show a psedu-code of the test you're attempting to write, and explain why it does not work? As the question currently stands, it's a tad hard to understand. Thanks! – Mureinik Apr 23 '15 at 18:43
  • I am using isA for now. But I cannot use it from now. Can I achieve this without isA? – Arun Rahul Apr 23 '15 at 18:57

2 Answers2

0

you can do it this way

Easymock.expect(namedParamJdbcTemplateMock.query(EasyMock.anyObject(String.class),EasyMock.anyObject(Map.class),EasyMock.anyObject(ResultSetExtractor.class))).andReturn(...);

likewise you can do mocking for other Methods as well.

hope this helps!

good luck!

Vihar
  • 3,626
  • 2
  • 24
  • 47
0

If you can't use PowerMock to tell the constructors to return mock instances, then you'll have to use some form of Matcher.

isA is a good one. As is anyObject which is suggested in another answer.

If I were you though, I'd be using Captures. A capture is an object that holds the value you provided to a method so that you can later perform assertions on the captured values and check they have the state you wanted. So you could write something like this:

Capture<MapSqlParameterSource> captureMyInput = new Capture<MapSqlParameterSource>();

//I'm not entirely sure of the types you're using, but the important one is the capture method 
Easymock.expect(namedParamJdbcTemplateMock.query(
    EasyMock.anyObject(Query.class), EasyMock.capture(captureMyInput), EasyMock.eq(myresultSetExtractor.class))).andReturn(...);

MapSqlParameterSource caughtValue = captureMyInput.getValue(); 
//Then perform your assertions on the state of your caught value.

There are lots of examples floating around for how captures work, but this blog post is a decent example.

Dan Temple
  • 2,736
  • 2
  • 22
  • 39