Skip to content

Instantly share code, notes, and snippets.

@roman-mazur
Last active December 21, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roman-mazur/6316618 to your computer and use it in GitHub Desktop.
Save roman-mazur/6316618 to your computer and use it in GitHub Desktop.
Robolectric PhoneWindow test error example. Pull request: https://github.com/robolectric/robolectric/pull/659
package com.chuze.ui.activity.test;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import static org.fest.assertions.api.Assertions.*;
@RunWith(RobolectricTestRunner.class)
public class AppCompatTest {
/** Activity under the test. */
private ActionBarActivity activity;
@Before
public void create() {
activity = Robolectric.buildActivity(ActionBarActivity.class).attach().create().get();
}
@Test
public void activityShouldBeCreated() {
assertThat(activity).isNotNull();
}
@Test
public void shouldChangeDisplayOptions() {
activity.getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
assertThat(activity.getSupportActionBar().getDisplayOptions()).isEqualTo(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
}
@Test
public void shouldChangeTitle() {
activity.getSupportActionBar().setTitle("custom title");
assertThat(activity.getTitle()).isEqualTo("custom title");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment