protected virtual void ParseAndCheckError(string expression, SpelMessage expectedMessage, params object[] otherProperties) { var ex = Assert.Throws <SpelParseException>(() => { var expr = _parser.ParseExpression(expression); if (DEBUG) { SpelUtilities.PrintAbstractSyntaxTree(Console.Out, expr); } }); Assert.Equal(expectedMessage, ex.MessageCode); if (otherProperties != null && otherProperties.Length != 0) { // first one is expected position of the error within the string var pos = (int)otherProperties[0]; Assert.Equal(pos, ex.Position); if (otherProperties.Length > 1) { // Check inserts match var inserts = ex.Inserts; Assert.True(inserts.Length >= otherProperties.Length - 1); var expectedInserts = new object[inserts.Length]; Array.Copy(otherProperties, 1, expectedInserts, 0, expectedInserts.Length); Assert.Equal(expectedInserts.Length, inserts.Length); for (var i = 0; i < inserts.Length; i++) { Assert.Equal(expectedInserts[i], inserts[i]); } } } }
protected virtual void EvaluateAndCheckError(string expression, Type expectedReturnType, SpelMessage expectedMessage, params object[] otherProperties) { var ex = Assert.Throws <SpelEvaluationException>(() => { var expr = _parser.ParseExpression(expression); Assert.NotNull(expr); if (expectedReturnType != null) { expr.GetValue(_context, expectedReturnType); } else { expr.GetValue(_context); } }); Assert.Equal(expectedMessage, ex.MessageCode); if (otherProperties != null && otherProperties.Length != 0) { // first one is expected position of the error within the string var pos = (int)otherProperties[0]; Assert.Equal(pos, ex.Position); if (otherProperties.Length > 1) { // Check inserts match var inserts = ex.Inserts; Assert.True(inserts.Length >= otherProperties.Length - 1); var expectedInserts = new object[inserts.Length]; Array.Copy(otherProperties, 1, expectedInserts, 0, expectedInserts.Length); Assert.Equal(expectedInserts.Length, inserts.Length); for (var i = 0; i < inserts.Length; i++) { Assert.Equal(expectedInserts[i], inserts[i]); } } } }
protected virtual void EvaluateAndCheckError(string expression, SpelMessage expectedMessage, params object[] otherProperties) { EvaluateAndCheckError(expression, null, expectedMessage, otherProperties); }
public SpelParseException(int position, Exception cause, SpelMessage message, params object[] inserts) : base(position, message.FormatMessage(inserts), cause) { MessageCode = message; Inserts = inserts; }
public SpelParseException(string expressionString, int position, SpelMessage message, params object[] inserts) : base(expressionString, position, message.FormatMessage(inserts)) { MessageCode = message; Inserts = inserts; }
public SpelEvaluationException(Exception cause, SpelMessage message, params object[] inserts) : base(message.FormatMessage(inserts), cause) { MessageCode = message; Inserts = inserts; }
public SpelEvaluationException(int position, SpelMessage message, params object[] inserts) : base(position, message.FormatMessage(inserts)) { MessageCode = message; Inserts = inserts; }