本文整理匯總了Java中org.robolectric.shadows.ShadowLog.getLogs方法的典型用法代碼示例。如果您正苦於以下問題:Java ShadowLog.getLogs方法的具體用法?Java ShadowLog.getLogs怎麽用?Java ShadowLog.getLogs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.robolectric.shadows.ShadowLog
的用法示例。
在下文中一共展示了ShadowLog.getLogs方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: assertExceptionLogged
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
private static void assertExceptionLogged(int logType, String message, String exceptionClassname, String tag,
int index) {
List<LogItem> logs = ShadowLog.getLogs();
assertThat(logs).hasSize(index + 1);
LogItem log = logs.get(index);
assertThat(log.type).isEqualTo(logType);
assertThat(log.tag).isEqualTo(tag != null ? tag : "TimberTest");
if (message != null) {
assertThat(log.msg).startsWith(message);
}
assertThat(log.msg).contains(exceptionClassname);
// We use a low-level primitive that Robolectric doesn't populate.
assertThat(log.throwable).isNull();
}
示例2: loadPositions_withNoConnection_shouldLogMoPubErrorCodeNoConnection_shouldCallFailureHandler
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test
public void loadPositions_withNoConnection_shouldLogMoPubErrorCodeNoConnection_shouldCallFailureHandler() {
MoPubLog.setSdkHandlerLevel(Level.ALL);
when(mockContext.checkCallingOrSelfPermission(anyString()))
.thenReturn(PackageManager.PERMISSION_DENIED);
when(spyActivity.getApplicationContext()).thenReturn(mockContext);
// Reinit the subject so we get our mocked context.
subject = new ServerPositioningSource(spyActivity);
// Simulate failure after max time.
subject.setMaximumRetryTimeMilliseconds(999);
subject.loadPositions("test_ad_unit", mockPositioningListener);
verify(mockRequestQueue).add(positionRequestCaptor.capture());
positionRequestCaptor.getValue().deliverError(new NoConnectionError());
verify(mockPositioningListener).onFailed();
final List<ShadowLog.LogItem> allLogMessages = ShadowLog.getLogs();
final ShadowLog.LogItem latestLogMessage = allLogMessages.get(allLogMessages.size() - 2);
// All log messages end with a newline character.
assertThat(latestLogMessage.msg.trim()).isEqualTo(MoPubErrorCode.NO_CONNECTION.toString());
}
示例3: displayWarningForMissingActivities_withAllMissingActivities_shouldLogMessage
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test
public void displayWarningForMissingActivities_withAllMissingActivities_shouldLogMessage() throws Exception {
setDebugMode(true);
ShadowLog.setupLogging();
ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities);
final List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
assertLogIncludes(
"com.mopub.mobileads.MoPubActivity",
"com.mopub.mobileads.MraidActivity",
"com.mopub.mobileads.MraidVideoPlayerActivity",
"com.mopub.common.MoPubBrowser"
);
}
示例4: log
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test public void log() {
LogStrategy logStrategy = new LogcatLogStrategy();
logStrategy.log(DEBUG, "tag", "message");
List<ShadowLog.LogItem> logItems = ShadowLog.getLogs();
assertThat(logItems.get(0).type).isEqualTo(DEBUG);
assertThat(logItems.get(0).msg).isEqualTo("message");
assertThat(logItems.get(0).tag).isEqualTo("tag");
}
示例5: callOriginTest
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
/** Tests that the computed call origin is the correct one. */
@Test
public void callOriginTest() {
Log.d("Foo", "Bar");
List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
assertEquals("Only one log should be written", 1, logs.size());
assertTrue("The origin of the log message (" + logs.get(0).msg + ") looks wrong.",
logs.get(0).msg.matches("\\[LogTest.java:\\d+\\].*"));
}
示例6: exceptionLoggingTest
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
/** Tests that exceptions provided to the log functions are properly recognized and printed. */
@Test
public void exceptionLoggingTest() {
Throwable t = new Throwable() {
@Override
public String toString() {
return "MyThrowable";
}
};
Throwable t2 = new Throwable() {
@Override
public String toString() {
return "MyOtherThrowable";
}
};
List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
// The throwable gets printed out
Log.i("Foo", "Bar", t);
assertEquals(t, logs.get(logs.size() - 1).throwable);
assertEquals("Bar", logs.get(logs.size() - 1).msg);
// The throwable can be both added to the message itself and printed out
Log.i("Foo", "Bar %s", t);
assertEquals(t, logs.get(logs.size() - 1).throwable);
assertEquals("Bar MyThrowable", logs.get(logs.size() - 1).msg);
// Non throwable are properly identified
Log.i("Foo", "Bar %s", t, "Baz");
assertNull(logs.get(logs.size() - 1).throwable);
assertEquals("Bar MyThrowable", logs.get(logs.size() - 1).msg);
// The last throwable is the one used that is going to be printed out
Log.i("Foo", "Bar %s %s", t, t2);
assertEquals(t2, logs.get(logs.size() - 1).throwable);
assertEquals("Bar MyThrowable MyOtherThrowable", logs.get(logs.size() - 1).msg);
}
示例7: onAdError_withVolleyErrorWarmingUp_shouldLogMoPubErrorCodeWarmup_shouldNotifyListener
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test
public void onAdError_withVolleyErrorWarmingUp_shouldLogMoPubErrorCodeWarmup_shouldNotifyListener() {
MoPubLog.setSdkHandlerLevel(Level.ALL);
subject.onAdError(new MoPubNetworkError(MoPubNetworkError.Reason.WARMING_UP));
final List<ShadowLog.LogItem> allLogMessages = ShadowLog.getLogs();
final ShadowLog.LogItem latestLogMessage = allLogMessages.get(allLogMessages.size() - 1);
// All log messages end with a newline character.
assertThat(latestLogMessage.msg.trim()).isEqualTo(MoPubErrorCode.WARMUP.toString());
verify(mockNetworkListener).onNativeFail(eq(NativeErrorCode.EMPTY_AD_RESPONSE));
}
示例8: onAdError_withNoConnection_shouldLogMoPubErrorCodeNoConnection_shouldNotifyListener
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test
public void onAdError_withNoConnection_shouldLogMoPubErrorCodeNoConnection_shouldNotifyListener() {
MoPubLog.setSdkHandlerLevel(Level.ALL);
shadowOf(context).denyPermissions(INTERNET);
subject.onAdError(new NoConnectionError());
final List<ShadowLog.LogItem> allLogMessages = ShadowLog.getLogs();
final ShadowLog.LogItem latestLogMessage = allLogMessages.get(allLogMessages.size() - 1);
// All log messages end with a newline character.
assertThat(latestLogMessage.msg.trim()).isEqualTo(MoPubErrorCode.NO_CONNECTION.toString());
verify(mockNetworkListener).onNativeFail(eq(NativeErrorCode.CONNECTION_ERROR));
}
示例9: debugTest
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test public void debugTest() {
Timber.plant(new Timber.DebugTree());
logger.debug("Hello, world!");
List<LogItem> logs = ShadowLog.getLogs();
assertThat(logs).hasSize(1);
LogItem log = logs.get(0);
assertThat(log.type).isEqualTo(Log.DEBUG);
assertThat(log.tag).isEqualTo("TimberLoggerAdapterTest");
assertThat(log.msg).isEqualTo("Hello, world!");
assertThat(log.throwable).isNull();
}
示例10: setSearchResults_shouldCheckForNullPager
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test
public void setSearchResults_shouldCheckForNullPager() throws Exception {
ArrayList<Feature> features = new ArrayList<Feature>();
features.add(getTestFeature());
fragment.pager = null;
fragment.setSearchResults(features);
List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
assertThat(logs.get(logs.size() - 1).msg)
.isEqualTo("Unable to display search results: pager is null");
}
示例11: assertLog
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
private static LogAssert assertLog() {
return new LogAssert(ShadowLog.getLogs());
}
示例12: assertNotLogged
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
private void assertNotLogged() {
final List<ShadowLog.LogItem> logs = ShadowLog.getLogs();
assertThat(logs, empty());
}