|
17 | 17 |
|
18 | 18 | import static examples.animal.data.AnimalDataDynamicSqlSupport.*; |
19 | 19 | import static org.assertj.core.api.Assertions.assertThat; |
| 20 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
20 | 21 | import static org.assertj.core.api.Assertions.within; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertAll; |
22 | 23 | import static org.mybatis.dynamic.sql.SqlBuilder.*; |
|
26 | 27 | import java.sql.Connection; |
27 | 28 | import java.sql.DriverManager; |
28 | 29 | import java.util.ArrayList; |
| 30 | +import java.util.Collection; |
| 31 | +import java.util.Collections; |
29 | 32 | import java.util.List; |
30 | 33 | import java.util.Map; |
31 | 34 |
|
32 | 35 | import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; |
| 36 | +import org.apache.ibatis.exceptions.PersistenceException; |
33 | 37 | import org.apache.ibatis.jdbc.ScriptRunner; |
34 | 38 | import org.apache.ibatis.mapping.Environment; |
35 | 39 | import org.apache.ibatis.session.Configuration; |
|
52 | 56 | import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; |
53 | 57 | import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider; |
54 | 58 | import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils; |
| 59 | +import org.mybatis.dynamic.sql.where.condition.IsIn; |
55 | 60 | import org.mybatis.dynamic.sql.where.render.WhereClauseProvider; |
56 | 61 |
|
57 | 62 | class AnimalDataTest { |
@@ -564,6 +569,34 @@ void testInCondition() { |
564 | 569 | } |
565 | 570 | } |
566 | 571 |
|
| 572 | + @Test |
| 573 | + void testInConditionWithEmptyList() { |
| 574 | + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
| 575 | + AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class); |
| 576 | + |
| 577 | + SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight) |
| 578 | + .from(animalData) |
| 579 | + .where(id, IsInRequired.isIn(Collections.emptyList())) |
| 580 | + .build() |
| 581 | + .render(RenderingStrategies.MYBATIS3); |
| 582 | + |
| 583 | + assertThatExceptionOfType(PersistenceException.class).isThrownBy(() -> { |
| 584 | + mapper.selectMany(selectStatement); |
| 585 | + }); |
| 586 | + } |
| 587 | + } |
| 588 | + |
| 589 | + public static class IsInRequired<T> extends IsIn<T> { |
| 590 | + protected IsInRequired(Collection<T> values) { |
| 591 | + super(values); |
| 592 | + skipRenderingWhenEmpty = false; |
| 593 | + } |
| 594 | + |
| 595 | + public static <T> IsInRequired<T> isIn(Collection<T> values) { |
| 596 | + return new IsInRequired<>(values); |
| 597 | + } |
| 598 | + } |
| 599 | + |
567 | 600 | @Test |
568 | 601 | void testInCaseSensitiveCondition() { |
569 | 602 | try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
|
0 commit comments