単体テストに問題があります。以下は、サンプル コード スニペットです。Bean をモックして @configuration クラスに注入し、モックされたプロパティを使用して別の Bean を作成します。
以下では、検査すると、b.getSomething() は文字列の場合は ""、int の場合は 0 などのデフォルト値を返します。など。嘲笑された値が得られません。どうすればいいですか?
@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");
}
}