मैं मॉकिटो 1.8.5 का उपयोग करके एक विधि को स्टब करने की कोशिश कर रहा हूं, लेकिन ऐसा करने से वास्तविक विधि कार्यान्वयन ("" पार्म वैल्यू के रूप में) "को अपवाद देता है जो अपवाद फेंकता है ।पैकेज संरक्षित विधि स्टब करने का प्रयास करते समय मॉकिटो मॉक वास्तविक विधि कार्यान्वयन को कॉल करना
package background.internal; //located in trunk/tests/java/background/internal
public class MoveStepTest {
@Test
public void testMoveUpdate() {
final String returnValue = "value";
final FileAttachmentContainer file = mock(FileAttachmentContainer.class);
doReturn(returnValue).when(file).moveAttachment(anyString(), anyString(), anyString());
//this also fails
//when(file.moveAttachment(anyString(), anyString(), anyString())).thenReturn(returnValue);
final AttachmentMoveStep move = new AttachmentMoveStep(file);
final Action moveResult = move.advance(1, mock(Context.class));
assertEquals(Action.done, moveResult);
}
}
जिस विधि को मैं नकली करने की कोशिश कर रहा हूं वह इस तरह दिखता है। कोई अंतिम विधि या कक्षाएं नहीं हैं।
package background.internal; //located in trunk/src/background/internal
public class FileAttachmentContainer {
String moveAttachment(final String arg1, final String arg2, final String arg3)
throws CustomException {
...
}
String getPersistedValue(final Context context) {
...
}
}
और वर्ग मैं इस तरह नकली लगता गुजर रही है:
package background.internal; //located in trunk/src/background/internal
public class AttachmentMoveStep {
private final FileAttachmentContainer file;
public AttachmentMoveStep(final FileAttachmentContainer file) {
this.file = file;
}
public Action advance(final double acceleration, final Context context) {
try {
final String attachmentValue = this.file.getPersistedValue(context);
final String entryId = this.file.moveAttachment(attachmentValue, "attachment", context.getUserName());
//do some other stuff with entryId
} catch (CustomException e) {
e.log(context);
}
return Action.done;
}
}
क्या वास्तविक कार्यान्वयन खड़ी कर रहा है लागू किया जा करने के लिए और मैं इसे कैसे रोक सकते हैं?
क्या आप वह कोड जोड़ सकते हैं जो वास्तव में परीक्षण निष्पादित कर रहा है? – jhericks
'FileAttachmentContainer' या विधि' moveAttachment() 'अंतिम है? मॉकिटो अंतिम तरीकों का नकल नहीं कर सकता है। –
क्या चल रहा है अटैचमेंट वास्तव में किसी भी स्ट्रिंग() के मानों के साथ बुलाया जाता है? – markus