Skip to content

Commit bcf6ff4

Browse files
authored
Add test for LikeExpression.setEscape and LikeExpression.getStringExpression (#1568)
* Add test for LikeExpression.setEscape and LikeExpression.getStringExpression * like + set escape test for $ as escape character
1 parent 964fa49 commit bcf6ff4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/test/java/net/sf/jsqlparser/expression/operators/relational/LikeExpressionTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
*/
1010
package net.sf.jsqlparser.expression.operators.relational;
1111

12-
import static org.junit.jupiter.api.Assertions.assertFalse;
13-
import static org.junit.jupiter.api.Assertions.assertTrue;
12+
import net.sf.jsqlparser.JSQLParserException;
13+
import net.sf.jsqlparser.expression.Expression;
14+
import net.sf.jsqlparser.expression.StringValue;
15+
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
1416
import org.junit.jupiter.api.Test;
1517

18+
import static org.junit.jupiter.api.Assertions.*;
19+
1620
/**
1721
*
1822
* @author Tobias Warneke (t.warneke@gmx.net)
@@ -25,4 +29,15 @@ public void testLikeNotIssue660() {
2529
assertFalse(instance.isNot());
2630
assertTrue(instance.withNot(true).isNot());
2731
}
32+
33+
@Test
34+
public void testSetEscapeAndGetStringExpression() throws JSQLParserException {
35+
LikeExpression instance = (LikeExpression) CCJSqlParserUtil.parseExpression("name LIKE 'J%$_%'");
36+
// escape character should be $
37+
Expression instance2 = new StringValue("$");
38+
instance.setEscape(instance2);
39+
40+
// match all records with names that start with letter ’J’ and have the ’_’ character in them
41+
assertEquals("name LIKE 'J%$_%' ESCAPE '$'", instance.toString());
42+
}
2843
}

0 commit comments

Comments
 (0)