1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package examples.animal.data;
17
18 import static examples.animal.data.AnimalDataDynamicSqlSupport.*;
19 import static org.assertj.core.api.Assertions.assertThat;
20 import static org.junit.jupiter.api.Assertions.assertAll;
21 import static org.mybatis.dynamic.sql.SqlBuilder.*;
22
23 import java.io.InputStream;
24 import java.io.InputStreamReader;
25 import java.sql.Connection;
26 import java.sql.DriverManager;
27 import java.util.List;
28
29 import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
30 import org.apache.ibatis.jdbc.ScriptRunner;
31 import org.apache.ibatis.mapping.Environment;
32 import org.apache.ibatis.session.Configuration;
33 import org.apache.ibatis.session.SqlSession;
34 import org.apache.ibatis.session.SqlSessionFactory;
35 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
36 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
37 import org.jspecify.annotations.Nullable;
38 import org.junit.jupiter.api.BeforeEach;
39 import org.junit.jupiter.api.Test;
40 import org.mybatis.dynamic.sql.render.RenderingStrategies;
41 import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
42
43 class OptionalConditionsAnimalDataTest {
44
45 private static final String JDBC_URL = "jdbc:hsqldb:mem:aname";
46 private static final String JDBC_DRIVER = "org.hsqldb.jdbcDriver";
47 private static final @Nullable Integer NULL_INTEGER = null;
48
49 private SqlSessionFactory sqlSessionFactory;
50
51 @BeforeEach
52 void setup() throws Exception {
53 Class.forName(JDBC_DRIVER);
54 InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
55 assert is != null;
56 try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
57 ScriptRunner sr = new ScriptRunner(connection);
58 sr.setLogWriter(null);
59 sr.runScript(new InputStreamReader(is));
60 }
61
62 UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
63 Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
64 Configuration config = new Configuration(environment);
65 config.addMapper(AnimalDataMapper.class);
66 sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
67 }
68
69 @Test
70 void testAllIgnored() {
71 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
72 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
73 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
74 .from(animalData)
75 .where(id, isGreaterThanWhenPresent(NULL_INTEGER))
76 .orderBy(id)
77 .configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
78 .build()
79 .render(RenderingStrategies.MYBATIS3);
80 List<AnimalData> animals = mapper.selectMany(selectStatement);
81 assertAll(
82 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData order by id"),
83 () -> assertThat(animals).hasSize(65),
84 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1),
85 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(2)
86 );
87 }
88 }
89
90 @Test
91 void testIgnoredBetweenRendered() {
92 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
93 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
94 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
95 .from(animalData)
96 .where(id, isEqualTo(3))
97 .and(id, isNotEqualToWhenPresent(NULL_INTEGER))
98 .or(id, isEqualToWhenPresent(4))
99 .orderBy(id)
100 .build()
101 .render(RenderingStrategies.MYBATIS3);
102 List<AnimalData> animals = mapper.selectMany(selectStatement);
103 assertAll(
104 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"),
105 () -> assertThat(animals).hasSize(2),
106 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3),
107 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(4)
108 );
109 }
110 }
111
112 @Test
113 void testIgnoredInWhere() {
114 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
115 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
116 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
117 .from(animalData)
118 .where(id, isLessThanWhenPresent(NULL_INTEGER))
119 .and(id, isEqualToWhenPresent(3))
120 .or(id, isEqualToWhenPresent(4))
121 .orderBy(id)
122 .build()
123 .render(RenderingStrategies.MYBATIS3);
124 List<AnimalData> animals = mapper.selectMany(selectStatement);
125 assertAll(
126 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"),
127 () -> assertThat(animals).hasSize(2),
128 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3),
129 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(4)
130 );
131 }
132 }
133
134 @Test
135 void testManyIgnored() {
136 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
137 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
138 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
139 .from(animalData)
140 .where(id, isLessThanWhenPresent(NULL_INTEGER), and(id, isGreaterThanOrEqualToWhenPresent(NULL_INTEGER)))
141 .and(id, isEqualToWhenPresent(NULL_INTEGER), or(id, isEqualTo(3), and(id, isLessThanWhenPresent(NULL_INTEGER))))
142 .or(id, isEqualToWhenPresent(4), and(id, isGreaterThanOrEqualToWhenPresent(NULL_INTEGER)))
143 .and(id, isNotEqualToWhenPresent(NULL_INTEGER))
144 .orderBy(id)
145 .build()
146 .render(RenderingStrategies.MYBATIS3);
147 List<AnimalData> animals = mapper.selectMany(selectStatement);
148 assertAll(
149 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"),
150 () -> assertThat(animals).hasSize(2),
151 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3),
152 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(4)
153 );
154 }
155 }
156
157 @Test
158 void testIgnoredInitialWhere() {
159 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
160 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
161 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
162 .from(animalData)
163 .where(id, isLessThanWhenPresent(NULL_INTEGER), and(id, isEqualToWhenPresent(3)))
164 .or(id, isEqualToWhenPresent(4))
165 .orderBy(id)
166 .build()
167 .render(RenderingStrategies.MYBATIS3);
168 List<AnimalData> animals = mapper.selectMany(selectStatement);
169 assertAll(
170 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"),
171 () -> assertThat(animals).hasSize(2),
172 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3),
173 () -> assertThat(animals).element(1).isNotNull().extracting(AnimalData::id).isEqualTo(4)
174 );
175 }
176 }
177
178 @Test
179 void testEqualWhenPresentWithValue() {
180 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
181 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
182 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
183 .from(animalData)
184 .where(id, isEqualToWhenPresent(4))
185 .orderBy(id)
186 .build()
187 .render(RenderingStrategies.MYBATIS3);
188 List<AnimalData> animals = mapper.selectMany(selectStatement);
189 assertAll(
190 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} order by id"),
191 () -> assertThat(animals).hasSize(1),
192 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
193 );
194 }
195 }
196
197 @Test
198 void testEqualWhenPresentWithoutValue() {
199 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
200 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
201 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
202 .from(animalData)
203 .where(id, isEqualToWhenPresent(NULL_INTEGER))
204 .and(id, isLessThanOrEqualTo(10))
205 .orderBy(id)
206 .build()
207 .render(RenderingStrategies.MYBATIS3);
208 List<AnimalData> animals = mapper.selectMany(selectStatement);
209 assertAll(
210 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
211 () -> assertThat(animals).hasSize(10),
212 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
213 );
214 }
215 }
216
217 @Test
218 void testNotEqualWhenPresentWithValue() {
219 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
220 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
221 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
222 .from(animalData)
223 .where(id, isNotEqualToWhenPresent(4))
224 .and(id, isLessThanOrEqualTo(10))
225 .orderBy(id)
226 .build()
227 .render(RenderingStrategies.MYBATIS3);
228 List<AnimalData> animals = mapper.selectMany(selectStatement);
229 assertAll(
230 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <> #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
231 () -> assertThat(animals).hasSize(9),
232 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
233 );
234 }
235 }
236
237 @Test
238 void testNotEqualWhenPresentWithoutValue() {
239 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
240 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
241 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
242 .from(animalData)
243 .where(id, isNotEqualToWhenPresent(NULL_INTEGER))
244 .and(id, isLessThanOrEqualTo(10))
245 .orderBy(id)
246 .build()
247 .render(RenderingStrategies.MYBATIS3);
248 List<AnimalData> animals = mapper.selectMany(selectStatement);
249 assertAll(
250 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
251 () -> assertThat(animals).hasSize(10),
252 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
253 );
254 }
255 }
256
257 @Test
258 void testGreaterThanWhenPresentWithValue() {
259 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
260 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
261 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
262 .from(animalData)
263 .where(id, isGreaterThanWhenPresent(4))
264 .and(id, isLessThanOrEqualTo(10))
265 .orderBy(id)
266 .build()
267 .render(RenderingStrategies.MYBATIS3);
268 List<AnimalData> animals = mapper.selectMany(selectStatement);
269 assertAll(
270 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id > #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
271 () -> assertThat(animals).hasSize(6),
272 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(5)
273 );
274 }
275 }
276
277 @Test
278 void testGreaterThanWhenPresentWithoutValue() {
279 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
280 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
281 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
282 .from(animalData)
283 .where(id, isGreaterThanWhenPresent(NULL_INTEGER))
284 .and(id, isLessThanOrEqualTo(10))
285 .orderBy(id)
286 .build()
287 .render(RenderingStrategies.MYBATIS3);
288 List<AnimalData> animals = mapper.selectMany(selectStatement);
289 assertAll(
290 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
291 () -> assertThat(animals).hasSize(10),
292 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
293 );
294 }
295 }
296
297 @Test
298 void testGreaterThanOrEqualToWhenPresentWithValue() {
299 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
300 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
301 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
302 .from(animalData)
303 .where(id, isGreaterThanOrEqualToWhenPresent(4))
304 .and(id, isLessThanOrEqualTo(10))
305 .orderBy(id)
306 .build()
307 .render(RenderingStrategies.MYBATIS3);
308 List<AnimalData> animals = mapper.selectMany(selectStatement);
309 assertAll(
310 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id >= #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
311 () -> assertThat(animals).hasSize(7),
312 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
313 );
314 }
315 }
316
317 @Test
318 void testGreaterThanOrEqualToWhenPresentWithoutValue() {
319 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
320 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
321 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
322 .from(animalData)
323 .where(id, isGreaterThanOrEqualToWhenPresent(NULL_INTEGER))
324 .and(id, isLessThanOrEqualTo(10))
325 .orderBy(id)
326 .build()
327 .render(RenderingStrategies.MYBATIS3);
328 List<AnimalData> animals = mapper.selectMany(selectStatement);
329 assertAll(
330 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
331 () -> assertThat(animals).hasSize(10),
332 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
333 );
334 }
335 }
336
337 @Test
338 void testLessThanWhenPresentWithValue() {
339 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
340 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
341 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
342 .from(animalData)
343 .where(id, isLessThanWhenPresent(4))
344 .orderBy(id)
345 .build()
346 .render(RenderingStrategies.MYBATIS3);
347 List<AnimalData> animals = mapper.selectMany(selectStatement);
348 assertAll(
349 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} order by id"),
350 () -> assertThat(animals).hasSize(3),
351 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
352 );
353 }
354 }
355
356 @Test
357 void testLessThanWhenPresentWithoutValue() {
358 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
359 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
360 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
361 .from(animalData)
362 .where(id, isLessThanWhenPresent(NULL_INTEGER))
363 .and(id, isLessThanOrEqualTo(10))
364 .orderBy(id)
365 .build()
366 .render(RenderingStrategies.MYBATIS3);
367 List<AnimalData> animals = mapper.selectMany(selectStatement);
368 assertAll(
369 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
370 () -> assertThat(animals).hasSize(10),
371 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
372 );
373 }
374 }
375
376 @Test
377 void testLessThanOrEqualToWhenPresentWithValue() {
378 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
379 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
380 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
381 .from(animalData)
382 .where(id, isLessThanOrEqualToWhenPresent(4))
383 .orderBy(id)
384 .build()
385 .render(RenderingStrategies.MYBATIS3);
386 List<AnimalData> animals = mapper.selectMany(selectStatement);
387 assertAll(
388 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
389 () -> assertThat(animals).hasSize(4),
390 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
391 );
392 }
393 }
394
395 @Test
396 void testLessThanOrEqualToWhenPresentWithoutValue() {
397 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
398 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
399 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
400 .from(animalData)
401 .where(id, isLessThanOrEqualToWhenPresent(NULL_INTEGER))
402 .and(id, isLessThanOrEqualTo(10))
403 .orderBy(id)
404 .build()
405 .render(RenderingStrategies.MYBATIS3);
406 List<AnimalData> animals = mapper.selectMany(selectStatement);
407 assertAll(
408 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
409 () -> assertThat(animals).hasSize(10),
410 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
411 );
412 }
413 }
414
415 @Test
416 void testIsInWhenPresentWithValue() {
417 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
418 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
419 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
420 .from(animalData)
421 .where(id, isInWhenPresent(4, 5, 6))
422 .orderBy(id)
423 .build()
424 .render(RenderingStrategies.MYBATIS3);
425 List<AnimalData> animals = mapper.selectMany(selectStatement);
426 assertAll(
427 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) order by id"),
428 () -> assertThat(animals).hasSize(3),
429 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
430 );
431 }
432 }
433
434 @Test
435 void testIsInWhenPresentWithSomeValues() {
436 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
437 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
438 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
439 .from(animalData)
440 .where(id, isInWhenPresent(3, NULL_INTEGER, 5))
441 .orderBy(id)
442 .build()
443 .render(RenderingStrategies.MYBATIS3);
444 List<AnimalData> animals = mapper.selectMany(selectStatement);
445 assertAll(
446 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) order by id"),
447 () -> assertThat(animals).hasSize(2),
448 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3)
449 );
450 }
451 }
452
453 @Test
454 void testIsInWhenPresentWithNoValues() {
455 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
456 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
457 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
458 .from(animalData)
459 .where(id, isInWhenPresent())
460 .and(id, isLessThanOrEqualTo(10))
461 .orderBy(id)
462 .build()
463 .render(RenderingStrategies.MYBATIS3);
464 List<AnimalData> animals = mapper.selectMany(selectStatement);
465 assertAll(
466 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
467 () -> assertThat(animals).hasSize(10),
468 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
469 );
470 }
471 }
472
473 @Test
474 void testIsInCaseInsensitiveWhenPresentWithValue() {
475 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
476 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
477 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
478 .from(animalData)
479 .where(animalName, isInCaseInsensitiveWhenPresent("mouse", "musk shrew"))
480 .orderBy(id)
481 .build()
482 .render(RenderingStrategies.MYBATIS3);
483 List<AnimalData> animals = mapper.selectMany(selectStatement);
484 assertAll(
485 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"),
486 () -> assertThat(animals).hasSize(2),
487 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
488 );
489 }
490 }
491
492 @Test
493 void testIsInCaseInsensitiveWhenPresentWithSomeValues() {
494 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
495 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
496 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
497 .from(animalData)
498 .where(animalName, isInCaseInsensitiveWhenPresent("mouse", null, "musk shrew"))
499 .orderBy(id)
500 .build()
501 .render(RenderingStrategies.MYBATIS3);
502 List<AnimalData> animals = mapper.selectMany(selectStatement);
503 assertAll(
504 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"),
505 () -> assertThat(animals).hasSize(2),
506 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(4)
507 );
508 }
509 }
510
511 @Test
512 void testIsInCaseInsensitiveWhenPresentWithNoValues() {
513 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
514 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
515 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
516 .from(animalData)
517 .where(animalName, isInCaseInsensitiveWhenPresent())
518 .and(id, isLessThanOrEqualTo(10))
519 .orderBy(id)
520 .build()
521 .render(RenderingStrategies.MYBATIS3);
522 List<AnimalData> animals = mapper.selectMany(selectStatement);
523 assertAll(
524 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
525 () -> assertThat(animals).hasSize(10),
526 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
527 );
528 }
529 }
530
531 @Test
532 void testIsNotInWhenPresentWithValue() {
533 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
534 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
535 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
536 .from(animalData)
537 .where(id, isNotInWhenPresent(4, 5, 6))
538 .and(id, isLessThanOrEqualTo(10))
539 .orderBy(id)
540 .build()
541 .render(RenderingStrategies.MYBATIS3);
542 List<AnimalData> animals = mapper.selectMany(selectStatement);
543 assertAll(
544 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) and id <= #{parameters.p4,jdbcType=INTEGER} order by id"),
545 () -> assertThat(animals).hasSize(7),
546 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
547 );
548 }
549 }
550
551 @Test
552 void testIsNotInWhenPresentWithSomeValues() {
553 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
554 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
555 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
556 .from(animalData)
557 .where(id, isNotInWhenPresent(3, NULL_INTEGER, 5))
558 .and(id, isLessThanOrEqualTo(10))
559 .orderBy(id)
560 .build()
561 .render(RenderingStrategies.MYBATIS3);
562 List<AnimalData> animals = mapper.selectMany(selectStatement);
563 assertAll(
564 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
565 () -> assertThat(animals).hasSize(8),
566 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
567 );
568 }
569 }
570
571 @Test
572 void testIsNotInWhenPresentWithNoValues() {
573 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
574 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
575 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
576 .from(animalData)
577 .where(id, isNotInWhenPresent())
578 .and(id, isLessThanOrEqualTo(10))
579 .orderBy(id)
580 .build()
581 .render(RenderingStrategies.MYBATIS3);
582 List<AnimalData> animals = mapper.selectMany(selectStatement);
583 assertAll(
584 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
585 () -> assertThat(animals).hasSize(10),
586 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
587 );
588 }
589 }
590
591 @Test
592 void testIsNotInCaseInsensitiveWhenPresentWithValue() {
593 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
594 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
595 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
596 .from(animalData)
597 .where(animalName, isNotInCaseInsensitiveWhenPresent("mouse", "musk shrew"))
598 .and(id, isLessThanOrEqualTo(10))
599 .orderBy(id)
600 .build()
601 .render(RenderingStrategies.MYBATIS3);
602 List<AnimalData> animals = mapper.selectMany(selectStatement);
603 assertAll(
604 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
605 () -> assertThat(animals).hasSize(8),
606 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
607 );
608 }
609 }
610
611 @Test
612 void testIsNotInCaseInsensitiveWhenPresentWithSomeValues() {
613 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
614 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
615 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
616 .from(animalData)
617 .where(animalName, isNotInCaseInsensitiveWhenPresent("mouse", null, "musk shrew"))
618 .and(id, isLessThanOrEqualTo(10))
619 .orderBy(id)
620 .build()
621 .render(RenderingStrategies.MYBATIS3);
622 List<AnimalData> animals = mapper.selectMany(selectStatement);
623 assertAll(
624 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
625 () -> assertThat(animals).hasSize(8),
626 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
627 );
628 }
629 }
630
631 @Test
632 void testIsNotInCaseInsensitiveWhenPresentWithNoValues() {
633 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
634 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
635 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
636 .from(animalData)
637 .where(animalName, isNotInCaseInsensitiveWhenPresent())
638 .and(id, isLessThanOrEqualTo(10))
639 .orderBy(id)
640 .build()
641 .render(RenderingStrategies.MYBATIS3);
642 List<AnimalData> animals = mapper.selectMany(selectStatement);
643 assertAll(
644 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
645 () -> assertThat(animals).hasSize(10),
646 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
647 );
648 }
649 }
650
651 @Test
652 void testIsBetweenWhenPresentWithValues() {
653 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
654 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
655 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
656 .from(animalData)
657 .where(id, isBetweenWhenPresent(3).and(6))
658 .orderBy(id)
659 .build()
660 .render(RenderingStrategies.MYBATIS3);
661 List<AnimalData> animals = mapper.selectMany(selectStatement);
662 assertAll(
663 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} order by id"),
664 () -> assertThat(animals).hasSize(4),
665 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(3)
666 );
667 }
668 }
669
670 @Test
671 void testIsBetweenWhenPresentWithFirstMissing() {
672 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
673 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
674 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
675 .from(animalData)
676 .where(id, isBetweenWhenPresent(NULL_INTEGER).and(6))
677 .and(id, isLessThanOrEqualTo(10))
678 .orderBy(id)
679 .build()
680 .render(RenderingStrategies.MYBATIS3);
681 List<AnimalData> animals = mapper.selectMany(selectStatement);
682 assertAll(
683 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
684 () -> assertThat(animals).hasSize(10),
685 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
686 );
687 }
688 }
689
690 @Test
691 void testIsBetweenWhenPresentWithSecondMissing() {
692 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
693 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
694 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
695 .from(animalData)
696 .where(id, isBetweenWhenPresent(3).and(NULL_INTEGER))
697 .and(id, isLessThanOrEqualTo(10))
698 .orderBy(id)
699 .build()
700 .render(RenderingStrategies.MYBATIS3);
701 List<AnimalData> animals = mapper.selectMany(selectStatement);
702 assertAll(
703 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
704 () -> assertThat(animals).hasSize(10),
705 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
706 );
707 }
708 }
709
710 @Test
711 void testIsBetweenWhenPresentWithBothMissing() {
712 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
713 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
714 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
715 .from(animalData)
716 .where(id, isBetweenWhenPresent(NULL_INTEGER).and(NULL_INTEGER))
717 .and(id, isLessThanOrEqualTo(10))
718 .orderBy(id)
719 .build()
720 .render(RenderingStrategies.MYBATIS3);
721 List<AnimalData> animals = mapper.selectMany(selectStatement);
722 assertAll(
723 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
724 () -> assertThat(animals).hasSize(10),
725 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
726 );
727 }
728 }
729
730 @Test
731 void testIsNotBetweenWhenPresentWithValues() {
732 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
733 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
734 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
735 .from(animalData)
736 .where(id, isNotBetweenWhenPresent(3).and(6))
737 .and(id, isLessThanOrEqualTo(10))
738 .orderBy(id)
739 .build()
740 .render(RenderingStrategies.MYBATIS3);
741 List<AnimalData> animals = mapper.selectMany(selectStatement);
742 assertAll(
743 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
744 () -> assertThat(animals).hasSize(6),
745 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
746 );
747 }
748 }
749
750 @Test
751 void testIsNotBetweenWhenPresentWithFirstMissing() {
752 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
753 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
754 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
755 .from(animalData)
756 .where(id, isNotBetweenWhenPresent(NULL_INTEGER).and(6))
757 .and(id, isLessThanOrEqualTo(10))
758 .orderBy(id)
759 .build()
760 .render(RenderingStrategies.MYBATIS3);
761 List<AnimalData> animals = mapper.selectMany(selectStatement);
762 assertAll(
763 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
764 () -> assertThat(animals).hasSize(10),
765 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
766 );
767 }
768 }
769
770 @Test
771 void testIsNotBetweenWhenPresentWithSecondMissing() {
772 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
773 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
774 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
775 .from(animalData)
776 .where(id, isNotBetweenWhenPresent(3).and(NULL_INTEGER))
777 .and(id, isLessThanOrEqualTo(10))
778 .orderBy(id)
779 .build()
780 .render(RenderingStrategies.MYBATIS3);
781 List<AnimalData> animals = mapper.selectMany(selectStatement);
782 assertAll(
783 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
784 () -> assertThat(animals).hasSize(10),
785 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
786 );
787 }
788 }
789
790 @Test
791 void testIsNotBetweenWhenPresentWithBothMissing() {
792 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
793 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
794 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
795 .from(animalData)
796 .where(id, isNotBetweenWhenPresent(NULL_INTEGER).and(NULL_INTEGER))
797 .and(id, isLessThanOrEqualTo(10))
798 .orderBy(id)
799 .build()
800 .render(RenderingStrategies.MYBATIS3);
801 List<AnimalData> animals = mapper.selectMany(selectStatement);
802 assertAll(
803 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
804 () -> assertThat(animals).hasSize(10),
805 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
806 );
807 }
808 }
809
810 @Test
811 void testIsLikeWhenPresentWithValue() {
812 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
813 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
814 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
815 .from(animalData)
816 .where(animalName, isLikeWhenPresent("%mole"))
817 .and(id, isLessThanOrEqualTo(10))
818 .orderBy(id)
819 .build()
820 .render(RenderingStrategies.MYBATIS3);
821 List<AnimalData> animals = mapper.selectMany(selectStatement);
822 assertAll(
823 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
824 () -> assertThat(animals).hasSize(2),
825 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(6)
826 );
827 }
828 }
829
830 @Test
831 void testIsLikeWhenPresentWithoutValue() {
832 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
833 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
834 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
835 .from(animalData)
836 .where(animalName, isLikeWhenPresent((String) null))
837 .and(id, isLessThanOrEqualTo(10))
838 .orderBy(id)
839 .build()
840 .render(RenderingStrategies.MYBATIS3);
841 List<AnimalData> animals = mapper.selectMany(selectStatement);
842 assertAll(
843 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
844 () -> assertThat(animals).hasSize(10),
845 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
846 );
847 }
848 }
849
850 @Test
851 void testIsLikeCaseInsensitiveWhenPresentWithValue() {
852 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
853 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
854 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
855 .from(animalData)
856 .where(animalName, isLikeCaseInsensitiveWhenPresent("%MoLe"))
857 .and(id, isLessThanOrEqualTo(10))
858 .orderBy(id)
859 .build()
860 .render(RenderingStrategies.MYBATIS3);
861 List<AnimalData> animals = mapper.selectMany(selectStatement);
862 assertAll(
863 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
864 () -> assertThat(animals).hasSize(2),
865 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(6)
866 );
867 }
868 }
869
870 @Test
871 void testIsLikeCaseInsensitiveWhenPresentWithoutValue() {
872 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
873 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
874 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
875 .from(animalData)
876 .where(animalName, isLikeCaseInsensitiveWhenPresent((String) null))
877 .and(id, isLessThanOrEqualTo(10))
878 .orderBy(id)
879 .build()
880 .render(RenderingStrategies.MYBATIS3);
881 List<AnimalData> animals = mapper.selectMany(selectStatement);
882 assertAll(
883 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
884 () -> assertThat(animals).hasSize(10),
885 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
886 );
887 }
888 }
889
890 @Test
891 void testIsNotLikeWhenPresentWithValue() {
892 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
893 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
894 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
895 .from(animalData)
896 .where(animalName, isNotLikeWhenPresent("%mole"))
897 .and(id, isLessThanOrEqualTo(10))
898 .orderBy(id)
899 .build()
900 .render(RenderingStrategies.MYBATIS3);
901 List<AnimalData> animals = mapper.selectMany(selectStatement);
902 assertAll(
903 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
904 () -> assertThat(animals).hasSize(8),
905 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
906 );
907 }
908 }
909
910 @Test
911 void testIsNotLikeWhenPresentWithoutValue() {
912 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
913 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
914 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
915 .from(animalData)
916 .where(animalName, isNotLikeWhenPresent((String) null))
917 .and(id, isLessThanOrEqualTo(10))
918 .orderBy(id)
919 .build()
920 .render(RenderingStrategies.MYBATIS3);
921 List<AnimalData> animals = mapper.selectMany(selectStatement);
922 assertAll(
923 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
924 () -> assertThat(animals).hasSize(10),
925 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
926 );
927 }
928 }
929
930 @Test
931 void testIsNotLikeCaseInsensitiveWhenPresentWithValue() {
932 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
933 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
934 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
935 .from(animalData)
936 .where(animalName, isNotLikeCaseInsensitiveWhenPresent("%MoLe"))
937 .and(id, isLessThanOrEqualTo(10))
938 .orderBy(id)
939 .build()
940 .render(RenderingStrategies.MYBATIS3);
941 List<AnimalData> animals = mapper.selectMany(selectStatement);
942 assertAll(
943 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"),
944 () -> assertThat(animals).hasSize(8),
945 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
946 );
947 }
948 }
949
950 @Test
951 void testIsNotLikeCaseInsensitiveWhenPresentWithoutValue() {
952 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
953 AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
954 SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
955 .from(animalData)
956 .where(animalName, isNotLikeCaseInsensitiveWhenPresent((String) null))
957 .and(id, isLessThanOrEqualTo(10))
958 .orderBy(id)
959 .build()
960 .render(RenderingStrategies.MYBATIS3);
961 List<AnimalData> animals = mapper.selectMany(selectStatement);
962 assertAll(
963 () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"),
964 () -> assertThat(animals).hasSize(10),
965 () -> assertThat(animals).first().isNotNull().extracting(AnimalData::id).isEqualTo(1)
966 );
967 }
968 }
969 }