diff --git a/app/src/test/java/org/fdroid/fdroid/shadows/ShadowContextImpl.java b/app/src/test/java/org/fdroid/fdroid/shadows/ShadowContextImpl.java new file mode 100644 index 000000000..f4f412bff --- /dev/null +++ b/app/src/test/java/org/fdroid/fdroid/shadows/ShadowContextImpl.java @@ -0,0 +1,23 @@ +package org.fdroid.fdroid.shadows; + +import android.annotation.SuppressLint; + +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; + +/** + * Workaround for the large amount of "WARNING: unknown service appops" messages which clogged up our CI output. + */ +@Implements(className = org.robolectric.shadows.ShadowContextImpl.CLASS_NAME) +@SuppressLint("Unused") +public class ShadowContextImpl extends org.robolectric.shadows.ShadowContextImpl { + @Override + @Implementation + public Object getSystemService(String name) { + if ("appops".equals(name)) { + return null; + } + + return super.getSystemService(name); + } +} diff --git a/app/src/test/java/org/fdroid/fdroid/shadows/ShadowLog.java b/app/src/test/java/org/fdroid/fdroid/shadows/ShadowLog.java new file mode 100644 index 000000000..fadeb57f6 --- /dev/null +++ b/app/src/test/java/org/fdroid/fdroid/shadows/ShadowLog.java @@ -0,0 +1,32 @@ +package org.fdroid.fdroid.shadows; + +import android.annotation.SuppressLint; +import android.text.TextUtils; +import android.util.Log; + +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; + +/** + * There are two lines of output which end up in our CI 1000s of times: + * + * - I/CursorWindowStats: Created a new Cursor. # Open Cursors=1 (# cursors opened by this proc=1) + * - D/SQLiteCursor: received count(*) from native_fill_window: 0 + * + * Neither of them seem like they are telling us anything useful, so this suppresses them by intercepting the call + * to {@link Log#isLoggable(String, int)} and returning if it matches either of them. + */ +@Implements(Log.class) +@SuppressLint("Unused") +public class ShadowLog extends org.robolectric.shadows.ShadowLog { + + @Implementation + public static synchronized boolean isLoggable(String tag, int level) { + if ((TextUtils.equals(tag, "CursorWindowStats") && level <= Log.INFO) + || (TextUtils.equals(tag, "SQLiteCursor") && level <= Log.DEBUG)) { + return false; + } + + return org.robolectric.shadows.ShadowLog.isLoggable(tag, level); + } +} diff --git a/app/src/test/java/org/fdroid/fdroid/updater/RepoXMLHandlerTest.java b/app/src/test/java/org/fdroid/fdroid/updater/RepoXMLHandlerTest.java index 9d6878e3f..b5df872ce 100644 --- a/app/src/test/java/org/fdroid/fdroid/updater/RepoXMLHandlerTest.java +++ b/app/src/test/java/org/fdroid/fdroid/updater/RepoXMLHandlerTest.java @@ -32,12 +32,10 @@ import org.fdroid.fdroid.data.App; import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.data.RepoPushRequest; import org.fdroid.fdroid.mock.RepoDetails; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -import org.robolectric.shadows.ShadowLog; import java.io.File; import java.io.IOException; @@ -62,11 +60,6 @@ public class RepoXMLHandlerTest { private static final String FAKE_SIGNING_CERT = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"; // NOCHECKSTYLE LineLength - @Before - public void setUp() { - ShadowLog.stream = System.out; - } - @Test public void testExtendedPerms() throws IOException { Repo expectedRepo = new Repo(); diff --git a/app/src/test/resources/robolectric.properties b/app/src/test/resources/robolectric.properties new file mode 100644 index 000000000..66dbd4679 --- /dev/null +++ b/app/src/test/resources/robolectric.properties @@ -0,0 +1 @@ +shadows=org.fdroid.fdroid.shadows.ShadowContextImpl,org.fdroid.fdroid.shadows.ShadowLog