ServerFoundActivity extends BaseActivity implements ServerFoundView { public static Intent getCallingIntent(Context context, ServerModel serverModel) { Intent intent = new Intent(context, ServerFoundActivity.class); Bundle bundle = new Bundle(); bundle.putParcelable(KEY_SERVER, serverModel); intent.putExtras(bundle); return intent; }  static Intent getCallingIntent(Context context, ServerModel serverModel); @Override boolean onOptionsItemSelected(MenuItem item); @Override void renderServer(@NonNull ServerModel serverModel); @Override void showError(@NonNull String errorMessage); @Override void navigateBack(boolean isSuccess, ServerModel serverModel); @OnClick(R.id.button_connect) void onConnectButtonClick(View view); static final String KEY_SERVER; }
@Test public void shouldCreateValidCallingIntent() throws Exception { Context mockContext = mock(Context.class); ServerModel serverModel = getServerModel(); Intent callingIntent = ServerFoundActivity.getCallingIntent(mockContext, serverModel); assertThat(callingIntent, notNullValue()); Bundle extras = callingIntent.getExtras(); assertThat(extras, notNullValue()); assertThat(extras.containsKey(ServerFoundActivity.KEY_SERVER), is(true)); assertThat(extras.getParcelable(ServerFoundActivity.KEY_SERVER), notNullValue()); assertThat(extras.getParcelable(ServerFoundActivity.KEY_SERVER), instanceOf(ServerModel.class)); ServerModel actualServerModel = extras.getParcelable(ServerFoundActivity.KEY_SERVER); assertThat(actualServerModel, notNullValue()); assertThat(actualServerModel.ip(), notNullValue()); assertThat(actualServerModel.ip(), is("192.168.15.47")); }
@Test public void shouldPassServerModelToPresenterWhenGiven() throws Exception { Context mockContext = mock(Context.class); ServerModel serverModel = getServerModel(); Intent callingIntent = ServerFoundActivity.getCallingIntent(mockContext, serverModel); ServerFoundActivity serverFoundActivityWithIntent = Robolectric.buildActivity(ServerFoundActivity.class, callingIntent) .create() .get(); verify(mockServerFoundPresenter, times(1)).setServer(any(ServerModel.class)); }