为什么尽管我已指定结果,但Jmockit模拟接口始终返回null?

问题描述

jmockit版本1.46 Java 1.8 简单的代码如下:

class PhoneControllerTest{

@Tested
PhoneController phoneController;

@Injectable
IPhoneservice phoneservice;
....
public void testMethod(@Tested Map map){
new Expections{{
  // example 1.mock success when param is 
  // primitive
  phoneservice.call("12345");
  result="0";

  //example 2 .mock fail when param is 
  
   phoneservice.call(map);
   result="0";

  
}}  
}}
interface IPhoneservice{ 
     String call(String id);
     String call(Map map);
}

我对example2感到困惑,为什么它返回null而不是0?我应该怎么做 result 可以在example2中正常工作。 @injectable对“结果”有影响吗?

解决方法

我想解决这个问题,只需用替换任何复杂的参数。 phoneService.call((Map)any);