我正在寫用TestNG和Mockito.The問題單元箱子匿名類對象,我面臨與下面給出的方法:如何測試內部方法
public void publishRequest(final NotificationRequest request){
MessageCreator messageCreator = new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
if (logger.isDebugEnabled()) {
logger.debug("Start of MessagePublisher publishRequest");
}
ObjectMessage msg = session.createObjectMessage();
msg.setStringProperty(
"SELECTOR",
request.getAvailaibilityTier() + "-"
+ request.getEsbReference());
if (logger.isDebugEnabled()) {
logger.debug("Message Selector=>"+msg.getStringProperty("SELECTOR"));
}
msg.setStringProperty(NotificationConstants.CACHE_KEY.name(),
request.getId());
msg.setObject(request.getData());
if (logger.isDebugEnabled()) {
logger.debug("Publishing request -->" + request);
}
if (logger.isDebugEnabled()) {
logger.debug("End of MessagePublisher publishRequest");
}
return msg;
}
};
producerTemplate.send(messageCreator);
}
在寫單元殼體的CreateMessage( )方法沒有被調用,即使我的測試用例創建了MessageCreater對象。我想在我的單位情況下也包括這一點,以獲得更好的報道。任何想法如何測試內部類的方法?
你的測試看起來像什麼?你想表達什麼? – NilsH 2013-04-10 05:06:58