|
@@ -4,52 +4,60 @@ import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class ConditionTest {
|
|
public class ConditionTest {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void toStringTest() {
|
|
public void toStringTest() {
|
|
|
Condition conditionNull = new Condition("user", null);
|
|
Condition conditionNull = new Condition("user", null);
|
|
|
Assert.assertEquals("user IS NULL", conditionNull.toString());
|
|
Assert.assertEquals("user IS NULL", conditionNull.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionNotNull = new Condition("user", "!= null");
|
|
Condition conditionNotNull = new Condition("user", "!= null");
|
|
|
Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString());
|
|
Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition condition2 = new Condition("user", "= zhangsan");
|
|
Condition condition2 = new Condition("user", "= zhangsan");
|
|
|
Assert.assertEquals("user = ?", condition2.toString());
|
|
Assert.assertEquals("user = ?", condition2.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionLike = new Condition("user", "like %aaa");
|
|
Condition conditionLike = new Condition("user", "like %aaa");
|
|
|
Assert.assertEquals("user LIKE ?", conditionLike.toString());
|
|
Assert.assertEquals("user LIKE ?", conditionLike.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionIn = new Condition("user", "in 1,2,3");
|
|
Condition conditionIn = new Condition("user", "in 1,2,3");
|
|
|
Assert.assertEquals("user IN (?,?,?)", conditionIn.toString());
|
|
Assert.assertEquals("user IN (?,?,?)", conditionIn.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionBetween = new Condition("user", "between 12 and 13");
|
|
Condition conditionBetween = new Condition("user", "between 12 and 13");
|
|
|
Assert.assertEquals("user BETWEEN ? AND ?", conditionBetween.toString());
|
|
Assert.assertEquals("user BETWEEN ? AND ?", conditionBetween.toString());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void toStringNoPlaceHolderTest() {
|
|
public void toStringNoPlaceHolderTest() {
|
|
|
Condition conditionNull = new Condition("user", null);
|
|
Condition conditionNull = new Condition("user", null);
|
|
|
conditionNull.setPlaceHolder(false);
|
|
conditionNull.setPlaceHolder(false);
|
|
|
Assert.assertEquals("user IS NULL", conditionNull.toString());
|
|
Assert.assertEquals("user IS NULL", conditionNull.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionNotNull = new Condition("user", "!= null");
|
|
Condition conditionNotNull = new Condition("user", "!= null");
|
|
|
conditionNotNull.setPlaceHolder(false);
|
|
conditionNotNull.setPlaceHolder(false);
|
|
|
Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString());
|
|
Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionEquals = new Condition("user", "= zhangsan");
|
|
Condition conditionEquals = new Condition("user", "= zhangsan");
|
|
|
conditionEquals.setPlaceHolder(false);
|
|
conditionEquals.setPlaceHolder(false);
|
|
|
Assert.assertEquals("user = zhangsan", conditionEquals.toString());
|
|
Assert.assertEquals("user = zhangsan", conditionEquals.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionLike = new Condition("user", "like %aaa");
|
|
Condition conditionLike = new Condition("user", "like %aaa");
|
|
|
conditionLike.setPlaceHolder(false);
|
|
conditionLike.setPlaceHolder(false);
|
|
|
Assert.assertEquals("user LIKE %aaa", conditionLike.toString());
|
|
Assert.assertEquals("user LIKE %aaa", conditionLike.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionIn = new Condition("user", "in 1,2,3");
|
|
Condition conditionIn = new Condition("user", "in 1,2,3");
|
|
|
conditionIn.setPlaceHolder(false);
|
|
conditionIn.setPlaceHolder(false);
|
|
|
Assert.assertEquals("user IN (1,2,3)", conditionIn.toString());
|
|
Assert.assertEquals("user IN (1,2,3)", conditionIn.toString());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Condition conditionBetween = new Condition("user", "between 12 and 13");
|
|
Condition conditionBetween = new Condition("user", "between 12 and 13");
|
|
|
conditionBetween.setPlaceHolder(false);
|
|
conditionBetween.setPlaceHolder(false);
|
|
|
Assert.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString());
|
|
Assert.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void parseTest(){
|
|
|
|
|
+ final Condition age = Condition.parse("age", "< 10");
|
|
|
|
|
+ Assert.assertEquals("age < ?", age.toString());
|
|
|
|
|
+ // issue I38LTM
|
|
|
|
|
+ Assert.assertSame(Long.class, age.getValue().getClass());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|