Created
May 29, 2015 10:43
-
-
Save kmdupr33/f3462dc4bb1cc76ddac5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 static org.hamcrest.MatcherAssert.assertThat; | |
| import static org.hamcrest.CoreMatchers.*; | |
| import static org.mockito.Mockito.*; | |
| import org.junit.Test; | |
| import org.junit.runner.RunWith; | |
| import org.mockito.Mock; | |
| import org.mockito.runners.MockitoJUnitRunner; | |
| import android.content.SharedPreferences; | |
| @RunWith(MockitoJUnitRunner.class) | |
| public class UnitTestSample { | |
| private static final String FAKE_STRING = "HELLO WORLD"; | |
| @Mock | |
| Context mMockContext; | |
| @Test | |
| public void readStringFromContext_LocalizedString() { | |
| // Given a mocked Context injected into the object under test... | |
| when(mMockContext.getString(R.string.hello_word)) | |
| .thenReturn(FAKE_STRING); | |
| ClassUnderTest myObjectUnderTest = new ClassUnderTest(mMockContext); | |
| // ...when the string is returned from the object under test... | |
| String result = myObjectUnderTest.getHelloWorldString(); | |
| // ...then the result should be the expected one. | |
| assertThat(result, is(FAKE_STRING)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment