summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java4
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/util/wakelock/WakeLockTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/recents/LauncherProxyServiceTest.kt3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java21
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/log/LogAssert.kt114
5 files changed, 79 insertions, 65 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java
index 82a4583f9ce9..b80ff3466007 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java
@@ -142,7 +142,7 @@ public class PluginInstanceTest extends SysuiTestCase {
mPluginInstanceFactory.create(
mContext, mAppInfo, wrongVersionTestPluginComponentName,
TestPlugin.class, mPluginListener);
- LogAssertKt.assertLogsWtf(()-> {
+ LogAssertKt.assertRunnableLogsWtf(()-> {
mPluginInstance.onCreate();
});
assertTrue(mPluginInstance.hasError());
@@ -195,7 +195,7 @@ public class PluginInstanceTest extends SysuiTestCase {
mPluginInstance.onCreate();
assertFalse(mPluginInstance.hasError());
- LogAssertKt.assertLogsWtf(()-> {
+ LogAssertKt.assertRunnableLogsWtf(()-> {
Object result = mPluginInstance.getPlugin().methodThrowsError();
assertNotNull(result); // Wrapper function should return non-null;
});
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/util/wakelock/WakeLockTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/util/wakelock/WakeLockTest.java
index 84b6a2d40cd8..3951670c4125 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/util/wakelock/WakeLockTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/util/wakelock/WakeLockTest.java
@@ -93,6 +93,6 @@ public class WakeLockTest extends SysuiTestCase {
@Test
public void prodBuild_wakeLock_releaseWithoutAcquire_noThrow() {
// shouldn't throw an exception on production builds
- LogAssertKt.assertLogsWtf(() -> mWakeLock.release(WHY));
+ LogAssertKt.assertRunnableLogsWtf(() -> mWakeLock.release(WHY));
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/recents/LauncherProxyServiceTest.kt b/packages/SystemUI/tests/src/com/android/systemui/recents/LauncherProxyServiceTest.kt
index 2d3f538689b3..155059ea5ed9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/recents/LauncherProxyServiceTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/recents/LauncherProxyServiceTest.kt
@@ -36,6 +36,7 @@ import com.android.systemui.dump.DumpManager
import com.android.systemui.keyguard.KeyguardUnlockAnimationController
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.keyguard.ui.view.InWindowLauncherUnlockAnimationManager
+import com.android.systemui.log.assertLogsWtf
import com.android.systemui.model.sysUiState
import com.android.systemui.navigationbar.NavigationBarController
import com.android.systemui.navigationbar.NavigationModeController
@@ -221,7 +222,7 @@ class LauncherProxyServiceTest : SysuiTestCase() {
`when`(processWrapper.isSystemUser).thenReturn(false)
`when`(userManager.isVisibleBackgroundUsersSupported()).thenReturn(false)
val spyContext = spy(context)
- val ops = createLauncherProxyService(spyContext)
+ val ops = assertLogsWtf { createLauncherProxyService(spyContext) }.result
ops.startConnectionToCurrentUser()
verify(spyContext, times(0)).bindServiceAsUser(any(), any(), anyInt(), any())
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java
index 81213caaa5f4..3570cf827808 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilderTest.java
@@ -77,7 +77,6 @@ import com.android.systemui.statusbar.notification.collection.listbuilder.plugga
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifStabilityManager;
import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.Pluggable;
import com.android.systemui.statusbar.notification.collection.notifcollection.CollectionReadyForBuildListener;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.NotificationTestHelper;
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi;
import com.android.systemui.util.time.FakeSystemClock;
@@ -1795,7 +1794,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS);
// THEN an exception is NOT thrown directly, but a WTF IS logged.
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
});
@@ -1818,7 +1817,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
addNotif(0, PACKAGE_2);
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 1);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
Assert.assertThrows(IllegalStateException.class, () -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
@@ -1844,13 +1843,13 @@ public class ShadeListBuilderTest extends SysuiTestCase {
addNotif(0, PACKAGE_2);
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
});
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
// Note: dispatchBuild itself triggers a non-reentrant pipeline run.
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
@@ -1874,7 +1873,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
addNotif(0, PACKAGE_1);
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
});
@@ -1897,7 +1896,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
addNotif(0, PACKAGE_1);
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 1);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
Assert.assertThrows(IllegalStateException.class, () -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
@@ -1922,7 +1921,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
addNotif(0, PACKAGE_2);
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
});
@@ -1945,7 +1944,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
addNotif(0, PACKAGE_2);
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 1);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
Assert.assertThrows(IllegalStateException.class, () -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
@@ -1970,7 +1969,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
addNotif(0, PACKAGE_2);
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
});
@@ -1993,7 +1992,7 @@ public class ShadeListBuilderTest extends SysuiTestCase {
addNotif(0, PACKAGE_2);
invalidator.setInvalidationCount(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 1);
- LogAssertKt.assertLogsWtfs(() -> {
+ LogAssertKt.assertRunnableLogsWtfs(() -> {
Assert.assertThrows(IllegalStateException.class, () -> {
dispatchBuild();
runWhileScheduledUpTo(MAX_CONSECUTIVE_REENTRANT_REBUILDS + 2);
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/log/LogAssert.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/log/LogAssert.kt
index 5e67182d7353..b41ceff5f581 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/log/LogAssert.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/log/LogAssert.kt
@@ -13,89 +13,103 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.android.systemui.log
import android.util.Log
import android.util.Log.TerribleFailureHandler
-import junit.framework.Assert
+import com.google.common.truth.Truth.assertWithMessage
+import java.util.concurrent.Callable
-/** Asserts that the given block does not make a call to Log.wtf */
-fun assertDoesNotLogWtf(
+/** Asserts that [notLoggingBlock] does not make a call to [Log.wtf] */
+fun <T> assertDoesNotLogWtf(
message: String = "Expected Log.wtf not to be called",
- notLoggingBlock: () -> Unit,
-) {
+ notLoggingBlock: () -> T,
+): T {
var caught: TerribleFailureLog? = null
val newHandler = TerribleFailureHandler { tag, failure, system ->
caught = TerribleFailureLog(tag, failure, system)
}
val oldHandler = Log.setWtfHandler(newHandler)
- try {
- notLoggingBlock()
- } finally {
- Log.setWtfHandler(oldHandler)
- }
+ val result =
+ try {
+ notLoggingBlock()
+ } finally {
+ Log.setWtfHandler(oldHandler)
+ }
caught?.let { throw AssertionError("$message: $it", it.failure) }
+ return result
}
-fun assertDoesNotLogWtf(
- message: String = "Expected Log.wtf not to be called",
- notLoggingRunnable: Runnable,
-) = assertDoesNotLogWtf(message = message) { notLoggingRunnable.run() }
-
-/**
- * Assert that the given block makes a call to Log.wtf
- *
- * @return the details of the log
- */
-fun assertLogsWtf(
+/** Assert that [loggingBlock] makes a call to [Log.wtf] */
+@JvmOverloads
+fun <T> assertLogsWtf(
message: String = "Expected Log.wtf to be called",
allowMultiple: Boolean = false,
- loggingBlock: () -> Unit,
-): TerribleFailureLog {
- var caught: TerribleFailureLog? = null
- var count = 0
+ loggingBlock: () -> T,
+): WtfBlockResult<T> {
+ val caught = mutableListOf<TerribleFailureLog>()
val newHandler = TerribleFailureHandler { tag, failure, system ->
- if (caught == null) {
- caught = TerribleFailureLog(tag, failure, system)
- }
- count++
+ caught.add(TerribleFailureLog(tag, failure, system))
}
val oldHandler = Log.setWtfHandler(newHandler)
- try {
- loggingBlock()
- } finally {
- Log.setWtfHandler(oldHandler)
- }
- Assert.assertNotNull(message, caught)
- if (!allowMultiple && count != 1) {
- Assert.fail("Unexpectedly caught Log.Wtf $count times; expected only 1. First: $caught")
+ val result =
+ try {
+ loggingBlock()
+ } finally {
+ Log.setWtfHandler(oldHandler)
+ }
+ assertWithMessage(message).that(caught).isNotEmpty()
+ if (!allowMultiple) {
+ assertWithMessage("Unexpectedly caught Log.Wtf multiple times").that(caught).hasSize(1)
}
- return caught!!
+ return WtfBlockResult(caught, result)
}
+/** Assert that [loggingCallable] makes a call to [Log.wtf] */
@JvmOverloads
-fun assertLogsWtf(
+fun <T> assertLogsWtf(
message: String = "Expected Log.wtf to be called",
allowMultiple: Boolean = false,
- loggingRunnable: Runnable,
-): TerribleFailureLog =
- assertLogsWtf(message = message, allowMultiple = allowMultiple) { loggingRunnable.run() }
+ loggingCallable: Callable<T>,
+): WtfBlockResult<T> =
+ assertLogsWtf(message = message, allowMultiple = allowMultiple, loggingCallable::call)
-fun assertLogsWtfs(
+/** Assert that [loggingBlock] makes at least one call to [Log.wtf] */
+@JvmOverloads
+fun <T> assertLogsWtfs(
message: String = "Expected Log.wtf to be called once or more",
- loggingBlock: () -> Unit,
-): TerribleFailureLog = assertLogsWtf(message, allowMultiple = true, loggingBlock)
+ loggingBlock: () -> T,
+): WtfBlockResult<T> = assertLogsWtf(message, allowMultiple = true, loggingBlock)
+/** Assert that [loggingCallable] makes at least one call to [Log.wtf] */
@JvmOverloads
-fun assertLogsWtfs(
+fun <T> assertLogsWtfs(
message: String = "Expected Log.wtf to be called once or more",
- loggingRunnable: Runnable,
-): TerribleFailureLog = assertLogsWtfs(message) { loggingRunnable.run() }
+ loggingCallable: Callable<T>,
+): WtfBlockResult<T> = assertLogsWtf(message, allowMultiple = true, loggingCallable)
/** The data passed to [TerribleFailureHandler.onTerribleFailure] */
data class TerribleFailureLog(
val tag: String,
val failure: Log.TerribleFailure,
- val system: Boolean
+ val system: Boolean,
)
+
+/** The [Log.wtf] logs and return value of the block */
+data class WtfBlockResult<T>(val logs: List<TerribleFailureLog>, val result: T)
+
+/** Assert that [loggingRunnable] makes a call to [Log.wtf] */
+@JvmOverloads
+fun assertRunnableLogsWtf(
+ message: String = "Expected Log.wtf to be called",
+ allowMultiple: Boolean = false,
+ loggingRunnable: Runnable,
+): WtfBlockResult<Unit> =
+ assertLogsWtf(message = message, allowMultiple = allowMultiple) { loggingRunnable.run() }
+
+/** Assert that [loggingRunnable] makes at least one call to [Log.wtf] */
+@JvmOverloads
+fun assertRunnableLogsWtfs(
+ message: String = "Expected Log.wtf to be called once or more",
+ loggingRunnable: Runnable,
+): WtfBlockResult<Unit> = assertRunnableLogsWtf(message, allowMultiple = true, loggingRunnable)