GreenSaguaro
GreenSaguaro

Reputation: 3387

JMockit - mocked methods in Expectations not returning result

JMockit - 1.31

I have the following test method using JUnit (and Groovy):

@Test
void test(@Mocked RequestLine line) {

  new Expectations() {{
    line.getUri()
    result = '123'
  }}

  println line.getUri()

}

line is not null. It is getting an instance. But the problem is that line.getUri() should be returning 123, but is returning null.

Am I doing something wrong? Or should this be working?

UPDATE:

I implemented the test in Java, and it works using result. So it seems to be a problem between JMockit and Groovy.

Upvotes: 3

Views: 1931

Answers (1)

Alfergon
Alfergon

Reputation: 5919

For some reason it works using returns() instead of result. Not sure why, maybe you should open and issue in their issue tracker.

@Test
void test(@Mocked RequestLine line) {

  new Expectations() {{
    line.getUri(); 
    returns('123');
  }}

  System.out.println(line.getUri());

}

Upvotes: 1

Related Questions