Mercurial > hg > rhino-tests
changeset 28:f0a7d262fc6d draft
Added new test case with 20 tests:
src/org/RhinoTests/SimpleBindingsClassTest.java.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Mon, 27 Aug 2012 14:41:04 +0200 |
parents | c3cf3478f465 |
children | 9e4f9b602df1 |
files | ChangeLog Makefile src/org/RhinoTests/SimpleBindingsClassTest.java |
diffstat | 3 files changed, 414 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Aug 23 14:49:33 2012 +0200 +++ b/ChangeLog Mon Aug 27 14:41:04 2012 +0200 @@ -1,3 +1,10 @@ +2012-08-27 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/SimpleBindingsClassTest.java: + Added new test case with 20 tests. + * Makefile: + Added new class to compile and new test to run. + 2012-08-23 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/AbstractScriptEngineClassTest.java:
--- a/Makefile Thu Aug 23 14:49:33 2012 +0200 +++ b/Makefile Mon Aug 27 14:41:04 2012 +0200 @@ -66,6 +66,7 @@ ScriptExceptionTest \ ScriptExceptionClassTest \ SimpleBindingsTests \ + SimpleBindingsClassTests \ SimpleScriptContextTest \ SimpleScriptContextClassTest \ AbstractScriptEngineClassTest @@ -98,6 +99,7 @@ $(BUILD_DIR)/$(TEST_PACKAGE)/ScriptExceptionTest.class \ $(BUILD_DIR)/$(TEST_PACKAGE)/ScriptExceptionClassTest.class \ $(BUILD_DIR)/$(TEST_PACKAGE)/SimpleBindingsTest.class \ + $(BUILD_DIR)/$(TEST_PACKAGE)/SimpleBindingsClassTest.class \ $(BUILD_DIR)/$(TEST_PACKAGE)/SimpleScriptContextTest.class \ $(BUILD_DIR)/$(TEST_PACKAGE)/SimpleScriptContextClassTest.class \ $(BUILD_DIR)/$(TEST_PACKAGE)/AbstractScriptEngineClassTest.class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/RhinoTests/SimpleBindingsClassTest.java Mon Aug 27 14:41:04 2012 +0200 @@ -0,0 +1,405 @@ +/* + 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.SimpleBindings; +import javax.script.Bindings; + + + +/** + * Set of tests which check the API of SimpleBindings class using + * Java reflection API. + * + * @author Pavel Tisnovsky + */ +public class SimpleBindingsClassTest extends BaseRhinoTest { + + /** + * Object that represents the type of SimpleBindings. + */ + Class simpleBindingsClass = null; + + @Override + protected void setUp(String[] args) { + // setup attribute used by tests + this.simpleBindingsClass = SimpleBindings.class; + } + + @Override + protected void tearDown() { + // this block could be empty + return; + } + + /** + * Test for method javax.script.SimpleBindings.getClass().isAssignableFrom() + */ + protected void testIsAssignableFrom() { + assertTrue(this.simpleBindingsClass.isAssignableFrom(SimpleBindings.class), + "Method SimpleBindings.getClass().isAssignableFrom() returns wrong value"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().isInstance() + */ + protected void testIsInstance() { + assertTrue(this.simpleBindingsClass.isInstance(new SimpleBindings()), + "Method SimpleBindings.getClass().isInstance() returns wrong value"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().isInterface() + */ + protected void testIsInterface() { + assertFalse(this.simpleBindingsClass.isInterface(), + "Method SimpleBindings.getClass().isInterface() returns wrong value"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().isLocalClass() + */ + protected void testIsLocalClass() { + assertFalse(this.simpleBindingsClass.isLocalClass(), + "Method SimpleBindings.getClass().isLocalClass() returns wrong value"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().isMemberClass() + */ + protected void testIsMemberClass() { + assertFalse(this.simpleBindingsClass.isMemberClass(), + "Method SimpleBindings.getClass().isMemberClass() returns wrong value"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().isPrimitive() + */ + protected void testIsPrimitive() { + assertFalse(this.simpleBindingsClass.isPrimitive(), + "Method SimpleBindings.getClass().isPrimitive() returns wrong value"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().isSynthetic() + */ + protected void testIsSynthetic() { + assertFalse(this.simpleBindingsClass.isSynthetic(), + "Method SimpleBindings.getClass().isSynthetic() returns wrong value"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getInterfaces() + */ + protected void testGetInterfaces() { + List interfaces = Arrays.asList(this.simpleBindingsClass.getInterfaces()); + assertTrue(interfaces.contains(Bindings.class), + "list of implemented interfaces does not contain Bindings"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getModifiers() + */ + protected void testGetModifiers() { + int modifiers = this.simpleBindingsClass.getModifiers(); + assertTrue(Modifier.isPublic(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isPublic modifier is set to a wrong value"); + assertFalse(Modifier.isPrivate(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isPrivate modifier is set to a wrong value"); + assertFalse(Modifier.isProtected(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isProtected modifier is set to a wrong value"); + assertFalse(Modifier.isAbstract(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isAbstract modifier is set to a wrong value"); + assertFalse(Modifier.isFinal(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isFinal modifier is set to a wrong value"); + assertFalse(Modifier.isInterface(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isInterface modifier is set to a wrong value"); + assertFalse(Modifier.isNative(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isNative modifier is set to a wrong value"); + assertFalse(Modifier.isStatic(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isStatic modifier is set to a wrong value"); + assertFalse(Modifier.isStrict(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isStrict modifier is set to a wrong value"); + assertFalse(Modifier.isSynchronized(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isSynchronized modifier is set to a wrong value"); + assertFalse(Modifier.isTransient(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isTransient modifier is set to a wrong value"); + assertFalse(Modifier.isVolatile(modifiers), + "Method SimpleBindings.getClass().getModifiers() - isVolatile modifier is set to a wrong value"); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getName() + */ + protected void testGetName() { + String name = this.simpleBindingsClass.getName(); + assertEquals(name, "javax.script.SimpleBindings", + "Method SimpleBindings.getClass().getName() returns wrong value " + name); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getPackage() + */ + protected void testGetPackage() { + Package p = this.simpleBindingsClass.getPackage(); + String packageName = p.getName(); + assertEquals(packageName, "javax.script", + "Method SimpleBindings.getClass().getPackage().getName() returns wrong value " + packageName); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getSimpleName() + */ + protected void testGetSimpleName() { + String simpleName = this.simpleBindingsClass.getSimpleName(); + assertEquals(simpleName, "SimpleBindings", + "Method SimpleBindings.getClass().getSimpleName() returns wrong value " + simpleName); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getSuperclass() + */ + protected void testGetSuperclass() { + Class superClass = this.simpleBindingsClass.getSuperclass(); + String superClassName = superClass.getName(); + assertEquals(superClassName, "java.lang.Object", + "Method SimpleBindings.getClass().getSuperclass() returns wrong value " + superClassName); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getConstructors() + */ + protected void testGetConstructors() { + Constructor[] constructors = this.simpleBindingsClass.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.SimpleBindings", + "wrong constructor name " + constructorName); + assertEquals(constructorString, "public javax.script.SimpleBindings(java.util.Map)", + "wrong constructor.toString() " + constructorName); + constructorName = constructors[1].getName(); + constructorString = constructors[1].toString(); + assertEquals(constructorName, "javax.script.SimpleBindings", + "wrong constructor name " + constructorName); + assertEquals(constructorString, "public javax.script.SimpleBindings()", + "wrong constructor.toString() " + constructorName); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getDeclaredConstructors() + */ + protected void testGetDeclaredConstructors() { + Constructor[] constructors = this.simpleBindingsClass.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.SimpleBindings", + "wrong constructor name " + constructorName); + assertEquals(constructorString, "public javax.script.SimpleBindings(java.util.Map)", + "wrong constructor.toString() " + constructorName); + constructorName = constructors[1].getName(); + constructorString = constructors[1].toString(); + assertEquals(constructorName, "javax.script.SimpleBindings", + "wrong constructor name " + constructorName); + assertEquals(constructorString, "public javax.script.SimpleBindings()", + "wrong constructor.toString() " + constructorName); + } + + /** + * Test for method javax.script.SimpleBindings.getClass().getFields() + */ + protected void testGetFields() { + // following fields should exists + final String[] fieldsThatShouldExists = { + }; + // get all fields + Field[] fields = this.simpleBindingsClass.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.SimpleBindings.getClass().getDeclaredFields() + */ + protected void testGetDeclaredFields() { + // following fields should be declared + final String[] fieldsThatShouldExists = { + "private java.util.Map javax.script.SimpleBindings.map", + }; + // get all declared fields + Field[] declaredFields = this.simpleBindingsClass.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.SimpleBindings.getClass().getMethods() + */ + protected void testGetMethods() { + // following methods should be inherited + final String[] methodsThatShouldExists = { + "public boolean java.lang.Object.equals(java.lang.Object)", + "public boolean javax.script.SimpleBindings.containsKey(java.lang.Object)", + "public boolean javax.script.SimpleBindings.containsValue(java.lang.Object)", + "public boolean javax.script.SimpleBindings.isEmpty()", + "public final native java.lang.Class java.lang.Object.getClass()", + "public final native void java.lang.Object.notify()", + "public final native void java.lang.Object.notifyAll()", + "public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException", + "public final void java.lang.Object.wait() throws java.lang.InterruptedException", + "public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException", + "public int javax.script.SimpleBindings.size()", + "public java.lang.Object javax.script.SimpleBindings.get(java.lang.Object)", + "public java.lang.Object javax.script.SimpleBindings.put(java.lang.Object,java.lang.Object)", + "public java.lang.Object javax.script.SimpleBindings.put(java.lang.String,java.lang.Object)", + "public java.lang.Object javax.script.SimpleBindings.remove(java.lang.Object)", + "public java.lang.String java.lang.Object.toString()", + "public java.util.Collection javax.script.SimpleBindings.values()", + "public java.util.Set javax.script.SimpleBindings.entrySet()", + "public java.util.Set javax.script.SimpleBindings.keySet()", + "public native int java.lang.Object.hashCode()", + "public void javax.script.SimpleBindings.clear()", + "public void javax.script.SimpleBindings.putAll(java.util.Map)", + }; + // get all inherited methods + Method[] methods = this.simpleBindingsClass.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.SimpleBindings.getClass().getDeclaredMethods() + */ + protected void testGetDeclaredMethods() { + // following methods should be declared + final String[] declaredMethodsThatShouldExists = { + "private void javax.script.SimpleBindings.checkKey(java.lang.Object)", + "public boolean javax.script.SimpleBindings.containsKey(java.lang.Object)", + "public boolean javax.script.SimpleBindings.containsValue(java.lang.Object)", + "public boolean javax.script.SimpleBindings.isEmpty()", + "public int javax.script.SimpleBindings.size()", + "public java.lang.Object javax.script.SimpleBindings.get(java.lang.Object)", + "public java.lang.Object javax.script.SimpleBindings.put(java.lang.Object,java.lang.Object)", + "public java.lang.Object javax.script.SimpleBindings.put(java.lang.String,java.lang.Object)", + "public java.lang.Object javax.script.SimpleBindings.remove(java.lang.Object)", + "public java.util.Collection javax.script.SimpleBindings.values()", + "public java.util.Set javax.script.SimpleBindings.entrySet()", + "public java.util.Set javax.script.SimpleBindings.keySet()", + "public void javax.script.SimpleBindings.clear()", + "public void javax.script.SimpleBindings.putAll(java.util.Map)", + }; + // get all declared methods + Method[] declaredMethods = this.simpleBindingsClass.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.SimpleBindings + */ + protected void testInstanceOf() { + // tested object + Object o = new SimpleBindings(); + + // basic check of instanceof operator + assertTrue(o instanceof SimpleBindings, "instanceof SimpleBindings is wrongly evaluated to false"); + + // check operator instanceof against all superclasses + assertTrue(o instanceof Object, "instanceof Object is wrongly evaluated to false"); + 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 SimpleBindingsClassTest().doTests(args); + } +} +