Skip to content

Commit 9c6cb74

Browse files
committed
Polishing
1 parent 1488b67 commit 9c6cb74

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -168,39 +168,35 @@ public void testRelOperatorsInstanceof06() {
168168
}
169169

170170
@Test
171-
public void testRelOperatorsMatches01() {
172-
evaluate("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'", "false", Boolean.class);
171+
void matchesTrue() {
172+
evaluate("'5.00' matches '^-?\\d+(\\.\\d{2})?$'", "true", Boolean.class);
173173
}
174174

175175
@Test
176-
public void testRelOperatorsMatches02() {
177-
evaluate("'5.00' matches '^-?\\d+(\\.\\d{2})?$'", "true", Boolean.class);
176+
void matchesFalse() {
177+
evaluate("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'", "false", Boolean.class);
178178
}
179179

180180
@Test
181-
public void testRelOperatorsMatches03() {
182-
evaluateAndCheckError("null matches '^.*$'", SpelMessage.INVALID_FIRST_OPERAND_FOR_MATCHES_OPERATOR, 0, null);
181+
void matchesWithInputConversion() {
182+
evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int --> string
183183
}
184184

185185
@Test
186-
public void testRelOperatorsMatches04() {
187-
evaluateAndCheckError("'abc' matches null", SpelMessage.INVALID_SECOND_OPERAND_FOR_MATCHES_OPERATOR, 14, null);
186+
void matchesWithNullInput() {
187+
evaluateAndCheckError("null matches '^.*$'", SpelMessage.INVALID_FIRST_OPERAND_FOR_MATCHES_OPERATOR, 0, null);
188188
}
189189

190190
@Test
191-
public void testRelOperatorsMatches05() {
192-
evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int>string
191+
void matchesWithNullPattern() {
192+
evaluateAndCheckError("'abc' matches null", SpelMessage.INVALID_SECOND_OPERAND_FOR_MATCHES_OPERATOR, 14, null);
193193
}
194194

195195
@Test // SPR-16731
196-
public void testMatchesWithPatternAccessThreshold() {
196+
void matchesWithPatternAccessThreshold() {
197197
String pattern = "^(?=[a-z0-9-]{1,47})([a-z0-9]+[-]{0,1}){1,47}[a-z0-9]{1}$";
198-
String expression = "'abcde-fghijklmn-o42pasdfasdfasdf.qrstuvwxyz10x.xx.yyy.zasdfasfd' matches \'" + pattern + "\'";
199-
Expression expr = parser.parseExpression(expression);
200-
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(
201-
expr::getValue)
202-
.withCauseInstanceOf(IllegalStateException.class)
203-
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.FLAWED_PATTERN));
198+
String expression = "'abcde-fghijklmn-o42pasdfasdfasdf.qrstuvwxyz10x.xx.yyy.zasdfasfd' matches '" + pattern + "'";
199+
evaluateAndCheckError(expression, SpelMessage.FLAWED_PATTERN);
204200
}
205201

206202
// mixing operators

0 commit comments

Comments
 (0)