現在單元測試我需要authenticate方法只是假裝它工作正常,在我的情況下什麼都不做,所以我可以測試方法本身是否做預期的工作(身份驗證測試其他地方根據單元測試的原則,但驗證需要調用該方法內)模擬對象的身份驗證在春季安全
這是我的TestNG的類,我需要做的模擬對象進行身份驗證:
package in.hexgen.api.facade;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.testng.annotations.Test;
import com.hexgen.api.facade.security.HexGenPermissionEvaluator;
public class HexGenPermissionEvaluatorTest {
private static final Logger logger = LoggerFactory.getLogger(HexGenPermissionEvaluatorTest.class);
Object name="akash";
Object permission="CREATE_REQUISITION";
Authentication authentication;
//@Resource(name = "permissionEval")
private HexGenPermissionEvaluator permissionEval;
@Test
public void hasPermission() {
//authentication.setAuthenticated(true);
logger.debug("HexGenPermissionEvaluator Generate - starting ...");
permissionEval.hasPermission(authentication,name, permission);
logger.debug("HexGenPermissionEvaluator Generate - completed ...");
}
}
如何做到這一點。
問候