I'm really lost with my error, I saw a lot of documentation and not able to find my error.
I'm testing a method service, which has a class and method inside:
@Service
public class myServiceImpl implements myService {
public void myMethod(MyObject myObject) throws Exception {
Object2 object2 = new Object2(myObject) // just some mapping and properties
MyClass myClass = new MyClass();
myClass.doStuff(object2); // this is a void method
}
}
so my test is like this:
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"javax.managenemt.*"}
public class MyServiceImplTest{
@InjectMocks
private MyServiceImpl myService;
@Test
public void myMethodTest() throws Exception {
MyClass myClass = mock(MyClass.class);
doNothing().when(myClass).doStuff(any());
MyObject myObject = //get from mock file, it works
myService.myMethod(myObject);
}
}
the test crashes because it the doStuff method is invoked, so my mock is not working.
What I'm doing wrong?