尝试在另一个类中添加mockupTest案例时,我在BannerUpdatedBoltTest中收到以下错误:TagLevelDataBoltTest。 我试图在@Before中添加MockUp测试用例,但它给了我同样的错误。知道为什么吗?
测试用例:
@BeforeClass
public static void setUpClass() throws Exception {
new MockUp<TagImpl>() {
@Mock
public String getSinglePrimaryColor() {
return "Grey";
}
};
conf.put(HConstants.ZOOKEEPER_QUORUM + "." + HBaseConnectionPool.CATALOG_POOL, "");
conf.put(AbstractBolt.MAX_TAG_COUNT_DOCS_PROPERTY, Integer.toString(2));
conf.put(AbstractBolt.NO_TAG_COUNT_FOR_PTITLE_DOC_PROPERTY, Integer.toString(2));
Config.init(conf);
}
TagLevelDataBoltTest.java
@RunWith(PowerMockRunner.class)
@PrepareForTest(SellerProgram.class)
public class TagLevelDataBoltTest extends AbstractBoltTest {
private static Map<String, String> conf = new HashMap<String, String>();
private TagLevelDataBolt bolt = new TagLevelDataBolt();
private Map<String, String> expectedFieldValueMap = new HashMap<String, String>();
private Map<String, String> inputFieldValueMapToBolt = new HashMap<String, String>();
private Map<String, String> storedFieldValueMapToBolt = new HashMap<String, String>();
private ProductTitleEvent event = new ProductTitleEvent(this.ptitleId, Action.UPDATE, null);
private HBaseTagDao tagDao = Mockito.mock(HBaseTagDao.class);
private HbasePdirNodeDao pdirNodeDao = Mockito.mock(HbasePdirNodeDao.class);
private HBaseGlobalModelDao globalModelDao = Mockito.mock(HBaseGlobalModelDao.class);
@BeforeClass
public static void setUpClass() throws Exception {
new MockUp<TagImpl>() {
@Mock
public String getSinglePrimaryColor() {
return "Grey";
}
};
conf.put(HConstants.ZOOKEEPER_QUORUM + "." + HBaseConnectionPool.CATALOG_POOL, "");
conf.put(AbstractBolt.MAX_TAG_COUNT_DOCS_PROPERTY, Integer.toString(2));
conf.put(AbstractBolt.NO_TAG_COUNT_FOR_PTITLE_DOC_PROPERTY, Integer.toString(2));
Config.init(conf);
}
@AfterClass
public static void tearDownClass() throws Exception {
Config.clear();
}
@Before
public void setUp() throws IOException {
PowerMockito.mockStatic(SellerProgram.class);
Mockito.when(SellerProgram.getCPCInfo(SellerProgram.SELLER_GROUP_PROGRAM_ID, 4825235L)).thenReturn(getCPCInfo());
Mockito.when(tagDao.getActiveTagsByPtitleId(989417179L)).thenReturn(getTags());
Mockito.when(pdirNodeDao.get(98760003L)).thenReturn(getPdirNode98760003());
Mockito.when(globalModelDao.getVariantData(1010234L, "us", 989417179L, 1146662679L)).thenReturn(getTagVariantData(1146662679L));
Mockito.when(globalModelDao.getVariantData(1010234L, "us", 989417179L, 1145602023L)).thenReturn(getTagVariantData(1145602023L));
this.bolt.tagDao = this.tagDao;
this.bolt.pdirNodeDao = this.pdirNodeDao;
this.bolt.globalModelDao = this.globalModelDao;
this.bolt.groupSeparator = ",";
this.bolt.market = "us";
this.bolt.init();
}
@Test
public void testPtitleLevelField() throws Exception {
inputFieldValueMapToBolt.put(SolrIndexTableConst.TAG_SUMMARY.getColumnName(), "1.0|2014-12-31 23:59:59.9|1972900427|1145602023,2576883,25,99.99,0,2880,0,0,0,0,-1,-1,-2,0,-2,0,-,0,0|1146662679,4825235,25,99.99,0,2880,0,0,0,0,-1,-1,-2,0,-2,0,-,0,0");
inputFieldValueMapToBolt.put(SolrIndexTableConst.SELLER_DATA_SOURCE.getColumnName(), "{}");
inputFieldValueMapToBolt.put(SolrIndexTableConst.MODEL_ID.getColumnName(), "1010234");
inputFieldValueMapToBolt.put(SolrIndexTableConst.NODE_IDS.getColumnName(), "98760003");
inputFieldValueMapToBolt.put(SolrIndexTableConst.LEAF_NODE_IDS.getColumnName(), "98760003");
expectedFieldValueMap.put(SolrIndexTableConst.TAG_ID.getColumnName(), "1146662679 1145602023");
expectedFieldValueMap.put(SolrIndexTableConst.TAG_NAME.getColumnName(), "{\"1145602023\":\"NEW Ancient Minerals PURE Ultra Magnesium Oil Spray with OPT MSM - 8oz Bottle\",\"1146662679\":\"Ancient Minerals Ultra Pure with MSM 8 Oz\"}");
//expectedFieldValueMap.put(SolrIndexTableConst.TAG_DESCRIPTION.getColumnName(), "{\"1145602023\":\"Ancient Minerals\",\"1146662679\":\"Ancient Minerals Magnesium Oil Ultra with OptiMSM by LL Magnetic Clay is a rapidly absorbed ultra pure and concentrated easy topical spray that incorporates the unique synergistic benefits of MSM and magnesium. MSM has long been revered as a superior form of sulfur supplementation, but as a topical it enhances cell membrane permeability and may facilitate more efficient uptake of magnesium ions. Ancient Minerals Magnesium Oil Ultra contains approximately 1.6g elemental magnesium and 3.6g of MSM (OptiMSM) per fl oz. Ancient Minerals Magnesium Oil Ultra utilizes premium distilled OptiMSM, the worlds purity standard for MSM. Ancient Minerals ultra pure magnesium oil is extracted from the Ancient Zechstein Seabed in Europe, 1600 to 2000 meters deep in the interior of the Earth. Well protected for the last 250 million years, it is the most pure magnesium oil in the world and a mark of purity on every bottle of Ancient Minerals. Magnesium oil is not actually an oil but was named that because it has an oil-like texture due to a high saturation of magnesium chloride in water. Possible Benefits of Ancient Minerals Magnesium Oil: Support for restoring cellular magnesium levels* Provides cellular protecting support* Supports detoxification* Support for relieving aches and pains* Support for improving mood and relieving stress* Encourages healthy skin tissue* For the amazing benefits of Genuine Zechstein magnesium, try Ancient Minerals Magnesium Oil Ultra today!\"}");
expectedFieldValueMap.put(SolrIndexTableConst.TAG_EAN.getColumnName(), "{\"1145602023\":\"EAN 2\",\"1146662679\":\"EAN 1\"}");
expectedFieldValueMap.put(SolrIndexTableConst.TAG_MFR_PART_NO.getColumnName(), "{\"1145602023\":\"MFR 2\",\"1146662679\":\"MFR 1\"}");
expectedFieldValueMap.put(SolrIndexTableConst.TAG_SUMMARY.getColumnName(), "1.0|2014-12-31 23:59:59.9|1972900427|1145602023,2576883,25,99.99,0,2880,0,0,0,0,-1,-1,-2,0,-2,0,-,0,0|1146662679,4825235,25,99.99,0,2880,0,0,0,0,-1,-1,-2,0,-2,0,-,0,0");
//expectedFieldValueMap.put(SolrIndexTableConst.TAG_NLA.getColumnName(), "{\"1145602023\":[\"image_color~Grey\"]}");
expectedFieldValueMap.put(SolrIndexTableConst.TAXONOMY_IDS.getColumnName(), "{\"1145602023\":22345,\"1146662679\":12345}");
expectedFieldValueMap.put(SolrIndexTableConst.SELLER_TAG_RANK.getColumnName(), "{\"1145602023\":2222,\"1146662679\":1111}");
expectedFieldValueMap.put(SolrIndexTableConst.SELLER_GROUP.getColumnName(),"{\"1146662679\":[\"8888\",\"6060\"]}");
expectedFieldValueMap.put(SolrIndexTableConst.MODEL_KEY.getColumnName(),"{\"1145602023\":\"1010234``color:white~hinge side:right\",\"1146662679\":\"1010234``color:silver~hinge side:left\"}");
compareFieldsValue(expectedFieldValueMap, this.bolt.process(this.event, inputFieldValueMapToBolt, storedFieldValueMapToBolt));
}
}
这是接收错误:
initializationError(com.nextag.build.index.product.bolt.BannerUpdatedBoltTest) Time elapsed: 0 sec <<< ERROR!
java.lang.StackOverflowError
at java.lang.ThreadLocal$ThreadLocalMap.getEntry(ThreadLocal.java:376)
at java.lang.ThreadLocal$ThreadLocalMap.access$000(ThreadLocal.java:261)
at java.lang.ThreadLocal.get(ThreadLocal.java:146)
at mockit.internal.mockups.MockState.update(MockState.java:54)
at mockit.internal.mockups.MockStates.updateMockState(MockStates.java:93)
at mockit.internal.state.TestRun.updateMockState(TestRun.java:160)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
at org.junit.runners.model.FrameworkMethod.validatePublicVo
答案 0 :(得分:0)
在setup() -
中使用以下内容@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
}
调用initMocks方法初始化带注释的对象。 希望这有帮助。