List of usage examples for android.app Instrumentation getTargetContext
public Context getTargetContext()
From source file:com.cmput301.recipebot.test.MainActivityTest.java
/** * Set up some Preferences for testing. {@link MainActivity} checks these * on it's start, and launches {@link com.cmput301.recipebot.ui.GetUserActivity} if doesn't find these. *//* ww w. j a v a 2 s . c o m*/ private void setupTestPreferences(Instrumentation instrumentation) { Context context = instrumentation.getTargetContext(); SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.putString(AppConstants.KEY_USER_EMAIL, "f2prateek@gmail.com"); editor.putString(AppConstants.KEY_USER_NAME, "Prateek Srivastava"); editor.commit(); }
From source file:com.playhaven.android.diagnostic.test.MockPHRequestTest.java
@SmallTest public void testMockOpen() throws Exception { Instrumentation instrumentation = getInstrumentation(); Launcher launcher = startActivitySync(Launcher.class); sleep(250);//from w w w. j av a 2 s . co m MockOpenRequest req = new MockOpenRequest(); enableThreadedTesting(req); req.send(instrumentation.getTargetContext()); waitForReady(req); if (req.returnedException != null) fail(req.returnedException.getMessage()); String model = req.returnedModel; assertNotNull(model); assertFalse(JsonUtil.hasPath(model, "$.error")); assertFalse(JsonUtil.hasPath(model, "$.response.context.content")); launcher.finish(); }
From source file:com.playhaven.android.diagnostic.test.MockPHRequestTest.java
@SmallTest public void testMockMoreGames() throws Exception { Instrumentation instrumentation = getInstrumentation(); Launcher launcher = startActivitySync(Launcher.class); sleep(250);// w ww.j a v a 2 s. c o m MockContentRequest req = new MockContentRequest(); enableThreadedTesting(req); req.send(instrumentation.getTargetContext()); waitForReady(req); if (req.returnedException != null) fail(req.returnedException.getMessage()); String model = req.returnedModel; assertNotNull(model); assertNull(JsonUtil.getPath(model, "$.error")); assertEquals("more_games", JsonUtil.getPath(model, "$.response.content")); launcher.finish(); }
From source file:com.playhaven.android.diagnostic.test.MockPHRequestTest.java
@SmallTest public void testKTMockOpen() throws Exception { Instrumentation instrumentation = getInstrumentation(); Launcher launcher = startActivitySync(Launcher.class); sleep(250);// ww w .j a va 2s. c o m MockKTOpenRequest req = new MockKTOpenRequest(); enableThreadedTesting(req); req.send(instrumentation.getTargetContext()); waitForReady(req); if (req.returnedException != null) fail(req.returnedException.getMessage()); String model = req.returnedModel; assertNotNull(model); assertFalse(JsonUtil.hasPath(model, "$.error")); assertFalse(JsonUtil.hasPath(model, "$.response.context.content")); assertTrue(JsonUtil.hasPath(model, "$.response.ktapi")); assertTrue(JsonUtil.hasPath(model, "$.response.ktsid")); launcher.finish(); }