org.robolectric.fakes.RoboMenuItem Java Examples
The following examples show how to use
org.robolectric.fakes.RoboMenuItem.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 6 votes |
@SuppressLint("NewApi") @Test public void testWebControls() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); activity.findViewById(R.id.button_more).performClick(); shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_in)); assertThat(shadowWebView.getZoomDegree()).isEqualTo(1); activity.findViewById(R.id.button_more).performClick(); shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_out)); assertThat(shadowWebView.getZoomDegree()).isEqualTo(0); activity.findViewById(R.id.button_forward).performClick(); assertThat(shadowWebView.getPageIndex()).isEqualTo(1); activity.findViewById(R.id.button_back).performClick(); assertThat(shadowWebView.getPageIndex()).isEqualTo(0); }
Example #2
Source File: FavoriteActivityTest.java From materialistic with Apache License 2.0 | 6 votes |
@Test public void testDelete() { RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0); holder.itemView.performLongClick(); ActionMode actionMode = mock(ActionMode.class); activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear)); AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog(); dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick(); assertEquals(2, adapter.getItemCount()); activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear)); dialog = ShadowAlertDialog.getLatestAlertDialog(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); verify(favoriteManager).remove(any(Context.class), selection.capture()); assertThat(selection.getValue()).contains("1"); verify(actionMode).finish(); when(favoriteManager.getSize()).thenReturn(1); observerCaptor.getValue().onChanged(); assertEquals(1, adapter.getItemCount()); }
Example #3
Source File: DeviceActivityTest.java From openwebnet-android with MIT License | 5 votes |
private void expectRequired(TextView view) { activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); verify(deviceService, never()).add(any(DeviceModel.class)); verify(deviceService, never()).update(any(DeviceModel.class)); assertEquals("bad validation", validationRequired, view.getError()); //assertTrue("bad focus", view.hasFocus()); }
Example #4
Source File: IpcamActivityTest.java From openwebnet-android with MIT License | 5 votes |
private IpcamModel common_onMenuSave_valid(String uuidExtra) { String IPCAM_NAME = "myName"; String IPCAM_URL = "http://myUrl"; String IPCAM_USERNAME = "myUsername"; String IPCAM_PASSWORD = "myPassword"; Integer IPCAM_ENVIRONMENT_SELECTED = 108; boolean IPCAM_FAVOURITE = true; when(environmentService.findAll()).thenReturn(Observable. just(Arrays.asList(newEnvironment(IPCAM_ENVIRONMENT_SELECTED, "env1")))); String IPCAM_UUID = uuidExtra != null ? uuidExtra : "myNewUuid"; when(ipcamService.add(any(IpcamModel.class))).thenReturn(Observable.just(IPCAM_UUID)); when(ipcamService.update(any(IpcamModel.class))).thenReturn(Observable.just(null)); createWithIntent(uuidExtra); editTextIpcamName.setText(IPCAM_NAME); editTextIpcamUrl.setText(IPCAM_URL); switchIpcamAuthentication.setChecked(true); editTextIpcamUsername.setText(IPCAM_USERNAME); editTextIpcamPassword.setText(IPCAM_PASSWORD); spinnerIpcamStreamType.setSelection(0); spinnerDeviceEnvironment.setSelection(0); checkBoxDeviceFavourite.setChecked(IPCAM_FAVOURITE); activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); IpcamModel ipcamModel = IpcamModel.updateBuilder(IPCAM_UUID) .name(IPCAM_NAME) .url(IPCAM_URL) .username(IPCAM_USERNAME) .password(IPCAM_PASSWORD) .streamType(IpcamModel.StreamType.MJPEG) .environment(IPCAM_ENVIRONMENT_SELECTED) .favourite(IPCAM_FAVOURITE) .build(); return ipcamModel; }
Example #5
Source File: IpcamActivityTest.java From openwebnet-android with MIT License | 5 votes |
private void expectViewError(TextView view, String error) { activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); verify(ipcamService, never()).add(any(IpcamModel.class)); verify(ipcamService, never()).update(any(IpcamModel.class)); assertEquals("should be required", error, view.getError()); // fix error: // The specified child already has a parent. You must call removeView() on the child's parent first. if (view.getParent() != null && view instanceof EditText) { ((ViewGroup) view.getParent()).removeView(view); } }
Example #6
Source File: LightActivityTest.java From openwebnet-android with MIT License | 5 votes |
private void expectRequired(TextView view) { activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); verify(lightService, never()).add(any(LightModel.class)); verify(lightService, never()).update(any(LightModel.class)); assertEquals("bad validation", validationRequired, view.getError()); //assertTrue("bad focus", view.hasFocus()); }
Example #7
Source File: AutomationActivityTest.java From openwebnet-android with MIT License | 5 votes |
private void expectRequired(TextView view) { activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); verify(automationService, never()).add(any(AutomationModel.class)); verify(automationService, never()).update(any(AutomationModel.class)); assertEquals("bad validation", validationRequired, view.getError()); //assertTrue("bad focus", view.hasFocus()); }
Example #8
Source File: TemperatureActivityTest.java From openwebnet-android with MIT License | 5 votes |
private TemperatureModel common_onMenuSave_valid(String uuidExtra) { String TEMPERATURE_NAME = "myName"; String TEMPERATURE_GATEWAY_SELECTED = "uuid2"; String TEMPERATURE_WHERE = "08"; Integer TEMPERATURE_ENVIRONMENT_SELECTED = 101; boolean TEMPERATURE_FAVOURITE = true; when(environmentService.findAll()).thenReturn(Observable. just(Arrays.asList(newEnvironment(TEMPERATURE_ENVIRONMENT_SELECTED, "env1")))); when(gatewayService.findAll()).thenReturn(Observable. just(Arrays.asList(newGateway(TEMPERATURE_GATEWAY_SELECTED, "2.2.2.2", 2)))); String TEMPERATURE_UUID = uuidExtra != null ? uuidExtra : "myNewUuid"; when(temperatureService.add(any(TemperatureModel.class))).thenReturn(Observable.just(TEMPERATURE_UUID)); when(temperatureService.update(any(TemperatureModel.class))).thenReturn(Observable.just(null)); createWithIntent(uuidExtra); editTextTemperatureName.setText(String.valueOf(TEMPERATURE_NAME)); editTextTemperatureWhere.setText(String.valueOf(TEMPERATURE_WHERE)); checkBoxDeviceFavourite.setChecked(TEMPERATURE_FAVOURITE); // for simplicity only 1 items spinnerDeviceEnvironment.setSelection(0); spinnerDeviceGateway.setSelection(0); activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); TemperatureModel temperatureMock = new TemperatureModel(); temperatureMock.setUuid(uuidExtra); temperatureMock.setName(TEMPERATURE_NAME); temperatureMock.setWhere(TEMPERATURE_WHERE); temperatureMock.setEnvironmentId(TEMPERATURE_ENVIRONMENT_SELECTED); temperatureMock.setGatewayUuid(TEMPERATURE_GATEWAY_SELECTED); temperatureMock.setFavourite(TEMPERATURE_FAVOURITE); return temperatureMock; }
Example #9
Source File: SoundActivityTest.java From openwebnet-android with MIT License | 5 votes |
private void expectRequired(TextView view) { activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); verify(soundService, never()).add(any(SoundModel.class)); verify(soundService, never()).update(any(SoundModel.class)); assertEquals("bad validation", validationRequired, view.getError()); //assertTrue("bad focus", view.hasFocus()); }
Example #10
Source File: ScenarioActivityTest.java From openwebnet-android with MIT License | 5 votes |
private ScenarioModel common_onMenuSave_valid(String uuidExtra) { String SCENARIO_NAME = "myName"; String SCENARIO_GATEWAY_SELECTED = "uuid2"; String SCENARIO_WHERE = "08"; Integer SCENARIO_ENVIRONMENT_SELECTED = 101; boolean SCENARIO_FAVOURITE = true; when(environmentService.findAll()).thenReturn(Observable. just(Arrays.asList(newEnvironment(SCENARIO_ENVIRONMENT_SELECTED, "env1")))); when(gatewayService.findAll()).thenReturn(Observable. just(Arrays.asList(newGateway(SCENARIO_GATEWAY_SELECTED, "2.2.2.2", 2)))); String SCENARIO_UUID = uuidExtra != null ? uuidExtra : "myNewUuid"; when(scenarioService.add(any(ScenarioModel.class))).thenReturn(Observable.just(SCENARIO_UUID)); when(scenarioService.update(any(ScenarioModel.class))).thenReturn(Observable.just(null)); createWithIntent(uuidExtra); editTextScenarioName.setText(String.valueOf(SCENARIO_NAME)); editTextScenarioWhere.setText(String.valueOf(SCENARIO_WHERE)); checkBoxDeviceFavourite.setChecked(SCENARIO_FAVOURITE); // for simplicity only 1 items spinnerDeviceEnvironment.setSelection(0); spinnerDeviceGateway.setSelection(0); activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); ScenarioModel scenarioModel = new ScenarioModel(); scenarioModel.setUuid(uuidExtra); scenarioModel.setName(SCENARIO_NAME); scenarioModel.setWhere(SCENARIO_WHERE); scenarioModel.setEnvironmentId(SCENARIO_ENVIRONMENT_SELECTED); scenarioModel.setGatewayUuid(SCENARIO_GATEWAY_SELECTED); scenarioModel.setFavourite(SCENARIO_FAVOURITE); return scenarioModel; }
Example #11
Source File: ScenarioActivityTest.java From openwebnet-android with MIT License | 5 votes |
private void expectRequired(TextView view) { activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); verify(scenarioService, never()).add(any(ScenarioModel.class)); verify(scenarioService, never()).update(any(ScenarioModel.class)); assertEquals("bad validation", validationRequired, view.getError()); //assertTrue("bad focus", view.hasFocus()); }
Example #12
Source File: FavoriteActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testRefresh() { RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0); holder.itemView.performLongClick(); ActionMode actionMode = mock(ActionMode.class); activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_refresh)); verify(syncScheduler).scheduleSync(any(), any()); verify(actionMode).finish(); }
Example #13
Source File: FavoriteActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Test public void testVoteItem() { shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick(); PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu(); Assert.assertNotNull(popupMenu); shadowOf(popupMenu).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote)); verify(userServices).voteUp(any(Context.class), any(), userServicesCallback.capture()); userServicesCallback.getValue().onDone(true); assertEquals(activity.getString(R.string.voted), ShadowToast.getTextOfLatestToast()); }
Example #14
Source File: FavoriteActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Test public void testVoteItemPromptToLogin() { shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick(); PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu(); Assert.assertNotNull(popupMenu); shadowOf(popupMenu).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote)); verify(userServices).voteUp(any(Context.class), any(), userServicesCallback.capture()); userServicesCallback.getValue().onDone(false); assertThat(shadowOf(activity).getNextStartedActivity()) .hasComponent(activity, LoginActivity.class); }
Example #15
Source File: FavoriteActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Test public void testVoteItemFailed() { shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick(); PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu(); Assert.assertNotNull(popupMenu); shadowOf(popupMenu).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote)); verify(userServices).voteUp(any(Context.class), any(), userServicesCallback.capture()); userServicesCallback.getValue().onError(new IOException()); assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast()); }
Example #16
Source File: FavoriteActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Test public void testShare() { TestApplication.addResolver(new Intent(Intent.ACTION_SEND)); shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick(); PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu(); Assert.assertNotNull(popupMenu); shadowOf(popupMenu).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_share)); assertThat(shadowOf(activity).getNextStartedActivity()) .hasAction(Intent.ACTION_SEND); }
Example #17
Source File: FavoriteActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Test public void testReply() { shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick(); PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu(); Assert.assertNotNull(popupMenu); shadowOf(popupMenu).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_comment)); assertThat(shadowOf(activity).getNextStartedActivity()) .hasComponent(activity, ComposeActivity.class); }
Example #18
Source File: SoundActivityTest.java From openwebnet-android with MIT License | 4 votes |
private SoundModel common_onMenuSave_valid(String uuidExtra) { String SOUND_NAME = "myName"; String SOUND_GATEWAY_SELECTED = "uuid2"; String SOUND_WHERE = "08"; SoundSystem.Source SOUND_SOURCE = SoundSystem.Source.STEREO_CHANNEL; SoundSystem.Type SOUND_TYPE = SoundSystem.Type.AMPLIFIER_P2P; Integer SOUND_ENVIRONMENT_SELECTED = 101; boolean SOUND_FAVOURITE = true; when(environmentService.findAll()).thenReturn(Observable. just(Arrays.asList(newEnvironment(SOUND_ENVIRONMENT_SELECTED, "env1")))); when(gatewayService.findAll()).thenReturn(Observable. just(Arrays.asList(newGateway(SOUND_GATEWAY_SELECTED, "2.2.2.2", 2)))); String SOUND_UUID = uuidExtra != null ? uuidExtra : "myNewUuid"; when(soundService.add(any(SoundModel.class))).thenReturn(Observable.just(SOUND_UUID)); when(soundService.update(any(SoundModel.class))).thenReturn(Observable.just(null)); createWithIntent(uuidExtra); checkBoxDeviceFavourite.setChecked(SOUND_FAVOURITE); // for simplicity only 1 items spinnerDeviceEnvironment.setSelection(0); spinnerDeviceGateway.setSelection(0); spinnerSoundType.setSelection(2); editTextSoundName.setText(String.valueOf(SOUND_NAME)); editTextSoundWhere.setText(String.valueOf(SOUND_WHERE)); activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); SoundModel soundMock = new SoundModel(); soundMock.setUuid(uuidExtra); soundMock.setName(SOUND_NAME); soundMock.setWhere(SOUND_WHERE); soundMock.setSoundSystemSource(SOUND_SOURCE); soundMock.setSoundSystemType(SOUND_TYPE); soundMock.setEnvironmentId(SOUND_ENVIRONMENT_SELECTED); soundMock.setGatewayUuid(SOUND_GATEWAY_SELECTED); soundMock.setFavourite(SOUND_FAVOURITE); return soundMock; }
Example #19
Source File: LightActivityTest.java From openwebnet-android with MIT License | 4 votes |
private LightModel common_onMenuSave_valid(String uuidExtra) { String LIGHT_NAME = "myName"; String LIGHT_GATEWAY_SELECTED = "uuid2"; String LIGHT_WHERE = "08"; String LIGHT_BUS = Lighting.NO_BUS; Lighting.Type LIGHT_TYPE = Lighting.Type.POINT_TO_POINT; Integer LIGHT_ENVIRONMENT_SELECTED = 101; boolean LIGHT_FAVOURITE = true; when(environmentService.findAll()).thenReturn(Observable. just(Arrays.asList(newEnvironment(LIGHT_ENVIRONMENT_SELECTED, "env1")))); when(gatewayService.findAll()).thenReturn(Observable. just(Arrays.asList(newGateway(LIGHT_GATEWAY_SELECTED, "2.2.2.2", 2)))); String LIGHT_UUID = uuidExtra != null ? uuidExtra : "myNewUuid"; when(lightService.add(any(LightModel.class))).thenReturn(Observable.just(LIGHT_UUID)); when(lightService.update(any(LightModel.class))).thenReturn(Observable.just(null)); createWithIntent(uuidExtra); checkBoxDeviceFavourite.setChecked(LIGHT_FAVOURITE); // for simplicity only 1 items spinnerDeviceEnvironment.setSelection(0); spinnerDeviceGateway.setSelection(0); spinnerLightType.setSelection(6); editTextLightName.setText(String.valueOf(LIGHT_NAME)); editTextLightWhere.setText(String.valueOf(LIGHT_WHERE)); editTextLightBus.setText(String.valueOf(LIGHT_BUS)); activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); LightModel lightMock = new LightModel(); lightMock.setUuid(uuidExtra); lightMock.setName(LIGHT_NAME); lightMock.setWhere(LIGHT_WHERE); lightMock.setLightingType(LIGHT_TYPE); lightMock.setBus(LIGHT_BUS); lightMock.setEnvironmentId(LIGHT_ENVIRONMENT_SELECTED); lightMock.setGatewayUuid(LIGHT_GATEWAY_SELECTED); lightMock.setFavourite(LIGHT_FAVOURITE); return lightMock; }
Example #20
Source File: AutomationActivityTest.java From openwebnet-android with MIT License | 4 votes |
private AutomationModel common_onMenuSave_valid(String uuidExtra) { String AUTOMATION_NAME = "myName"; String AUTOMATION_GATEWAY_SELECTED = "uuid2"; String AUTOMATION_WHERE = "08"; Integer AUTOMATION_ENVIRONMENT_SELECTED = 101; boolean AUTOMATION_FAVOURITE = true; Automation.Type AUTOMATION_TYPE = Automation.Type.POINT_TO_POINT; String AUTOMATION_BUS = Automation.NO_BUS; when(environmentService.findAll()).thenReturn(Observable. just(Arrays.asList(newEnvironment(AUTOMATION_ENVIRONMENT_SELECTED, "env1")))); when(gatewayService.findAll()).thenReturn(Observable. just(Arrays.asList(newGateway(AUTOMATION_GATEWAY_SELECTED, "2.2.2.2", 2)))); String AUTOMATION_UUID = uuidExtra != null ? uuidExtra : "myNewUuid"; when(automationService.add(any(AutomationModel.class))).thenReturn(Observable.just(AUTOMATION_UUID)); when(automationService.update(any(AutomationModel.class))).thenReturn(Observable.just(null)); createWithIntent(uuidExtra); checkBoxDeviceFavourite.setChecked(AUTOMATION_FAVOURITE); // for simplicity only 1 items spinnerDeviceEnvironment.setSelection(0); spinnerDeviceGateway.setSelection(0); spinnerAutomationType.setSelection(6); editTextAutomationName.setText(String.valueOf(AUTOMATION_NAME)); editTextAutomationWhere.setText(String.valueOf(AUTOMATION_WHERE)); editTextAutomationBus.setText(String.valueOf(AUTOMATION_BUS)); activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); AutomationModel automationMock = new AutomationModel(); automationMock.setUuid(uuidExtra); automationMock.setName(AUTOMATION_NAME); automationMock.setWhere(AUTOMATION_WHERE); automationMock.setAutomationType(AUTOMATION_TYPE); automationMock.setBus(AUTOMATION_BUS); automationMock.setEnvironmentId(AUTOMATION_ENVIRONMENT_SELECTED); automationMock.setGatewayUuid(AUTOMATION_GATEWAY_SELECTED); automationMock.setFavourite(AUTOMATION_FAVOURITE); return automationMock; }
Example #21
Source File: TemperatureActivityTest.java From openwebnet-android with MIT License | 4 votes |
private void expectRequired(TextView view) { activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); verify(temperatureService, never()).add(any(TemperatureModel.class)); verify(temperatureService, never()).update(any(TemperatureModel.class)); assertEquals("bad validation", validationRequired, view.getError()); }
Example #22
Source File: WebFragmentLocalTest.java From materialistic with Apache License 2.0 | 4 votes |
@Test public void testMenu() { TestWebItem item = new TestWebItem() { @NonNull @Override public String getType() { return STORY_TYPE; } @Override public String getId() { return "1"; } @Override public String getUrl() { return String.format(HackerNewsClient.WEB_ITEM_PATH, "1"); } @Override public String getDisplayedTitle() { return "Ask HN"; } }; Intent intent = new Intent(); intent.putExtra(WebActivity.EXTRA_ITEM, item); controller = Robolectric.buildActivity(WebActivity.class, intent); controller.create().start().resume().visible(); activity = controller.get(); verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture()); listener.getValue().onResponse(new TestItem() { @Override public String getText() { return "text"; } }); Fragment fragment = activity.getSupportFragmentManager() .findFragmentByTag(WebFragment.class.getName()); assertTrue(fragment.hasOptionsMenu()); fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_font_options)); assertNotNull(ShadowDialog.getLatestDialog()); PreferenceManager.getDefaultSharedPreferences(activity) .edit() .putString(activity.getString(R.string.pref_readability_font), "DroidSans.ttf") .apply(); WebView webView = activity.findViewById(R.id.web_view); ShadowWebView shadowWebView = shadowOf(webView); shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank"); assertThat(shadowWebView.getLastLoadDataWithBaseURL().data) .contains("text") .contains("DroidSans.ttf"); }
Example #23
Source File: EnergyActivityTest.java From openwebnet-android with MIT License | 4 votes |
private EnergyModel common_onMenuSave_valid(String uuidExtra) { String ENERGY_NAME = "myName"; String ENERGY_GATEWAY_SELECTED = "uuid2"; String ENERGY_WHERE = "08"; EnergyManagement.Version ENERGY_VERSION = EnergyManagement.Version.MODEL_F523_A; Integer ENERGY_ENVIRONMENT_SELECTED = 101; boolean ENERGY_FAVOURITE = true; when(environmentService.findAll()).thenReturn(Observable. just(Arrays.asList(newEnvironment(ENERGY_ENVIRONMENT_SELECTED, "env1")))); when(gatewayService.findAll()).thenReturn(Observable. just(Arrays.asList(newGateway(ENERGY_GATEWAY_SELECTED, "2.2.2.2", 2)))); String ENERGY_UUID = uuidExtra != null ? uuidExtra : "myNewUuid"; when(energyService.add(any(EnergyModel.class))).thenReturn(Observable.just(ENERGY_UUID)); when(energyService.update(any(EnergyModel.class))).thenReturn(Observable.just(null)); createWithIntent(uuidExtra); editTextEnergyName.setText(String.valueOf(ENERGY_NAME)); editTextEnergyWhere.setText(String.valueOf(ENERGY_WHERE)); checkBoxDeviceFavourite.setChecked(ENERGY_FAVOURITE); spinnerEnergyVersion.setSelection(1); // for simplicity only 1 items spinnerDeviceEnvironment.setSelection(0); spinnerDeviceGateway.setSelection(0); activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); EnergyModel energyModelMock = new EnergyModel(); energyModelMock.setUuid(uuidExtra); energyModelMock.setName(ENERGY_NAME); energyModelMock.setWhere(ENERGY_WHERE); energyModelMock.setEnergyManagementVersion(ENERGY_VERSION); energyModelMock.setEnvironmentId(ENERGY_ENVIRONMENT_SELECTED); energyModelMock.setGatewayUuid(ENERGY_GATEWAY_SELECTED); energyModelMock.setFavourite(ENERGY_FAVOURITE); return energyModelMock; }
Example #24
Source File: EnergyActivityTest.java From openwebnet-android with MIT License | 4 votes |
private void expectRequired(TextView view) { activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); verify(energyService, never()).add(any(EnergyModel.class)); verify(energyService, never()).update(any(EnergyModel.class)); assertEquals("bad validation", validationRequired, view.getError()); }
Example #25
Source File: DeviceActivityTest.java From openwebnet-android with MIT License | 4 votes |
private DeviceModel common_onMenuSave_valid(String uuidExtra) { String DEVICE_NAME = "myName"; String DEVICE_GATEWAY_SELECTED = "uuid8"; String DEVICE_REQUEST = "myRequest"; String DEVICE_RESPONSE = "myResponse"; Integer DEVICE_ENVIRONMENT_SELECTED = 108; boolean DEVICE_FAVOURITE = true; boolean DEVICE_RUN_ON_LOAD = true; boolean DEVICE_SHOW_CONFIRMATION = false; when(environmentService.findAll()).thenReturn(Observable. just(Arrays.asList(newEnvironment(DEVICE_ENVIRONMENT_SELECTED, "env8")))); when(gatewayService.findAll()).thenReturn(Observable. just(Arrays.asList(newGateway(DEVICE_GATEWAY_SELECTED, "8.8.8.8", 8)))); String DEVICE_UUID = uuidExtra != null ? uuidExtra : "myNewUuid"; when(deviceService.add(any(DeviceModel.class))).thenReturn(Observable.just(DEVICE_UUID)); when(deviceService.update(any(DeviceModel.class))).thenReturn(Observable.just(null)); createActivityWithIntent(uuidExtra, null, null); editTextDeviceName.setText(DEVICE_NAME); editTextDeviceRequest.setText(DEVICE_REQUEST); editTextDeviceResponse.setText(DEVICE_RESPONSE); checkBoxDeviceFavourite.setChecked(DEVICE_FAVOURITE); checkBoxDeviceRunOnLoad.setChecked(DEVICE_RUN_ON_LOAD); checkBoxDeviceConfirm.setChecked(DEVICE_SHOW_CONFIRMATION); checkBoxDeviceAccept.setChecked(true); spinnerDeviceEnvironment.setSelection(0); spinnerDeviceGateway.setSelection(0); activity.onOptionsItemSelected(new RoboMenuItem(R.id.action_device_save)); return DeviceModel.updateBuilder(DEVICE_UUID) .name(DEVICE_NAME) .request(DEVICE_REQUEST) .response(DEVICE_RESPONSE) .environment(DEVICE_ENVIRONMENT_SELECTED) .gateway(DEVICE_GATEWAY_SELECTED) .favourite(DEVICE_FAVOURITE) .runOnLoad(DEVICE_RUN_ON_LOAD) .showConfirmation(DEVICE_SHOW_CONFIRMATION) .build(); }
Example #26
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 4 votes |
@Test public void testReadabilityToggle() { activity.fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_readability)); verify(readabilityClient).parse(any(), eq("http://example.com"), any()); }
Example #27
Source File: ItemActivityTest.java From materialistic with Apache License 2.0 | 4 votes |
@SuppressLint("NewApi") @Test public void testOptionExternal() { ShadowPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager()); packageManager.addResolveInfoForIntent( new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity")); packageManager.addResolveInfoForIntent( new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"))), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity")); Intent intent = new Intent(); intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() { @NonNull @Override public String getType() { return STORY_TYPE; } @Override public String getUrl() { return "http://example.com"; } @Override public boolean isStoryType() { return true; } @Override public String getId() { return "1"; } }); controller = Robolectric.buildActivity(ItemActivity.class, intent); controller.create().start().resume(); activity = controller.get(); // inflate menu, see https://github.com/robolectric/robolectric/issues/1326 ShadowLooper.pauseMainLooper(); controller.visible(); ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable(); // open article shadowOf(activity).clickMenuItem(R.id.menu_external); shadowOf(ShadowPopupMenu.getLatestPopupMenu()) .getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_article)); ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable(); assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW); // open item shadowOf(activity).clickMenuItem(R.id.menu_external); shadowOf(ShadowPopupMenu.getLatestPopupMenu()) .getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_comments)); ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable(); assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW); }
Example #28
Source File: ItemActivityTest.java From materialistic with Apache License 2.0 | 4 votes |
@SuppressLint("NewApi") @Test public void testShare() { TestApplication.addResolver(new Intent(Intent.ACTION_SEND)); Intent intent = new Intent(); intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() { @NonNull @Override public String getType() { return STORY_TYPE; } @Override public String getUrl() { return "http://example.com"; } @Override public boolean isStoryType() { return true; } @Override public String getId() { return "1"; } }); controller = Robolectric.buildActivity(ItemActivity.class, intent); controller.create().start().resume(); activity = controller.get(); // inflate menu, see https://github.com/robolectric/robolectric/issues/1326 ShadowLooper.pauseMainLooper(); controller.visible(); ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable(); // share article shadowOf(activity).clickMenuItem(R.id.menu_share); shadowOf(ShadowPopupMenu.getLatestPopupMenu()) .getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_article)); ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable(); Intent actual = shadowOf(activity).getNextStartedActivity(); assertThat(actual) .hasAction(Intent.ACTION_SEND); // share item shadowOf(activity).clickMenuItem(R.id.menu_share); shadowOf(ShadowPopupMenu.getLatestPopupMenu()) .getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_comments)); ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable(); actual = shadowOf(activity).getNextStartedActivity(); assertThat(actual) .hasAction(Intent.ACTION_SEND); }