/hg/rhino-tests: Added new test case with 20 tests.
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Wed Aug 15 04:45:29 PDT 2012
changeset 425a6823067b in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=425a6823067b
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Aug 15 13:48:07 2012 +0200
Added new test case with 20 tests.
diffstat:
ChangeLog | 9 +
Makefile | 2 +
src/org/RhinoTests/ScriptContextClassTest.java | 49 +-
src/org/RhinoTests/ScriptEngineManagerClassTest.java | 411 +++++++++++++++++++
4 files changed, 447 insertions(+), 24 deletions(-)
diffs (truncated from 596 to 500 lines):
diff -r 0a6ba1bff82f -r 425a6823067b ChangeLog
--- a/ChangeLog Tue Aug 14 14:21:42 2012 +0200
+++ b/ChangeLog Wed Aug 15 13:48:07 2012 +0200
@@ -1,3 +1,12 @@
+2012-08-15 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/RhinoTests/ScriptContextClassTest.java:
+ Fixed various typos.
+ * src/org/RhinoTests/ScriptEngineManagerClassTest.java:
+ Added new test case with 20 tests.
+ * Makefile:
+ Added new class to compile and new test to run.
+
2012-08-14 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/RhinoTests/SimpleScriptContextClassTest.java:
diff -r 0a6ba1bff82f -r 425a6823067b Makefile
--- a/Makefile Tue Aug 14 14:21:42 2012 +0200
+++ b/Makefile Wed Aug 15 13:48:07 2012 +0200
@@ -52,6 +52,7 @@
TESTS = \
ScriptEngineManagerTest \
+ ScriptEngineManagerClassTest \
ScriptEngineTest \
ScriptEngineFactoryTest \
JavaScriptsTest \
@@ -88,6 +89,7 @@
$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptContextClassTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineFactoryTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineManagerTest.class \
+ $(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineManagerClassTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptEngineTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/ScriptExceptionTest.class \
$(BUILD_DIR)/$(TEST_PACKAGE)/SimpleBindingsTest.class \
diff -r 0a6ba1bff82f -r 425a6823067b src/org/RhinoTests/ScriptContextClassTest.java
--- a/src/org/RhinoTests/ScriptContextClassTest.java Tue Aug 14 14:21:42 2012 +0200
+++ b/src/org/RhinoTests/ScriptContextClassTest.java Wed Aug 15 13:48:07 2012 +0200
@@ -43,10 +43,12 @@
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.ScriptContext;
import javax.script.SimpleScriptContext;
@@ -120,7 +122,7 @@
/**
* Test for method javax.script.ScriptContext.getClass().isPrimitive()
*/
- protected void testIsIsPrimitive() {
+ protected void testIsPrimitive() {
assertFalse(this.scriptContextClass.isPrimitive(),
"Method ScriptContext.getClass().isPrimitive() returns wrong value");
}
@@ -128,7 +130,7 @@
/**
* Test for method javax.script.ScriptContext.getClass().isSynthetic()
*/
- protected void testIsIsSynthetic() {
+ protected void testIsSynthetic() {
assertFalse(this.scriptContextClass.isSynthetic(),
"Method ScriptContext.getClass().isSynthetic() returns wrong value");
}
@@ -211,7 +213,7 @@
}
/**
- * Test for method javax.script.ScriptContext.getClass().getGetConstructors()
+ * Test for method javax.script.ScriptContext.getClass().getConstructors()
*/
protected void testGetConstructors() {
Constructor[] constructors = this.scriptContextClass.getConstructors();
@@ -219,7 +221,7 @@
}
/**
- * Test for method javax.script.ScriptContext.getClass().getGetDeclaredConstructors()
+ * Test for method javax.script.ScriptContext.getClass().getDeclaredConstructors()
*/
protected void testGetDeclaredConstructors() {
Constructor[] constructors = this.scriptContextClass.getDeclaredConstructors();
@@ -227,7 +229,7 @@
}
/**
- * Test for method javax.script.ScriptContext.getClass().getGetFields()
+ * Test for method javax.script.ScriptContext.getClass().getFields()
*/
protected void testGetFields() {
// following fields should exists
@@ -250,7 +252,7 @@
}
/**
- * Test for method javax.script.ScriptContext.getClass().getGetDeclaredFields()
+ * Test for method javax.script.ScriptContext.getClass().getDeclaredFields()
*/
protected void testGetDeclaredFields() {
// following fields should be declared
@@ -261,32 +263,32 @@
// get all declared fields
Field[] declaredFields = this.scriptContextClass.getDeclaredFields();
// and transform the array into a list of field names
- List<String> fieldsAsString = new ArrayList<String>();
+ List<String> declaredFieldsAsString = new ArrayList<String>();
for (Field field : declaredFields) {
- fieldsAsString.add(field.toString());
+ declaredFieldsAsString.add(field.toString());
}
// check if all required fields really exists
for (String fieldThatShouldExists : fieldsThatShouldExists) {
- assertTrue(fieldsAsString.contains(fieldThatShouldExists),
+ assertTrue(declaredFieldsAsString.contains(fieldThatShouldExists),
"field " + fieldThatShouldExists + " not found");
}
}
/**
- * Test for method javax.script.ScriptContext.getClass().getGetMethods()
+ * Test for method javax.script.ScriptContext.getClass().getMethods()
*/
protected void testGetMethods() {
// following methods should be inherited
final String[] methodsThatShouldExists = {
+ "public abstract int javax.script.ScriptContext.getAttributesScope(java.lang.String)",
+ "public abstract java.io.Reader javax.script.ScriptContext.getReader()",
+ "public abstract java.io.Writer javax.script.ScriptContext.getErrorWriter()",
+ "public abstract java.io.Writer javax.script.ScriptContext.getWriter()",
"public abstract java.lang.Object javax.script.ScriptContext.getAttribute(java.lang.String)",
"public abstract java.lang.Object javax.script.ScriptContext.getAttribute(java.lang.String,int)",
- "public abstract int javax.script.ScriptContext.getAttributesScope(java.lang.String)",
+ "public abstract java.lang.Object javax.script.ScriptContext.removeAttribute(java.lang.String,int)",
+ "public abstract java.util.List javax.script.ScriptContext.getScopes()",
"public abstract javax.script.Bindings javax.script.ScriptContext.getBindings(int)",
- "public abstract java.io.Writer javax.script.ScriptContext.getErrorWriter()",
- "public abstract java.io.Reader javax.script.ScriptContext.getReader()",
- "public abstract java.util.List javax.script.ScriptContext.getScopes()",
- "public abstract java.io.Writer javax.script.ScriptContext.getWriter()",
- "public abstract java.lang.Object javax.script.ScriptContext.removeAttribute(java.lang.String,int)",
"public abstract void javax.script.ScriptContext.setAttribute(java.lang.String,java.lang.Object,int)",
"public abstract void javax.script.ScriptContext.setBindings(javax.script.Bindings,int)",
"public abstract void javax.script.ScriptContext.setErrorWriter(java.io.Writer)",
@@ -308,20 +310,20 @@
}
/**
- * Test for method javax.script.ScriptContext.getClass().getGetDeclaredMethods()
+ * Test for method javax.script.ScriptContext.getClass().getDeclaredMethods()
*/
protected void testGetDeclaredMethods() {
// following methods should be declared
final String[] declaredMethodsThatShouldExists = {
+ "public abstract int javax.script.ScriptContext.getAttributesScope(java.lang.String)",
+ "public abstract java.io.Reader javax.script.ScriptContext.getReader()",
+ "public abstract java.io.Writer javax.script.ScriptContext.getErrorWriter()",
+ "public abstract java.io.Writer javax.script.ScriptContext.getWriter()",
"public abstract java.lang.Object javax.script.ScriptContext.getAttribute(java.lang.String)",
"public abstract java.lang.Object javax.script.ScriptContext.getAttribute(java.lang.String,int)",
- "public abstract int javax.script.ScriptContext.getAttributesScope(java.lang.String)",
+ "public abstract java.lang.Object javax.script.ScriptContext.removeAttribute(java.lang.String,int)",
+ "public abstract java.util.List javax.script.ScriptContext.getScopes()",
"public abstract javax.script.Bindings javax.script.ScriptContext.getBindings(int)",
- "public abstract java.io.Writer javax.script.ScriptContext.getErrorWriter()",
- "public abstract java.io.Reader javax.script.ScriptContext.getReader()",
- "public abstract java.util.List javax.script.ScriptContext.getScopes()",
- "public abstract java.io.Writer javax.script.ScriptContext.getWriter()",
- "public abstract java.lang.Object javax.script.ScriptContext.removeAttribute(java.lang.String,int)",
"public abstract void javax.script.ScriptContext.setAttribute(java.lang.String,java.lang.Object,int)",
"public abstract void javax.script.ScriptContext.setBindings(javax.script.Bindings,int)",
"public abstract void javax.script.ScriptContext.setErrorWriter(java.io.Writer)",
@@ -366,4 +368,3 @@
}
}
-
diff -r 0a6ba1bff82f -r 425a6823067b src/org/RhinoTests/ScriptEngineManagerClassTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/RhinoTests/ScriptEngineManagerClassTest.java Wed Aug 15 13:48:07 2012 +0200
@@ -0,0 +1,411 @@
+/*
+ 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.ScriptEngineManager;
+
+
+
+
+/**
+ * Set of tests which check the API of ScriptEngineManager class using
+ * Java reflection API.
+ *
+ * @author Pavel Tisnovsky
+ */
+public class ScriptEngineManagerClassTest extends BaseRhinoTest {
+
+ /**
+ * Object that represents the type of ScriptEngineManager.
+ */
+ Class scriptEngineManagerClass = null;
+
+ @Override
+ protected void setUp(String[] args) {
+ // setup attribute used by tests
+ this.scriptEngineManagerClass = ScriptEngineManager.class;
+ }
+
+ @Override
+ protected void tearDown() {
+ // this block could be empty
+ return;
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().isAssignableFrom()
+ */
+ protected void testIsAssignableFrom() {
+ assertTrue(this.scriptEngineManagerClass.isAssignableFrom(ScriptEngineManager.class),
+ "Method ScriptEngineManager.getClass().isAssignableFrom() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().isInstance()
+ */
+ protected void testIsInstance() {
+ assertTrue(this.scriptEngineManagerClass.isInstance(new ScriptEngineManager()),
+ "Method ScriptEngineManager.getClass().isInstance() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().isInterface()
+ */
+ protected void testIsInterface() {
+ assertFalse(this.scriptEngineManagerClass.isInterface(),
+ "Method ScriptEngineManager.getClass().isInterface() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().isLocalClass()
+ */
+ protected void testIsLocalClass() {
+ assertFalse(this.scriptEngineManagerClass.isLocalClass(),
+ "Method ScriptEngineManager.getClass().isLocalClass() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().isMemberClass()
+ */
+ protected void testIsMemberClass() {
+ assertFalse(this.scriptEngineManagerClass.isMemberClass(),
+ "Method ScriptEngineManager.getClass().isMemberClass() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().isPrimitive()
+ */
+ protected void testIsPrimitive() {
+ assertFalse(this.scriptEngineManagerClass.isPrimitive(),
+ "Method ScriptEngineManager.getClass().isPrimitive() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().isSynthetic()
+ */
+ protected void testIsSynthetic() {
+ assertFalse(this.scriptEngineManagerClass.isSynthetic(),
+ "Method ScriptEngineManager.getClass().isSynthetic() returns wrong value");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getInterfaces()
+ */
+ protected void testGetInterfaces() {
+ List interfaces = Arrays.asList(this.scriptEngineManagerClass.getInterfaces());
+ assertTrue(interfaces.isEmpty(),
+ "list of implemented interfaces should be empty");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getModifiers()
+ */
+ protected void testGetModifiers() {
+ int modifiers = this.scriptEngineManagerClass.getModifiers();
+ assertTrue(Modifier.isPublic(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isPublic modifier is set to a wrong value");
+ assertFalse(Modifier.isPrivate(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isPrivate modifier is set to a wrong value");
+ assertFalse(Modifier.isProtected(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isProtected modifier is set to a wrong value");
+ assertFalse(Modifier.isAbstract(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isAbstract modifier is set to a wrong value");
+ assertFalse(Modifier.isFinal(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isFinal modifier is set to a wrong value");
+ assertFalse(Modifier.isInterface(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isInterface modifier is set to a wrong value");
+ assertFalse(Modifier.isNative(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isNative modifier is set to a wrong value");
+ assertFalse(Modifier.isStatic(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isStatic modifier is set to a wrong value");
+ assertFalse(Modifier.isStrict(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isStrict modifier is set to a wrong value");
+ assertFalse(Modifier.isSynchronized(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isSynchronized modifier is set to a wrong value");
+ assertFalse(Modifier.isTransient(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isTransient modifier is set to a wrong value");
+ assertFalse(Modifier.isVolatile(modifiers),
+ "Method ScriptEngineManager.getClass().getModifiers() - isVolatile modifier is set to a wrong value");
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getName()
+ */
+ protected void testGetName() {
+ String name = this.scriptEngineManagerClass.getName();
+ assertEquals(name, "javax.script.ScriptEngineManager",
+ "Method ScriptEngineManager.getClass().getName() returns wrong value " + name);
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getPackage()
+ */
+ protected void testGetPackage() {
+ Package p = this.scriptEngineManagerClass.getPackage();
+ String packageName = p.getName();
+ assertEquals(packageName, "javax.script",
+ "Method ScriptEngineManager.getClass().getPackage().getName() returns wrong value " + packageName);
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getSimpleName()
+ */
+ protected void testGetSimpleName() {
+ String simpleName = this.scriptEngineManagerClass.getSimpleName();
+ assertEquals(simpleName, "ScriptEngineManager",
+ "Method ScriptEngineManager.getClass().getSimpleName() returns wrong value " + simpleName);
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getSuperclass()
+ */
+ protected void testGetSuperclass() {
+ Class superClass = this.scriptEngineManagerClass.getSuperclass();
+ String superClassName = superClass.getName();
+ assertEquals(superClassName, "java.lang.Object",
+ "Method ScriptEngineManager.getClass().getSuperclass() returns wrong value " + superClassName);
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getConstructors()
+ */
+ protected void testGetConstructors() {
+ Constructor[] constructors = this.scriptEngineManagerClass.getConstructors();
+ assertEquals(constructors.length, 2, "only 2 constructors should be set");
+ String constructorName;
+ String constructorString;
+ constructorName = constructors[0].getName();
+ constructorString = constructors[0].toString();
+ assertEquals(constructorName, "javax.script.ScriptEngineManager",
+ "wrong constructor name " + constructorName);
+ assertEquals(constructorString, "public javax.script.ScriptEngineManager()",
+ "wrong constructor.toString() " + constructorName);
+ constructorName = constructors[1].getName();
+ constructorString = constructors[1].toString();
+ assertEquals(constructorName, "javax.script.ScriptEngineManager",
+ "wrong constructor name " + constructorName);
+ assertEquals(constructorString, "public javax.script.ScriptEngineManager(java.lang.ClassLoader)",
+ "wrong constructor.toString() " + constructorName);
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getDeclaredConstructors()
+ */
+ protected void testGetDeclaredConstructors() {
+ Constructor[] constructors = this.scriptEngineManagerClass.getDeclaredConstructors();
+ assertEquals(constructors.length, 2, "only 2 constructors should be set");
+ String constructorName;
+ String constructorString;
+ constructorName = constructors[0].getName();
+ constructorString = constructors[0].toString();
+ assertEquals(constructorName, "javax.script.ScriptEngineManager",
+ "wrong constructor name " + constructorName);
+ assertEquals(constructorString, "public javax.script.ScriptEngineManager()",
+ "wrong constructor.toString() " + constructorName);
+ constructorName = constructors[1].getName();
+ constructorString = constructors[1].toString();
+ assertEquals(constructorName, "javax.script.ScriptEngineManager",
+ "wrong constructor name " + constructorName);
+ assertEquals(constructorString, "public javax.script.ScriptEngineManager(java.lang.ClassLoader)",
+ "wrong constructor.toString() " + constructorName);
+ }
+
+ /**
+ * Test for method javax.script.ScriptEngineManager.getClass().getFields()
+ */
+ protected void testGetFields() {
+ // following fields should exists
+ final String[] fieldsThatShouldExists = {
+ };
+ // get all fields
+ Field[] fields = this.scriptEngineManagerClass.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.ScriptEngineManager.getClass().getDeclaredFields()
+ */
+ protected void testGetDeclaredFields() {
+ // following fields should be declared
+ final String[] fieldsThatShouldExists = {
+ "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 all declared fields
+ Field[] declaredFields = this.scriptEngineManagerClass.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.ScriptEngineManager.getClass().getMethods()
+ */
+ protected void testGetMethods() {
+ // following methods should be inherited
+ final String[] methodsThatShouldExists = {
+ "public boolean java.lang.Object.equals(java.lang.Object)",
+ "public final native java.lang.Class java.lang.Object.getClass()",
More information about the distro-pkg-dev
mailing list