में एक तर्क कैप्चर करें मैं एक निश्चित कक्षा का परीक्षण कर रहा हूं। यह कक्षा आंतरिक रूप से "GetMethod" ऑब्जेक्ट को तुरंत चालू कर रही है जो "HttpClient" ऑब्जेक्ट को पास की जाती है जिसे परीक्षण कक्षा में इंजेक्शन दिया जाता है।मॉकिटो
मैं "एचटीपी क्लाइंट" कक्षा का मज़ाक उड़ा रहा हूं, लेकिन मुझे "GetMethod" कक्षा के एक विधि के व्यवहार को भी संशोधित करने की आवश्यकता होगी। मैं ArgumentCaptor के साथ खेल रहा हूं लेकिन मुझे लगता है कि "कब" कॉल में तत्काल वस्तु को पकड़ने में सक्षम नहीं है।
उदाहरण:
HttpClient mockHttpClient = mock(HttpClient.class);
ArgumentCaptor<GetMethod> getMethod = ArgumentCaptor.forClass(GetMethod.class);
when(mockHttpClient.executeMethod(getMethod.capture())).thenReturn(HttpStatus.SC_OK);
when(getMethod.getValue().getResponseBodyAsStream()).thenReturn(new FileInputStream(source));
प्रतिक्रिया:
org.mockito.exceptions.base.MockitoException:
No argument value was captured!
You might have forgotten to use argument.capture() in verify()...
...or you used capture() in stubbing but stubbed method was not called.
Be aware that it is recommended to use capture() only with verify()
जब आप मेरा जवाब संपादित कर रहे थे तो आपने इसे पोस्ट किया था। खैर, हम दोनों ने इसे उसी तरह हल किया :) – amorfis
हां, मुझे उपलब्ध टूल के साथ ऐसा करने का कोई और तरीका नहीं मिल रहा है। गंदा हैक :) लेकिन यह काम करता है जब यह चट्टानों! –