ロジックPowerMockito:未完のスタブが検出された(未完成スタブ例外)
public class Logic {
String date = (LocalDateTime.now()).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
}
モックコード
私は上記の機能のためのJUnitテストケースを記述しようとしています@RunWith(PowerMockRunner.class)
@PrepareForTest({ LocalDateTime.class })
public class LogicTest {
@InjectMocks
Logic target = new Logic();
PowerMockito.mockStatic(LocalDateTime.class);
when(LocalDateTime.now()).thenReturn(LocalDateTime.of(2017, 8, 24, 8, 50, 9));
}
、例外「UnfinishedStubbingException」示されています。
私は他の回答を読んだが、それ以降もエラーの理由を理解できません。
'LocalDateTime.of(2017,8,24,8,50,9)'の値を中間変数に格納し、その変数を 'thenReturn'パラメータとして渡すことができますか? – Berger
'(...'のときにはメソッドがありません –
@Berger It Worked! ありがとう! –