Created
May 9, 2014 08:37
-
-
Save izmajlowiczl/072564cdbfb82340d7c2 to your computer and use it in GitHub Desktop.
SharedPreferences with Robolectric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.SharedPreferences; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.robolectric.Robolectric; | |
import org.robolectric.RobolectricTestRunner; | |
import static org.junit.Assert.assertEquals; | |
@RunWith(RobolectricTestRunner.class) | |
public class TheLastSyncTimestamp { | |
private ILastSyncTimestamp tested; | |
@Before | |
public void beforeEachTest() { | |
final SharedPreferences syncPreferences = Robolectric.application.getSharedPreferences("_sync_preferences", 0); | |
tested = new LastSyncTimestamp(syncPreferences); | |
} | |
@Test | |
public void setLastSyncTimestamp_stores_timestamp() { | |
// given | |
tested.setLastSyncTimestamp(1); | |
// when | |
final long lastTimestampOrZero = tested.getLastTimestampOrZero(); | |
// then | |
assertEquals(1, lastTimestampOrZero); | |
} | |
@Test | |
public void setLastSyncTimestamp_default_value() { | |
// when | |
final long lastTimestampOrZero = tested.getLastTimestampOrZero(); | |
// then | |
assertEquals(0, lastTimestampOrZero); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment