changeset 230:9a2fbbac6020 draft

Added new test testCast (that checks Class.cast() method) into test test suite InvocableClassTest.
author Pavel Tisnovsky <ptisnovs@redhat.com>
date Wed, 11 Sep 2013 09:52:46 +0200
parents caa2fc835dda
children 78bab1320e16
files ChangeLog src/org/RhinoTests/ScriptContextClassTest.java
diffstat 2 files changed, 196 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Sep 10 13:47:12 2013 +0200
+++ b/ChangeLog	Wed Sep 11 09:52:46 2013 +0200
@@ -1,3 +1,9 @@
+2013-09-11  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* src/org/RhinoTests/ScriptContextClassTest.java:
+	Added new test testCast (that checks Class.cast() method) into test
+	test suite InvocableClassTest.
+
 2013-09-10  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/org/RhinoTests/InvocableClassTest.java:
--- a/src/org/RhinoTests/ScriptContextClassTest.java	Tue Sep 10 13:47:12 2013 +0200
+++ b/src/org/RhinoTests/ScriptContextClassTest.java	Wed Sep 11 09:52:46 2013 +0200
@@ -1214,6 +1214,196 @@
     }
 
     /**
+     * Test for method javax.script.ScriptContext.getClass().cast()
+     */
+    protected void testCast() {
+        try {
+            this.scriptContextClass.cast(new Object());
+            throw new AssertionError("Class.cast(new Object()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new Object().getClass());
+            throw new AssertionError("Class.cast(new Object().getClass()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new String());
+            throw new AssertionError("Class.cast(new String()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(Boolean.valueOf(true));
+            throw new AssertionError("Class.cast(Boolean.valueOf(true)) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(Boolean.valueOf(false));
+            throw new AssertionError("Class.cast(Boolean.valueOf(false)) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(Byte.valueOf((byte)42));
+            throw new AssertionError("Class.cast(Byte.valueOf((byte)42)) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(Short.valueOf((short)42));
+            throw new AssertionError("Class.cast(Short.valueOf((short)42)) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(Integer.valueOf(42));
+            throw new AssertionError("Class.cast(Integer.valueOf(42)) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(Long.valueOf(42L));
+            throw new AssertionError("Class.cast(Long.valueOf(42L)) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(Float.valueOf(42f));
+            throw new AssertionError("Class.cast(Float.valueOf(42f)) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(Double.valueOf(42.));
+            throw new AssertionError("Class.cast(Double.valueOf(42.)) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new Throwable());
+            throw new AssertionError("Class.cast(new Throwable()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new RuntimeException());
+            throw new AssertionError("Class.cast(new RuntimeException()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new Error());
+            throw new AssertionError("Class.cast(new Error()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new java.lang.String());
+            throw new AssertionError("Class.cast(new java.lang.String()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new java.lang.StringBuffer());
+            throw new AssertionError("Class.cast(new java.lang.StringBuffer()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new java.lang.StringBuilder());
+            throw new AssertionError("Class.cast(new java.lang.StringBuilder()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(java.awt.Color.black);
+            throw new AssertionError("Class.cast(java.awt.Color.black) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new java.awt.Frame());
+            throw new AssertionError("Class.cast(new java.awt.Frame()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new java.awt.Frame(new String()));
+            throw new AssertionError("Class.cast(new java.awt.Frame(new String())) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new javax.swing.JLabel());
+            throw new AssertionError("Class.cast(new javax.swing.JLabel()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new javax.swing.JLabel(new String()));
+            throw new AssertionError("Class.cast(new javax.swing.JLabel(new String())) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+        try {
+            this.scriptContextClass.cast(new javax.swing.JPanel());
+            throw new AssertionError("Class.cast(new javax.swing.JPanel()) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+
+    }
+
+    /**
      * Test for instanceof operator applied to a class javax.script.ScriptContext
      */
     @SuppressWarnings("cast")