jeudi 26 novembre 2015

Mockito- mock field in class

I have got a question connected with Mockito framework. Is there any way to mocka field inside a class? Lets say we have got:

@Component
public class A{

@Autowired
 B b;

public methodExample(){ b.doSth();}
}


public class C{

@Autowired
A a;
@Test
public void testMethodExample(){
...}
}

Is there any possibility to mock B object in order to impose return value of method doSth? I know I can pass mocked object as an argument of constructor but I wonder if there is any other option?

Aucun commentaire:

Enregistrer un commentaire