本文整理匯總了Java中org.robolectric.util.ActivityController.setup方法的典型用法代碼示例。如果您正苦於以下問題:Java ActivityController.setup方法的具體用法?Java ActivityController.setup怎麽用?Java ActivityController.setup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.robolectric.util.ActivityController
的用法示例。
在下文中一共展示了ActivityController.setup方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testPresenterReceivesPermissionWhenRequestedFromActivity
import org.robolectric.util.ActivityController; //導入方法依賴的package包/類
@Test
public void testPresenterReceivesPermissionWhenRequestedFromActivity() {
TodayWeatherPresenterBuilder builder = new TodayWeatherPresenterBuilder(
new TodayWeatherFragmentController(new TodayWeatherFragment(), MainActivity.class), provider)
.in(R.id.container);
TodayWeatherPresenterBuilder.BindingResult bindingResult = configurePresenter(builder, ViewType.REAL, PresenterType.MOCK);
TodayWeatherPresenter presenter = bindingResult.presenter();
ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class);
controller.setup();
String[] permissions = {Manifest.permission.ACCESS_COARSE_LOCATION};
int[] grantResults = {PackageManager.PERMISSION_GRANTED};
MainActivity mainActivity = controller.get();
mainActivity.onRequestPermissionsResult(1, permissions, grantResults);
verify(presenter).onEventPermissionsResult(eq(new PermissionEvent(1, permissions, grantResults)));
}
示例2: mainActivityReceivesErrorIfLoadingWeatherFails
import org.robolectric.util.ActivityController; //導入方法依賴的package包/類
@Test
public void mainActivityReceivesErrorIfLoadingWeatherFails() throws IOException
{
WeatherService weatherService = mock(WeatherService.class);
when(weatherService.getCurrentWeather(anyDouble(), anyDouble(), anyString()))
.thenThrow(new IOException("Loading weather failed: with some internal exception message..."));
LocationProvider locationProvider = mock(LocationProvider.class);
when(locationProvider.lastLocation()).thenReturn(createLocation(1.0, 1.0));
ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class);
controller.setup();
TodayWeatherPresenterBuilder builder = new TodayWeatherPresenterBuilder(
new TodayWeatherFragmentController(new TodayWeatherFragment(), MainActivity.class), provider)
.parameter(weatherService)
.parameter(locationProvider)
.in(R.id.container);
WeatherView mockView = mock(WeatherView.class);
doReturn(true).when(mockView).isPermissionGranted(anyString());
TodayWeatherPresenterBuilder.BindingResult bindingResult = configurePresenter(builder, mockView, PresenterType.REAL);
when(bindingResult.view().isPermissionGranted(anyString())).thenReturn(true);
assertTrue(ShadowToast.getTextOfLatestToast().startsWith("Loading weather failed:"));
}
示例3: startActivity
import org.robolectric.util.ActivityController; //導入方法依賴的package包/類
protected void startActivity(@NonNull final Intent intent) {
final ActivityController<ActivityT> controller = Robolectric.buildActivity(getActivityType()).withIntent(intent);
this.activity = controller.get();
this.presenter = mock(getPresenterType());
activity.presenter = presenter;
controller.setup();
this.view = activity.view;
}