Prevent ArtServiceTests Mockito strictness from masking test error

The finishMocking logic should only be run if no exception was thrown
by the test. Otherwise the strictness violation could mask any real
test errors and make the logs less useful.

This moves it out of the finally block and makes it mirror the original
MockitoRule, passing the Exception into Mockito so that it can skip
the validation logic if another error was encountered.

Test: atest ArtServiceTests

Ignore-AOSP-First: ART Services.

Change-Id: I499356f49bb4e3325de38959c5d2609bc95c0486
diff --git a/libartservice/service/javatests/com/android/server/art/testing/StaticMockitoRule.java b/libartservice/service/javatests/com/android/server/art/testing/StaticMockitoRule.java
index f6e1107..595370b 100644
--- a/libartservice/service/javatests/com/android/server/art/testing/StaticMockitoRule.java
+++ b/libartservice/service/javatests/com/android/server/art/testing/StaticMockitoRule.java
@@ -24,6 +24,7 @@
 import org.junit.rules.MethodRule;
 import org.junit.runners.model.FrameworkMethod;
 import org.junit.runners.model.Statement;
+import org.mockito.junit.MockitoRule;
 import org.mockito.quality.Strictness;
 
 /**
@@ -52,11 +53,19 @@
                 }
 
                 StaticMockitoSession session = builder.startMocking();
+                Throwable testFailure = evaluateSafely(base);
+                session.finishMocking(testFailure);
+                if (testFailure != null) {
+                    throw testFailure;
+                }
+            }
 
+            private Throwable evaluateSafely(Statement base) {
                 try {
                     base.evaluate();
-                } finally {
-                    session.finishMocking();
+                    return null;
+                } catch (Throwable throwable) {
+                    return throwable;
                 }
             }
         };