/hg/rhino-tests: Added new test case src/org/RhinoTests/ScriptEn...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Fri Sep 14 01:56:27 PDT 2012


changeset df52afae62a2 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=df52afae62a2
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Fri Sep 14 10:59:01 2012 +0200

	Added new test case src/org/RhinoTests/ScriptEngineFactoryClassTest.java.


diffstat:

 ChangeLog                                            |    7 +
 Makefile                                             |    2 +
 src/org/RhinoTests/ScriptEngineFactoryClassTest.java |  362 +++++++++++++++++++
 3 files changed, 371 insertions(+), 0 deletions(-)

diffs (399 lines):

diff -r 658afb0e403e -r df52afae62a2 ChangeLog
--- a/ChangeLog	Thu Sep 13 10:03:49 2012 +0200
+++ b/ChangeLog	Fri Sep 14 10:59:01 2012 +0200
@@ -1,3 +1,10 @@
+2012-09-14  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/RhinoTests/ScriptEngineFactoryClassTest.java:
+	Added new test case with 20 tests.
+	* Makefile:
+	Added new class to compile and new test to run.
+
 2012-09-13  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/CompilableClassTest.java:
diff -r 658afb0e403e -r df52afae62a2 Makefile
--- a/Makefile	Thu Sep 13 10:03:49 2012 +0200
+++ b/Makefile	Fri Sep 14 10:59:01 2012 +0200
@@ -56,6 +56,7 @@
 	ScriptEngineTest \
 	ScriptEngineClassTest \
 	ScriptEngineFactoryTest \
+	ScriptEngineFactoryClassTest \
 	JavaScriptsTest \
 	BindingsTest \
 	CompilableTest \
@@ -98,6 +99,7 @@
 	$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptContextTest.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptContextClassTest.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineFactoryTest.class \
+	$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineFactoryClassTest.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineManagerTest.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineManagerClassTest.class \
 	$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineTest.class \
diff -r 658afb0e403e -r df52afae62a2 src/org/RhinoTests/ScriptEngineFactoryClassTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/RhinoTests/ScriptEngineFactoryClassTest.java	Fri Sep 14 10:59:01 2012 +0200
@@ -0,0 +1,362 @@
+/*
+  Rhino test framework
+
+   Copyright (C) 2011, 2012  Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package org.RhinoTests;
+
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+
+
+
+/**
+ * Set of tests which check the API of ScriptEngineFactory interface using
+ * Java reflection API.
+ *
+ * @author Pavel Tisnovsky
+ */
+public class ScriptEngineFactoryClassTest extends BaseRhinoTest {
+
+    /**
+     * Object that represents the type of ScriptEngineFactory.
+     */
+    Class scriptEngineFactoryClass = null;
+
+    @Override
+    protected void setUp(String[] args) {
+        // setup attribute used by tests
+        this.scriptEngineFactoryClass = ScriptEngineFactory.class;
+    }
+
+    @Override
+    protected void tearDown() {
+        // this block could be empty
+        return;
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().isAssignableFrom()
+     */
+    protected void testIsAssignableFrom() {
+        assertTrue(this.scriptEngineFactoryClass.isAssignableFrom(ScriptEngineFactory.class),
+                "Method ScriptEngineFactory.getClass().isAssignableFrom() returns wrong value");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().isInstance()
+     */
+    protected void testIsInstance() {
+        assertTrue(this.scriptEngineFactoryClass.isInstance(new ScriptEngineManager().getEngineFactories().get(0)),
+                "Method ScriptEngineFactory.getClass().isInstance() returns wrong value");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().isInterface()
+     */
+    protected void testIsInterface() {
+        assertTrue(this.scriptEngineFactoryClass.isInterface(),
+                "Method ScriptEngineFactory.getClass().isInterface() returns wrong value");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().isLocalClass()
+     */
+    protected void testIsLocalClass() {
+        assertFalse(this.scriptEngineFactoryClass.isLocalClass(),
+                "Method ScriptEngineFactory.getClass().isLocalClass() returns wrong value");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().isMemberClass()
+     */
+    protected void testIsMemberClass() {
+        assertFalse(this.scriptEngineFactoryClass.isMemberClass(),
+                "Method ScriptEngineFactory.getClass().isMemberClass() returns wrong value");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().isPrimitive()
+     */
+    protected void testIsPrimitive() {
+        assertFalse(this.scriptEngineFactoryClass.isPrimitive(),
+                "Method ScriptEngineFactory.getClass().isPrimitive() returns wrong value");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().isSynthetic()
+     */
+    protected void testIsSynthetic() {
+        assertFalse(this.scriptEngineFactoryClass.isSynthetic(),
+                "Method ScriptEngineFactory.getClass().isSynthetic() returns wrong value");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getInterfaces()
+     */
+    protected void testGetInterfaces() {
+        List interfaces = Arrays.asList(this.scriptEngineFactoryClass.getInterfaces());
+        assertTrue(interfaces.isEmpty(),
+                "list of implemented interfaces should be empty");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getModifiers()
+     */
+    protected void testGetModifiers() {
+        int modifiers = this.scriptEngineFactoryClass.getModifiers();
+        assertTrue(Modifier.isPublic(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isPublic modifier is set to a wrong value");
+        assertFalse(Modifier.isPrivate(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isPrivate modifier is set to a wrong value");
+        assertFalse(Modifier.isProtected(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isProtected modifier is set to a wrong value");
+        assertTrue(Modifier.isAbstract(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isAbstract modifier is set to a wrong value");
+        assertFalse(Modifier.isFinal(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isFinal modifier is set to a wrong value");
+        assertTrue(Modifier.isInterface(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isInterface modifier is set to a wrong value");
+        assertFalse(Modifier.isNative(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isNative modifier is set to a wrong value");
+        assertFalse(Modifier.isStatic(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isStatic modifier is set to a wrong value");
+        assertFalse(Modifier.isStrict(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isStrict modifier is set to a wrong value");
+        assertFalse(Modifier.isSynchronized(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isSynchronized modifier is set to a wrong value");
+        assertFalse(Modifier.isTransient(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isTransient modifier is set to a wrong value");
+        assertFalse(Modifier.isVolatile(modifiers),
+                "Method ScriptEngineFactory.getClass().getModifiers() - isVolatile modifier is set to a wrong value");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getName()
+     */
+    protected void testGetName() {
+        String name = this.scriptEngineFactoryClass.getName();
+        assertEquals(name, "javax.script.ScriptEngineFactory",
+                "Method ScriptEngineFactory.getClass().getName() returns wrong value " + name);
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getPackage()
+     */
+    protected void testGetPackage() {
+        Package p = this.scriptEngineFactoryClass.getPackage();
+        String packageName = p.getName();
+        assertEquals(packageName, "javax.script",
+                "Method ScriptEngineFactory.getClass().getPackage().getName() returns wrong value " + packageName);
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getSimpleName()
+     */
+    protected void testGetSimpleName() {
+        String simpleName = this.scriptEngineFactoryClass.getSimpleName();
+        assertEquals(simpleName, "ScriptEngineFactory",
+                "Method ScriptEngineFactory.getClass().getSimpleName() returns wrong value " + simpleName);
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getSuperclass()
+     */
+    protected void testGetSuperclass() {
+        Class superClass = this.scriptEngineFactoryClass.getSuperclass();
+        assertNull(superClass,
+                "Method ScriptEngineFactory.getClass().getSuperclass() does not return null");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getConstructors()
+     */
+    protected void testGetConstructors() {
+        Constructor[] constructors = this.scriptEngineFactoryClass.getConstructors();
+        assertEquals(constructors.length, 0, "no constructors should be set");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getDeclaredConstructors()
+     */
+    protected void testGetDeclaredConstructors() {
+        Constructor[] constructors = this.scriptEngineFactoryClass.getDeclaredConstructors();
+        assertEquals(constructors.length, 0, "no constructors should be set");
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getFields()
+     */
+    protected void testGetFields() {
+        // following fields should exists
+        final String[] fieldsThatShouldExists = {
+        };
+        // get all fields
+        Field[] fields = this.scriptEngineFactoryClass.getFields();
+        // and transform the array into a list of field names
+        List<String> fieldsAsString = new ArrayList<String>();
+        for (Field field : fields) {
+            fieldsAsString.add(field.toString());
+        }
+        // check if all required fields really exists
+        for (String fieldThatShouldExists : fieldsThatShouldExists) {
+            assertTrue(fieldsAsString.contains(fieldThatShouldExists),
+                    "field " + fieldThatShouldExists + " not found");
+        }
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getDeclaredFields()
+     */
+    protected void testGetDeclaredFields() {
+        // following fields should be declared
+        final String[] fieldsThatShouldExists = {
+        };
+        // get all declared fields
+        Field[] declaredFields = this.scriptEngineFactoryClass.getDeclaredFields();
+        // and transform the array into a list of field names
+        List<String> declaredFieldsAsString = new ArrayList<String>();
+        for (Field field : declaredFields) {
+            declaredFieldsAsString.add(field.toString());
+        }
+        // check if all required fields really exists
+        for (String fieldThatShouldExists : fieldsThatShouldExists) {
+            assertTrue(declaredFieldsAsString.contains(fieldThatShouldExists),
+                    "field " + fieldThatShouldExists + " not found");
+        }
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getMethods()
+     */
+    protected void testGetMethods() {
+        // following methods should be inherited
+        final String[] methodsThatShouldExists = {
+            "public abstract java.lang.Object javax.script.ScriptEngineFactory.getParameter(java.lang.String)",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getEngineName()",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getEngineVersion()",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getLanguageName()",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getLanguageVersion()",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getMethodCallSyntax(java.lang.String,java.lang.String,java.lang.String[])",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getOutputStatement(java.lang.String)",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getProgram(java.lang.String[])",
+            "public abstract java.util.List javax.script.ScriptEngineFactory.getExtensions()",
+            "public abstract java.util.List javax.script.ScriptEngineFactory.getMimeTypes()",
+            "public abstract java.util.List javax.script.ScriptEngineFactory.getNames()",
+            "public abstract javax.script.ScriptEngine javax.script.ScriptEngineFactory.getScriptEngine()",
+        };
+        // get all inherited methods
+        Method[] methods = this.scriptEngineFactoryClass.getMethods();
+        // and transform the array into a list of method names
+        List<String> methodsAsString = new ArrayList<String>();
+        for (Method method : methods) {
+            methodsAsString.add(method.toString());
+        }
+        // check if all required methods really exists
+        for (String methodThatShouldExists : methodsThatShouldExists) {
+            assertTrue(methodsAsString.contains(methodThatShouldExists),
+                    "method " + methodThatShouldExists + " not found");
+        }
+    }
+
+    /**
+     * Test for method javax.script.ScriptEngineFactory.getClass().getDeclaredMethods()
+     */
+    protected void testGetDeclaredMethods() {
+        // following methods should be declared
+        final String[] declaredMethodsThatShouldExists = {
+            "public abstract java.lang.Object javax.script.ScriptEngineFactory.getParameter(java.lang.String)",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getEngineName()",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getEngineVersion()",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getLanguageName()",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getLanguageVersion()",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getMethodCallSyntax(java.lang.String,java.lang.String,java.lang.String[])",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getOutputStatement(java.lang.String)",
+            "public abstract java.lang.String javax.script.ScriptEngineFactory.getProgram(java.lang.String[])",
+            "public abstract java.util.List javax.script.ScriptEngineFactory.getExtensions()",
+            "public abstract java.util.List javax.script.ScriptEngineFactory.getMimeTypes()",
+            "public abstract java.util.List javax.script.ScriptEngineFactory.getNames()",
+            "public abstract javax.script.ScriptEngine javax.script.ScriptEngineFactory.getScriptEngine()",
+        };
+        // get all declared methods
+        Method[] declaredMethods = this.scriptEngineFactoryClass.getDeclaredMethods();
+        // and transform the array into a list of method names
+        List<String> methodsAsString = new ArrayList<String>();
+        for (Method method : declaredMethods) {
+            methodsAsString.add(method.toString());
+        }
+        // check if all required methods really exists
+        for (String methodThatShouldExists : declaredMethodsThatShouldExists) {
+            assertTrue(methodsAsString.contains(methodThatShouldExists),
+                    "declared method " + methodThatShouldExists + " not found");
+        }
+    }
+
+    /**
+     * Test for instanceof operator applied to a class javax.script.ScriptEngineFactory
+     */
+    protected void testInstanceOf() {
+        // tested object
+        Object o = new ScriptEngineManager().getEngineFactories().get(0);
+
+        // basic check of instanceof operator
+        assertTrue(o instanceof ScriptEngineFactory, "instanceof ScriptEngineFactory is wrongly evaluated to false");
+
+        // check operator instanceof against all superclasses
+        assertTrue(o instanceof Object, "instanceof Object is wrongly evaluated to false");
+    }
+
+    /**
+     * Entry point to this test case.
+     *
+     * @param args parameters passed from command line
+     */
+    public static void main(String[] args) {
+        new ScriptEngineFactoryClassTest().doTests(args);
+    }
+}
+



More information about the distro-pkg-dev mailing list