Search in sources :

Example 6 with LogItem

use of org.robolectric.shadows.ShadowLog.LogItem in project androidannotations by androidannotations.

the class TracedActivityTest method logContains.

/**
 * Check if a message has been logged
 *
 * @param msg
 * @return {@code true} if a log entry starting with {@code msg} exists
 */
private static boolean logContains(String msg) {
    List<LogItem> logs = ShadowLog.getLogs();
    boolean found = false;
    for (LogItem logItem : logs) {
        if (logItem.msg.startsWith(msg)) {
            found = true;
        }
    }
    return found;
}
Also used : LogItem(org.robolectric.shadows.ShadowLog.LogItem)

Example 7 with LogItem

use of org.robolectric.shadows.ShadowLog.LogItem in project robolectric by robolectric.

the class ShadowLogTest method assertUniformLogsForTag.

private static void assertUniformLogsForTag(String tag, int count) {
    List<LogItem> tag1Items = ShadowLog.getLogsForTag(tag);
    assertThat(tag1Items.size()).isEqualTo(count);
    int last = -1;
    for (LogItem item : tag1Items) {
        assertThat(item.tag).isEqualTo(tag);
        int current = Integer.parseInt(item.msg);
        assertThat(current > last).isTrue();
        last = current;
    }
}
Also used : LogItem(org.robolectric.shadows.ShadowLog.LogItem)

Example 8 with LogItem

use of org.robolectric.shadows.ShadowLog.LogItem in project robolectric by robolectric.

the class ShadowLogTest method shouldLogAccordingToTag.

@Test
public void shouldLogAccordingToTag() throws Exception {
    ShadowLog.reset();
    Log.d("tag1", "1");
    Log.i("tag2", "2");
    Log.e("tag3", "3");
    Log.w("tag1", "4");
    Log.i("tag1", "5");
    Log.d("tag2", "6");
    Log.d("throwable", "7", specificMethodName());
    List<LogItem> allItems = ShadowLog.getLogs();
    assertThat(allItems.size()).isEqualTo(7);
    int i = 1;
    for (LogItem item : allItems) {
        assertThat(item.msg).isEqualTo(Integer.toString(i));
        assertThat(item.toString()).contains(item.msg);
        i++;
    }
    assertThat(allItems.get(6).toString()).contains("specificMethodName");
    assertUniformLogsForTag("tag1", 3);
    assertUniformLogsForTag("tag2", 2);
    assertUniformLogsForTag("tag3", 1);
}
Also used : LogItem(org.robolectric.shadows.ShadowLog.LogItem) Test(org.junit.Test)

Example 9 with LogItem

use of org.robolectric.shadows.ShadowLog.LogItem in project robolectric by robolectric.

the class ShadowLogTest method assertLogged.

private static void assertLogged(String timeString, int type, String tag, String msg, Throwable throwable) {
    LogItem lastLog = Iterables.getLast(ShadowLog.getLogsForTag(tag));
    assertEquals(timeString, lastLog.timeString);
    assertLogged(type, tag, msg, throwable);
}
Also used : LogItem(org.robolectric.shadows.ShadowLog.LogItem)

Aggregations

LogItem (org.robolectric.shadows.ShadowLog.LogItem)9 Test (org.junit.Test)2 PackageParser (android.content.pm.PackageParser)1 Package (android.content.pm.PackageParser.Package)1 DisplayMetrics (android.util.DisplayMetrics)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Statement (org.junit.runners.model.Statement)1