I have a bean:
class Bean {
public Bean(String name, Integer number, Resource... resources ) {
// ...
}
}
I want to mock constructor of the bean. Here is my test:
@Test
public void shouldReturnMockedBean() throws Exception {
PowerMockito.whenNew(Bean.class)
.withArguments(
Mockito.anyString(),
Mockito.anyInt(),
Mockito.<Resource>anyVararg()
).thenReturn(beanMock);
Bean bean = new Bean("abc", 1);
Assert.assertNotNull(bean);
}
I also use PowerMockito
annotation in my test class:
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bean.class})
But I get an error a null
instead of my mock. What I'm doing wrong here?