Report all TestDelegate failures in a single run.

Change-Id: I37fa0a6f300ea89c8d0a60380b77b7d61db01cb7
diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java
index 274516c..8b362ec 100644
--- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java
+++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/TestDelegates.java
@@ -41,27 +41,29 @@
  */
 public class TestDelegates extends TestCase {
 
+    private List<String> mErrors = new ArrayList<String>();
+
     public void testNativeDelegates() {
 
         final String[] classes = CreateInfo.DELEGATE_CLASS_NATIVES;
-        final int count = classes.length;
-        for (int i = 0 ; i < count ; i++) {
-            loadAndCompareClasses(classes[i], classes[i] + "_Delegate");
+        mErrors.clear();
+        for (String clazz : classes) {
+            loadAndCompareClasses(clazz, clazz + "_Delegate");
         }
+        assertTrue(getErrors(), mErrors.isEmpty());
     }
 
     public void testMethodDelegates() {
         final String[] methods = CreateInfo.DELEGATE_METHODS;
-        final int count = methods.length;
-        for (int i = 0 ; i < count ; i++) {
-            String methodName = methods[i];
-
+        mErrors.clear();
+        for (String methodName : methods) {
             // extract the class name
             String className = methodName.substring(0, methodName.indexOf('#'));
             String targetClassName = className.replace('$', '_') + "_Delegate";
 
             loadAndCompareClasses(className, targetClassName);
         }
+        assertTrue(getErrors(), mErrors.isEmpty());
     }
 
     private void loadAndCompareClasses(String originalClassName, String delegateClassName) {
@@ -73,9 +75,9 @@
 
             compare(originalClass, delegateClass);
         } catch (ClassNotFoundException e) {
-           fail("Failed to load class: " + e.getMessage());
+            mErrors.add("Failed to load class: " + e.getMessage());
         } catch (SecurityException e) {
-            fail("Failed to load class: " + e.getMessage());
+            mErrors.add("Failed to load class: " + e.getMessage());
         }
     }
 
@@ -122,35 +124,39 @@
                         parameters);
 
                 // check the return type of the methods match.
-                assertTrue(
-                        String.format("Delegate method %1$s.%2$s does not match the corresponding " +
-                                "framework method which returns %3$s",
-                                delegateClass.getName(),
-                                getMethodName(delegateMethod),
-                                originalMethod.getReturnType().getName()),
-                        delegateMethod.getReturnType() == originalMethod.getReturnType());
+                if (delegateMethod.getReturnType() != originalMethod.getReturnType()) {
+                    mErrors.add(
+                            String.format("Delegate method %1$s.%2$s does not match the " +
+                                    "corresponding framework method which returns %3$s",
+                            delegateClass.getName(),
+                            getMethodName(delegateMethod),
+                            originalMethod.getReturnType().getName()));
+                }
 
                 // check that the method has the annotation
-                assertNotNull(
-                        String.format(
-                                "Delegate method %1$s for class %2$s does not have the @LayoutlibDelegate annotation",
-                                delegateMethod.getName(),
-                                originalClass.getName()),
-                        delegateMethod.getAnnotation(LayoutlibDelegate.class));
+                if (delegateMethod.getAnnotation(LayoutlibDelegate.class) == null) {
+                    mErrors.add(
+                            String.format("Delegate method %1$s for class %2$s does not have the " +
+                                            "@LayoutlibDelegate annotation",
+                                    delegateMethod.getName(),
+                                    originalClass.getName()));
+                }
 
                 // check that the method is static
-                assertTrue(
-                        String.format(
-                                "Delegate method %1$s for class %2$s is not static",
-                                delegateMethod.getName(),
-                                originalClass.getName()),
-                        (delegateMethod.getModifiers() & Modifier.STATIC) == Modifier.STATIC);
+                if ((delegateMethod.getModifiers() & Modifier.STATIC) != Modifier.STATIC) {
+                    mErrors.add(
+                            String.format(
+                                    "Delegate method %1$s for class %2$s is not static",
+                                    delegateMethod.getName(),
+                                    originalClass.getName())
+                    );
+                }
 
                 // add the method as checked.
                 checkedDelegateMethods.add(delegateMethod);
             } catch (NoSuchMethodException e) {
                 String name = getMethodName(originalMethod, parameters);
-                fail(String.format("Missing %1$s.%2$s", delegateClass.getName(), name));
+                mErrors.add(String.format("Missing %1$s.%2$s", delegateClass.getName(), name));
             }
         }
 
@@ -167,12 +173,12 @@
                 continue;
             }
 
-            assertTrue(
-                    String.format(
-                            "Delegate method %1$s.%2$s is not used anymore and must be removed",
-                            delegateClass.getName(),
-                            getMethodName(delegateMethod)),
-                    checkedDelegateMethods.contains(delegateMethod));
+            if (!checkedDelegateMethods.contains(delegateMethod)) {
+                mErrors.add(String.format(
+                        "Delegate method %1$s.%2$s is not used anymore and must be removed",
+                        delegateClass.getName(),
+                        getMethodName(delegateMethod)));
+            }
         }
 
     }
@@ -203,4 +209,12 @@
 
         return sb.toString();
     }
+
+    private String getErrors() {
+        StringBuilder s = new StringBuilder();
+        for (String error : mErrors) {
+            s.append(error).append('\n');
+        }
+        return s.toString();
+    }
 }