Package com.hp.jena3.rules.acceptance.test

Source Code of com.hp.jena3.rules.acceptance.test.TestScriptElement

/*
  (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
   All rights reserved.
   $Id$
*/


package com.hp.jena3.rules.acceptance.test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

import com.hp.jena3.rules.acceptance.ScriptElement;
import static com.hp.jena.ymris.util.StringParseUtils.*;

public class TestScriptElement
    {
    @Test public void ensureGetCommandReturnsCommandComponent()
        {
        ScriptElement e = new ScriptElement( "command", "body" );
        assertEquals( "command", e.getCommand() );
        }
   
    @Test public void ensureGetCommandWithArgumentsReturnsCommandComponent()
        {
        ScriptElement e = new ScriptElement( "command", listOfStrings( "ignored" ), "body" );
        assertEquals( "command", e.getCommand() );
        }
   
    @Test public void ensureGetBodyReturnsBodyComponent()
        {
        ScriptElement e = new ScriptElement( "command", "body" );
        assertEquals( "body", e.getBody() );
        }
   
    @Test public void ensureGetBodyWithArgumentsReturnsBodyComponent()
        {
        ScriptElement e = new ScriptElement( "command", listOfStrings( "" ), "body" );
        assertEquals( "body", e.getBody() );
        }
   
    @Test public void ensureGetArgumentsWithNoneReturnsEmpty()
        {
        ScriptElement e = new ScriptElement( "command", "body" );
        assertEquals( new ArrayList<String>(), e.getArguments() );
        }
   
    @Test public void ensureToStringDisplaysComponents()
        {
        ScriptElement e = new ScriptElement( "command", "body" );
        assertEquals( "<command|body>", e.toString() );
        }
   
    @Test public void ensureToStringDisplaysArgumentComponents()
        {
        ScriptElement e = new ScriptElement( "command", listOfStrings( "grey 17" ), "body" );
        assertEquals( "<command grey 17|body>", e.toString() );
        }
   
    @Test public void ensureToStringEscapesNewlines()
        {
        ScriptElement e = new ScriptElement( "command", "bo\ndy\n" );
        assertEquals( "<command|bo\\ndy\\n>", e.toString() );
        }
   
    @Test public void ensureScriptElementHashcodeDependsOnComponents()
        {
        String command = "advance", body = "clock";
        ScriptElement e = new ScriptElement( command, body );
        assertEquals( command.hashCode() ^ body.hashCode(), e.hashCode() );
        }
   
    @Test public void ensureScriptElementEqualityWorks()
        {
        assertEquals( new ScriptElement( "A", "B" ), new ScriptElement( "A", "B" ) );
        assertEquals( new ScriptElement( "A", listOfStrings( "grey 17" ), "B" ), new ScriptElement( "A", listOfStrings( "grey 17" ), "B" ) );
        assertDiffer( new ScriptElement( "A", listOfStrings( "grey 17" ), "B" ), new ScriptElement( "A", listOfStrings( "gray 17" ), "B" ) );
        assertDiffer( new ScriptElement( "A", listOfStrings( "grey 17" ), "B" ), new ScriptElement( "A", "B" ) );
        assertDiffer( new ScriptElement( "A", listOfStrings( "grey 17" ), "B" ), new ScriptElement( "A", listOfStrings( "grey" ), "B" ) );
        assertDiffer( new ScriptElement( "A", "B" ), new ScriptElement( "A", "C" ) );
        assertDiffer( new ScriptElement( "A", "B" ), new ScriptElement( "D", "B" ) );
        assertDiffer( new ScriptElement( "A", "B" ), new ScriptElement( "C", "D" ) );
        }

    private void assertDiffer( Object x, Object y )
        {
        if (x == null && y == null || x.equals( y ))
            fail( "expected different values, not just " + x );
        }
    }

/*
    (c) Copyright 2009 Hewlett-Packard Development Company, LP
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. The name of the author may not be used to endorse or promote products
       derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ 
TOP

Related Classes of com.hp.jena3.rules.acceptance.test.TestScriptElement

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.