Make sure no suppressed expression is present when they shouldn't

In fact the test already passes, because addSuppressed contains
an explicit test that if this === argument, then it doesn't add
it. But otherwise that's a bug in tryCleanup

Test: NetworkStaticLibTests
Change-Id: I202790bbe8d82445c5affdd9076561c2c6ea9b59
diff --git a/staticlibs/tests/unit/src/com/android/net/module/util/CleanupTest.kt b/staticlibs/tests/unit/src/com/android/net/module/util/CleanupTest.kt
index af4d818..05faed1 100644
--- a/staticlibs/tests/unit/src/com/android/net/module/util/CleanupTest.kt
+++ b/staticlibs/tests/unit/src/com/android/net/module/util/CleanupTest.kt
@@ -18,14 +18,13 @@
 
 import android.util.Log
 import com.android.testutils.tryTest
-import kotlin.test.assertFailsWith
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.junit.runners.JUnit4
+import kotlin.test.assertFailsWith
 import kotlin.test.assertTrue
-import kotlin.test.fail
 
-private val TAG = CleanupTest::class.toString()
+private val TAG = CleanupTest::class.simpleName
 
 @RunWith(JUnit4::class)
 class CleanupTest {
@@ -49,7 +48,7 @@
     @Test
     fun testThrowTry() {
         var x = 1
-        assertFailsWith<TestException1> {
+        val thrown = assertFailsWith<TestException1> {
             tryTest {
                 x = 2
                 throw TestException1()
@@ -60,13 +59,14 @@
                 Log.e(TAG, "Do nothing")
             }
         }
+        assertTrue(thrown.suppressedExceptions.isEmpty())
         assertTrue(x == 3)
     }
 
     @Test
     fun testThrowCleanup() {
         var x = 1
-        assertFailsWith<TestException2> {
+        val thrown = assertFailsWith<TestException2> {
             tryTest {
                 x = 2
                 Log.e(TAG, "Do nothing")
@@ -77,13 +77,14 @@
                 x = 4
             }
         }
+        assertTrue(thrown.suppressedExceptions.isEmpty())
         assertTrue(x == 3)
     }
 
     @Test
     fun testThrowBoth() {
         var x = 1
-        try {
+        val thrown = assertFailsWith<TestException1> {
             tryTest {
                 x = 2
                 throw TestException1()
@@ -94,10 +95,8 @@
                 throw TestException2()
                 x = 5
             }
-            fail("Expected failure with TestException1")
-        } catch (e: TestException1) {
-            assertTrue(e.suppressedExceptions[0] is TestException2)
         }
+        assertTrue(thrown.suppressedExceptions[0] is TestException2)
         assertTrue(x == 4)
     }
 }
diff --git a/staticlibs/testutils/hostdevice/com/android/testutils/Cleanup.kt b/staticlibs/testutils/hostdevice/com/android/testutils/Cleanup.kt
index 769d980..fb45582 100644
--- a/staticlibs/testutils/hostdevice/com/android/testutils/Cleanup.kt
+++ b/staticlibs/testutils/hostdevice/com/android/testutils/Cleanup.kt
@@ -63,7 +63,6 @@
     inline infix fun cleanup(block: () -> Unit) {
         try {
             block()
-            if (null != originalException) throw originalException
         } catch (e: Exception) {
             if (null == originalException) {
                 throw e
@@ -72,6 +71,7 @@
                 throw originalException
             }
         }
+        if (null != originalException) throw originalException
     }
 }