0
我有下面的方法,我需要單元測試。如何使用靜態內部類來模擬對象的實例化?
如何在下面模擬創建LDUser
對象?
public void isFeatureFlagOn(String featureFlagId, TransactionContext transContext, boolean defaultReturnState)
throws TAServiceException {
boolean returnState = defaultReturnState;
try {
LDUser ldUser = new LDUser.Builder(transContext.getAuthId()).build();
returnState = ldClient.boolVariation(featureFlagId, ldUser, defaultReturnState);
} catch (Exception e) {
returnState = defaultReturnState;
}
if (!returnState) {
throw new TAServiceException("This service is not available", HttpStatus.NOT_FOUND);
}
}
是[我的文章](https://github.com/mockito/mockito/wiki/Mocking-Object-Creation)有什麼用? –