org.robolectric.shadows.ShadowLog Java Examples
The following examples show how to use
org.robolectric.shadows.ShadowLog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PreferencesTest.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
/** * Manually read the {@code preferences.xml} defaults to a separate * instance. Clear the preference state before each test so that each * test starts as if it was a first time install. */ @Before public void setup() { ShadowLog.stream = System.out; String sharedPreferencesName = CONTEXT.getPackageName() + "_preferences_defaults"; PreferenceManager pm = new PreferenceManager(CONTEXT); pm.setSharedPreferencesName(sharedPreferencesName); pm.setSharedPreferencesMode(Context.MODE_PRIVATE); pm.inflateFromResource(CONTEXT, R.xml.preferences, null); defaults = pm.getSharedPreferences(); assertTrue(defaults.getAll().size() > 0); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(CONTEXT); Log.d(TAG, "Clearing DefaultSharedPreferences containing: " + sharedPreferences.getAll().size()); sharedPreferences.edit().clear().commit(); assertEquals(0, sharedPreferences.getAll().size()); SharedPreferences defaultValueSp = CONTEXT.getSharedPreferences(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, Context.MODE_PRIVATE); defaultValueSp.edit().remove(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES).commit(); }
Example #2
Source File: ConnectivityAwereUrlClientTest.java From MVPAndroidBootstrap with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { ShadowLog.stream = System.out; mockWebServer = new MockWebServer(); mockWebServer.start(9999); baseRetryHandler = BaseRetryHandler_.getInstance_(RuntimeEnvironment.application); connectivityAwareUrlClient = ConnectivityAwareUrlClient_.getInstance_(RuntimeEnvironment.application); connectivityAwareUrlClient.setWrappedClient(new OkClient(new OkHttpClient())); connectivityAwareUrlClient.setRetryHandler(baseRetryHandler); RestAdapter restAdapter = new RestAdapter.Builder() .setClient(connectivityAwareUrlClient) .setLogLevel(RestAdapter.LogLevel.FULL) .setEndpoint(mockWebServer.getUrl("/").toString()).build(); sodaService = restAdapter.create(SodaService.class); }
Example #3
Source File: TestActivityTest.java From Awesome-WanAndroid with Apache License 2.0 | 6 votes |
@Test public void showToast() { Toast latestToast = ShadowToast.getLatestToast(); Assert.assertNull(latestToast); Button button = (Button) mTestActivity.findViewById(R.id.button2); button.performClick(); latestToast = ShadowToast.getLatestToast(); Assert.assertNotNull(latestToast); ShadowToast shadowToast = Shadows.shadowOf(latestToast); ShadowLog.d("toast_time", shadowToast.getDuration() + ""); Assert.assertEquals(Toast.LENGTH_SHORT, shadowToast.getDuration()); Assert.assertEquals("hahaha", ShadowToast.getTextOfLatestToast()); }
Example #4
Source File: TestActivityTest.java From Awesome-WanAndroid with Apache License 2.0 | 6 votes |
@Test public void showDialog() { AlertDialog latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog(); Assert.assertNull(latestAlertDialog); Button button = (Button) mTestActivity.findViewById(R.id.button3); button.performClick(); latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog(); Assert.assertNotNull(latestAlertDialog); ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(latestAlertDialog); Assert.assertEquals("Dialog", shadowAlertDialog.getTitle()); ShadowLog.d("dialog_tag", (String) shadowAlertDialog.getMessage()); Assert.assertEquals("showDialog", shadowAlertDialog.getMessage()); }
Example #5
Source File: BaseRoboTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Before public void setup() { SDKSettings.setExternalExecutor(null); Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT); ShadowSettings.setTestURL(url.toString()); TestResponsesUT.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
Example #6
Source File: BaseAndroidTest.java From kripton with Apache License 2.0 | 6 votes |
/** * Setup. */ @Before public void setup() { //final String value = System.getProperty(KRIPTON_DEBUG_MODE); final String value = System.getProperty(KRIPTON_DEBUG_MODE); if ("false".equals(value)) { ShadowLog.stream = new PrintStream(new NullOutputStream()); // we are in test, but we don't see log on System.out System.setOut(new PrintStream(new NullOutputStream())); System.setErr(new PrintStream(new NullOutputStream())); } else { ShadowLog.stream = System.out; } KriptonLibrary.init(RuntimeEnvironment.application); }
Example #7
Source File: DatabaseCleanupTaskTest.java From budget-watch with GNU General Public License v3.0 | 6 votes |
@Before public void setUp() throws IOException { // Output logs emitted during tests so they may be accessed ShadowLog.stream = System.out; activity = Robolectric.setupActivity(ImportExportActivity.class); db = new DBHelper(activity); imageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES); assertNotNull(imageDir); boolean result; if(imageDir.exists() == false) { result = imageDir.mkdirs(); assertTrue(result); } missingReceipt = new File(imageDir, "missing"); orphanReceipt = new File(imageDir, "orphan"); result = orphanReceipt.createNewFile(); assertTrue(result); }
Example #8
Source File: BaseRoboTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Before public void setup() { Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT); ShadowSettings.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
Example #9
Source File: GeoJSONUtilTest.java From appinventor-extensions with Apache License 2.0 | 6 votes |
@Test public void testProcessGeoJSONFeaturePolygonWithHoles() { ShadowLog.setupLogging(); Polygon polygon = (Polygon) GeoJSONUtil.processGeoJSONFeature(LOG_TAG, getMap(), alist("type", "Feature", "geometry", alist("type", "Polygon", "coordinates", list( // Polygon list(list(-71, 42), list(-70, 42), list(-70, 41), list(-71, 42)), // Holes list(list(-70.75, 41.75), list(-70.25, 41.75), list(-70.25, 41.25), list(-70.75, 41.75)) )), "properties", getTestProperties())); assertNotNull(polygon); assertEquals(new GeoPoint(42.0, -71.0), polygon.getPoints().get(0).get(0)); assertEquals(new GeoPoint(42.0, -70.0), polygon.getPoints().get(0).get(1)); assertEquals(new GeoPoint(41.0, -70.0), polygon.getPoints().get(0).get(2)); assertEquals(new GeoPoint(42.0, -71.0), polygon.getPoints().get(0).get(3)); assertEquals(new GeoPoint(41.75, -70.75), polygon.getHolePoints().get(0).get(0).get(0)); assertEquals(new GeoPoint(41.75, -70.25), polygon.getHolePoints().get(0).get(0).get(1)); assertEquals(new GeoPoint(41.25, -70.25), polygon.getHolePoints().get(0).get(0).get(2)); assertEquals(new GeoPoint(41.75, -70.75), polygon.getHolePoints().get(0).get(0).get(3)); assertTestProperties(polygon); assertLogTriggered(); }
Example #10
Source File: CommCareShadowLog.java From commcare-android with Apache License 2.0 | 5 votes |
@Implementation public static int d(String tag, String msg, Throwable throwable) { if (shouldShowTag(tag)) { ShadowLog.d(tag, msg, throwable); } return 0; }
Example #11
Source File: AppStatesServiceTest.java From android-testdpc with Apache License 2.0 | 5 votes |
@Test public void onReceive_shouldNotify_oneLogPerState() { setNotificationPreference(true); mService.onReceive(Arrays.asList(STATE1, STATE2), /* requestSync= */ false); assertThat(ShadowLog.getLogsForTag(AppStatesService.TAG)).hasSize(2); }
Example #12
Source File: PermissionsHelperTest.java From android-testdpc with Apache License 2.0 | 5 votes |
@Test public void ensureRequiredPermissions_ifPermissionMissingFromManifest_shouldReturnFalseAndLogError() { boolean requiredPermissionsGranted = PermissionsHelper .ensureRequiredPermissions(new String[]{MISSING_PERMISSION}, NON_TESTDPC_ADMIN, mContext); assertFalse(requiredPermissionsGranted); assertTrue(ShadowLog.getLogsForTag(PermissionsHelper.TAG).get(0).msg .contains("Missing required permission from manifest: " + MISSING_PERMISSION)); }
Example #13
Source File: LogLifeCycleProcessorTest.java From loglifecycle with Apache License 2.0 | 5 votes |
@Test public void shouldLog_fragment() { Robolectric.buildActivity(TestActivityWitFragment.class).create().start().stop().destroy().get(); List<ShadowLog.LogItem> logItems = ShadowLog.getLogsForTag("LogLifeCycle"); assertNotNull(logItems); assertLogContainsMessage(logItems, "onStart"); assertLogContainsMessage(logItems, "onStop"); }
Example #14
Source File: LogUtilsTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void logDebug_isLoggableDisabled() { ShadowLog.setLoggable(LogUtilsTest.class.getSimpleName(), Log.INFO); String message = "Order me a %s"; LogUtil.logDebug(LogUtilsTest.class.getSimpleName(), message, "latte"); assertThat(ShadowLog.getLogsForTag(LogUtilsTest.class.getSimpleName())).isEmpty(); }
Example #15
Source File: DownloadManagerTest.java From Android-HttpDownloadManager with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { ShadowLog.stream = System.out; mockWebServer = new MockWebServer(); downloadManager = new DownloadManager.Builder().context( ShadowApplication.getInstance().getApplicationContext()).build(); String filePath = ShadowEnvironment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + File.separator + "download.apk"; request = new DownloadRequest.Builder().url(mockWebServer.url("/").toString()) .destinationFilePath(filePath) .build(); }
Example #16
Source File: LogLifeCycleProcessorTest.java From loglifecycle with Apache License 2.0 | 5 votes |
private void assertLogContainsMessage(List<ShadowLog.LogItem> logItems, String logMessage) { for(ShadowLog.LogItem logItem : logItems ) { if (logItem.msg.contains(logMessage)) { return; } } fail("No message " + logMessage + " in log"); }
Example #17
Source File: CommCareShadowLog.java From commcare-android with Apache License 2.0 | 5 votes |
@Implementation public static int w(String tag, String msg, Throwable throwable) { if (shouldShowTag(tag)) { ShadowLog.w(tag, msg, throwable); } return 0; }
Example #18
Source File: CommCareShadowLog.java From commcare-android with Apache License 2.0 | 5 votes |
@Implementation public static int wtf(String tag, String msg, Throwable throwable) { if (shouldShowTag(tag)) { ShadowLog.wtf(tag, msg, throwable); } return 0; }
Example #19
Source File: LogUtilsTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void logDebug_isLoggableEnabled() { ShadowLog.setLoggable(LogUtilsTest.class.getSimpleName(), Log.DEBUG); String message = "Order me a %s"; LogUtil.logDebug(LogUtilsTest.class.getSimpleName(), message, "latte"); assertThat(ShadowLog.getLogsForTag(LogUtilsTest.class.getSimpleName()).get(0).msg) .contains("Order me a latte"); }
Example #20
Source File: AppStatesServiceTest.java From android-testdpc with Apache License 2.0 | 5 votes |
@Test public void onReceive_shouldNotify_requestSync_logContainsRequestSync() { setNotificationPreference(true); mService.onReceive(Arrays.asList(STATE1), /* requestSync= */ true); ShadowLog.LogItem logItem = ShadowLog.getLogsForTag(AppStatesService.TAG).get(0); assertThat(logItem.msg).contains(REQUEST_SYNC_LOG_TEXT); }
Example #21
Source File: AppStatesServiceTest.java From android-testdpc with Apache License 2.0 | 5 votes |
@Test public void onReceive_shouldNotify_noRequestSync_logDoesNotContainRequestSync() { setNotificationPreference(true); mService.onReceive(Arrays.asList(STATE1), /* requestSync= */ false); ShadowLog.LogItem logItem = ShadowLog.getLogsForTag(AppStatesService.TAG).get(0); assertThat(logItem.msg).doesNotContain(REQUEST_SYNC_LOG_TEXT); }
Example #22
Source File: OpenWeatherClientTest.java From MVPAndroidBootstrap with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { ShadowLog.stream = System.out; mockWebServer = new MockWebServer(); mockWebServer.start(9999); TestHelper.setFinalStatic(OpenWeatherClient.class.getField("ENDPOINT"), mockWebServer.getUrl("/").toString()); openWeatherClient = OpenWeatherClient_.getInstance_(RuntimeEnvironment.application); }
Example #23
Source File: AppStatesServiceTest.java From android-testdpc with Apache License 2.0 | 5 votes |
@Test public void onReceive_infoLog_shouldNotify_logIsInfoLevel() { setNotificationPreference(true); mService.onReceive(Arrays.asList(INFO_STATE), /* requestSync= */ false); assertThat(ShadowLog.getLogsForTag(AppStatesService.TAG).get(0).type).isEqualTo(INFO); }
Example #24
Source File: AppStatesServiceTest.java From android-testdpc with Apache License 2.0 | 5 votes |
private void assertThatLogContainsRequiredInformation( ShadowLog.LogItem logItem, ReceivedKeyedAppState state) { assertThat(logItem.msg).contains(Long.toString(state.getTimestamp())); assertThat(logItem.msg).contains(state.getPackageName()); assertThat(logItem.msg).contains(state.getKey()); assertThat(logItem.msg).contains(state.getData()); assertThat(logItem.msg).contains(state.getMessage()); }
Example #25
Source File: AppStatesServiceTest.java From android-testdpc with Apache License 2.0 | 5 votes |
@Test public void onReceive_shouldNotify_logContainsRequiredInformation() { setNotificationPreference(true); mService.onReceive(Arrays.asList(STATE1), /* requestSync= */ false); assertThatLogContainsRequiredInformation( ShadowLog.getLogsForTag(AppStatesService.TAG).get(0), STATE1); }
Example #26
Source File: AppStatesServiceTest.java From android-testdpc with Apache License 2.0 | 5 votes |
@Test public void onReceive_shouldNotNotify_noLogs() { setNotificationPreference(false); mService.onReceive(Arrays.asList(STATE1), /* requestSync= */ false); assertThat(ShadowLog.getLogsForTag(AppStatesService.TAG)).isEmpty(); }
Example #27
Source File: BaseAndroidTest.java From kripton with Apache License 2.0 | 5 votes |
/** * Setup. */ @Before public void setup() { final String value = System.getProperty(KRIPTON_DEBUG_MODE); if ("false".equals(value)) { ShadowLog.stream = new PrintStream(new NullOutputStream()); // we are in test, but we don't see log on System.out System.setOut(new PrintStream(new NullOutputStream())); System.setErr(new PrintStream(new NullOutputStream())); } else { ShadowLog.stream = System.out; } KriptonLibrary.init(RuntimeEnvironment.application); }
Example #28
Source File: LogLifeCycleProcessorTest.java From loglifecycle with Apache License 2.0 | 5 votes |
@Test public void shouldLog_activity() { Robolectric.buildActivity(TestActivity.class).create().start().stop().destroy().get(); List<ShadowLog.LogItem> logItems = ShadowLog.getLogsForTag("LogLifeCycle"); assertNotNull(logItems); assertLogContainsMessage(logItems, "onCreate"); assertLogContainsMessage(logItems, "onStart"); assertLogContainsMessage(logItems, "onStop"); assertLogContainsMessage(logItems, "onDestroy"); }
Example #29
Source File: OllieTest.java From Ollie with Apache License 2.0 | 5 votes |
@Before public void initialize() { ContentProvider contentProvider = new OllieSampleProvider(); contentProvider.onCreate(); ShadowLog.stream = System.out; ShadowContentResolver.registerProvider("com.example.ollie", contentProvider); Ollie.with(Robolectric.application) .setName("OllieSample.db") .setLogLevel(LogLevel.FULL) .init(); }
Example #30
Source File: BasePresenterTest.java From Awesome-WanAndroid with Apache License 2.0 | 5 votes |
@Before public void setUp() { ShadowLog.stream = System.out; mApplication = RuntimeEnvironment.application; mDataManager = WanAndroidApp.getAppComponent().getDataManager(); mLoginPresenter = new LoginPresenter(mDataManager); mLoginPresenter.attachView(mView); }