Я пытаюсь запустить тест для фрагмента Dialog, который привязан к viewId в своей активности хостинга
@Test
public void largeScreenDeviceUsesPopup() {
final FragmentUtilActivity fragmentActivity = new FragmentUtilActivity();
fragmentActivity.onCreate(null);
myDialogFragment = MyDialogFragment.create(FragmentUtilActivity.anchorId);
myDialogFragment.showNow(fragmentActivity.getSupportFragmentManager(), "");
assertThat(....)
}
private static class FragmentUtilActivity extends FragmentActivity {
public static int anchorId = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout view = new LinearLayout(this);
view.setId(anchorId);
setContentView(view);
}
}
однако я получаю эту ошибку:
Your activity is not yet attached to the Application instance. You can't request ViewModel before onCreate call.
как я могу это исправить?