Wie kann ich verspotte alle Argumente zu einer privaten Methode mit PowerMockito?

Ich bin mit Mockito 1.9.5, PowerMock 1.5.1, JUnit 4.11 und Frühjahr 3.1.4.RELEASE. Ich bin versucht zu schreiben Sie einen JUnit-test in die ich will, zu verhöhnen, eine private Methode nichts zu tun. Die private Signatur der Methode ist

public class MyService
{

    …
    private void myMethod(byte[] data, UserFile userFile, User user)
    {

Und in meinem JUnit-test habe ich

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:test-context.xml" })
@PrepareForTest(MyServiceImpl.class)
public class MyServiceIT 
{

    @Rule
    public PowerMockRule rule = new PowerMockRule();

    @Autowired
    private MyService m_mySvc;
    private MyService m_mySvcSpy;

    @Before
    public final void setup() throws Exception
    {
        m_mySvcSpy = PowerMockito.spy(m_mySvc);
        PowerMockito.doNothing().when(m_mySvcSpy, “myMethod”, Matchers.any(byte[].class), Matchers.any(UserFile.class), Matchers.any(User.class));

Leider die zweite Zeile stirbt mit der Ausnahme

testUploadFile(org.mainco.subco.user.service.MyServiceIT)  Time elapsed: 12.693 sec  <<< ERROR!

org.powermock.reflektieren.Ausnahmen.MethodNotFoundException: Keine Methode mit dem Namen 'myMethod' mit parameter-Typen: [ null, null, null ] in class org.mainco.subco.Benutzer.service.UserFileService$$EnhancerByMockitoWithCGLIB$$4e52bc77.
bei org.powermock.reflektieren.intern.WhiteboxImpl.throwExceptionIfMethodWasNotFound(WhiteboxImpl.java:1247)
bei org.powermock.reflektieren.intern.WhiteboxImpl.findMethodOrThrowException(WhiteboxImpl.java:985)
bei org.powermock.reflektieren.intern.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:882)
bei org.powermock.reflektieren.intern.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:713)
bei org.powermock.reflektieren.Whitebox.invokeMethod(Whitebox.java:401)
bei org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.when(PowerMockitoStubberImpl.java:93)
bei org.mainco.subco.Benutzer.service.MyServiceIT.setup(UserFileServiceIT.java:42)

Was ist die richtige Art und Weise zu verspotten Allgemeine Argumente für eine private Methode mit PowerMockito?

  • Ich verstehe nicht, warum die PowerMockito.doNothing().wenn(m_mySvcSpy, "myMethod", null, null, null); Zeile befindet. Was ist es eigentlich?
InformationsquelleAutor Dave | 2014-09-25
Schreibe einen Kommentar