/hg/rhino-tests: Added three tests into the ScriptEngineManagerC...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Wed Apr 3 00:54:36 PDT 2013


changeset 102a062e2ee2 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=102a062e2ee2
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Apr 03 09:57:50 2013 +0200

	Added three tests into the ScriptEngineManagerClassTest:
	getDeclaredField, getMethod and getDeclaredMethod.


diffstat:

 ChangeLog                                            |    6 +
 src/org/RhinoTests/ScriptEngineManagerClassTest.java |  196 ++++++++++++++++++-
 2 files changed, 197 insertions(+), 5 deletions(-)

diffs (247 lines):

diff -r 3db7d0c4c031 -r 102a062e2ee2 ChangeLog
--- a/ChangeLog	Tue Apr 02 09:49:53 2013 +0200
+++ b/ChangeLog	Wed Apr 03 09:57:50 2013 +0200
@@ -1,3 +1,9 @@
+2013-04-03  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/RhinoTests/ScriptEngineManagerClassTest.java:
+	Added three tests into the ScriptEngineManagerClassTest:
+	getDeclaredField, getMethod and getDeclaredMethod.
+
 2013-04-02  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/ScriptEngineFactoryClassTest.java:
diff -r 3db7d0c4c031 -r 102a062e2ee2 src/org/RhinoTests/ScriptEngineManagerClassTest.java
--- a/src/org/RhinoTests/ScriptEngineManagerClassTest.java	Tue Apr 02 09:49:53 2013 +0200
+++ b/src/org/RhinoTests/ScriptEngineManagerClassTest.java	Wed Apr 03 09:57:50 2013 +0200
@@ -445,8 +445,8 @@
      * Test for method javax.script.ScriptEngineManager.getClass().getDeclaredFields()
      */
     protected void testGetDeclaredFields() {
-        // following fields should be declared
-        final String[] fieldsThatShouldExists = {
+        // following declared fields should exists
+        final String[] declaredFieldsThatShouldExist_jdk6 = {
             "private static final boolean javax.script.ScriptEngineManager.DEBUG",
             "private java.util.HashSet javax.script.ScriptEngineManager.engineSpis",
             "private java.util.HashMap javax.script.ScriptEngineManager.nameAssociations",
@@ -454,6 +454,19 @@
             "private java.util.HashMap javax.script.ScriptEngineManager.mimeTypeAssociations",
             "private javax.script.Bindings javax.script.ScriptEngineManager.globalScope",
         };
+        final String[] declaredFieldsThatShouldExist_jdk7 = {
+            "private static final boolean javax.script.ScriptEngineManager.DEBUG",
+            "private java.util.HashSet javax.script.ScriptEngineManager.engineSpis",
+            "private java.util.HashMap javax.script.ScriptEngineManager.nameAssociations",
+            "private java.util.HashMap javax.script.ScriptEngineManager.extensionAssociations",
+            "private java.util.HashMap javax.script.ScriptEngineManager.mimeTypeAssociations",
+            "private javax.script.Bindings javax.script.ScriptEngineManager.globalScope",
+        };
+
+        // get the right array of field signatures
+        // following fields should be declared
+        final String[] declaredFieldsThatShouldExist = getJavaVersion() < 7 ? declaredFieldsThatShouldExist_jdk6 : declaredFieldsThatShouldExist_jdk7;
+
         // get all declared fields
         Field[] declaredFields = this.scriptEngineManagerClass.getDeclaredFields();
         // and transform the array into a list of field names
@@ -462,9 +475,9 @@
             declaredFieldsAsString.add(field.toString());
         }
         // check if all required fields really exists
-        for (String fieldThatShouldExists : fieldsThatShouldExists) {
-            assertTrue(declaredFieldsAsString.contains(fieldThatShouldExists),
-                    "field " + fieldThatShouldExists + " not found");
+        for (String declaredFieldThatShouldExists : declaredFieldsThatShouldExist) {
+            assertTrue(declaredFieldsAsString.contains(declaredFieldThatShouldExists),
+                    "field " + declaredFieldThatShouldExists + " not found");
         }
     }
 
@@ -496,6 +509,45 @@
     }
 
     /**
+     * Test for method javax.script.ScriptEngineManager.getClass().getDeclaredField()
+     */
+    protected void testGetDeclaredField() {
+        // following declared fields should exists
+        final String[] declaredFieldsThatShouldExist_jdk6 = {
+            "DEBUG",
+            "engineSpis",
+            "nameAssociations",
+            "extensionAssociations",
+            "mimeTypeAssociations",
+            "globalScope",
+        };
+        final String[] declaredFieldsThatShouldExist_jdk7 = {
+            "DEBUG",
+            "engineSpis",
+            "nameAssociations",
+            "extensionAssociations",
+            "mimeTypeAssociations",
+            "globalScope",
+        };
+
+        final String[] declaredFieldsThatShouldExist = getJavaVersion() < 7 ? declaredFieldsThatShouldExist_jdk6 : declaredFieldsThatShouldExist_jdk7;
+
+        // check if all required declared fields really exists
+        for (String declaredFieldThatShouldExists : declaredFieldsThatShouldExist) {
+            try {
+                Field field = this.scriptEngineManagerClass.getDeclaredField(declaredFieldThatShouldExists);
+                String fieldName = field.getName();
+                assertTrue(fieldName.equals(declaredFieldThatShouldExists),
+                        "field " + declaredFieldThatShouldExists + " not found");
+            }
+            catch (Exception e) {
+                e.printStackTrace();
+                throw new AssertionError(e.getMessage());
+            }
+        }
+    }
+
+    /**
      * Test for method javax.script.ScriptEngineManager.getClass().getMethods()
      */
     protected void testGetMethods() {
@@ -622,6 +674,140 @@
     }
 
     /**
+     * Test for method javax.script.ScriptEngineManager.getClass().getMethod()
+     */
+    protected void testGetMethod() {
+        // following methods should exist
+        Map<String, Class[]> methodsThatShouldExist_jdk6 = new TreeMap<String, Class[]>();
+        methodsThatShouldExist_jdk6.put("get", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk6.put("put", new Class[] {java.lang.String.class, java.lang.Object.class});
+        methodsThatShouldExist_jdk6.put("setBindings", new Class[] {javax.script.Bindings.class});
+        methodsThatShouldExist_jdk6.put("getBindings", new Class[] {});
+        methodsThatShouldExist_jdk6.put("getEngineByName", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk6.put("getEngineByExtension", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk6.put("getEngineByMimeType", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk6.put("getEngineFactories", new Class[] {});
+        methodsThatShouldExist_jdk6.put("registerEngineName", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk6.put("registerEngineMimeType", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk6.put("registerEngineExtension", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk6.put("wait", new Class[] {long.class});
+        methodsThatShouldExist_jdk6.put("wait", new Class[] {long.class, int.class});
+        methodsThatShouldExist_jdk6.put("wait", new Class[] {});
+        methodsThatShouldExist_jdk6.put("hashCode", new Class[] {});
+        methodsThatShouldExist_jdk6.put("getClass", new Class[] {});
+        methodsThatShouldExist_jdk6.put("equals", new Class[] {java.lang.Object.class});
+        methodsThatShouldExist_jdk6.put("toString", new Class[] {});
+        methodsThatShouldExist_jdk6.put("notify", new Class[] {});
+        methodsThatShouldExist_jdk6.put("notifyAll", new Class[] {});
+
+        Map<String, Class[]> methodsThatShouldExist_jdk7 = new TreeMap<String, Class[]>();
+        methodsThatShouldExist_jdk7.put("get", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk7.put("put", new Class[] {java.lang.String.class, java.lang.Object.class});
+        methodsThatShouldExist_jdk7.put("getBindings", new Class[] {});
+        methodsThatShouldExist_jdk7.put("setBindings", new Class[] {javax.script.Bindings.class});
+        methodsThatShouldExist_jdk7.put("getEngineByExtension", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk7.put("getEngineByMimeType", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk7.put("getEngineByName", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk7.put("getEngineFactories", new Class[] {});
+        methodsThatShouldExist_jdk7.put("registerEngineExtension", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk7.put("registerEngineMimeType", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk7.put("registerEngineName", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk7.put("wait", new Class[] {long.class, int.class});
+        methodsThatShouldExist_jdk7.put("wait", new Class[] {long.class});
+        methodsThatShouldExist_jdk7.put("wait", new Class[] {});
+        methodsThatShouldExist_jdk7.put("equals", new Class[] {java.lang.Object.class});
+        methodsThatShouldExist_jdk7.put("toString", new Class[] {});
+        methodsThatShouldExist_jdk7.put("hashCode", new Class[] {});
+        methodsThatShouldExist_jdk7.put("getClass", new Class[] {});
+        methodsThatShouldExist_jdk7.put("notify", new Class[] {});
+        methodsThatShouldExist_jdk7.put("notifyAll", new Class[] {});
+
+        Map<String, Class[]> methodsThatShouldExist = getJavaVersion() < 7 ? methodsThatShouldExist_jdk6 : methodsThatShouldExist_jdk7;
+
+        // check if all required methods really exist
+        for (Map.Entry<String, Class[]> methodThatShouldExists : methodsThatShouldExist.entrySet()) {
+            try {
+                Method method = this.scriptEngineManagerClass.getMethod(methodThatShouldExists.getKey(), methodThatShouldExists.getValue());
+                assertNotNull(method,
+                        "method " + methodThatShouldExists.getKey() + " not found");
+                String methodName = method.getName();
+                assertNotNull(methodName,
+                        "method " + methodThatShouldExists.getKey() + " does not have name assigned");
+                assertTrue(methodName.equals(methodThatShouldExists.getKey()),
+                        "method " + methodThatShouldExists.getKey() + " not found");
+            }
+            catch (Exception e) {
+                e.printStackTrace();
+                throw new AssertionError(e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineManager.getClass().getDeclaredMethod()
+     */
+    protected void testGetDeclaredMethod() {
+        // following methods should exist
+        Map<String, Class[]> methodsThatShouldExist_jdk6 = new TreeMap<String, Class[]>();
+        methodsThatShouldExist_jdk6.put("get", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk6.put("put", new Class[] {java.lang.String.class, java.lang.Object.class});
+        methodsThatShouldExist_jdk6.put("getCallerClassLoader", new Class[] {});
+        methodsThatShouldExist_jdk6.put("isAncestor", new Class[] {java.lang.ClassLoader.class, java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk6.put("access$000", new Class[] {javax.script.ScriptEngineManager.class, java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk6.put("init", new Class[] {java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk6.put("setBindings", new Class[] {javax.script.Bindings.class});
+        methodsThatShouldExist_jdk6.put("getBindings", new Class[] {});
+        methodsThatShouldExist_jdk6.put("initEngines", new Class[] {java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk6.put("getEngineByName", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk6.put("getEngineByExtension", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk6.put("getEngineByMimeType", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk6.put("getEngineFactories", new Class[] {});
+        methodsThatShouldExist_jdk6.put("registerEngineName", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk6.put("registerEngineMimeType", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk6.put("registerEngineExtension", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk6.put("canCallerAccessLoader", new Class[] {java.lang.ClassLoader.class});
+
+        Map<String, Class[]> methodsThatShouldExist_jdk7 = new TreeMap<String, Class[]>();
+        methodsThatShouldExist_jdk7.put("get", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk7.put("put", new Class[] {java.lang.String.class, java.lang.Object.class});
+        methodsThatShouldExist_jdk7.put("getCallerClassLoader", new Class[] {});
+        methodsThatShouldExist_jdk7.put("isAncestor", new Class[] {java.lang.ClassLoader.class, java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk7.put("access$000", new Class[] {javax.script.ScriptEngineManager.class, java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk7.put("init", new Class[] {java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk7.put("getBindings", new Class[] {});
+        methodsThatShouldExist_jdk7.put("setBindings", new Class[] {javax.script.Bindings.class});
+        methodsThatShouldExist_jdk7.put("getEngineByExtension", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk7.put("canCallerAccessLoader", new Class[] {java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk7.put("getEngineByMimeType", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk7.put("getEngineByName", new Class[] {java.lang.String.class});
+        methodsThatShouldExist_jdk7.put("getEngineFactories", new Class[] {});
+        methodsThatShouldExist_jdk7.put("initEngines", new Class[] {java.lang.ClassLoader.class});
+        methodsThatShouldExist_jdk7.put("registerEngineExtension", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk7.put("registerEngineMimeType", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+        methodsThatShouldExist_jdk7.put("registerEngineName", new Class[] {java.lang.String.class, javax.script.ScriptEngineFactory.class});
+
+        Map<String, Class[]> methodsThatShouldExist = getJavaVersion() < 7 ? methodsThatShouldExist_jdk6 : methodsThatShouldExist_jdk7;
+
+        // check if all required methods really exist
+        for (Map.Entry<String, Class[]> methodThatShouldExists : methodsThatShouldExist.entrySet()) {
+            try {
+                Method method = this.scriptEngineManagerClass.getDeclaredMethod(methodThatShouldExists.getKey(), methodThatShouldExists.getValue());
+                assertNotNull(method,
+                        "method " + methodThatShouldExists.getKey() + " not found");
+                String methodName = method.getName();
+                assertNotNull(methodName,
+                        "method " + methodThatShouldExists.getKey() + " does not have name assigned");
+                assertTrue(methodName.equals(methodThatShouldExists.getKey()),
+                        "method " + methodThatShouldExists.getKey() + " not found");
+            }
+            catch (Exception e) {
+                e.printStackTrace();
+                throw new AssertionError(e.getMessage());
+            }
+        }
+    }
+
+    /**
      * Test for method javax.script.ScriptEngineManager.getClass().getAnnotations()
      */
     protected void testGetAnnotations() {



More information about the distro-pkg-dev mailing list