Cleanup Throwable test and fix jsinterop related warnings.

Change-Id: I272f63fa66e6097d00d672ad9f8af6982e483b1e
diff --git a/user/test/com/google/gwt/emultest/java/lang/JsExceptionTest.java b/user/test/com/google/gwt/emultest/java/lang/JsExceptionTest.java
index d18843d..0c2abbb 100644
--- a/user/test/com/google/gwt/emultest/java/lang/JsExceptionTest.java
+++ b/user/test/com/google/gwt/emultest/java/lang/JsExceptionTest.java
@@ -13,9 +13,6 @@
  */
 package com.google.gwt.emultest.java.lang;
 
-import static com.google.gwt.emultest.java.lang.JsExceptionViolator.createJsException;
-import static com.google.gwt.emultest.java.lang.JsExceptionViolator.getBackingJsObject;
-
 import com.google.gwt.testing.TestUtils;
 
 import jsinterop.annotations.JsMethod;
@@ -43,19 +40,19 @@
 
   public void testCatchJava() {
     Object obj = new Object();
-    Exception e = createJsException(obj);
+    Throwable e = createJsException(obj);
     assertJsException(obj, catchJava(createThrower(e)));
   }
 
   public void testCatchNative() {
     Object obj = new Object();
-    Exception e = createJsException(obj);
+    Throwable e = createJsException(obj);
     assertSame(obj, catchNative(createThrower(e)));
   }
 
   public void testCatchNativePropagatedFromFinally() {
     Object obj = new Object();
-    Exception e = createJsException(obj);
+    Throwable e = createJsException(obj);
     assertSame(obj, catchNative(wrapWithFinally(createThrower(e))));
     assertTrue(keepFinallyAlive);
   }
@@ -76,7 +73,7 @@
 
   public void testJavaNativeJavaSandwichCatch() {
     Object obj = new Object();
-    Exception e = createJsException(obj);
+    Throwable e = createJsException(obj);
     assertJsException(obj, javaNativeJavaSandwich(e));
   }
 
diff --git a/user/test/com/google/gwt/emultest/java/lang/JsExceptionViolator.java b/user/test/com/google/gwt/emultest/java/lang/JsExceptionViolator.java
deleted file mode 100644
index 9ab620f..0000000
--- a/user/test/com/google/gwt/emultest/java/lang/JsExceptionViolator.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.emultest.java.lang;
-
-/**
- * Provides access to JsException emul that is not normally available in JRE.
- */
-class JsExceptionViolator {
-  public static native Exception createJsException(Object wrapped) /*-{
-    return @com.google.gwt.core.client.JavaScriptException::new(Ljava/lang/Object;)(wrapped);
-  }-*/;
-  public static native Object getBackingJsObject(Throwable t) /*-{
-    return t.@Throwable::backingJsObject;
-  }-*/;
-}
diff --git a/user/test/com/google/gwt/emultest/java/lang/ThrowableTest.java b/user/test/com/google/gwt/emultest/java/lang/ThrowableTest.java
index cd72e7d..ae01e46 100644
--- a/user/test/com/google/gwt/emultest/java/lang/ThrowableTest.java
+++ b/user/test/com/google/gwt/emultest/java/lang/ThrowableTest.java
@@ -16,9 +16,6 @@
 package com.google.gwt.emultest.java.lang;
 
 import com.google.gwt.testing.TestUtils;
-
-import javaemul.internal.JsUtils;
-
 import jsinterop.annotations.JsType;
 
 /** Unit tests for the GWT emulation of java.lang.Throwable class. */
@@ -74,7 +71,7 @@
     }
     Throwable e = new Throwable("<my msg>");
     Object caughtNative = catchNative(createThrower(e));
-    assertTrue(caughtNative instanceof Error);
+    assertTrue(caughtNative instanceof JsError);
     assertTrue(caughtNative.toString().contains("<my msg>"));
     assertTrue(caughtNative.toString().contains(Throwable.class.getName()));
   }
@@ -91,7 +88,7 @@
     };
 
     Object caughtNative = catchNative(createThrower(e));
-    assertTrue(caughtNative instanceof Error);
+    assertTrue(caughtNative instanceof JsError);
     assertTrue(caughtNative.toString().contains("<my msg>"));
     assertTrue(caughtNative.toString().contains(e.getClass().getName()));
   }
@@ -120,12 +117,7 @@
     Throwable rootCause = new Throwable("Root cause");
     Throwable subError = new Throwable("Sub-error", rootCause);
 
-    Error backingError = (Error) catchNative(createThrower(subError));
-    Error rootBackingError = (Error) catchNative(createThrower(rootCause));
-    assertEquals(
-        "backingJsObject should have a cause linked to the parent backingJsObject",
-        rootBackingError,
-        JsUtils.getProperty(backingError, "cause"));
+    assertEquals(getBackingJsObject(rootCause), getBackingJsObject(subError).getCause());
   }
 
   public void testLinkedBackingObjects_initCause() {
@@ -136,12 +128,7 @@
     Throwable subError = new Throwable("Sub-error");
     subError.initCause(rootCause);
 
-    Error backingError = (Error) catchNative(createThrower(subError));
-    Error rootBackingError = (Error) catchNative(createThrower(rootCause));
-    assertEquals(
-        "backingJsObject should have a cause linked to the parent backingJsObject",
-        rootBackingError,
-        JsUtils.getProperty(backingError, "cause"));
+    assertEquals(getBackingJsObject(rootCause), getBackingJsObject(subError).getCause());
   }
 
   public void testLinkedBackingObjects_noCause() {
@@ -150,11 +137,10 @@
     }
     Throwable subError = new Throwable("Sub-error");
 
-    Error backingError = (Error) catchNative(createThrower(subError));
-    assertNull(
-        "backingJsObject should have no linked cause", JsUtils.getProperty(backingError, "cause"));
+    assertNull(getBackingJsObject(subError).getCause());
   }
 
-  @JsType(isNative = true, namespace = "<window>")
-  private static class Error { }
+
+  @JsType(isNative = true, name = "Error", namespace = "<window>")
+  private static class JsError { }
 }
diff --git a/user/test/com/google/gwt/emultest/java/lang/ThrowableTestBase.java b/user/test/com/google/gwt/emultest/java/lang/ThrowableTestBase.java
index c5bea6f..967eb5f 100644
--- a/user/test/com/google/gwt/emultest/java/lang/ThrowableTestBase.java
+++ b/user/test/com/google/gwt/emultest/java/lang/ThrowableTestBase.java
@@ -16,8 +16,12 @@
 package com.google.gwt.emultest.java.lang;
 
 import com.google.gwt.junit.client.GWTTestCase;
-
+import javaemul.internal.JsUtils;
 import jsinterop.annotations.JsFunction;
+import jsinterop.annotations.JsMethod;
+import jsinterop.annotations.JsOverlay;
+import jsinterop.annotations.JsPackage;
+import jsinterop.annotations.JsType;
 
 /**
  * Base class that provides utilities for testing subclasses of Throwable.
@@ -29,10 +33,17 @@
     void throwException() throws Throwable;
   }
 
+  @JsMethod
+  protected static native Throwable createJsException(Object wrapped) /*-{
+    return @com.google.gwt.core.client.JavaScriptException::new(Ljava/lang/Object;)(wrapped);
+  }-*/;
+
+  @JsMethod
   protected static native void throwNative(Object e) /*-{
     throw e;
   }-*/;
 
+  @JsMethod
   protected static native Object catchNative(Thrower thrower) /*-{
     try {
       thrower();
@@ -68,7 +79,25 @@
   }
 
   // java throw -> jsni catch -> jsni throw -> java catch
-  protected Throwable javaNativeJavaSandwich(Throwable e) {
+  protected static Throwable javaNativeJavaSandwich(Throwable e) {
     return catchJava(createNativeThrower(catchNative(createThrower(e))));
   }
+
+  protected static BackingJsObject getBackingJsObject(Throwable t) {
+    return (BackingJsObject) catchNative(createThrower(t));
+  }
+
+  /** A JavaScript object backing a Throwable. */
+  @JsType(isNative = true, name = "*", namespace = JsPackage.GLOBAL)
+  interface BackingJsObject {
+    @JsOverlay
+    default Object getCause() {
+      return JsUtils.getProperty(this, "cause");
+    }
+
+    @JsOverlay
+    default Object[] getSuppressed() {
+      return JsUtils.getProperty(this, "suppressed");
+    }
+  }
 }