Skip to content

Commit 7cb17bd

Browse files
committed
Coverage
1 parent 1df401a commit 7cb17bd

File tree

8 files changed

+123
-0
lines changed

8 files changed

+123
-0
lines changed

src/main/java/org/mybatis/dynamic/sql/util/StringUtilities.java

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.mybatis.dynamic.sql.util;
1717

18+
import java.util.function.Function;
19+
1820
import org.jspecify.annotations.Nullable;
1921

2022
public interface StringUtilities {
@@ -59,4 +61,8 @@ static String formatConstantForSQL(String in) {
5961
String escaped = in.replace("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
6062
return "'" + escaped + "'"; //$NON-NLS-1$ //$NON-NLS-2$
6163
}
64+
65+
static Function<String, String> mapToUpperCase(Function<String, String> f) {
66+
return f.andThen(String::toUpperCase);
67+
}
6268
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitive.java

+13
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public IsInCaseInsensitive<T> filter(Predicate<? super T> predicate) {
5757
return filterSupport(predicate, IsInCaseInsensitive::new, this, IsInCaseInsensitive::empty);
5858
}
5959

60+
/**
61+
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
62+
* condition that will not render (this).
63+
*
64+
* <p>This function DOES NOT automatically transform values to uppercase, so it potentially creates a
65+
* case-sensitive query. For String conditions you can use {@link StringUtilities#mapToUpperCase(Function)}
66+
* to add an uppercase transform after your mapping function.
67+
*
68+
* @param mapper a mapping function to apply to the value, if renderable
69+
* @param <R> type of the new condition
70+
* @return a new condition with the result of applying the mapper to the value of this condition,
71+
* if renderable, otherwise a condition that will not render.
72+
*/
6073
@Override
6174
public <R> IsInCaseInsensitive<R> map(Function<? super T, ? extends R> mapper) {
6275
return mapSupport(mapper, IsInCaseInsensitive::new, IsInCaseInsensitive::empty);

src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.jspecify.annotations.Nullable;
2626
import org.mybatis.dynamic.sql.AbstractListValueCondition;
27+
import org.mybatis.dynamic.sql.util.StringUtilities;
2728

2829
public class IsInCaseInsensitiveWhenPresent<T> extends AbstractListValueCondition<T>
2930
implements CaseInsensitiveRenderableCondition<T>, AbstractListValueCondition.Filterable<T>,
@@ -52,6 +53,19 @@ public IsInCaseInsensitiveWhenPresent<T> filter(Predicate<? super T> predicate)
5253
IsInCaseInsensitiveWhenPresent::empty);
5354
}
5455

56+
/**
57+
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
58+
* condition that will not render (this).
59+
*
60+
* <p>This function DOES NOT automatically transform values to uppercase, so it potentially creates a
61+
* case-sensitive query. For String conditions you can use {@link StringUtilities#mapToUpperCase(Function)}
62+
* to add an uppercase transform after your mapping function.
63+
*
64+
* @param mapper a mapping function to apply to the value, if renderable
65+
* @param <R> type of the new condition
66+
* @return a new condition with the result of applying the mapper to the value of this condition,
67+
* if renderable, otherwise a condition that will not render.
68+
*/
5569
@Override
5670
public <R> IsInCaseInsensitiveWhenPresent<R> map(Function<? super T, ? extends R> mapper) {
5771
return mapSupport(mapper, IsInCaseInsensitiveWhenPresent::new, IsInCaseInsensitiveWhenPresent::empty);

src/main/java/org/mybatis/dynamic/sql/where/condition/IsLikeCaseInsensitive.java

+13
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public IsLikeCaseInsensitive<T> filter(Predicate<? super T> predicate) {
5757
return filterSupport(predicate, IsLikeCaseInsensitive::empty, this);
5858
}
5959

60+
/**
61+
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
62+
* condition that will not render (this).
63+
*
64+
* <p>This function DOES NOT automatically transform values to uppercase, so it potentially creates a
65+
* case-sensitive query. For String conditions you can use {@link StringUtilities#mapToUpperCase(Function)}
66+
* to add an uppercase transform after your mapping function.
67+
*
68+
* @param mapper a mapping function to apply to the value, if renderable
69+
* @param <R> type of the new condition
70+
* @return a new condition with the result of applying the mapper to the value of this condition,
71+
* if renderable, otherwise a condition that will not render.
72+
*/
6073
@Override
6174
public <R> IsLikeCaseInsensitive<R> map(Function<? super T, ? extends R> mapper) {
6275
return mapSupport(mapper, IsLikeCaseInsensitive::new, IsLikeCaseInsensitive::empty);

src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitive.java

+13
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public IsNotInCaseInsensitive<T> filter(Predicate<? super T> predicate) {
5757
return filterSupport(predicate, IsNotInCaseInsensitive::new, this, IsNotInCaseInsensitive::empty);
5858
}
5959

60+
/**
61+
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
62+
* condition that will not render (this).
63+
*
64+
* <p>This function DOES NOT automatically transform values to uppercase, so it potentially creates a
65+
* case-sensitive query. For String conditions you can use {@link StringUtilities#mapToUpperCase(Function)}
66+
* to add an uppercase transform after your mapping function.
67+
*
68+
* @param mapper a mapping function to apply to the value, if renderable
69+
* @param <R> type of the new condition
70+
* @return a new condition with the result of applying the mapper to the value of this condition,
71+
* if renderable, otherwise a condition that will not render.
72+
*/
6073
@Override
6174
public <R> IsNotInCaseInsensitive<R> map(Function<? super T, ? extends R> mapper) {
6275
return mapSupport(mapper, IsNotInCaseInsensitive::new, IsNotInCaseInsensitive::empty);

src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.jspecify.annotations.Nullable;
2626
import org.mybatis.dynamic.sql.AbstractListValueCondition;
27+
import org.mybatis.dynamic.sql.util.StringUtilities;
2728

2829
public class IsNotInCaseInsensitiveWhenPresent<T> extends AbstractListValueCondition<T>
2930
implements CaseInsensitiveRenderableCondition<T>, AbstractListValueCondition.Filterable<T>,
@@ -52,6 +53,19 @@ public IsNotInCaseInsensitiveWhenPresent<T> filter(Predicate<? super T> predicat
5253
this, IsNotInCaseInsensitiveWhenPresent::empty);
5354
}
5455

56+
/**
57+
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
58+
* condition that will not render (this).
59+
*
60+
* <p>This function DOES NOT automatically transform values to uppercase, so it potentially creates a
61+
* case-sensitive query. For String conditions you can use {@link StringUtilities#mapToUpperCase(Function)}
62+
* to add an uppercase transform after your mapping function.
63+
*
64+
* @param mapper a mapping function to apply to the value, if renderable
65+
* @param <R> type of the new condition
66+
* @return a new condition with the result of applying the mapper to the value of this condition,
67+
* if renderable, otherwise a condition that will not render.
68+
*/
5569
@Override
5670
public <R> IsNotInCaseInsensitiveWhenPresent<R> map(Function<? super T, ? extends R> mapper) {
5771
return mapSupport(mapper, IsNotInCaseInsensitiveWhenPresent::new, IsNotInCaseInsensitiveWhenPresent::empty);

src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotLikeCaseInsensitive.java

+13
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public IsNotLikeCaseInsensitive<T> filter(Predicate<? super T> predicate) {
5757
return filterSupport(predicate, IsNotLikeCaseInsensitive::empty, this);
5858
}
5959

60+
/**
61+
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
62+
* condition that will not render (this).
63+
*
64+
* <p>This function DOES NOT automatically transform values to uppercase, so it potentially creates a
65+
* case-sensitive query. For String conditions you can use {@link StringUtilities#mapToUpperCase(Function)}
66+
* to add an uppercase transform after your mapping function.
67+
*
68+
* @param mapper a mapping function to apply to the value, if renderable
69+
* @param <R> type of the new condition
70+
* @return a new condition with the result of applying the mapper to the value of this condition,
71+
* if renderable, otherwise a condition that will not render.
72+
*/
6073
@Override
6174
public <R> IsNotLikeCaseInsensitive<R> map(Function<? super T, ? extends R> mapper) {
6275
return mapSupport(mapper, IsNotLikeCaseInsensitive::new, IsNotLikeCaseInsensitive::empty);

src/test/java/org/mybatis/dynamic/sql/where/condition/FilterAndMapTest.java

+37
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.junit.jupiter.api.Test;
2626
import org.mybatis.dynamic.sql.SqlBuilder;
27+
import org.mybatis.dynamic.sql.util.StringUtilities;
2728

2829
class FilterAndMapTest {
2930
@Test
@@ -533,4 +534,40 @@ void testNotBetweenMapWithSingleMapper() {
533534
assertThat(cond.value2()).isEqualTo(4);
534535
}
535536

537+
@Test
538+
void testMappingAnEmptyListCondition() {
539+
var cond = SqlBuilder.isNotIn("Fred", "Wilma");
540+
var filtered = cond.filter(s -> false);
541+
var mapped = filtered.map(s -> s);
542+
assertThat(mapped.isEmpty()).isTrue();
543+
assertThat(filtered).isSameAs(mapped);
544+
}
545+
546+
@Test
547+
void testIsInCaseInsensitiveWhenPresentMap() {
548+
var cond = SqlBuilder.isInCaseInsensitiveWhenPresent("Fred", "Wilma");
549+
var mapped = cond.map(s -> s + " Flintstone");
550+
assertThat(mapped.values().toList()).containsExactly("FRED Flintstone", "WILMA Flintstone");
551+
}
552+
553+
@Test
554+
void testIsInCaseInsensitiveWhenPresentMapCaseInsensitive() {
555+
var cond = SqlBuilder.isInCaseInsensitiveWhenPresent("Fred", "Wilma");
556+
var mapped = cond.map(StringUtilities.mapToUpperCase(s -> s + " Flintstone"));
557+
assertThat(mapped.values().toList()).containsExactly("FRED FLINTSTONE", "WILMA FLINTSTONE");
558+
}
559+
560+
@Test
561+
void testIsNotInCaseInsensitiveWhenPresentMap() {
562+
var cond = SqlBuilder.isNotInCaseInsensitiveWhenPresent("Fred", "Wilma");
563+
var mapped = cond.map(s -> s + " Flintstone");
564+
assertThat(mapped.values().toList()).containsExactly("FRED Flintstone", "WILMA Flintstone");
565+
}
566+
567+
@Test
568+
void testIsNotInCaseInsensitiveWhenPresentMapCaseInsensitive() {
569+
var cond = SqlBuilder.isNotInCaseInsensitiveWhenPresent("Fred", "Wilma");
570+
var mapped = cond.map(StringUtilities.mapToUpperCase(s -> s + " Flintstone"));
571+
assertThat(mapped.values().toList()).containsExactly("FRED FLINTSTONE", "WILMA FLINTSTONE");
572+
}
536573
}

0 commit comments

Comments
 (0)