Search in sources :

Example 1 with EmptyStackException

use of java.util.EmptyStackException in project core-java by SpineEventEngine.

the class VerifyShould method pass_assertThrows_if_callable_throws_specified_exception.

@Test
public void pass_assertThrows_if_callable_throws_specified_exception() {
    final Callable throwsEmptyStackException = new Callable() {

        @Override
        public Object call() throws Exception {
            throw new EmptyStackException();
        }
    };
    assertThrows(EmptyStackException.class, throwsEmptyStackException);
}
Also used : EmptyStackException(java.util.EmptyStackException) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 2 with EmptyStackException

use of java.util.EmptyStackException in project core-java by SpineEventEngine.

the class VerifyShould method pass_assertThrowsWithCause_if_callable_throws_specified_exception_with_specified_cause.

@Test
public void pass_assertThrowsWithCause_if_callable_throws_specified_exception_with_specified_cause() {
    final Throwable cause = new EmptyStackException();
    final RuntimeException runtimeException = new RuntimeException(cause);
    final Callable throwsRuntimeException = new Callable() {

        @Override
        public Object call() {
            throw runtimeException;
        }
    };
    assertThrowsWithCause(runtimeException.getClass(), cause.getClass(), throwsRuntimeException);
}
Also used : EmptyStackException(java.util.EmptyStackException) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 3 with EmptyStackException

use of java.util.EmptyStackException in project core-java by SpineEventEngine.

the class VerifyShould method fail_assertThrowsWithCause_if_runnable_expected_cause_is_null.

@SuppressWarnings("ConstantConditions")
@Test(expected = AssertionError.class)
public void fail_assertThrowsWithCause_if_runnable_expected_cause_is_null() {
    final Runnable throwsRuntimeException = new Runnable() {

        @Override
        public void run() {
            throw new RuntimeException(new EmptyStackException());
        }
    };
    assertThrowsWithCause(EmptyStackException.class, null, throwsRuntimeException);
}
Also used : EmptyStackException(java.util.EmptyStackException) Test(org.junit.Test)

Example 4 with EmptyStackException

use of java.util.EmptyStackException in project voltdb by VoltDB.

the class PlannerTestCase method assertTopDownTree.

/**
     * Assert that a plan node tree contains the expected types of plan nodes
     * in the order listed, assuming a top-down left-to-right depth-first
     * traversal through the child vector. A null plan node type in the list
     * will match any plan node or subtree at the corresponding position.
     **/
protected static void assertTopDownTree(AbstractPlanNode start, PlanNodeType... nodeTypes) {
    Stack<AbstractPlanNode> stack = new Stack<>();
    stack.push(start);
    for (PlanNodeType type : nodeTypes) {
        // Process each node before its children or later siblings.
        AbstractPlanNode parent;
        try {
            parent = stack.pop();
        } catch (EmptyStackException ese) {
            fail("No node was found in the tree to match node type " + type);
            // This dead code hushes warnings.
            return;
        }
        int childCount = parent.getChildCount();
        if (type == null) {
            // A null type wildcard matches any child TREE or NODE.
            System.out.println("DEBUG: Suggestion -- expect " + parent.getPlanNodeType() + " with " + childCount + " direct children.");
            continue;
        }
        assertEquals(type, parent.getPlanNodeType());
        // Iterate from the last child to the first.
        while (childCount > 0) {
            // Push each child to be processed before its parent's
            // or its own later (already pushed) siblings.
            stack.push(parent.getChild(--childCount));
        }
    }
    assertTrue("Extra plan node(s) (" + stack.size() + ") were found in the tree with no node type to match", stack.isEmpty());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType) EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

Example 5 with EmptyStackException

use of java.util.EmptyStackException in project voltdb by VoltDB.

the class PlannerTestCase method assertExprTopDownTree.

/**
     * Assert that an expression tree contains the expected types of expressions
     * in the order listed, assuming a top-down left-to-right depth-first
     * traversal through left, right, and args children.
     * A null expression type in the list will match any expression
     * node or tree at the corresponding position.
     **/
protected static void assertExprTopDownTree(AbstractExpression start, ExpressionType... exprTypes) {
    assertNotNull(start);
    Stack<AbstractExpression> stack = new Stack<>();
    stack.push(start);
    for (ExpressionType type : exprTypes) {
        // Process each node before its children or later siblings.
        AbstractExpression parent;
        try {
            parent = stack.pop();
        } catch (EmptyStackException ese) {
            fail("No expression was found in the tree to match type " + type);
            // This dead code hushes warnings.
            return;
        }
        List<AbstractExpression> args = parent.getArgs();
        AbstractExpression rightExpr = parent.getRight();
        AbstractExpression leftExpr = parent.getLeft();
        int argCount = (args == null) ? 0 : args.size();
        int childCount = argCount + (rightExpr == null ? 0 : 1) + (leftExpr == null ? 0 : 1);
        if (type == null) {
            // A null type wildcard matches any child TREE or NODE.
            System.out.println("DEBUG: Suggestion -- expect " + parent.getExpressionType() + " with " + childCount + " direct children.");
            continue;
        }
        assertEquals(type, parent.getExpressionType());
        // Iterate from the last child to the first.
        while (argCount > 0) {
            // Push each child to be processed before its parent's
            // or its own later siblings (already pushed).
            stack.push(parent.getArgs().get(--argCount));
        }
        if (rightExpr != null) {
            stack.push(rightExpr);
        }
        if (leftExpr != null) {
            stack.push(leftExpr);
        }
    }
    assertTrue("Extra expression node(s) (" + stack.size() + ") were found in the tree with no expression type to match", stack.isEmpty());
}
Also used : EmptyStackException(java.util.EmptyStackException) AbstractExpression(org.voltdb.expressions.AbstractExpression) ExpressionType(org.voltdb.types.ExpressionType) Stack(java.util.Stack)

Aggregations

EmptyStackException (java.util.EmptyStackException)47 Stack (java.util.Stack)13 Test (org.junit.Test)6 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)5 Callable (java.util.concurrent.Callable)5 NamespaceSupport (org.xml.sax.helpers.NamespaceSupport)5 ActivityImple (com.arjuna.mwlabs.wsas.activity.ActivityImple)3 IOException (java.io.IOException)3 ResourceApplicationContext (com.cloud.spring.module.context.ResourceApplicationContext)2 ConfigCompileException (com.laytonsmith.core.exceptions.ConfigCompileException)2 ArrayList (java.util.ArrayList)2 SystemException (org.omg.CORBA.SystemException)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ActionControl (com.arjuna.ArjunaOTS.ActionControl)1 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)1 LightScrollPane (com.jsql.view.swing.scrollpane.LightScrollPane)1 TabHeader (com.jsql.view.swing.tab.TabHeader)1 FileOptions (com.laytonsmith.core.compiler.FileOptions)1 KeywordList (com.laytonsmith.core.compiler.KeywordList)1 CDecimal (com.laytonsmith.core.constructs.CDecimal)1