I have problem with unit test. Below is the sample code snippet. I have mock a bean and inject into @configuration class and use the mocked property to create another bean.
In the below, if i inspect, b.getSomething() returning me the default value like "" for string, 0 for int. etc. I am not getting the mocked value. Any idea how to do?
@Configuration
class A{
@Autowired B b;
@Bean
public SomeClass someBean(){
SomeClass clas = new SomeClass();
clas.setSomething(b.getSomething());
return clas;
}
}
@ContextConfiguration(classes = { A.class}, loader = SpringockitoAnnotatedContextLoader.class)
class ATest{
@ReplaceWithMock
@Autowired
B b;
@Before
public void setup(){
Mockito.when(b.getSomething()).thenReturn("ABC");
}
}