Class AssertStatementCreationUtility
java.lang.Object
org.apache.groovy.contracts.generation.AssertStatementCreationUtility
Central place to create
AssertStatement instances in groovy-contracts.
Utilized to centralize AssertionError message generation.- See Also:
-
AssertStatementAssertionError
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classReplaces a givenReturnStatementwith the appropriate assertion call statement and returns a result variable expression.static classReplaces a givenReturnStatementwith the appropriate assertion call statement and returns a result variable expression.static classCollects allReturnStatementinstances from a given code block. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAssertionCallStatementToReturnStatement(org.codehaus.groovy.ast.stmt.BlockStatement statement, org.codehaus.groovy.ast.stmt.ReturnStatement returnStatement, org.codehaus.groovy.ast.stmt.Statement assertionCallStatement) static org.codehaus.groovy.ast.stmt.AssertStatementgetAssertionStatement(org.codehaus.groovy.ast.expr.BooleanExpression booleanExpression) Reusable method for creating assert statements for the given booleanExpression.static org.codehaus.groovy.ast.stmt.BlockStatementgetAssertionStatements(List<org.codehaus.groovy.ast.expr.BooleanExpression> booleanExpressions) Reusable method for creating assert statements for the given booleanExpression.static List<org.codehaus.groovy.ast.stmt.ReturnStatement>getReturnStatements(org.codehaus.groovy.ast.MethodNode method) Gets a list ofReturnStatementinstances from the givenMethodNode.static voidinjectResultVariableReturnStatementAndAssertionCallStatement(org.codehaus.groovy.ast.stmt.BlockStatement statement, org.codehaus.groovy.ast.ClassNode returnType, org.codehaus.groovy.ast.stmt.ReturnStatement returnStatement, org.codehaus.groovy.ast.stmt.BlockStatement assertionCallStatement)
-
Constructor Details
-
AssertStatementCreationUtility
public AssertStatementCreationUtility()
-
-
Method Details
-
getAssertionStatements
public static org.codehaus.groovy.ast.stmt.BlockStatement getAssertionStatements(List<org.codehaus.groovy.ast.expr.BooleanExpression> booleanExpressions) Reusable method for creating assert statements for the given booleanExpression.- Parameters:
booleanExpressions- the assertion'sBooleanExpressioninstances- Returns:
- a newly created
AssertStatement
-
getAssertionStatement
public static org.codehaus.groovy.ast.stmt.AssertStatement getAssertionStatement(org.codehaus.groovy.ast.expr.BooleanExpression booleanExpression) Reusable method for creating assert statements for the given booleanExpression.- Parameters:
booleanExpression- the assertion'sBooleanExpression- Returns:
- a newly created
AssertStatement
-
getReturnStatements
public static List<org.codehaus.groovy.ast.stmt.ReturnStatement> getReturnStatements(org.codehaus.groovy.ast.MethodNode method) Gets a list ofReturnStatementinstances from the givenMethodNode.- Parameters:
method- theMethodNodethat holds the given lastStatement- Returns:
- a
ReturnStatementor null
-
injectResultVariableReturnStatementAndAssertionCallStatement
public static void injectResultVariableReturnStatementAndAssertionCallStatement(org.codehaus.groovy.ast.stmt.BlockStatement statement, org.codehaus.groovy.ast.ClassNode returnType, org.codehaus.groovy.ast.stmt.ReturnStatement returnStatement, org.codehaus.groovy.ast.stmt.BlockStatement assertionCallStatement) -
addAssertionCallStatementToReturnStatement
public static void addAssertionCallStatementToReturnStatement(org.codehaus.groovy.ast.stmt.BlockStatement statement, org.codehaus.groovy.ast.stmt.ReturnStatement returnStatement, org.codehaus.groovy.ast.stmt.Statement assertionCallStatement)
-