changeset 212:a336cdbee118 draft

Added two new tests getGenericSuperclass() and getGenericInterfaces() into BindingsClassTest.
author Pavel Tisnovsky <ptisnovs@redhat.com>
date Thu, 15 Aug 2013 10:27:49 +0200
parents 3f08a736ce66
children baa3f1d2d03c
files ChangeLog src/org/RhinoTests/BindingsClassTest.java
diffstat 2 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Aug 14 10:51:30 2013 +0200
+++ b/ChangeLog	Thu Aug 15 10:27:49 2013 +0200
@@ -1,3 +1,9 @@
+2013-08-15  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* src/org/RhinoTests/BindingsClassTest.java:
+	Added two new tests getGenericSuperclass() and getGenericInterfaces()
+	into BindingsClassTest.
+
 2013-08-14  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/org/RhinoTests/BindingsClassTest.java:
--- a/src/org/RhinoTests/BindingsClassTest.java	Wed Aug 14 10:51:30 2013 +0200
+++ b/src/org/RhinoTests/BindingsClassTest.java	Thu Aug 15 10:27:49 2013 +0200
@@ -1055,6 +1055,63 @@
     }
 
     /**
+     * Test for method javax.script.Bindings.getClass().getGenericSuperclass()
+     */
+    protected void testGetGenericSuperclass() {
+        Type genericSuperclass = this.bindingsClass.getGenericSuperclass();
+        assertNull(genericSuperclass, "getGenericSuperclass() does not return null");
+    }
+
+    /**
+     * Test for method javax.script.Bindings.getClass().getGenericInterfaces()
+     */
+    protected void testGetGenericInterfaces() {
+        // array of interface names that should exists
+        final String[] genericInterfaceNames_jdk6 = {
+            "java.util.Map<java.lang.String, java.lang.Object>"
+        };
+
+        final String[] genericInterfaceNames_jdk7 = {
+            "java.util.Map<java.lang.String, java.lang.Object>"
+        };
+
+        final String[] genericInterfaceNames_jdk8 = {
+            "java.util.Map<java.lang.String, java.lang.Object>"
+        };
+
+        // get the right array of field signatures
+        String[] genericInterfaceNames = null;
+        switch (getJavaVersion()) {
+            case 6:
+                genericInterfaceNames = genericInterfaceNames_jdk6;
+                break;
+            case 7:
+                genericInterfaceNames = genericInterfaceNames_jdk7;
+                break;
+            case 8:
+                genericInterfaceNames = genericInterfaceNames_jdk8;
+                break;
+        }
+
+        // get all generic interfaces
+        Type[] genericInterfaces = this.bindingsClass.getGenericInterfaces();
+        assertNotNull(genericInterfaces, "getGenericInterfaces() returns null");
+        assertEquals(1, genericInterfaces.length, "array of wrong size returned by getGenericInterfaces " + genericInterfaces.length);
+
+        // and transform the array into a list of field names
+        List<String> interfacesAsString = new ArrayList<String>();
+        for (Type genericInterface : genericInterfaces) {
+            interfacesAsString.add(genericInterface.toString());
+        }
+
+        // check if all required interfaces really exists
+        for (String interfaceThatShouldExists : genericInterfaceNames) {
+            assertTrue(interfacesAsString.contains(interfaceThatShouldExists),
+                    "interface " + interfaceThatShouldExists + " not found");
+        }
+    }
+
+    /**
      * Test for method javax.script.Bindings.getClass().getEnumConstants()
      */
     protected void testGetEnumConstants() {