view src/org/RhinoTests/ScriptContextTest.java @ 359:324c54e484c1 draft

Fixed object types.
author ptisnovs
date Thu, 15 May 2014 15:17:50 +0200
parents 3c0edf5a83fc
children 7ec0f5310ca5
line wrap: on
line source

/*
  Rhino test framework

   Copyright (C) 2011, 2012, 2013, 2014  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 javax.script.ScriptContext;
import javax.script.SimpleScriptContext;

/**
 * TODO: not implemented
 * @author ptisnovs
 *
 */
public class ScriptContextTest extends BaseRhinoTest {

    @Override
    protected void setUp(String[] args) {
        // this block could be empty
        return;
    }

    @Override
    protected void tearDown() {
        // this block could be empty
        return;
    }

    /**
     * Test for toString() method.
     */
    protected void testToString() {
        // tested object
        Object object = new SimpleScriptContext();

        // call the toString() method
        String string = object.toString();

        assertTrue(string != null, "toString() method returned null!");
        assertTrue(string.startsWith("javax.script.SimpleScriptContext"), "bad toString() return value " + string);
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute1() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", "value", ScriptContext.ENGINE_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute2() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", "", ScriptContext.ENGINE_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute3() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", null, ScriptContext.ENGINE_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute4() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", "value", ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", \"value\", ScriptContext.ENGINE_SCOPE.) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute5() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", "", ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", \"\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute6() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", null, ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", null, ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute7() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, "value", ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, \"value\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute8() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, "", ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, \"\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute9() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, null, ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, null, ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Entry point to this test case.
     *
     * @param args parameters passed from command line
     */
    public static void main(String[] args) {
        new ScriptContextTest().doTests(args);
    }

}