0

I'm using EasyMock to mock a class called "Tuple". The Tuple.getString(int i) method is supposed to return the String at position i in the tuple. If that field is not a String, it will give a runtime error.

In order for andReturn to work, I will have to cast the value to String like below: expect(tuple.getString(i)).andReturn((String) json.get(list[i])).atLeastOnce(); which is not the desired behavior.

For example, if json.get(list[i]) is an integer, I want to give a runtime error instead of casting it to String.
Is there a way to get around this? Thank you!

Dao Lam
  • 2,837
  • 11
  • 38
  • 44
  • By "give a runtime error" do you mean you want to simulate the case where tuple.getString(i) throws a runtime error presumably because it normally checks it's output? – Gus Aug 20 '12 at 15:00

1 Answers1

0

So I actually don't have to cast it because JSONObject has a getString() method. I don't know why I didn't think of this earlier.

Dao Lam
  • 2,837
  • 11
  • 38
  • 44