/hg/rhino-tests: Added new test into the SimpleScriptContextClas...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Fri Mar 8 00:49:21 PST 2013


changeset f037ba60f477 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=f037ba60f477
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Fri Mar 08 09:52:25 2013 +0100

	Added new test into the SimpleScriptContextClassTest.
	Updated other two tests to work correctly in JDK6 and JDK7.


diffstat:

 ChangeLog                                            |   6 +
 src/org/RhinoTests/SimpleScriptContextClassTest.java |  75 +++++++++++++++++--
 2 files changed, 73 insertions(+), 8 deletions(-)

diffs (144 lines):

diff -r 7668089de997 -r f037ba60f477 ChangeLog
--- a/ChangeLog	Thu Mar 07 10:22:22 2013 +0100
+++ b/ChangeLog	Fri Mar 08 09:52:25 2013 +0100
@@ -1,3 +1,9 @@
+2013-03-09  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/RhinoTests/SimpleScriptContextClassTest.java:
+	Added new test into the SimpleScriptContextClassTest.
+	Updated other two tests to work correctly in JDK6 and JDK7.
+
 2013-03-08  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/BindingsTest.java:
diff -r 7668089de997 -r f037ba60f477 src/org/RhinoTests/SimpleScriptContextClassTest.java
--- a/src/org/RhinoTests/SimpleScriptContextClassTest.java	Thu Mar 07 10:22:22 2013 +0100
+++ b/src/org/RhinoTests/SimpleScriptContextClassTest.java	Fri Mar 08 09:52:25 2013 +0100
@@ -415,7 +415,7 @@
      */
     protected void testGetFields() {
         // following fields should exists
-        final String[] fieldsThatShouldExists = {
+        final String[] fieldsThatShouldExist = {
             "public static final int javax.script.ScriptContext.ENGINE_SCOPE",
             "public static final int javax.script.ScriptContext.GLOBAL_SCOPE",
         };
@@ -427,7 +427,7 @@
             fieldsAsString.add(field.toString());
         }
         // check if all required fields really exists
-        for (String fieldThatShouldExists : fieldsThatShouldExists) {
+        for (String fieldThatShouldExists : fieldsThatShouldExist) {
             assertTrue(fieldsAsString.contains(fieldThatShouldExists),
                     "field " + fieldThatShouldExists + " not found");
         }
@@ -438,7 +438,7 @@
      */
     protected void testGetDeclaredFields() {
         // following fields should be declared
-        final String[] fieldsThatShouldExists = {
+        final String[] declaredFieldsThatShouldExist_jdk6 = {
             "protected java.io.Writer javax.script.SimpleScriptContext.writer",
             "protected java.io.Writer javax.script.SimpleScriptContext.errorWriter",
             "protected java.io.Reader javax.script.SimpleScriptContext.reader",
@@ -446,6 +446,19 @@
             "protected javax.script.Bindings javax.script.SimpleScriptContext.globalScope",
             "private static java.util.List javax.script.SimpleScriptContext.scopes",
         };
+        final String[] declaredFieldsThatShouldExist_jdk7 = {
+            "protected java.io.Writer javax.script.SimpleScriptContext.writer",
+            "protected java.io.Writer javax.script.SimpleScriptContext.errorWriter",
+            "protected java.io.Reader javax.script.SimpleScriptContext.reader",
+            "protected javax.script.Bindings javax.script.SimpleScriptContext.engineScope",
+            "protected javax.script.Bindings javax.script.SimpleScriptContext.globalScope",
+            "private static java.util.List javax.script.SimpleScriptContext.scopes",
+        };
+
+        // 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.simpleScriptContextClass.getDeclaredFields();
         // and transform the array into a list of field names
@@ -454,9 +467,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");
         }
     }
 
@@ -465,12 +478,19 @@
      */
     protected void testGetField() {
         // following fields should exists
-        final String[] fieldsThatShouldExists = {
+        final String[] fieldsThatShouldExist_jdk6 = {
             "ENGINE_SCOPE",
             "GLOBAL_SCOPE",
         };
+        final String[] fieldsThatShouldExist_jdk7 = {
+            "ENGINE_SCOPE",
+            "GLOBAL_SCOPE",
+        };
+
+        final String[] fieldsThatShouldExist = getJavaVersion() < 7 ? fieldsThatShouldExist_jdk6 : fieldsThatShouldExist_jdk7;
+
         // check if all required fields really exists
-        for (String fieldThatShouldExists : fieldsThatShouldExists) {
+        for (String fieldThatShouldExists : fieldsThatShouldExist) {
             try {
                 Field field = this.simpleScriptContextClass.getField(fieldThatShouldExists);
                 String fieldName = field.getName();
@@ -485,6 +505,45 @@
     }
 
     /**
+     * Test for method javax.script.SimpleScriptContext.getClass().getDeclaredField()
+     */
+    protected void testGetDeclaredField() {
+        // following declared fields should exists
+        final String[] declaredFieldsThatShouldExist_jdk6 = {
+            "writer",
+            "errorWriter",
+            "reader",
+            "engineScope",
+            "globalScope",
+            "scopes",
+        };
+        final String[] declaredFieldsThatShouldExist_jdk7 = {
+            "writer",
+            "errorWriter",
+            "reader",
+            "engineScope",
+            "globalScope",
+            "scopes",
+        };
+
+        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.simpleScriptContextClass.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.SimpleScriptContext.getClass().getMethods()
      */
     protected void testGetMethods() {



More information about the distro-pkg-dev mailing list