Clean jsinterop tests.
Change-Id: I3c6fb99c1fecc29c2a33b92bc2ce47323d553e72
Review-Link: https://gwt-review.googlesource.com/#/c/18740/
diff --git a/user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java8Test.java b/user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java8Test.java
index 7962573..782a42c 100644
--- a/user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java8Test.java
+++ b/user/test-super/com/google/gwt/dev/jjs/super/com/google/gwt/dev/jjs/test/Java8Test.java
@@ -1604,7 +1604,22 @@
}
@JsFunction
- interface JsFunctionInterface {
+ interface MyJsFunctionInterface {
+ int foo(int a);
+ }
+
+ public void testJsFunction_lambda() {
+ MyJsFunctionInterface jsFunctionInterface = a -> a + 2;
+ assertEquals(12, callAsFunction(jsFunctionInterface, 10));
+ assertEquals(12, jsFunctionInterface.foo(10));
+ }
+
+ private static native int callAsFunction(Object fn, int arg) /*-{
+ return fn(arg);
+ }-*/;
+
+ @JsFunction
+ interface MyJsFunctionInterfaceWithOverlay {
Double m();
@JsOverlay
default Double callM() {
@@ -1612,11 +1627,12 @@
}
}
- private static native JsFunctionInterface createNative() /*-{
+ private static native MyJsFunctionInterfaceWithOverlay createNative() /*-{
return function () { return 5; };
}-*/;
+
public void testJsFunction_withOverlay() {
- JsFunctionInterface f = new JsFunctionInterface() {
+ MyJsFunctionInterfaceWithOverlay f = new MyJsFunctionInterfaceWithOverlay() {
@Override
public Double m() {
return new Double(2.0);
diff --git a/user/test/com/google/gwt/core/CoreJsInteropSuite.java b/user/test/com/google/gwt/core/CoreJsInteropSuite.java
index 211aecb..98bff5c 100644
--- a/user/test/com/google/gwt/core/CoreJsInteropSuite.java
+++ b/user/test/com/google/gwt/core/CoreJsInteropSuite.java
@@ -23,7 +23,6 @@
import com.google.gwt.core.interop.JsTypeArrayTest;
import com.google.gwt.core.interop.JsTypeBridgeTest;
import com.google.gwt.core.interop.JsTypeObjectMethodsTest;
-import com.google.gwt.core.interop.JsTypeSpecialTypesTest;
import com.google.gwt.core.interop.JsTypeTest;
import com.google.gwt.core.interop.JsTypeVarargsTest;
import com.google.gwt.core.interop.NativeJsTypeTest;
@@ -42,7 +41,6 @@
suite.addTestSuite(JsExportOptimizationTest.class);
suite.addTestSuite(JsTypeTest.class);
suite.addTestSuite(JsTypeBridgeTest.class);
- suite.addTestSuite(JsTypeSpecialTypesTest.class);
suite.addTestSuite(JsTypeObjectMethodsTest.class);
suite.addTestSuite(JsPropertyTest.class);
suite.addTestSuite(JsMethodTest.class);
diff --git a/user/test/com/google/gwt/core/interop/JsFunctionTest.java b/user/test/com/google/gwt/core/interop/JsFunctionTest.java
index d7b2cbb..8c56e97 100644
--- a/user/test/com/google/gwt/core/interop/JsFunctionTest.java
+++ b/user/test/com/google/gwt/core/interop/JsFunctionTest.java
@@ -24,6 +24,7 @@
/**
* Tests JsFunction functionality.
+ * Note that JsOverlay and lambda's are tested in Java8Test.
*/
@SuppressWarnings("cast")
public class JsFunctionTest extends GWTTestCase {
@@ -249,7 +250,6 @@
}
public void testGetClass() {
-
MyJsFunctionInterface jsfunctionImplementation =
new MyJsFunctionInterface() {
@Override
@@ -264,7 +264,6 @@
}
public void testInstanceField() {
-
MyJsFunctionInterface jsfunctionImplementation =
new MyJsFunctionInterface() {
String hello = new Object().getClass().getName();
@@ -276,26 +275,6 @@
assertEquals(Object.class.getName().length() + 4, jsfunctionImplementation.foo(4));
}
- // uncomment when Java8 is supported.
-// public void testJsFunctionLambda_JS() {
-// MyJsFunctionInterface jsFunctionInterface = a -> { return a + 2; };
-// assertEquals(12, callAsFunction(jsFunctionInterface, 10));
-// assertEquals(12, callAsCallBackFunction(jsFunctionInterface, 10));
-// }
-//
-// public void testJsFunctionLambda_Java() {
-// MyJsFunctionInterface jsFunctionInterface = a -> { return a + 2; };
-// assertEquals(12, jsFunctionInterface.foo(10));
-// }
-//
-// public void testJsFunctionDefaultMethod() {
-// MyJsFunctionSubInterfaceWithDefaultMethod impl =
-// new MyJsFunctionSubInterfaceWithDefaultMethod() {
-// };
-// assertEquals(10, impl.foo(10));
-// assertEquals(10, callAsFunction(impl, 10));
-// }
-
private static native Object callAsFunction(Object fn) /*-{
return fn();
}-*/;
diff --git a/user/test/com/google/gwt/core/interop/JsTypeArrayTest.java b/user/test/com/google/gwt/core/interop/JsTypeArrayTest.java
index 7ac5fec..b1e50d4 100644
--- a/user/test/com/google/gwt/core/interop/JsTypeArrayTest.java
+++ b/user/test/com/google/gwt/core/interop/JsTypeArrayTest.java
@@ -97,7 +97,6 @@
public SimpleJsTypeAsAField[] arrayField;
}
- // TODO(rluble): Needs fixes in ImlementCastsAndTypeChecks, ArrayNormalizer and maybe type oracle.
public void testJsTypeArray_asAField() {
SimpleJsTypeAsAFieldHolder holder = new SimpleJsTypeAsAFieldHolder();
fillArrayField(holder);
@@ -202,6 +201,17 @@
assertTrue(array instanceof SimpleJsTypeReturnForMultiDimArray[][][]);
}
+ @JsType(isNative = true)
+ private static class UnreferencedNativeType { }
+
+ private static native Object createArray() /*-{
+ return [];
+ }-*/;
+
+ public void testJsTypeArray_unreferencedNativeArrayInstanceOf() {
+ assertTrue(createArray() instanceof UnreferencedNativeType[]);
+ }
+
@JsFunction
interface SomeFunction {
int m(int i);
diff --git a/user/test/com/google/gwt/core/interop/JsTypeSpecialTypesTest.java b/user/test/com/google/gwt/core/interop/JsTypeSpecialTypesTest.java
deleted file mode 100644
index afea9ee..0000000
--- a/user/test/com/google/gwt/core/interop/JsTypeSpecialTypesTest.java
+++ /dev/null
@@ -1,153 +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.core.interop;
-
-import com.google.gwt.junit.client.GWTTestCase;
-
-import jsinterop.annotations.JsFunction;
-import jsinterop.annotations.JsPackage;
-import jsinterop.annotations.JsType;
-
-/**
- * Tests special JsType functionality.
- */
-@SuppressWarnings("cast")
-public class JsTypeSpecialTypesTest extends GWTTestCase {
-
- @Override
- public String getModuleName() {
- return "com.google.gwt.core.Interop";
- }
-
- @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Array")
- static class NativeArray {
- }
-
- public void testNativeArray() {
- Object object = new Object[10];
-
- assertNotNull((NativeArray) object);
- assertTrue(object instanceof NativeArray);
-
- Object nativeArray = new NativeArray();
- assertNotNull((NativeArray[]) nativeArray);
- assertTrue(nativeArray instanceof NativeArray[]);
- }
-
- @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Function")
- static class NativeFunction {
- }
-
- @JsFunction
- interface SomeFunctionalInterface {
- void m();
- }
-
- public void testNativeFunction() {
- Object object = new SomeFunctionalInterface() {
- @Override
- public void m() {
- }
- };
-
- assertNotNull((NativeFunction) object);
- assertTrue(object instanceof NativeFunction);
-
- SomeFunctionalInterface nativeFunction = (SomeFunctionalInterface) new NativeFunction();
- assertTrue(nativeFunction instanceof SomeFunctionalInterface);
- }
-
- @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Number")
- static class NativeNumber {
- public NativeNumber(double number) { }
- public native NativeNumber valueOf();
- }
-
- public void testNativeNumber() {
- Object object = new Double(1);
-
- assertNotNull((NativeNumber) object);
- assertTrue(object instanceof NativeNumber);
-
- // new NativeString() returns a boxed JS number. Java Double object are only interchangeable
- // with unboxed JS numbers.
- Object nativeNumber = new NativeNumber(10.0).valueOf();
- assertNotNull((Double) nativeNumber);
- assertTrue(nativeNumber instanceof Double);
- assertEquals(10.0, (Double) nativeNumber);
- }
-
- @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "String")
- static class NativeString {
- public NativeString(String someString) { }
- public native NativeString valueOf();
- }
-
- public void testNativeString() {
- Object object = "Hello";
-
- assertNotNull((NativeString) object);
- assertTrue(object instanceof NativeString);
-
- // new NativeString() returns a boxed JS string. Java String objects are only interchangeable
- // with unboxed JS strings.
- Object nativeString = new NativeString("Hello").valueOf();
- assertNotNull((String) nativeString);
- assertTrue(nativeString instanceof String);
- assertEquals("Hello", nativeString);
- }
-
- @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
- static class NativeObject {
- }
-
- public void testNativeObject() {
- Object object = new Object();
-
- assertNotNull((NativeObject) object);
- assertTrue(object instanceof NativeObject);
-
- Object nativeObject = new NativeObject();
- assertNotNull((Object) nativeObject);
- assertTrue(nativeObject instanceof Object);
- }
-
- @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "*")
- interface Star {
- }
-
- public void testStar() {
- Object object = new Object();
-
- assertNotNull((Star) object);
-
- object = Double.valueOf(3.0);
- assertNotNull((Star) object);
- }
-
- @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "?")
- interface Wildcard {
- }
-
- public void testWildcard() {
- Object object = new Object();
-
- assertNotNull((Wildcard) object);
-
- object = Double.valueOf(3.0);
- assertNotNull((Wildcard) object);
- }
-}
diff --git a/user/test/com/google/gwt/core/interop/JsTypeTest.java b/user/test/com/google/gwt/core/interop/JsTypeTest.java
index 5b7fba7..dc1ea1c 100644
--- a/user/test/com/google/gwt/core/interop/JsTypeTest.java
+++ b/user/test/com/google/gwt/core/interop/JsTypeTest.java
@@ -515,6 +515,32 @@
assertEquals("bar", callFunction(instance, "bar", null));
}
+ @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "*")
+ interface Star {
+ }
+
+ public void testStar() {
+ Object object = new Object();
+
+ assertNotNull((Star) object);
+
+ object = Double.valueOf(3.0);
+ assertNotNull((Star) object);
+ }
+
+ @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "?")
+ interface Wildcard {
+ }
+
+ public void testWildcard() {
+ Object object = new Object();
+
+ assertNotNull((Wildcard) object);
+
+ object = Double.valueOf(3.0);
+ assertNotNull((Wildcard) object);
+ }
+
static class ClassWithJsMethod {
@JsMethod(name = "name")
public String className() {
diff --git a/user/test/com/google/gwt/core/interop/MyJsFunctionSubInterfaceWithDefaultMethod.java b/user/test/com/google/gwt/core/interop/MyJsFunctionSubInterfaceWithDefaultMethod.java
deleted file mode 100644
index ce0b410..0000000
--- a/user/test/com/google/gwt/core/interop/MyJsFunctionSubInterfaceWithDefaultMethod.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.core.interop;
-
-/**
- * An interface that extends JsFunction interface {@code MyJsFunctionInterface} with default method.
- */
-public interface MyJsFunctionSubInterfaceWithDefaultMethod extends MyJsFunctionInterface {
-
- // uncomment when Java8 is supported.
-// @Override
-// default int foo(int a) {
-// return a;
-// }
-}
diff --git a/user/test/com/google/gwt/core/interop/NativeJsTypeTest.java b/user/test/com/google/gwt/core/interop/NativeJsTypeTest.java
index 4cf5378..b36456e 100644
--- a/user/test/com/google/gwt/core/interop/NativeJsTypeTest.java
+++ b/user/test/com/google/gwt/core/interop/NativeJsTypeTest.java
@@ -18,7 +18,6 @@
import static jsinterop.annotations.JsPackage.GLOBAL;
import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.core.interop.JsTypeSpecialTypesTest.SomeFunctionalInterface;
import com.google.gwt.junit.client.GWTTestCase;
import javaemul.internal.annotations.DoNotInline;
@@ -273,7 +272,7 @@
Object aJsFunction = new SomeFunction();
// True cases.
assertTrue(aJsFunction instanceof NativeFunction);
- assertTrue(aJsFunction instanceof SomeFunctionalInterface);
+ assertTrue(aJsFunction instanceof SomeFunctionInterface);
assertTrue(aJsFunction instanceof NativeObject);
// False cases.
assertFalse(aJsFunction instanceof NativeArray);
@@ -283,7 +282,7 @@
Object anotherFunction = createFunction();
// True cases.
assertTrue(anotherFunction instanceof NativeFunction);
- assertTrue(anotherFunction instanceof SomeFunctionalInterface);
+ assertTrue(anotherFunction instanceof SomeFunctionInterface);
assertTrue(anotherFunction instanceof NativeObject);
// False cases.
assertFalse(anotherFunction instanceof NativeArray);
@@ -354,6 +353,15 @@
assertFalse(aBoxedNumber instanceof NativeFunction);
assertFalse(aBoxedNumber instanceof NativeString);
+ Object anObject = new Object();
+ // True cases.
+ assertTrue(anObject instanceof NativeObject);
+ // False cases.
+ assertFalse(anObject instanceof NativeNumber);
+ assertFalse(anObject instanceof NativeArray);
+ assertFalse(anObject instanceof NativeFunction);
+ assertFalse(anObject instanceof NativeString);
+
Object nullObject = null;
assertFalse(nullObject instanceof NativeObject);
@@ -373,17 +381,6 @@
private static native Object getUndefined() /*-{
}-*/;
- @JsType(isNative = true)
- private static class UnreferencedNativeType { }
-
- private static native Object createArray() /*-{
- return [];
- }-*/;
-
- public void testUnreferencedNativeArrayInstanceOf() {
- assertTrue(createArray() instanceof UnreferencedNativeType[]);
- }
-
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
interface NativeInterface {
void add(String element);