use of org.robolectric.shadows.ShadowLog.LogItem in project timber by JakeWharton.
the class TimberTest method assertExceptionLogged.
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();
}
use of org.robolectric.shadows.ShadowLog.LogItem in project WordPress-Android by wordpress-mobile.
the class JsCallbackReceiverTest method assertLogged.
private void assertLogged(int type, String tag, String msg, Throwable throwable) {
LogItem lastLog = ShadowLog.getLogs().get(0);
assertEquals(type, lastLog.type);
assertEquals(msg, lastLog.msg);
assertEquals(tag, lastLog.tag);
assertEquals(throwable, lastLog.throwable);
}
use of org.robolectric.shadows.ShadowLog.LogItem in project robolectric by robolectric.
the class ExpectedLogMessagesRule method apply.
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
base.evaluate();
List<LogItem> logs = ShadowLog.getLogs();
Map<ExpectedLogItem, Boolean> expectedLogItemMap = new HashMap<>();
for (ExpectedLogItem item : expectedLogs) {
expectedLogItemMap.put(item, false);
}
for (LogItem log : logs) {
LogItem logItem = new LogItem(log.type, log.tag, log.msg, log.throwable);
if (updateExpected(logItem, expectedLogItemMap)) {
observedLogs.add(logItem);
continue;
}
if (log.type >= Log.ERROR) {
if (UNPREVENTABLE_TAGS.contains(log.tag)) {
continue;
}
if (expectedTags.contains(log.tag)) {
observedTags.add(log.tag);
continue;
}
unexpectedErrorLogs.add(log);
}
}
if (!unexpectedErrorLogs.isEmpty() || expectedLogItemMap.containsValue(false)) {
Set<ExpectedLogItem> unobservedLogs = new HashSet<>();
for (Map.Entry<ExpectedLogItem, Boolean> entry : expectedLogItemMap.entrySet()) {
if (!entry.getValue()) {
unobservedLogs.add(entry.getKey());
}
}
throw new AssertionError("Expected and observed logs did not match." + "\nExpected: " + expectedLogs + "\nExpected, and observed: " + observedLogs + "\nExpected, but not observed: " + unobservedLogs + "\nObserved, but not expected: " + unexpectedErrorLogs);
}
if (!expectedTags.equals(observedTags) && !shouldIgnoreMissingLoggedTags) {
throw new AssertionError("Expected and observed tags did not match. " + "Expected tags should not be used to suppress errors, only expect them." + "\nExpected: " + expectedTags + "\nExpected, and observed: " + observedTags + "\nExpected, but not observed: " + Sets.difference(expectedTags, observedTags));
}
}
};
}
use of org.robolectric.shadows.ShadowLog.LogItem in project robolectric by robolectric.
the class ShadowLogTest method identicalLogItemInstancesAreEqual.
@Test
public void identicalLogItemInstancesAreEqual() {
LogItem item1 = new LogItem(Log.VERBOSE, "Foo", "Bar", null);
LogItem item2 = new LogItem(Log.VERBOSE, "Foo", "Bar", null);
assertThat(item1).isEqualTo(item2);
assertThat(item2).isEqualTo(item1);
}
use of org.robolectric.shadows.ShadowLog.LogItem in project robolectric by robolectric.
the class ShadowPackageParser method callParsePackage.
/**
* Parses an AndroidManifest.xml file using the framework PackageParser.
*/
public static Package callParsePackage(Path apkFile) {
PackageParser packageParser = new PackageParser();
int flags = PackageParser.PARSE_IGNORE_PROCESSES;
try {
Package thePackage;
if (RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.LOLLIPOP) {
// PackageParser#setMinAspectRatio(Package)
if (RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.Q) {
QHelper.setCallback(packageParser);
}
thePackage = packageParser.parsePackage(apkFile.toFile(), flags);
} else {
// JB -> KK
thePackage = reflector(_PackageParser_.class, packageParser).parsePackage(apkFile.toFile(), Fs.externalize(apkFile), new DisplayMetrics(), flags);
}
if (thePackage == null) {
List<LogItem> logItems = ShadowLog.getLogsForTag("PackageParser");
if (logItems.isEmpty()) {
throw new RuntimeException("Failed to parse package " + apkFile);
} else {
LogItem logItem = logItems.get(0);
throw new RuntimeException("Failed to parse package " + apkFile + ": " + logItem.msg, logItem.throwable);
}
}
return thePackage;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations