本文整理匯總了Java中org.robolectric.shadows.ShadowLog.LogItem方法的典型用法代碼示例。如果您正苦於以下問題:Java ShadowLog.LogItem方法的具體用法?Java ShadowLog.LogItem怎麽用?Java ShadowLog.LogItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.robolectric.shadows.ShadowLog
的用法示例。
在下文中一共展示了ShadowLog.LogItem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
示例2: 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"
);
}
示例3: 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");
}
示例4: 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+\\].*"));
}
示例5: 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);
}
示例6: 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));
}
示例7: 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));
}
示例8: assertLogged
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
public static void assertLogged(int type, String tag, String msg, Throwable throwable) {
ShadowLog.LogItem lastLog = ShadowLog.getLogs().get(0);
assertThat(type).isEqualTo(lastLog.type);
assertThat(msg).isEqualTo(lastLog.msg);
assertThat(tag).isEqualTo(lastLog.tag);
assertThat(throwable).isEqualTo(lastLog.throwable);
}
示例9: assertLogged
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
private void assertLogged(int type, String tag, String msg, Throwable throwable) {
ShadowLog.LogItem lastLog = ShadowLog.getLogs().get(0);
assertEquals(type, lastLog.type);
assertEquals(msg, lastLog.msg);
assertEquals(tag, lastLog.tag);
assertEquals(throwable, lastLog.throwable);
}
示例10: shouldLog_activity
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@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");
}
示例11: shouldLog_fragment
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@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");
}
示例12: shouldLog_View
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test
public void shouldLog_View() {
Robolectric.buildActivity(TestActivityWitView.class).create().start().get();
List<ShadowLog.LogItem> logItems = ShadowLog.getLogsForTag("LogLifeCycle");
assertNotNull(logItems);
assertLogContainsMessage(logItems, "onFinishInflate");
}
示例13: shouldLog_Service
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
@Test
public void shouldLog_Service() {
Robolectric.buildService(TestService.class).attach().create().withIntent(null).startCommand(0,1).destroy().get();
List<ShadowLog.LogItem> logItems = ShadowLog.getLogsForTag("LogLifeCycle");
assertNotNull(logItems);
assertLogContainsMessage(logItems, "onCreate");
assertLogContainsMessage(logItems, "onStart");
assertLogContainsMessage(logItems, "onDestroy");
}
示例14: assertLogContainsMessage
import org.robolectric.shadows.ShadowLog; //導入方法依賴的package包/類
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");
}
示例15: 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");
}