本文整理匯總了Java中org.robolectric.shadows.ShadowApplication.getSharedPreferences方法的典型用法代碼示例。如果您正苦於以下問題:Java ShadowApplication.getSharedPreferences方法的具體用法?Java ShadowApplication.getSharedPreferences怎麽用?Java ShadowApplication.getSharedPreferences使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.robolectric.shadows.ShadowApplication
的用法示例。
在下文中一共展示了ShadowApplication.getSharedPreferences方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertStoreLocation
import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Test
public void givenAStoreNotificationHasBeenStoredWhenARequestToSendANotificationWithTheTheSameStoreIsReceivedBeforeTheMinimumUpdateTimeForTheSameStoreThenTheNotificationIsNotSent() {
ShadowApplication shadowApplication = (ShadowApplication) Shadows.shadowOf(RuntimeEnvironment.application);
insertStoreLocation(shadowApplication);
SharedPreferences sharedPreferences = shadowApplication.getSharedPreferences(shadowApplication.getString(R.string.reminder_pref_key), Context.MODE_PRIVATE);
sharedPreferences.edit().putString(GroceryReminderConstants.LAST_NOTIFIED_STORE_KEY, ARBITRARY_STORE_NAME)
.putLong(GroceryReminderConstants.LAST_NOTIFICATION_TIME_FOR_SAME_STORE, System.currentTimeMillis() - 1)
.commit();
ShadowLocation.setDistanceBetween(new float[]{(float) GroceryReminderConstants.LOCATION_GEOFENCE_RADIUS_METERS});
ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
groceryStoreNotificationManager.sendPotentialNotification(new Location(LocationManager.GPS_PROVIDER), System.currentTimeMillis());
Notification notification = shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT);
assertNull(notification);
}
示例2: whenANotificationIsSentThenTheTheNotificationDetailsAreSaved
import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Test
public void whenANotificationIsSentThenTheTheNotificationDetailsAreSaved() {
ShadowApplication shadowApplication = (ShadowApplication) Shadows.shadowOf(RuntimeEnvironment.application);
insertStoreLocation(shadowApplication);
ShadowLocation.setDistanceBetween(new float[]{(float) GroceryReminderConstants.LOCATION_GEOFENCE_RADIUS_METERS});
long currentTime = System.currentTimeMillis();
groceryStoreNotificationManager.sendPotentialNotification(new Location(LocationManager.GPS_PROVIDER), currentTime);
SharedPreferences sharedPreferences = shadowApplication.getSharedPreferences(shadowApplication.getString(R.string.reminder_pref_key), Context.MODE_PRIVATE);
assertEquals(ARBITRARY_STORE_NAME, sharedPreferences.getString(GroceryReminderConstants.LAST_NOTIFIED_STORE_KEY, ""));
assertEquals(currentTime, sharedPreferences.getLong(GroceryReminderConstants.LAST_NOTIFICATION_TIME, 0));
}
示例3: whenANotificationIsSentForTheSameStoreThenTheTheLastNotificationTimeForTheSameStoreIsSetAreSaved
import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Test
public void whenANotificationIsSentForTheSameStoreThenTheTheLastNotificationTimeForTheSameStoreIsSetAreSaved() {
ShadowApplication shadowApplication = (ShadowApplication) Shadows.shadowOf(RuntimeEnvironment.application);
SharedPreferences sharedPreferences = shadowApplication.getSharedPreferences(shadowApplication.getString(R.string.reminder_pref_key), Context.MODE_PRIVATE);
sharedPreferences.edit().putString(GroceryReminderConstants.LAST_NOTIFIED_STORE_KEY, ARBITRARY_STORE_NAME).commit();
insertStoreLocation(shadowApplication);
ShadowLocation.setDistanceBetween(new float[]{(float) GroceryReminderConstants.LOCATION_GEOFENCE_RADIUS_METERS});
long currentTime = System.currentTimeMillis();
groceryStoreNotificationManager.sendPotentialNotification(new Location(LocationManager.GPS_PROVIDER), currentTime);
assertEquals(currentTime, sharedPreferences.getLong(GroceryReminderConstants.LAST_NOTIFICATION_TIME_FOR_SAME_STORE, 0));
}