@Test(expected = RuntimeException.class) public void clickOn_shouldThrowIfViewIsDisabled() throws Exception { View view = new View(context); view.setEnabled(false); ShadowView.clickOn(view); }
@Test public void shouldAllowNullButtonListeners() throws Exception { AlertDialog.Builder builder = new AlertDialog.Builder(application); builder.setPositiveButton("OK", null); AlertDialog dialog = builder.create(); dialog.show(); ShadowView.clickOn(dialog.getButton(AlertDialog.BUTTON_POSITIVE)); }
@Test public void clickOn_shouldCallClickListener() throws Exception { View view = new View(context); shadowOf(view).setMyParent(ReflectionHelpers.createNullProxy(ViewParent.class)); OnClickListener testOnClickListener = mock(OnClickListener.class); view.setOnClickListener(testOnClickListener); ShadowView.clickOn(view); verify(testOnClickListener).onClick(view); }
@Test @Config(maxSdk = LOLLIPOP_MR1) public void DoneButtonShouldStartMapActivityOnVersionWithoutBackgroundRestriction() { // Shows welcome assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.btn_next).getVisibility()); assertEquals(View.GONE, welcomeActivity.findViewById(R.id.done).getVisibility()); assertTrue(welcomeActivity.findViewById(R.id.btn_next).isEnabled()); clickOn(welcomeActivity.findViewById(R.id.btn_next)); // Shows Done assertEquals(View.GONE, welcomeActivity.findViewById(R.id.btn_next).getVisibility()); assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.done).getVisibility()); assertFalse(welcomeActivity.findViewById(R.id.btn_next).isEnabled()); assertTrue(welcomeActivity.findViewById(R.id.done).isEnabled()); clickOn(welcomeActivity.findViewById(R.id.done)); Intent expectedIntent = new Intent(welcomeActivity, MapActivity.class); Intent actualIntent = ShadowApplication.getInstance().getNextStartedActivity(); assertEquals(expectedIntent.getComponent(), actualIntent.getComponent()); } }
@Test @Config(minSdk = M) public void DoneButtonShouldStartMapActivityOnVersionWithBackgroundRestriction() { // Shows welcome assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.btn_next).getVisibility()); assertEquals(View.GONE, welcomeActivity.findViewById(R.id.done).getVisibility()); assertTrue(welcomeActivity.findViewById(R.id.btn_next).isEnabled()); clickOn(welcomeActivity.findViewById(R.id.btn_next)); // Shows Restrictions assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.btn_next).getVisibility()); assertEquals(View.GONE, welcomeActivity.findViewById(R.id.done).getVisibility()); assertTrue(welcomeActivity.findViewById(R.id.btn_next).isEnabled()); clickOn(welcomeActivity.findViewById(R.id.btn_next)); // Shows done assertEquals(View.GONE, welcomeActivity.findViewById(R.id.btn_next).getVisibility()); assertEquals(View.VISIBLE, welcomeActivity.findViewById(R.id.done).getVisibility()); assertFalse(welcomeActivity.findViewById(R.id.btn_next).isEnabled()); assertTrue(welcomeActivity.findViewById(R.id.done).isEnabled()); clickOn(welcomeActivity.findViewById(R.id.done)); Intent expectedIntent = new Intent(welcomeActivity, MapActivity.class); Intent actualIntent = ShadowApplication.getInstance().getNextStartedActivity(); assertEquals(expectedIntent.getComponent(), actualIntent.getComponent()); }