Closed marcdonovan closed 9 years ago
Yes, the second expectation on "response.getStatusCode()" overwrites the first one. So, record just one expectation (and taking advantage of cascaded mocking):
@Mocked AsyncHttpClient asyncHttpClient;
@Mocked ListenableFuture<Response> listenableFuture;
@Test
public void testHappyPathWithCopierNotYetExistsInCourseCopy(@Mocked final Response response) throws Exception
{
new Expectations() {{
listenableFuture.get(); result = response;
response.getStatusCode(); returns(200, 201);
}};
MethodUnderTest plugin = new MethodUnderTest();
plugin.getId();
}
import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.Response;
import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future;
public final class MethodUnderTest {
}
/////////////////////////////////////////////
import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.ListenableFuture; import com.ning.http.client.Response; import mockit.Expectations; import mockit.Mocked; import org.testng.annotations.Test;
public class TestCode {
}
I expect the System to print out 200 first, then 201. Actual result is 201 then 201. It looks like the later result = 201 is overwriting the earlier 200. If I comment out the result = 201 line, then I get 200 output.
java version "1.7.0_55" OSX Darwin 13.1.0 JMockit 1.13 TestNG 6.8.17