Skip to content

Commit 42a905c

Browse files
committed
Checkstyle, Sonar, Coverage, etc.
1 parent 428fc91 commit 42a905c

File tree

8 files changed

+122
-224
lines changed

8 files changed

+122
-224
lines changed

Diff for: src/main/java/org/mybatis/dynamic/sql/where/condition/IsBetweenWhenPresent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private Builder(@Nullable T value1) {
103103

104104
@Override
105105
protected IsBetweenWhenPresent<T> build(@Nullable T value2) {
106-
return IsBetweenWhenPresent.of(value1, value2);
106+
return of(value1, value2);
107107
}
108108
}
109109
}

Diff for: src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotBetweenWhenPresent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private Builder(@Nullable T value1) {
104104

105105
@Override
106106
protected IsNotBetweenWhenPresent<T> build(@Nullable T value2) {
107-
return IsNotBetweenWhenPresent.of(value1, value2);
107+
return of(value1, value2);
108108
}
109109
}
110110
}

Diff for: src/test/java/examples/animal/data/AnimalDataTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.Collections;
3434
import java.util.List;
3535
import java.util.Map;
36-
import java.util.Objects;
3736
import java.util.Optional;
3837

3938
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
@@ -717,7 +716,7 @@ void testInConditionWithEventuallyEmptyListForceRendering() {
717716

718717
SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight)
719718
.from(animalData)
720-
.where(id, isInWhenPresent(inValues).filter(Objects::nonNull).filter(i -> i != 22))
719+
.where(id, isInWhenPresent(inValues).filter(i -> i != 22))
721720
.build();
722721

723722
assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() ->
@@ -744,7 +743,7 @@ void testInCaseSensitiveCondition() {
744743

745744
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
746745
.from(animalData)
747-
.where(animalName, isInCaseInsensitive("yellow-bellied marmot", "verbet", null))
746+
.where(animalName, isInCaseInsensitiveWhenPresent("yellow-bellied marmot", "verbet", null))
748747
.build()
749748
.render(RenderingStrategies.MYBATIS3);
750749

@@ -792,12 +791,13 @@ void testNotInCaseSensitiveConditionWithNull() {
792791

793792
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
794793
.from(animalData)
795-
.where(animalName, isNotInCaseInsensitive((String)null))
794+
.where(animalName, isNotInCaseInsensitiveWhenPresent((String) null))
795+
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
796796
.build()
797797
.render(RenderingStrategies.MYBATIS3);
798798

799799
List<AnimalData> animals = mapper.selectMany(selectStatement);
800-
assertThat(animals).isEmpty();
800+
assertThat(animals).hasSize(65);
801801
}
802802
}
803803

@@ -825,7 +825,7 @@ void testNotInConditionWithEventuallyEmptyListForceRendering() {
825825
SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight)
826826
.from(animalData)
827827
.where(id, isNotInWhenPresent(null, 22, null)
828-
.filter(Objects::nonNull).filter(i -> i != 22))
828+
.filter(i -> i != 22))
829829
.build();
830830

831831
assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() ->

Diff for: src/test/java/issues/gh105/Issue105Test.java

-176
Original file line numberDiff line numberDiff line change
@@ -519,22 +519,6 @@ void testNotLikeWhenPresentTransform() {
519519
assertThat(selectStatement.getParameters()).containsEntry("p1", "%fred%");
520520
}
521521

522-
@Test
523-
void testBetweenTransformWithNull() {
524-
525-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
526-
.from(person)
527-
.where(age, isBetweenWhenPresent(1).and((Integer) null).map(i1 -> i1 + 1, i2 -> i2 + 2))
528-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
529-
.build()
530-
.render(RenderingStrategies.MYBATIS3);
531-
532-
String expected = "select person_id, first_name, last_name"
533-
+ " from Person";
534-
535-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
536-
}
537-
538522
@Test
539523
void testBetweenWhenPresentTransformWithNull() {
540524

@@ -551,22 +535,6 @@ void testBetweenWhenPresentTransformWithNull() {
551535
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
552536
}
553537

554-
@Test
555-
void testEqualTransformWithNull() {
556-
557-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
558-
.from(person)
559-
.where(age, isEqualToWhenPresent((Integer) null).map(i -> i + 1))
560-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
561-
.build()
562-
.render(RenderingStrategies.MYBATIS3);
563-
564-
String expected = "select person_id, first_name, last_name"
565-
+ " from Person";
566-
567-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
568-
}
569-
570538
@Test
571539
void testEqualWhenPresentTransformWithNull() {
572540

@@ -583,38 +551,6 @@ void testEqualWhenPresentTransformWithNull() {
583551
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
584552
}
585553

586-
@Test
587-
void testGreaterThanTransformWithNull() {
588-
589-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
590-
.from(person)
591-
.where(age, isGreaterThanWhenPresent((Integer) null).map(i -> i + 1))
592-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
593-
.build()
594-
.render(RenderingStrategies.MYBATIS3);
595-
596-
String expected = "select person_id, first_name, last_name"
597-
+ " from Person";
598-
599-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
600-
}
601-
602-
@Test
603-
void testGreaterThanOrEqualTransformWithNull() {
604-
605-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
606-
.from(person)
607-
.where(age, isGreaterThanOrEqualToWhenPresent((Integer) null).map(i -> i + 1))
608-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
609-
.build()
610-
.render(RenderingStrategies.MYBATIS3);
611-
612-
String expected = "select person_id, first_name, last_name"
613-
+ " from Person";
614-
615-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
616-
}
617-
618554
@Test
619555
void testGreaterThanOrEqualWhenPresentTransformWithNull() {
620556

@@ -647,38 +583,6 @@ void testGreaterThanWhenPresentTransformWithNull() {
647583
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
648584
}
649585

650-
@Test
651-
void testLessThanTransformWithNull() {
652-
653-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
654-
.from(person)
655-
.where(age, isLessThanWhenPresent((Integer) null).map(i -> i + 1))
656-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
657-
.build()
658-
.render(RenderingStrategies.MYBATIS3);
659-
660-
String expected = "select person_id, first_name, last_name"
661-
+ " from Person";
662-
663-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
664-
}
665-
666-
@Test
667-
void testLessThanOrEqualTransformWithNull() {
668-
669-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
670-
.from(person)
671-
.where(age, isLessThanOrEqualToWhenPresent((Integer) null).map(i -> i + 1))
672-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
673-
.build()
674-
.render(RenderingStrategies.MYBATIS3);
675-
676-
String expected = "select person_id, first_name, last_name"
677-
+ " from Person";
678-
679-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
680-
}
681-
682586
@Test
683587
void testLessThanOrEqualWhenPresentTransformWithNull() {
684588

@@ -711,38 +615,6 @@ void testLessThanWhenPresentTransformWithNull() {
711615
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
712616
}
713617

714-
@Test
715-
void testLikeTransformWithNull() {
716-
717-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
718-
.from(person)
719-
.where(firstName, isLikeWhenPresent((String) null).map(SearchUtils::addWildcards))
720-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
721-
.build()
722-
.render(RenderingStrategies.MYBATIS3);
723-
724-
String expected = "select person_id, first_name, last_name"
725-
+ " from Person";
726-
727-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
728-
}
729-
730-
@Test
731-
void testLikeCaseInsensitiveTransformWithNull() {
732-
733-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
734-
.from(person)
735-
.where(firstName, isLikeCaseInsensitiveWhenPresent((String) null).map(SearchUtils::addWildcards))
736-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
737-
.build()
738-
.render(RenderingStrategies.MYBATIS3);
739-
740-
String expected = "select person_id, first_name, last_name"
741-
+ " from Person";
742-
743-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
744-
}
745-
746618
@Test
747619
void testLikeCaseInsensitiveWhenPresentTransformWithNull() {
748620

@@ -807,22 +679,6 @@ void testNotBetweenWhenPresentTransformWithNull() {
807679
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
808680
}
809681

810-
@Test
811-
void testNotEqualTransformWithNull() {
812-
813-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
814-
.from(person)
815-
.where(age, isNotEqualToWhenPresent((Integer) null).map(i -> i + 1))
816-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
817-
.build()
818-
.render(RenderingStrategies.MYBATIS3);
819-
820-
String expected = "select person_id, first_name, last_name"
821-
+ " from Person";
822-
823-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
824-
}
825-
826682
@Test
827683
void testNotEqualWhenPresentTransformWithNull() {
828684

@@ -839,38 +695,6 @@ void testNotEqualWhenPresentTransformWithNull() {
839695
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
840696
}
841697

842-
@Test
843-
void testNotLikeTransformWithNull() {
844-
845-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
846-
.from(person)
847-
.where(firstName, isNotLikeWhenPresent((String) null).map(SearchUtils::addWildcards))
848-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
849-
.build()
850-
.render(RenderingStrategies.MYBATIS3);
851-
852-
String expected = "select person_id, first_name, last_name"
853-
+ " from Person";
854-
855-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
856-
}
857-
858-
@Test
859-
void testNotLikeCaseInsensitiveTransformWithNull() {
860-
861-
SelectStatementProvider selectStatement = select(id, firstName, lastName)
862-
.from(person)
863-
.where(firstName, isNotLikeCaseInsensitiveWhenPresent((String) null).map(SearchUtils::addWildcards))
864-
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
865-
.build()
866-
.render(RenderingStrategies.MYBATIS3);
867-
868-
String expected = "select person_id, first_name, last_name"
869-
+ " from Person";
870-
871-
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
872-
}
873-
874698
@Test
875699
void testNotLikeCaseInsensitiveWhenPresentTransformWithNull() {
876700

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2016-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.util;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
class PredicatesTest {
23+
@Test
24+
void testFirstNull() {
25+
assertThat(Predicates.bothPresent().test(null, 1)).isFalse();
26+
}
27+
28+
@Test
29+
void testSecondNull() {
30+
assertThat(Predicates.bothPresent().test(1, null)).isFalse();
31+
}
32+
33+
@Test
34+
void testBothNull() {
35+
assertThat(Predicates.bothPresent().test(null, null)).isFalse();
36+
}
37+
38+
@Test
39+
void testNeitherNull() {
40+
assertThat(Predicates.bothPresent().test(1, 1)).isTrue();
41+
}
42+
}

0 commit comments

Comments
 (0)