我正在使用 JUnit 和 Spring 运行 Mockito 最新版本(3.11.2),并在创建模拟时遇到此错误-
`Fix required:this map must be added to the appropriate MapInitializer. Trying to recover from this error and continue...
at com./.integ.dal.map.BaseMap2.checkInitialized(BaseMap2.java:1540)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53) 13:18:19 main ERROR com./.integ.dal.map.BaseMap2
Failed to recover from previous errors and late-initialize the class=class com./.integ.uhslogicalhost.UhsLogicalHostMap. This class' initialization cannot be post-poned due to some dependencies. Fix required: add this class and its dependencies to a proper MapInitializer,and make sure that their DAL Init Policy is set to true in DALInitPolicy.properties. Exception: com./.integ.dal.DalRuntimeException: No token parser factory was found for a driverType of sql.
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class com./.integ.adscampaignitem.AdsCampaignItemDAO.
If you're not sure why you're getting this error, please report to the mailing list.
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.
Underlying exception : org.mockito.exceptions.base.MockitoException: Cannot instrument class com./.integ.adscampaignitem.AdsCampaignItemDAO because it or one of its supertypes could not be initialized
at com./.app.ploebat.client.SellerAdsDalClientTest.testGetItems(SellerAdsDalClientTest.java:94)
Fix required: add this class and its dependencies to a proper MapInitializer,and make sure that their DAL Init Policy is set to true in DALInitPolicy.properties. Exception: com./.integ.dal.DalRuntimeException: No token parser factory was found for a driverType of sql.
No token parser factory was found for a driverType of sql.
at com./.integ.dal.map.BaseMap2.checkInitialized(BaseMap2.java:1559)
Process finished with exit code 255`
以下代码行导致此错误 -
AdsDAO adsDAO = mock(AdsDAO.class);
我也尝试在 byte-buddy 上使用最新版本,但它不起作用。
这是 AdsCampaignItemDAO.class-
public class AdsCampaignItemDAO extends BaseDao2 {
private static volatile AdsCampaignItemDAO s_instance;
private static GenericMap<AdsCampaignItem> s_map;
private static AdsCampaignItemCodeGenDoImpl m_noFetchProtoDO;
private static AdsCampaignItemCachedSeqGenDAO s_seq = AdsCampaignItemCachedSeqGenDAO.getInstance();
public static AdsCampaignItemDAO getInstance() {
if (s_instance == null) {
synchronized(AdsCampaignItemDAO.class) {
if (s_instance == null) {
s_instance = new AdsCampaignItemDAO();
}
}
}
return s_instance;
}
protected AdsCampaignItemDAO() {
if (!m_mapInitialized) {
initMap();
}
}
public static void initMap() {
if (!m_mapInitialized) {
GenericMap<AdsCampaignItem> map = GenericMap.getMap(AdsCampaignItem.class);
map.setDalVersion("3.0");
m_mapInitialized = true;
s_map = map;
m_noFetchProtoDO = new AdsCampaignItemCodeGenDoImpl((BaseDao2)null, map);
m_noFetchProtoDO.setAdsCampaignItemId(-1L);
AdsCampaignItemCachedSeqGenDAO.init();
try {
map.registerToupleProvider("ADS_CAMPAIGN_ITEM", AdsCampaignItemToupleProvider.getAdsCampaignItemToupleProvider());
} catch (NullPointerException var2) {
throw new DalRuntimeException("DAL not properly initialized.");
}
initHintGroups(map);
map.setUpdateSets(getUpdateSets(map));
map.init();
}
}
}
这是 BaseMap2 的代码,看起来问题出在此类中-
public abstract class BaseMap2 {
protected BaseDo2 m_DOProtoCopyInstance;
protected Map<Integer, ReadSet> m_readSetsById = new IntKeyHashMap();
private Map<Object, Integer> m_mapDynamicReadSetsByGeneratedKey;
private AtomicInteger m_DynamicReadSetIndex;
protected BaseMap2() {
if (this instanceof DynamicReadSetMap) {
this.m_readSetsById = Collections.synchronizedMap(this.m_readSetsById);
this.m_mapDynamicReadSetsByGeneratedKey = new ConcurrentHashMap();
this.m_DynamicReadSetIndex = new AtomicInteger(-5000);
}
}
}