Java 类org.robolectric.shadows.ShadowPreferenceManager 实例源码

项目:AluShare    文件:FileTabFragmentTest.java   
@Before
public void setUp() {
    DummyDataSet.copyDataSet("ASDB_Tabs.db");
    helper = HelperFactory.getFileHelper(context);
    files = helper.getFiles();

    activity = Robolectric.buildActivity(TestActivity.class).create().start().resume().get();
    fragment = FileTabFragment.createInstance();
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.fragment_container, fragment);
    fragmentTransaction.commit();

    recyclerView = (RecyclerView) fragment.getView().findViewById(R.id.recyclerView);
    adapter = (FileTabRecyclerAdapter) recyclerView.getAdapter();
    manager = (LinearLayoutManager) recyclerView.getLayoutManager();

    menu = new MenuBuilder(activity);
    inflater = new MenuInflater(activity);

    preferences = ShadowPreferenceManager.getDefaultSharedPreferences(context);
}
项目:whereat-android    文件:OnOffActivityTest.java   
@Test
public void onCreate_should_initializeActivityAndApplicationCorrectly() {

    assertThat(a.mLocPubMgr).isNotNull();
    assertThat(a.mReceivers).isNotNull();
    assertThat(a.mMenu).isNotNull();

    assertThat(a.mPolling).isTrue();
    assertThat(a.mSecAlerted).isFalse();

    assertThat(
        ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application)
    ).isNotNull();

    assertThat(a.findViewById(R.id.go_button)).isNotNull();
}
项目:gearshift    文件:TransmissionSessionManagerTest.java   
@Before public void setUp() throws Exception {
    defaultPrefs = ShadowPreferenceManager.getDefaultSharedPreferences(
            RuntimeEnvironment.application.getApplicationContext());

    connMananager = mock(ConnectivityManager.class);
    when(connMananager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class));

    profile = mock(TransmissionProfile.class);
    when(profile.getTimeout()).thenReturn(1);
    when(profile.getId()).thenReturn("existingId");

    Activity activity = Robolectric.buildActivity(Activity.class).create().get();

    dataSource = new DataSource(activity);
    dataSource.open();

    connProvider = mock(ConnectionProvider.class);
    connection = new HttpsURLConnectionTest(new URL("http://example.com"));
    connection.outputStream = new ByteArrayOutputStream();
    when(connProvider.open(profile)).thenReturn(connection);

    manager = new TransmissionSessionManager(connMananager, defaultPrefs, profile,
        dataSource, connProvider);
}
项目:AluShare    文件:MainActivityTest.java   
@Test
public void testClickPauseAndReturn() {
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    shadowActivity.pauseAndThenResume();
    SharedPreferences p = ShadowPreferenceManager.getDefaultSharedPreferences(activity);
    assertTrue(p.getInt("POSITION_PAGER", -5) == 1);

    pager.setCurrentItem(0);
    shadowActivity.pauseAndThenResume();

    assertEquals(p.getInt("POSITION_PAGER", -5), 0);
}
项目:talkback    文件:KeyboardActionTest.java   
@Before
public void setUp() {
    mSharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(mContext);
    setupPreferenceForAction(mBackKeyDownEvent, R.string.pref_key_mapped_to_back_key);
    setupPreferenceForAction(mClickKeyDownEvent, R.string.pref_key_mapped_to_click_key);
    mCalledAction = null;
    mClickKeyboardAction.refreshPreferences(mContext);
}
项目:CCDroid    文件:PreferencesTest.java   
@Before public void setUp() throws Exception {
    Application application = RuntimeEnvironment.application;
    Context context = application.getApplicationContext();
    sharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(context);
    preferences = new Preferences(sharedPreferences);
    dummyUrl = "https://ccdroid.github.io";
}
项目:whereat-android    文件:LocationPublisherTest.java   
@Before
public void setup() {
    lp = spy(LocationPublisher.class);
    lp.mGoogClient = mock(GoogleApiClient.class);
    lp.mLocProvider = mock(FusedLocationProviderApi.class);

    shadowOf(RuntimeEnvironment.application)
        .setComponentNameAndServiceForBindService(
            new ComponentName("org.tlc.whereat.modules.pubsub", "LocationPublisher"),
            mock(IBinder.class));

    lp.mPrefs = ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application);
    lp.mPrefListener = lp.buildPrefListener();
    lp.mPrefs.registerOnSharedPreferenceChangeListener(lp.mPrefListener);
}
项目:lib    文件:BooleanPreferenceTest.java   
@SuppressLint("CommitPrefEdits") @Before public void setUp() {
  sharedPreferences =
      ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application);
  initMocks(this);
  given(mockSharedPreferences.edit()).willReturn(mockEditor);
  given(mockEditor.remove(anyString())).willReturn(mockEditor);
}
项目:lib    文件:BasePreferenceTest.java   
@SuppressLint("CommitPrefEdits") @Before public void setUp() {
  sharedPreferences =
      ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application);
  initMocks(this);
  given(mockSharedPreferences.edit()).willReturn(mockEditor);
  given(mockEditor.remove(anyString())).willReturn(mockEditor);
}
项目:lib    文件:StringPreferenceTest.java   
@SuppressLint("CommitPrefEdits") @Before public void setUp() {
  sharedPreferences =
      ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application);
  initMocks(this);
  given(mockSharedPreferences.edit()).willReturn(mockEditor);
  given(mockEditor.remove(anyString())).willReturn(mockEditor);
}
项目:gearshift    文件:DataSourceTest.java   
@Before public void setUp() throws Exception {
    Activity activity = Robolectric.buildActivity(Activity.class).create().get();
    helper = new SQLiteHelper(activity.getApplicationContext());
    assertNotNull(helper);

    ds = new DataSource(activity, helper);
    assertNotNull(ds);

    defaultPrefs = ShadowPreferenceManager.getDefaultSharedPreferences(
            RuntimeEnvironment.application.getApplicationContext());

    defaultPrefs.edit().putString(G.PREF_LIST_SORT_BY, G.SortBy.QUEUE.name()).commit();
}
项目:gearshift    文件:TransmissionProfileTest.java   
@Before public void setUp() {
    defaultPrefs = ShadowPreferenceManager.getDefaultSharedPreferences(
            RuntimeEnvironment.application.getApplicationContext());
    prefs = ShadowApplication.getInstance().getSharedPreferences(
            "profiles", Activity.MODE_PRIVATE);
    context = mock(Context.class);

    when(context.getFilesDir()).thenReturn(new File("/mock/dir"));

    when(
        context.getSharedPreferences(TransmissionProfile.getPreferencesName(), Activity.MODE_PRIVATE)
    ).thenReturn(prefs);

    prefs.edit().putString(G.PREF_NAME + existingId, "name").commit();
    prefs.edit().putString(G.PREF_HOST + existingId, "host").commit();
    prefs.edit().putString(G.PREF_PORT + existingId, "9911").commit();
    prefs.edit().putString(G.PREF_PATH + existingId, "/transmission/rpc").commit();
    prefs.edit().putString(G.PREF_USER + existingId, "").commit();
    prefs.edit().putString(G.PREF_PASS + existingId, "").commit();
    prefs.edit().putBoolean(G.PREF_SSL + existingId, true).commit();
    prefs.edit().putString(G.PREF_TIMEOUT + existingId, "2").commit();
    prefs.edit().putString(G.PREF_RETRIES + existingId, "15").commit();
    Set<String> directories = new HashSet<>();
    directories.add("/foo");
    directories.add("/bar/baz");
    prefs.edit().putStringSet(G.PREF_DIRECTORIES + existingId, directories).commit();
    prefs.edit().putString(G.PREF_LAST_DIRECTORY + existingId, "/alpha").commit();
    prefs.edit().putBoolean(G.PREF_MOVE_DATA + existingId, true).commit();
    prefs.edit().putBoolean(G.PREF_DELETE_LOCAL + existingId, false).commit();
    prefs.edit().putBoolean(G.PREF_START_PAUSED + existingId, false).commit();
}
项目:invio    文件:MapActivityTest.java   
@Before
public void setup() {

    resources = Robolectric.application.getResources();

    // During the creation of the test activity (MapActivity) some http-requests are sent to get the
    // tilemapresource.xml, the fingerprints and other data from the map server. Robolectric gives us the
    //  ability to fake the responses to these requests and put our data into the response body.

    // Respond to the tilemapdatasource.xml request with real data
    Robolectric.addHttpResponseRule(getTileMapResourceRequestMatcher(), getTileMapResourceResponse());

    // This line is required because Robolectric will inform us about unexpected requests via System.err
    Robolectric.addHttpResponseRule(getGeneralMapDataMatcher(), getGeneralMapDataResponse());

    // For any other unexpected requests response with 400 BAD REQUEST
    Robolectric.setDefaultHttpResponse(400, "Bad Request");

    // Create an intent and put the map name into its extras, but remember that we fake the responses so
    // it will not call the real server anyway and the map name can be whatever.
    Intent intent = new Intent(Robolectric.getShadowApplication().getApplicationContext(), MapActivity.class);
    intent.putExtra("MapName", "foo");

    //Create the activity and set our mock UserLocator to it
    activity = Robolectric.buildActivity(MapActivityWrapper.class).withIntent(intent).create().get();
    userLocator = mock(UserLocator.class);
    activity.setUserLocator(userLocator);

    sharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(Robolectric.application.getApplicationContext());
    sharedPreferences.edit().clear().commit();

    ParticleFilter pf = mock(ParticleFilter.class);
    when(userLocator.getParticleFilter()).thenReturn(pf);
}
项目:tedroid    文件:TetrominoTest.java   
@Before
public void setUp() throws Exception {
    dummyActivity = Robolectric.buildActivity(Activity.class).create().get();
    assertThat(dummyActivity).isNotNull();

    SharedPreferences sharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(Robolectric.application.getApplicationContext());
    sharedPreferences
        .edit()
        .putBoolean(Robolectric.application.getString(R.string.sounds_switch_key), false)
        .commit();
}
项目:tedroid    文件:GameBoardViewTest.java   
@Before
public void setUp() throws Exception {
    dummyActivity = Robolectric.buildActivity(Activity.class).create().get();
    assertThat(dummyActivity).isNotNull();

    SharedPreferences sharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(Robolectric.application.getApplicationContext());
    sharedPreferences
        .edit()
        .putBoolean(Robolectric.application.getString(R.string.sounds_switch_key), false)
        .commit();
}
项目:whereat-android    文件:SettingsFragmentTest.java   
@Before
public void setup() {
    frag = new SettingsFragment();
    startFragment(frag);
    prefs = ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application);
}
项目:android-uploader    文件:AndroidBarcodeTest.java   
@Before
public void setUp() {
    activity = Robolectric.buildActivity(SettingsActivity.class).create().get();
    sharedPrefs = ShadowPreferenceManager.getDefaultSharedPreferences(Robolectric.application.getApplicationContext());
    prefs = new AndroidPreferences(activity.getApplicationContext(), sharedPrefs);
}
项目:PanicButton    文件:HomeActivityTest.java   
private void setFirstRun(boolean flag) {
    SharedPreferences sharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(Robolectric.application);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putBoolean("FIRST_RUN", flag);
    editor.commit();
}
项目:PanicButton    文件:ApplicationSettingsTest.java   
@Before
public void setUp() {
    context = Robolectric.application;
    sharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(context);
}