Your code 나를 위해 NullPointerException이 발생합니다 :
@RunWith(PowerMockRunner.class)
@PrepareForTest(Bar.class)
public class MyTest {
@Test
public void test() throws InterruptedException{
Foo foo = new Foo();
Foo fooSpy = PowerMockito.spy(foo);
Bar barMock = PowerMockito.mock(Bar.class);
PowerMockito.doReturn(barMock).when(fooSpy).getBar();
PowerMockito.doNothing().when(barMock).wait();
fooSpy.makeBarWait();
}
}
public class Bar{}
public class Foo {
private Bar bar;
public Bar getBar() {
return bar;
}
public void makeBarWait() throws InterruptedException {
// do something...
synchronized (this) {
getBar().wait();
}
}
}
은 내가이 오류를 받고 있어요 때문에 여전히 호출되는 방법을 생각한다. 당신은 당신이에 염탐 한 개체에 makeBarWait()
를 호출해야합니다
@Test
public void test() throws InterruptedException {
Foo foo = new Foo();
Foo fooSpy = PowerMockito.spy(foo);
Bar barMock = PowerMockito.mock(Bar.class);
PowerMockito.doReturn(barMock).when(fooSpy).getBar();
PowerMockito.doNothing().when(barMock).wait();
fooSpy.makeBarWait(); // <-----
}
테스트는 나를 위해 전달합니다.
@Duncan 위의 코드를 편집했습니다. – bsferreira
현재 문제를 재현 할 수 없기 때문에 "재현 할 수 없습니다"라는 이유로 질문을 마감하도록 투표했습니다. –