From 52860cf8aae9da1890fd79312f3837ab0c3642a0 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 09:23:28 -0400 Subject: [PATCH 01/26] [Kotlin] Basic Infrastructure for Compiler Based Tests --- pom.xml | 6 ++ .../nullability/test/CompilerUtilities.kt | 70 +++++++++++++++++++ .../nullability/test/NullabilityTest.kt | 27 +++++++ 3 files changed, 103 insertions(+) create mode 100644 src/test/kotlin/nullability/test/CompilerUtilities.kt create mode 100644 src/test/kotlin/nullability/test/NullabilityTest.kt diff --git a/pom.xml b/pom.xml index 115294d7d..54741a889 100644 --- a/pom.xml +++ b/pom.xml @@ -230,6 +230,12 @@ true + + org.jetbrains.kotlin + kotlin-compiler + ${kotlin.version} + test + org.junit.jupiter junit-jupiter-api diff --git a/src/test/kotlin/nullability/test/CompilerUtilities.kt b/src/test/kotlin/nullability/test/CompilerUtilities.kt new file mode 100644 index 000000000..0c352a79a --- /dev/null +++ b/src/test/kotlin/nullability/test/CompilerUtilities.kt @@ -0,0 +1,70 @@ +package nullability.test + +import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation +import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler +import org.jetbrains.kotlin.config.Services +import java.io.File + +/** + * Compiles the source lines and looks for errors in the expected locations. + * Returns the number of errors that match the expected locations. + */ +fun compileIt(sourceLines: List, expectedErrorLocations: List): Int { + val file: File = File.createTempFile("KotlinTest", ".kt") + file.deleteOnExit() + + file.writeText(sourceLines.joinToString(separator = System.lineSeparator())) + + val compilerArgs = K2JVMCompilerArguments().apply { + freeArgs += file.path + classpath = System.getProperty("java.class.path") +// noStdlib = true +// noReflect = true + } + val errorCollector = CompilerErrorMessageCollector(expectedErrorLocations) + K2JVMCompiler().exec(errorCollector, Services.EMPTY, compilerArgs) + return errorCollector.matchingErrors() +} + +class CompilerErrorMessageCollector(private val expectedLocations: List): MessageCollector { + val errors = mutableListOf() + override fun clear() { + errors.clear() + } + + override fun hasErrors(): Boolean { + return errors.size > 0 + } + + fun matchingErrors(): Int = errors.filter { it.matchesExpected }.size + + override fun report( + severity: CompilerMessageSeverity, + message: String, + location: CompilerMessageSourceLocation? + ) { + if (severity.isError) { + errors.add(Report(severity, message, location, matchesExpected(location))) + } + } + + private fun matchesExpected(location: CompilerMessageSourceLocation?) : Boolean { + expectedLocations.forEach { + if (location?.line == it.line && location.column == it.column){ + return true + } + } + return false + } +} + +data class Report( + val severity: CompilerMessageSeverity, + val message: String, + val location: CompilerMessageSourceLocation?, + val matchesExpected: Boolean +) +data class ExpectedErrorLocation(val line: Int, val column: Int) diff --git a/src/test/kotlin/nullability/test/NullabilityTest.kt b/src/test/kotlin/nullability/test/NullabilityTest.kt new file mode 100644 index 000000000..1838d03b6 --- /dev/null +++ b/src/test/kotlin/nullability/test/NullabilityTest.kt @@ -0,0 +1,27 @@ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class NullabilityTest { + @Test + fun `Test That Null In Varargs In Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isIn + + fun testFunction() { + countFrom(person) { + where { id (isIn(4, 5, null)) } + } + } + """.trimIndent().lines() + + val matchingErrors = compileIt(sourceLines, listOf(ExpectedErrorLocation(10,32))) + assertThat(matchingErrors).isEqualTo(1) + } +} From 178f5ac6817f98a6136b23cca0daa1bfccba46bd Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 11:52:15 -0400 Subject: [PATCH 02/26] Refactor the compiler tests, write some failing tests for the between methods --- .../nullability/test/CompilerUtilities.kt | 62 +++++++-------- .../nullability/test/NullabilityTest.kt | 78 ++++++++++++++++++- 2 files changed, 107 insertions(+), 33 deletions(-) diff --git a/src/test/kotlin/nullability/test/CompilerUtilities.kt b/src/test/kotlin/nullability/test/CompilerUtilities.kt index 0c352a79a..d50d16459 100644 --- a/src/test/kotlin/nullability/test/CompilerUtilities.kt +++ b/src/test/kotlin/nullability/test/CompilerUtilities.kt @@ -9,37 +9,32 @@ import org.jetbrains.kotlin.config.Services import java.io.File /** - * Compiles the source lines and looks for errors in the expected locations. - * Returns the number of errors that match the expected locations. + * Compiles the source lines and returns any error reports generated by the compiler. */ -fun compileIt(sourceLines: List, expectedErrorLocations: List): Int { +fun compileIt(sourceLines: List): List { val file: File = File.createTempFile("KotlinTest", ".kt") file.deleteOnExit() - file.writeText(sourceLines.joinToString(separator = System.lineSeparator())) val compilerArgs = K2JVMCompilerArguments().apply { - freeArgs += file.path + freeArgs = listOf(file.path) + destination = System.getProperty("java.io.tmpdir") classpath = System.getProperty("java.class.path") -// noStdlib = true -// noReflect = true + noStdlib = true + useK2 = true } - val errorCollector = CompilerErrorMessageCollector(expectedErrorLocations) - K2JVMCompiler().exec(errorCollector, Services.EMPTY, compilerArgs) - return errorCollector.matchingErrors() -} -class CompilerErrorMessageCollector(private val expectedLocations: List): MessageCollector { - val errors = mutableListOf() - override fun clear() { - errors.clear() + return with(CompilerErrorMessageCollector()) { + K2JVMCompiler().exec(this, Services.EMPTY, compilerArgs) + this.errors } +} - override fun hasErrors(): Boolean { - return errors.size > 0 - } +class CompilerErrorMessageCollector: MessageCollector { + val errors = mutableListOf() + override fun clear() = errors.clear() - fun matchingErrors(): Int = errors.filter { it.matchesExpected }.size + override fun hasErrors() = errors.size > 0 override fun report( severity: CompilerMessageSeverity, @@ -47,24 +42,29 @@ class CompilerErrorMessageCollector(private val expectedLocations: List) = + expectedErrorLocations.firstOrNull { location.matchesExpected(it) } != null + +fun CompilerMessageSourceLocation?.matchesExpected(expectedErrorLocation: ExpectedErrorLocation) = + if (this == null) { + false + } else { + line == expectedErrorLocation.line && column == expectedErrorLocation.column } -} -data class Report( +fun List.matchCount(vararg expectedErrorLocations: ExpectedErrorLocation) = + this.filter { + it.matchesExpected(expectedErrorLocations) + }.size + +data class CompilerErrorReport( val severity: CompilerMessageSeverity, val message: String, - val location: CompilerMessageSourceLocation?, - val matchesExpected: Boolean + val location: CompilerMessageSourceLocation? ) data class ExpectedErrorLocation(val line: Int, val column: Int) diff --git a/src/test/kotlin/nullability/test/NullabilityTest.kt b/src/test/kotlin/nullability/test/NullabilityTest.kt index 1838d03b6..80ee02a4d 100644 --- a/src/test/kotlin/nullability/test/NullabilityTest.kt +++ b/src/test/kotlin/nullability/test/NullabilityTest.kt @@ -1,6 +1,7 @@ package nullability.test import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test class NullabilityTest { @@ -21,7 +22,80 @@ class NullabilityTest { } """.trimIndent().lines() - val matchingErrors = compileIt(sourceLines, listOf(ExpectedErrorLocation(10,32))) - assertThat(matchingErrors).isEqualTo(1) + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,32)) + assertThat(matchCount).isEqualTo(1) } + + @Test + fun `Test That First Null In Between Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isBetween null and 4 } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,30)) + assertThat(matchCount).isEqualTo(1) + } + + @Disabled + @Test + fun `Test That Second Null In Between Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isBetween 4 and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,36)) + assertThat(matchCount).isEqualTo(1) + } + + @Disabled + @Test + fun `Test That Both Null In Between Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isBetween null and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(2) + val matchCount = compilerErrorReports.matchCount( + ExpectedErrorLocation(9,30), + ExpectedErrorLocation(9, 39) + ) + assertThat(matchCount).isEqualTo(2) + } } From ffea8dcc492fd2d41137e64b7c0430bb5bb0d6c0 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 13:38:04 -0400 Subject: [PATCH 03/26] Tests for Between and BetweenWhenPresent Methods --- .../util/kotlin/GroupingCriteriaCollector.kt | 4 +- .../sql/util/kotlin/elements/SqlElements.kt | 4 +- .../{NullabilityTest.kt => BetweenTest.kt} | 84 +++++++++--- .../test/BetweenWhenPresentTest.kt | 129 ++++++++++++++++++ .../nullability/test/CompilerUtilities.kt | 1 - 5 files changed, 198 insertions(+), 24 deletions(-) rename src/test/kotlin/nullability/test/{NullabilityTest.kt => BetweenTest.kt} (58%) create mode 100644 src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt index 2ccd6d4e4..ef15b0705 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt @@ -341,8 +341,8 @@ class GroupingCriteriaCollector { infix fun BindableColumn.isNotInWhenPresent(values: Collection?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent(values)) - infix fun BindableColumn.isBetween(value1: T) = - SecondValueCollector { + infix fun BindableColumn.isBetween(value1: T & Any) = + SecondValueCollector { invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isBetween(value1).and(it)) } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt index 72e04a1bb..92d4e7b22 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt @@ -261,7 +261,7 @@ fun isNotInWhenPresent(vararg values: T?): IsNotIn = isNotInWhenPre fun isNotInWhenPresent(values: Collection?): IsNotIn = SqlBuilder.isNotInWhenPresent(values) -fun isBetween(value1: T): BetweenBuilder = BetweenBuilder(value1) +fun isBetween(value1: T & Any): BetweenBuilder = BetweenBuilder(value1) fun isBetweenWhenPresent(value1: T?): BetweenWhenPresentBuilder = BetweenWhenPresentBuilder(value1) @@ -339,7 +339,7 @@ fun sortColumn(tableAlias: String, column: SqlColumn<*>): SortSpecification = Sq // DSL Support Classes class BetweenBuilder(private val value1: T) { - fun and(value2: T): IsBetween = SqlBuilder.isBetween(value1).and(value2) + fun and(value2: T & Any): IsBetween = SqlBuilder.isBetween(value1).and(value2) } class BetweenWhenPresentBuilder(private val value1: T?) { diff --git a/src/test/kotlin/nullability/test/NullabilityTest.kt b/src/test/kotlin/nullability/test/BetweenTest.kt similarity index 58% rename from src/test/kotlin/nullability/test/NullabilityTest.kt rename to src/test/kotlin/nullability/test/BetweenTest.kt index 80ee02a4d..0884ad9c9 100644 --- a/src/test/kotlin/nullability/test/NullabilityTest.kt +++ b/src/test/kotlin/nullability/test/BetweenTest.kt @@ -1,35 +1,33 @@ package nullability.test import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -class NullabilityTest { +class BetweenTest { @Test - fun `Test That Null In Varargs In Method Causes Compile Error`() { + fun `Test That First Null Causes Compile Error`() { val sourceLines = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom - import org.mybatis.dynamic.sql.util.kotlin.elements.isIn fun testFunction() { countFrom(person) { - where { id (isIn(4, 5, null)) } + where { id isBetween null and 4 } } } """.trimIndent().lines() val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,32)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,30)) assertThat(matchCount).isEqualTo(1) - } + } @Test - fun `Test That First Null In Between Method Causes Compile Error`() { + fun `Test That Second Null Causes Compile Error`() { val sourceLines = """ package temp.kotlin.test @@ -39,20 +37,19 @@ class NullabilityTest { fun testFunction() { countFrom(person) { - where { id isBetween null and 4 } + where { id isBetween 4 and null } } } """.trimIndent().lines() val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,30)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,36)) assertThat(matchCount).isEqualTo(1) } - @Disabled @Test - fun `Test That Second Null In Between Method Causes Compile Error`() { + fun `Test That Both Null Causes Compile Errors`() { val sourceLines = """ package temp.kotlin.test @@ -62,30 +59,79 @@ class NullabilityTest { fun testFunction() { countFrom(person) { - where { id isBetween 4 and null } + where { id isBetween null and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(2) + val matchCount = compilerErrorReports.matchCount( + ExpectedErrorLocation(9,30), + ExpectedErrorLocation(9, 39) + ) + assertThat(matchCount).isEqualTo(2) + } + + @Test + fun `Test That First Null In Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isBetween + + fun testFunction() { + countFrom(person) { + where { id (isBetween(null).and(4)) } } } """.trimIndent().lines() val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,36)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,36)) assertThat(matchCount).isEqualTo(1) } - @Disabled @Test - fun `Test That Both Null In Between Method Causes Compile Error`() { + fun `Test That Second Null In Elements Method Causes Compile Error`() { val sourceLines = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isBetween fun testFunction() { countFrom(person) { - where { id isBetween null and null } + where { id (isBetween(4).and(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,38)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Both Null In Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isBetween + + fun testFunction() { + countFrom(person) { + where { id (isBetween(null).and(null)) } } } """.trimIndent().lines() @@ -93,8 +139,8 @@ class NullabilityTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( - ExpectedErrorLocation(9,30), - ExpectedErrorLocation(9, 39) + ExpectedErrorLocation(10,36), + ExpectedErrorLocation(10,46) ) assertThat(matchCount).isEqualTo(2) } diff --git a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt new file mode 100644 index 000000000..85cb24bd9 --- /dev/null +++ b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt @@ -0,0 +1,129 @@ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class BetweenWhenPresentTest { + @Test + fun `Test That First Null Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isBetweenWhenPresent null and 4 } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Second Null Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isBetweenWhenPresent 4 and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Both Null Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isBetweenWhenPresent null and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That First Null In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isBetweenWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isBetweenWhenPresent(null).and(4)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Second Null In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isBetweenWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isBetweenWhenPresent(4).and(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Both Null In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isBetweenWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isBetweenWhenPresent(null).and(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } +} diff --git a/src/test/kotlin/nullability/test/CompilerUtilities.kt b/src/test/kotlin/nullability/test/CompilerUtilities.kt index d50d16459..0cd2cf2ea 100644 --- a/src/test/kotlin/nullability/test/CompilerUtilities.kt +++ b/src/test/kotlin/nullability/test/CompilerUtilities.kt @@ -21,7 +21,6 @@ fun compileIt(sourceLines: List): List { destination = System.getProperty("java.io.tmpdir") classpath = System.getProperty("java.class.path") noStdlib = true - useK2 = true } return with(CompilerErrorMessageCollector()) { From a6bde0e10919c9840ddbd68475dfdba826c1f191 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 13:51:20 -0400 Subject: [PATCH 04/26] Tests for NotBetween and NotBetweenWhenPresent Methods --- .../util/kotlin/GroupingCriteriaCollector.kt | 8 +- .../sql/util/kotlin/elements/SqlElements.kt | 10 +- .../kotlin/nullability/test/NotBetweenTest.kt | 147 ++++++++++++++++++ .../test/NotBetweenWhenPresentTest.kt | 129 +++++++++++++++ 4 files changed, 285 insertions(+), 9 deletions(-) create mode 100644 src/test/kotlin/nullability/test/NotBetweenTest.kt create mode 100644 src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt index ef15b0705..53f7f779d 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt @@ -346,17 +346,17 @@ class GroupingCriteriaCollector { invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isBetween(value1).and(it)) } - infix fun BindableColumn.isBetweenWhenPresent(value1: T?) = + infix fun BindableColumn.isBetweenWhenPresent(value1: T?) = NullableSecondValueCollector { invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isBetweenWhenPresent(value1).and(it)) } - infix fun BindableColumn.isNotBetween(value1: T) = - SecondValueCollector { + infix fun BindableColumn.isNotBetween(value1: T & Any) = + SecondValueCollector { invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetween(value1).and(it)) } - infix fun BindableColumn.isNotBetweenWhenPresent(value1: T?) = + infix fun BindableColumn.isNotBetweenWhenPresent(value1: T?) = NullableSecondValueCollector { invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetweenWhenPresent(value1).and(it)) } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt index 92d4e7b22..2b01a724c 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt @@ -261,13 +261,13 @@ fun isNotInWhenPresent(vararg values: T?): IsNotIn = isNotInWhenPre fun isNotInWhenPresent(values: Collection?): IsNotIn = SqlBuilder.isNotInWhenPresent(values) -fun isBetween(value1: T & Any): BetweenBuilder = BetweenBuilder(value1) +fun isBetween(value1: T & Any): BetweenBuilder = BetweenBuilder(value1) -fun isBetweenWhenPresent(value1: T?): BetweenWhenPresentBuilder = BetweenWhenPresentBuilder(value1) +fun isBetweenWhenPresent(value1: T?): BetweenWhenPresentBuilder = BetweenWhenPresentBuilder(value1) -fun isNotBetween(value1: T): NotBetweenBuilder = NotBetweenBuilder(value1) +fun isNotBetween(value1: T & Any): NotBetweenBuilder = NotBetweenBuilder(value1) -fun isNotBetweenWhenPresent(value1: T?): NotBetweenWhenPresentBuilder = +fun isNotBetweenWhenPresent(value1: T?): NotBetweenWhenPresentBuilder = NotBetweenWhenPresentBuilder(value1) // for string columns, but generic for columns with type handlers @@ -339,7 +339,7 @@ fun sortColumn(tableAlias: String, column: SqlColumn<*>): SortSpecification = Sq // DSL Support Classes class BetweenBuilder(private val value1: T) { - fun and(value2: T & Any): IsBetween = SqlBuilder.isBetween(value1).and(value2) + fun and(value2: T): IsBetween = SqlBuilder.isBetween(value1).and(value2) } class BetweenWhenPresentBuilder(private val value1: T?) { diff --git a/src/test/kotlin/nullability/test/NotBetweenTest.kt b/src/test/kotlin/nullability/test/NotBetweenTest.kt new file mode 100644 index 000000000..9cc83b381 --- /dev/null +++ b/src/test/kotlin/nullability/test/NotBetweenTest.kt @@ -0,0 +1,147 @@ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class NotBetweenTest { + @Test + fun `Test That First Null Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isNotBetween null and 4 } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,33)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Second Null Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isNotBetween 4 and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,39)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Both Null Causes Compile Errors`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isNotBetween null and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(2) + val matchCount = compilerErrorReports.matchCount( + ExpectedErrorLocation(9,33), + ExpectedErrorLocation(9, 42) + ) + assertThat(matchCount).isEqualTo(2) + } + + @Test + fun `Test That First Null In Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetween + + fun testFunction() { + countFrom(person) { + where { id (isNotBetween(null).and(4)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,39)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Second Null In Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetween + + fun testFunction() { + countFrom(person) { + where { id (isNotBetween(4).and(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,41)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Both Null In Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetween + + fun testFunction() { + countFrom(person) { + where { id (isNotBetween(null).and(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(2) + val matchCount = compilerErrorReports.matchCount( + ExpectedErrorLocation(10,39), + ExpectedErrorLocation(10,49) + ) + assertThat(matchCount).isEqualTo(2) + } +} diff --git a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt new file mode 100644 index 000000000..7de3e36b5 --- /dev/null +++ b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt @@ -0,0 +1,129 @@ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class NotBetweenWhenPresentTest { + @Test + fun `Test That First Null Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isNotBetweenWhenPresent null and 4 } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Second Null Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isNotBetweenWhenPresent 4 and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Both Null Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isNotBetweenWhenPresent null and null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That First Null In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetweenWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isNotBetweenWhenPresent(null).and(4)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Second Null In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetweenWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isNotBetweenWhenPresent(4).and(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Both Null In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotBetweenWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isNotBetweenWhenPresent(null).and(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } +} From 36859769d9af4b0d2a8b4a59ad4427b8bcf33bea Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 14:06:58 -0400 Subject: [PATCH 05/26] Copyrights --- .../kotlin/nullability/test/BetweenTest.kt | 29 ++++++++++++++----- .../test/BetweenWhenPresentTest.kt | 15 ++++++++++ .../nullability/test/CompilerUtilities.kt | 15 ++++++++++ .../kotlin/nullability/test/NotBetweenTest.kt | 29 ++++++++++++++----- .../test/NotBetweenWhenPresentTest.kt | 15 ++++++++++ 5 files changed, 89 insertions(+), 14 deletions(-) diff --git a/src/test/kotlin/nullability/test/BetweenTest.kt b/src/test/kotlin/nullability/test/BetweenTest.kt index 0884ad9c9..82de8b739 100644 --- a/src/test/kotlin/nullability/test/BetweenTest.kt +++ b/src/test/kotlin/nullability/test/BetweenTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package nullability.test import org.assertj.core.api.Assertions.assertThat @@ -22,7 +37,7 @@ class BetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,30)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 30)) assertThat(matchCount).isEqualTo(1) } @@ -44,7 +59,7 @@ class BetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,36)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 36)) assertThat(matchCount).isEqualTo(1) } @@ -67,7 +82,7 @@ class BetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( - ExpectedErrorLocation(9,30), + ExpectedErrorLocation(9, 30), ExpectedErrorLocation(9, 39) ) assertThat(matchCount).isEqualTo(2) @@ -92,7 +107,7 @@ class BetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,36)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 36)) assertThat(matchCount).isEqualTo(1) } @@ -115,7 +130,7 @@ class BetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,38)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 38)) assertThat(matchCount).isEqualTo(1) } @@ -139,8 +154,8 @@ class BetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( - ExpectedErrorLocation(10,36), - ExpectedErrorLocation(10,46) + ExpectedErrorLocation(10, 36), + ExpectedErrorLocation(10, 46) ) assertThat(matchCount).isEqualTo(2) } diff --git a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt index 85cb24bd9..7a9c9c53a 100644 --- a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package nullability.test import org.assertj.core.api.Assertions.assertThat diff --git a/src/test/kotlin/nullability/test/CompilerUtilities.kt b/src/test/kotlin/nullability/test/CompilerUtilities.kt index 0cd2cf2ea..7a42a2bc3 100644 --- a/src/test/kotlin/nullability/test/CompilerUtilities.kt +++ b/src/test/kotlin/nullability/test/CompilerUtilities.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package nullability.test import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments diff --git a/src/test/kotlin/nullability/test/NotBetweenTest.kt b/src/test/kotlin/nullability/test/NotBetweenTest.kt index 9cc83b381..3000b870f 100644 --- a/src/test/kotlin/nullability/test/NotBetweenTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package nullability.test import org.assertj.core.api.Assertions.assertThat @@ -22,7 +37,7 @@ class NotBetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,33)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 33)) assertThat(matchCount).isEqualTo(1) } @@ -44,7 +59,7 @@ class NotBetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9,39)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 39)) assertThat(matchCount).isEqualTo(1) } @@ -67,7 +82,7 @@ class NotBetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( - ExpectedErrorLocation(9,33), + ExpectedErrorLocation(9, 33), ExpectedErrorLocation(9, 42) ) assertThat(matchCount).isEqualTo(2) @@ -92,7 +107,7 @@ class NotBetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,39)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 39)) assertThat(matchCount).isEqualTo(1) } @@ -115,7 +130,7 @@ class NotBetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10,41)) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 41)) assertThat(matchCount).isEqualTo(1) } @@ -139,8 +154,8 @@ class NotBetweenTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( - ExpectedErrorLocation(10,39), - ExpectedErrorLocation(10,49) + ExpectedErrorLocation(10, 39), + ExpectedErrorLocation(10, 49) ) assertThat(matchCount).isEqualTo(2) } diff --git a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt index 7de3e36b5..8c17f2839 100644 --- a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package nullability.test import org.assertj.core.api.Assertions.assertThat From 472a0cc8f42a83aa0bff896ed87e4bf7a4d66259 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 14:59:31 -0400 Subject: [PATCH 06/26] Nullability tests for In and InWhenPresent --- .../util/kotlin/GroupingCriteriaCollector.kt | 8 +- .../sql/util/kotlin/elements/SqlElements.kt | 8 +- src/test/kotlin/nullability/test/InTest.kt | 113 +++++++++++ .../nullability/test/InWhenPresentTest.kt | 190 ++++++++++++++++++ 4 files changed, 311 insertions(+), 8 deletions(-) create mode 100644 src/test/kotlin/nullability/test/InTest.kt create mode 100644 src/test/kotlin/nullability/test/InWhenPresentTest.kt diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt index 53f7f779d..9556bb0df 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt @@ -315,17 +315,17 @@ class GroupingCriteriaCollector { infix fun BindableColumn.isLessThanOrEqualToWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualToWhenPresent(value)) - fun BindableColumn.isIn(vararg values: T) = isIn(values.asList()) + fun BindableColumn.isIn(vararg values: T & Any) = isIn(values.asList()) - infix fun BindableColumn.isIn(values: Collection) = + infix fun BindableColumn.isIn(values: Collection) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isIn(values)) infix fun BindableColumn<*>.isIn(subQuery: KotlinSubQueryBuilder.() -> Unit) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isIn(subQuery)) - fun BindableColumn.isInWhenPresent(vararg values: T?) = isInWhenPresent(values.asList()) + fun BindableColumn.isInWhenPresent(vararg values: T?) = isInWhenPresent(values.asList()) - infix fun BindableColumn.isInWhenPresent(values: Collection?) = + infix fun BindableColumn.isInWhenPresent(values: Collection?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent(values)) fun BindableColumn.isNotIn(vararg values: T) = isNotIn(values.asList()) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt index 2b01a724c..54fbdf993 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt @@ -239,16 +239,16 @@ fun isLessThanOrEqualTo(column: BasicColumn): IsLessThanOrEqualToColumn = fun isLessThanOrEqualToWhenPresent(value: T?): IsLessThanOrEqualTo = SqlBuilder.isLessThanOrEqualToWhenPresent(value) -fun isIn(vararg values: T): IsIn = isIn(values.asList()) +fun isIn(vararg values: T & Any): IsIn = isIn(values.asList()) -fun isIn(values: Collection): IsIn = SqlBuilder.isIn(values) +fun isIn(values: Collection): IsIn = SqlBuilder.isIn(values) fun isIn(subQuery: KotlinSubQueryBuilder.() -> Unit): IsInWithSubselect = SqlBuilder.isIn(KotlinSubQueryBuilder().apply(subQuery)) -fun isInWhenPresent(vararg values: T?): IsIn = isInWhenPresent(values.asList()) +fun isInWhenPresent(vararg values: T?): IsIn = isInWhenPresent(values.asList()) -fun isInWhenPresent(values: Collection?): IsIn = SqlBuilder.isInWhenPresent(values) +fun isInWhenPresent(values: Collection?): IsIn = SqlBuilder.isInWhenPresent(values) fun isNotIn(vararg values: T): IsNotIn = isNotIn(values.asList()) diff --git a/src/test/kotlin/nullability/test/InTest.kt b/src/test/kotlin/nullability/test/InTest.kt new file mode 100644 index 000000000..be3167381 --- /dev/null +++ b/src/test/kotlin/nullability/test/InTest.kt @@ -0,0 +1,113 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class InTest { + @Test + fun `Test That Null In VarAgs Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id.isIn(4, null) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 28)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null in List Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { id isIn ids } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 25)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null In VarArgs Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isIn + + fun testFunction() { + countFrom(person) { + where { id (isIn(4, null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 29)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null In List Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isIn + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { id (isIn(ids)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 26)) + assertThat(matchCount).isEqualTo(1) + } +} diff --git a/src/test/kotlin/nullability/test/InWhenPresentTest.kt b/src/test/kotlin/nullability/test/InWhenPresentTest.kt new file mode 100644 index 000000000..1fdb6fe4a --- /dev/null +++ b/src/test/kotlin/nullability/test/InWhenPresentTest.kt @@ -0,0 +1,190 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class InWhenPresentTest { + @Test + fun `Test That Null In VarAgs Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id.isInWhenPresent(4, null) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null in List Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { id isInWhenPresent ids } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Empty VarAgs Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id.isInWhenPresent() } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null List Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + val ids: List? = null + countFrom(person) { + where { id isInWhenPresent ids } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null In VarArgs Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isInWhenPresent(4, null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null In List Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { id (isInWhenPresent(ids)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Empty VarAgs In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isInWhenPresent()) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null List In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent + + fun testFunction() { + val ids: List? = null + countFrom(person) { + where { id (isInWhenPresent(ids)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + +} From 4981bb17d7f66778a5dab98ca87a7165d75d6402 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 15:34:07 -0400 Subject: [PATCH 07/26] Nullability tests for NotIn and NotInWhenPresent --- .../util/kotlin/GroupingCriteriaCollector.kt | 8 +- .../sql/util/kotlin/elements/SqlElements.kt | 8 +- .../nullability/test/InWhenPresentTest.kt | 7 +- src/test/kotlin/nullability/test/NotInTest.kt | 113 +++++++++++ .../nullability/test/NotInWhenPresentTest.kt | 187 ++++++++++++++++++ 5 files changed, 310 insertions(+), 13 deletions(-) create mode 100644 src/test/kotlin/nullability/test/NotInTest.kt create mode 100644 src/test/kotlin/nullability/test/NotInWhenPresentTest.kt diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt index 9556bb0df..7f7c0d696 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt @@ -328,17 +328,17 @@ class GroupingCriteriaCollector { infix fun BindableColumn.isInWhenPresent(values: Collection?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent(values)) - fun BindableColumn.isNotIn(vararg values: T) = isNotIn(values.asList()) + fun BindableColumn.isNotIn(vararg values: T & Any) = isNotIn(values.asList()) - infix fun BindableColumn.isNotIn(values: Collection) = + infix fun BindableColumn.isNotIn(values: Collection) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotIn(values)) infix fun BindableColumn<*>.isNotIn(subQuery: KotlinSubQueryBuilder.() -> Unit) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotIn(subQuery)) - fun BindableColumn.isNotInWhenPresent(vararg values: T?) = isNotInWhenPresent(values.asList()) + fun BindableColumn.isNotInWhenPresent(vararg values: T?) = isNotInWhenPresent(values.asList()) - infix fun BindableColumn.isNotInWhenPresent(values: Collection?) = + infix fun BindableColumn.isNotInWhenPresent(values: Collection?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent(values)) infix fun BindableColumn.isBetween(value1: T & Any) = diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt index 54fbdf993..4d25ef711 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt @@ -250,16 +250,16 @@ fun isInWhenPresent(vararg values: T?): IsIn = isInWhenPresent(values.asL fun isInWhenPresent(values: Collection?): IsIn = SqlBuilder.isInWhenPresent(values) -fun isNotIn(vararg values: T): IsNotIn = isNotIn(values.asList()) +fun isNotIn(vararg values: T & Any): IsNotIn = isNotIn(values.asList()) -fun isNotIn(values: Collection): IsNotIn = SqlBuilder.isNotIn(values) +fun isNotIn(values: Collection): IsNotIn = SqlBuilder.isNotIn(values) fun isNotIn(subQuery: KotlinSubQueryBuilder.() -> Unit): IsNotInWithSubselect = SqlBuilder.isNotIn(KotlinSubQueryBuilder().apply(subQuery)) -fun isNotInWhenPresent(vararg values: T?): IsNotIn = isNotInWhenPresent(values.asList()) +fun isNotInWhenPresent(vararg values: T?): IsNotIn = isNotInWhenPresent(values.asList()) -fun isNotInWhenPresent(values: Collection?): IsNotIn = SqlBuilder.isNotInWhenPresent(values) +fun isNotInWhenPresent(values: Collection?): IsNotIn = SqlBuilder.isNotInWhenPresent(values) fun isBetween(value1: T & Any): BetweenBuilder = BetweenBuilder(value1) diff --git a/src/test/kotlin/nullability/test/InWhenPresentTest.kt b/src/test/kotlin/nullability/test/InWhenPresentTest.kt index 1fdb6fe4a..c29d87af8 100644 --- a/src/test/kotlin/nullability/test/InWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/InWhenPresentTest.kt @@ -90,9 +90,8 @@ class InWhenPresentTest { import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom fun testFunction() { - val ids: List? = null countFrom(person) { - where { id isInWhenPresent ids } + where { id.isInWhenPresent(null as List) } } } """.trimIndent().lines() @@ -176,9 +175,8 @@ class InWhenPresentTest { import org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent fun testFunction() { - val ids: List? = null countFrom(person) { - where { id (isInWhenPresent(ids)) } + where { id (isInWhenPresent(null)) } } } """.trimIndent().lines() @@ -186,5 +184,4 @@ class InWhenPresentTest { val compilerErrorReports = compileIt(sourceLines) assertThat(compilerErrorReports).isEmpty() } - } diff --git a/src/test/kotlin/nullability/test/NotInTest.kt b/src/test/kotlin/nullability/test/NotInTest.kt new file mode 100644 index 000000000..9b0df07c2 --- /dev/null +++ b/src/test/kotlin/nullability/test/NotInTest.kt @@ -0,0 +1,113 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class NotInTest { + @Test + fun `Test That Null In VarAgs Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id.isNotIn(4, null) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 31)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null in List Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { id isNotIn ids } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 28)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null In VarArgs Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotIn + + fun testFunction() { + countFrom(person) { + where { id (isNotIn(4, null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 32)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null In List Elements Method Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotIn + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { id (isNotIn(ids)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 29)) + assertThat(matchCount).isEqualTo(1) + } +} diff --git a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt new file mode 100644 index 000000000..0989d594b --- /dev/null +++ b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt @@ -0,0 +1,187 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class NotInWhenPresentTest { + @Test + fun `Test That Null In VarAgs Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id.isNotInWhenPresent(4, null) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null in List Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { id isNotInWhenPresent ids } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Empty VarAgs Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id.isNotInWhenPresent() } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null List Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id.isNotInWhenPresent(null as List) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null In VarArgs Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isNotInWhenPresent(4, null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null In List Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { id (isNotInWhenPresent(ids)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Empty VarAgs In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isNotInWhenPresent()) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null List In Elements Method Is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isNotInWhenPresent(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } +} From 57845dc2bccd39a79bcc90b615b316d7f105ad5d Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 17:12:32 -0400 Subject: [PATCH 08/26] Nullability tests for Like and NotLike --- src/test/kotlin/nullability/test/LikeTest.kt | 195 +++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/test/kotlin/nullability/test/LikeTest.kt diff --git a/src/test/kotlin/nullability/test/LikeTest.kt b/src/test/kotlin/nullability/test/LikeTest.kt new file mode 100644 index 000000000..bbda046c5 --- /dev/null +++ b/src/test/kotlin/nullability/test/LikeTest.kt @@ -0,0 +1,195 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class LikeTest { + @Test + fun `Test That Null Like Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { firstName isLike null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 34)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null Like When Present is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { firstName isLikeWhenPresent null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null Not Like Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { firstName isNotLike null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 37)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null Not Like When Present is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { firstName isNotLikeWhenPresent null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null Elements Like Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isLike + + fun testFunction() { + countFrom(person) { + where { firstName (isLike(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 35)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null Elements Like When Present is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isLikeWhenPresent + + fun testFunction() { + countFrom(person) { + where { firstName (isLikeWhenPresent(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null Elements Not Like Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotLike + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { firstName (isNotLike(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 38)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null Elements Not Like When Present is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotLikeWhenPresent + + fun testFunction() { + countFrom(person) { + where { firstName (isNotLikeWhenPresent(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } +} From 18a9e510e34de247e85c73d5a11461a514006841 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 17:12:44 -0400 Subject: [PATCH 09/26] Nullability tests for Like and NotLike --- .../dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt | 8 ++++---- .../dynamic/sql/util/kotlin/elements/SqlElements.kt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt index 7f7c0d696..a93781dc5 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt @@ -362,16 +362,16 @@ class GroupingCriteriaCollector { } // for string columns, but generic for columns with type handlers - infix fun BindableColumn.isLike(value: T) = + infix fun BindableColumn.isLike(value: T & Any) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLike(value)) - infix fun BindableColumn.isLikeWhenPresent(value: T?) = + infix fun BindableColumn.isLikeWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLikeWhenPresent(value)) - infix fun BindableColumn.isNotLike(value: T) = + infix fun BindableColumn.isNotLike(value: T & Any) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotLike(value)) - infix fun BindableColumn.isNotLikeWhenPresent(value: T?) = + infix fun BindableColumn.isNotLikeWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotLikeWhenPresent(value)) // shortcuts for booleans diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt index 4d25ef711..8b610a430 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt @@ -271,13 +271,13 @@ fun isNotBetweenWhenPresent(value1: T?): NotBetweenWhenPresentBuilder = NotBetweenWhenPresentBuilder(value1) // for string columns, but generic for columns with type handlers -fun isLike(value: T): IsLike = SqlBuilder.isLike(value) +fun isLike(value: T & Any): IsLike = SqlBuilder.isLike(value) -fun isLikeWhenPresent(value: T?): IsLike = SqlBuilder.isLikeWhenPresent(value) +fun isLikeWhenPresent(value: T?): IsLike = SqlBuilder.isLikeWhenPresent(value) -fun isNotLike(value: T): IsNotLike = SqlBuilder.isNotLike(value) +fun isNotLike(value: T & Any): IsNotLike = SqlBuilder.isNotLike(value) -fun isNotLikeWhenPresent(value: T?): IsNotLike = SqlBuilder.isNotLikeWhenPresent(value) +fun isNotLikeWhenPresent(value: T?): IsNotLike = SqlBuilder.isNotLikeWhenPresent(value) // shortcuts for booleans fun isTrue(): IsEqualTo = isEqualTo(true) From 445c339312103b202622c767c7b57b68337eb236 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 13 Jun 2022 18:11:27 -0400 Subject: [PATCH 10/26] Nullability tests for Equal and NotEqual --- .../util/kotlin/GroupingCriteriaCollector.kt | 8 +- .../sql/util/kotlin/elements/SqlElements.kt | 8 +- .../nullability/test/EqualNotEqualTest.kt | 195 ++++++++++++++++++ .../test/{LikeTest.kt => LikeNotLikeTest.kt} | 2 +- 4 files changed, 204 insertions(+), 9 deletions(-) create mode 100644 src/test/kotlin/nullability/test/EqualNotEqualTest.kt rename src/test/kotlin/nullability/test/{LikeTest.kt => LikeNotLikeTest.kt} (99%) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt index a93781dc5..6687f56e3 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt @@ -243,7 +243,7 @@ class GroupingCriteriaCollector { fun BindableColumn<*>.isNotNull() = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotNull()) - infix fun BindableColumn.isEqualTo(value: T) = + infix fun BindableColumn.isEqualTo(value: T & Any) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo(value)) infix fun BindableColumn<*>.isEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit) = @@ -252,10 +252,10 @@ class GroupingCriteriaCollector { infix fun BindableColumn<*>.isEqualTo(column: BasicColumn) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo(column)) - infix fun BindableColumn.isEqualToWhenPresent(value: T?) = + infix fun BindableColumn.isEqualToWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isEqualToWhenPresent(value)) - infix fun BindableColumn.isNotEqualTo(value: T) = + infix fun BindableColumn.isNotEqualTo(value: T & Any) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualTo(value)) infix fun BindableColumn<*>.isNotEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit) = @@ -264,7 +264,7 @@ class GroupingCriteriaCollector { infix fun BindableColumn<*>.isNotEqualTo(column: BasicColumn) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualTo(column)) - infix fun BindableColumn.isNotEqualToWhenPresent(value: T?) = + infix fun BindableColumn.isNotEqualToWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualToWhenPresent(value)) infix fun BindableColumn.isGreaterThan(value: T) = diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt index 8b610a430..60dd689e2 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt @@ -182,23 +182,23 @@ fun exists(subQuery: KotlinSubQueryBuilder.() -> Unit): ExistsPredicate = fun notExists(subQuery: KotlinSubQueryBuilder.() -> Unit): ExistsPredicate = SqlBuilder.notExists(KotlinSubQueryBuilder().apply(subQuery)) -fun isEqualTo(value: T): IsEqualTo = SqlBuilder.isEqualTo(value) +fun isEqualTo(value: T & Any): IsEqualTo = SqlBuilder.isEqualTo(value) fun isEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit): IsEqualToWithSubselect = SqlBuilder.isEqualTo(KotlinSubQueryBuilder().apply(subQuery)) fun isEqualTo(column: BasicColumn): IsEqualToColumn = SqlBuilder.isEqualTo(column) -fun isEqualToWhenPresent(value: T?): IsEqualTo = SqlBuilder.isEqualToWhenPresent(value) +fun isEqualToWhenPresent(value: T?): IsEqualTo = SqlBuilder.isEqualToWhenPresent(value) -fun isNotEqualTo(value: T): IsNotEqualTo = SqlBuilder.isNotEqualTo(value) +fun isNotEqualTo(value: T & Any): IsNotEqualTo = SqlBuilder.isNotEqualTo(value) fun isNotEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit): IsNotEqualToWithSubselect = SqlBuilder.isNotEqualTo(KotlinSubQueryBuilder().apply(subQuery)) fun isNotEqualTo(column: BasicColumn): IsNotEqualToColumn = SqlBuilder.isNotEqualTo(column) -fun isNotEqualToWhenPresent(value: T?): IsNotEqualTo = SqlBuilder.isNotEqualToWhenPresent(value) +fun isNotEqualToWhenPresent(value: T?): IsNotEqualTo = SqlBuilder.isNotEqualToWhenPresent(value) fun isGreaterThan(value: T): IsGreaterThan = SqlBuilder.isGreaterThan(value) diff --git a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt new file mode 100644 index 000000000..3d566e0fa --- /dev/null +++ b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt @@ -0,0 +1,195 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class EqualNotEqualTest { + @Test + fun `Test That Null Equal Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { firstName isEqualTo null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 37)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null Equal When Present is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { firstName isEqualToWhenPresent null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null Not Equal Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { firstName isNotEqualTo null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 40)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null Not Equal When Present is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { firstName isNotEqualToWhenPresent null } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null Elements Equal Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo + + fun testFunction() { + countFrom(person) { + where { firstName (isEqualTo(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 38)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null Elements Equal When Present is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isEqualToWhenPresent + + fun testFunction() { + countFrom(person) { + where { firstName (isEqualToWhenPresent(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } + + @Test + fun `Test That Null Elements Not Equal Causes Compile Error`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualTo + + fun testFunction() { + val ids = listOf(4, null) + countFrom(person) { + where { firstName (isNotEqualTo(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).hasSize(1) + val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 41)) + assertThat(matchCount).isEqualTo(1) + } + + @Test + fun `Test That Null Elements Not Equal When Present is OK`() { + val sourceLines = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualToWhenPresent + + fun testFunction() { + countFrom(person) { + where { firstName (isNotEqualToWhenPresent(null)) } + } + } + """.trimIndent().lines() + + val compilerErrorReports = compileIt(sourceLines) + assertThat(compilerErrorReports).isEmpty() + } +} diff --git a/src/test/kotlin/nullability/test/LikeTest.kt b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt similarity index 99% rename from src/test/kotlin/nullability/test/LikeTest.kt rename to src/test/kotlin/nullability/test/LikeNotLikeTest.kt index bbda046c5..b8742b4af 100644 --- a/src/test/kotlin/nullability/test/LikeTest.kt +++ b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt @@ -18,7 +18,7 @@ package nullability.test import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -class LikeTest { +class LikeNotLikeTest { @Test fun `Test That Null Like Causes Compile Error`() { val sourceLines = """ From 112d558609189b05d6ffaee0a0ee1c40af0be42f Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Tue, 14 Jun 2022 16:16:17 -0400 Subject: [PATCH 11/26] Better Method Name --- src/test/kotlin/nullability/test/BetweenTest.kt | 12 ++++++------ .../nullability/test/BetweenWhenPresentTest.kt | 12 ++++++------ .../kotlin/nullability/test/CompilerUtilities.kt | 2 +- .../kotlin/nullability/test/EqualNotEqualTest.kt | 16 ++++++++-------- src/test/kotlin/nullability/test/InTest.kt | 8 ++++---- .../kotlin/nullability/test/InWhenPresentTest.kt | 16 ++++++++-------- .../kotlin/nullability/test/LikeNotLikeTest.kt | 16 ++++++++-------- .../kotlin/nullability/test/NotBetweenTest.kt | 12 ++++++------ .../test/NotBetweenWhenPresentTest.kt | 12 ++++++------ src/test/kotlin/nullability/test/NotInTest.kt | 8 ++++---- .../nullability/test/NotInWhenPresentTest.kt | 16 ++++++++-------- 11 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/test/kotlin/nullability/test/BetweenTest.kt b/src/test/kotlin/nullability/test/BetweenTest.kt index 82de8b739..d47e4b250 100644 --- a/src/test/kotlin/nullability/test/BetweenTest.kt +++ b/src/test/kotlin/nullability/test/BetweenTest.kt @@ -35,7 +35,7 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 30)) assertThat(matchCount).isEqualTo(1) @@ -57,7 +57,7 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 36)) assertThat(matchCount).isEqualTo(1) @@ -79,7 +79,7 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( ExpectedErrorLocation(9, 30), @@ -105,7 +105,7 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 36)) assertThat(matchCount).isEqualTo(1) @@ -128,7 +128,7 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 38)) assertThat(matchCount).isEqualTo(1) @@ -151,7 +151,7 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( ExpectedErrorLocation(10, 36), diff --git a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt index 7a9c9c53a..a03cde2c9 100644 --- a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt @@ -35,7 +35,7 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -55,7 +55,7 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -75,7 +75,7 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -96,7 +96,7 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -117,7 +117,7 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -138,7 +138,7 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/CompilerUtilities.kt b/src/test/kotlin/nullability/test/CompilerUtilities.kt index 7a42a2bc3..630151e4c 100644 --- a/src/test/kotlin/nullability/test/CompilerUtilities.kt +++ b/src/test/kotlin/nullability/test/CompilerUtilities.kt @@ -26,7 +26,7 @@ import java.io.File /** * Compiles the source lines and returns any error reports generated by the compiler. */ -fun compileIt(sourceLines: List): List { +fun compile(sourceLines: List): List { val file: File = File.createTempFile("KotlinTest", ".kt") file.deleteOnExit() file.writeText(sourceLines.joinToString(separator = System.lineSeparator())) diff --git a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt index 3d566e0fa..26dcf0c4b 100644 --- a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt +++ b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt @@ -35,7 +35,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 37)) assertThat(matchCount).isEqualTo(1) @@ -57,7 +57,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -78,7 +78,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 40)) assertThat(matchCount).isEqualTo(1) @@ -100,7 +100,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -121,7 +121,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 38)) assertThat(matchCount).isEqualTo(1) @@ -144,7 +144,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -166,7 +166,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 41)) assertThat(matchCount).isEqualTo(1) @@ -189,7 +189,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/InTest.kt b/src/test/kotlin/nullability/test/InTest.kt index be3167381..370cd5c34 100644 --- a/src/test/kotlin/nullability/test/InTest.kt +++ b/src/test/kotlin/nullability/test/InTest.kt @@ -35,7 +35,7 @@ class InTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 28)) assertThat(matchCount).isEqualTo(1) @@ -58,7 +58,7 @@ class InTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 25)) assertThat(matchCount).isEqualTo(1) @@ -81,7 +81,7 @@ class InTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 29)) assertThat(matchCount).isEqualTo(1) @@ -105,7 +105,7 @@ class InTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 26)) assertThat(matchCount).isEqualTo(1) diff --git a/src/test/kotlin/nullability/test/InWhenPresentTest.kt b/src/test/kotlin/nullability/test/InWhenPresentTest.kt index c29d87af8..9d42931d4 100644 --- a/src/test/kotlin/nullability/test/InWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/InWhenPresentTest.kt @@ -35,7 +35,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -56,7 +56,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -76,7 +76,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -96,7 +96,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -117,7 +117,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -139,7 +139,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -160,7 +160,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -181,7 +181,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/LikeNotLikeTest.kt b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt index b8742b4af..62d6ea859 100644 --- a/src/test/kotlin/nullability/test/LikeNotLikeTest.kt +++ b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt @@ -35,7 +35,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 34)) assertThat(matchCount).isEqualTo(1) @@ -57,7 +57,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -78,7 +78,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 37)) assertThat(matchCount).isEqualTo(1) @@ -100,7 +100,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -121,7 +121,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 35)) assertThat(matchCount).isEqualTo(1) @@ -144,7 +144,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -166,7 +166,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 38)) assertThat(matchCount).isEqualTo(1) @@ -189,7 +189,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/NotBetweenTest.kt b/src/test/kotlin/nullability/test/NotBetweenTest.kt index 3000b870f..f75ba3fc3 100644 --- a/src/test/kotlin/nullability/test/NotBetweenTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenTest.kt @@ -35,7 +35,7 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 33)) assertThat(matchCount).isEqualTo(1) @@ -57,7 +57,7 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 39)) assertThat(matchCount).isEqualTo(1) @@ -79,7 +79,7 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( ExpectedErrorLocation(9, 33), @@ -105,7 +105,7 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 39)) assertThat(matchCount).isEqualTo(1) @@ -128,7 +128,7 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 41)) assertThat(matchCount).isEqualTo(1) @@ -151,7 +151,7 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(2) val matchCount = compilerErrorReports.matchCount( ExpectedErrorLocation(10, 39), diff --git a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt index 8c17f2839..84a3a5ffd 100644 --- a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt @@ -35,7 +35,7 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -55,7 +55,7 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -75,7 +75,7 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -96,7 +96,7 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -117,7 +117,7 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -138,7 +138,7 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/NotInTest.kt b/src/test/kotlin/nullability/test/NotInTest.kt index 9b0df07c2..14b971529 100644 --- a/src/test/kotlin/nullability/test/NotInTest.kt +++ b/src/test/kotlin/nullability/test/NotInTest.kt @@ -35,7 +35,7 @@ class NotInTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 31)) assertThat(matchCount).isEqualTo(1) @@ -58,7 +58,7 @@ class NotInTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 28)) assertThat(matchCount).isEqualTo(1) @@ -81,7 +81,7 @@ class NotInTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 32)) assertThat(matchCount).isEqualTo(1) @@ -105,7 +105,7 @@ class NotInTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).hasSize(1) val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 29)) assertThat(matchCount).isEqualTo(1) diff --git a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt index 0989d594b..2fa489a9c 100644 --- a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt @@ -35,7 +35,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -56,7 +56,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -76,7 +76,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -96,7 +96,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -117,7 +117,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -139,7 +139,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -160,7 +160,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } @@ -181,7 +181,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compileIt(sourceLines) + val compilerErrorReports = compile(sourceLines) assertThat(compilerErrorReports).isEmpty() } } From a6a75292e572ff26844d547c30564583f18f0358 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Tue, 14 Jun 2022 17:34:02 -0400 Subject: [PATCH 12/26] Refactor and simplify tests --- .../kotlin/nullability/test/BetweenTest.kt | 40 +++++++------------ .../test/BetweenWhenPresentTest.kt | 24 +++++------ .../nullability/test/CompilerUtilities.kt | 24 +++-------- .../nullability/test/EqualNotEqualTest.kt | 40 ++++++++----------- src/test/kotlin/nullability/test/InTest.kt | 24 ++++------- .../nullability/test/InWhenPresentTest.kt | 32 +++++++-------- .../nullability/test/LikeNotLikeTest.kt | 40 ++++++++----------- .../kotlin/nullability/test/NotBetweenTest.kt | 40 +++++++------------ .../test/NotBetweenWhenPresentTest.kt | 24 +++++------ src/test/kotlin/nullability/test/NotInTest.kt | 24 ++++------- .../nullability/test/NotInWhenPresentTest.kt | 32 +++++++-------- 11 files changed, 138 insertions(+), 206 deletions(-) diff --git a/src/test/kotlin/nullability/test/BetweenTest.kt b/src/test/kotlin/nullability/test/BetweenTest.kt index d47e4b250..329b86a23 100644 --- a/src/test/kotlin/nullability/test/BetweenTest.kt +++ b/src/test/kotlin/nullability/test/BetweenTest.kt @@ -35,10 +35,8 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 30)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 30))) } @Test @@ -57,10 +55,8 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 36)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 36))) } @Test @@ -79,13 +75,11 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(2) - val matchCount = compilerErrorReports.matchCount( + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( ExpectedErrorLocation(9, 30), ExpectedErrorLocation(9, 39) - ) - assertThat(matchCount).isEqualTo(2) + )) } @Test @@ -105,10 +99,8 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 36)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 36))) } @Test @@ -128,10 +120,8 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 38)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 38))) } @Test @@ -151,12 +141,10 @@ class BetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(2) - val matchCount = compilerErrorReports.matchCount( + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( ExpectedErrorLocation(10, 36), ExpectedErrorLocation(10, 46) - ) - assertThat(matchCount).isEqualTo(2) + )) } } diff --git a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt index a03cde2c9..2ab936108 100644 --- a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt @@ -35,8 +35,8 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -55,8 +55,8 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -75,8 +75,8 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -96,8 +96,8 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -117,8 +117,8 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -138,7 +138,7 @@ class BetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/CompilerUtilities.kt b/src/test/kotlin/nullability/test/CompilerUtilities.kt index 630151e4c..0f90d509a 100644 --- a/src/test/kotlin/nullability/test/CompilerUtilities.kt +++ b/src/test/kotlin/nullability/test/CompilerUtilities.kt @@ -26,7 +26,7 @@ import java.io.File /** * Compiles the source lines and returns any error reports generated by the compiler. */ -fun compile(sourceLines: List): List { +fun compile(sourceLines: List): CompilerErrorMessageCollector { val file: File = File.createTempFile("KotlinTest", ".kt") file.deleteOnExit() file.writeText(sourceLines.joinToString(separator = System.lineSeparator())) @@ -38,9 +38,8 @@ fun compile(sourceLines: List): List { noStdlib = true } - return with(CompilerErrorMessageCollector()) { + return CompilerErrorMessageCollector().apply { K2JVMCompiler().exec(this, Services.EMPTY, compilerArgs) - this.errors } } @@ -59,22 +58,11 @@ class CompilerErrorMessageCollector: MessageCollector { errors.add(CompilerErrorReport(severity, message, location)) } } -} - -fun CompilerErrorReport.matchesExpected(expectedErrorLocations: Array) = - expectedErrorLocations.firstOrNull { location.matchesExpected(it) } != null -fun CompilerMessageSourceLocation?.matchesExpected(expectedErrorLocation: ExpectedErrorLocation) = - if (this == null) { - false - } else { - line == expectedErrorLocation.line && column == expectedErrorLocation.column - } - -fun List.matchCount(vararg expectedErrorLocations: ExpectedErrorLocation) = - this.filter { - it.matchesExpected(expectedErrorLocations) - }.size + fun errorLocations() = + errors.mapNotNull { it.location } + .map { ExpectedErrorLocation(it.line, it.column) } +} data class CompilerErrorReport( val severity: CompilerMessageSeverity, diff --git a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt index 26dcf0c4b..558507832 100644 --- a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt +++ b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt @@ -35,10 +35,8 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 37)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 37))) } @Test @@ -57,8 +55,8 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -78,10 +76,8 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 40)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 40))) } @Test @@ -100,8 +96,8 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -121,10 +117,8 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 38)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 38))) } @Test @@ -144,8 +138,8 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -166,10 +160,8 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 41)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 41))) } @Test @@ -189,7 +181,7 @@ class EqualNotEqualTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/InTest.kt b/src/test/kotlin/nullability/test/InTest.kt index 370cd5c34..6fdcd8255 100644 --- a/src/test/kotlin/nullability/test/InTest.kt +++ b/src/test/kotlin/nullability/test/InTest.kt @@ -35,10 +35,8 @@ class InTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 28)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 28))) } @Test @@ -58,10 +56,8 @@ class InTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 25)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 25))) } @Test @@ -81,10 +77,8 @@ class InTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 29)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 29))) } @Test @@ -105,9 +99,7 @@ class InTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 26)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 26))) } } diff --git a/src/test/kotlin/nullability/test/InWhenPresentTest.kt b/src/test/kotlin/nullability/test/InWhenPresentTest.kt index 9d42931d4..92a5eb1eb 100644 --- a/src/test/kotlin/nullability/test/InWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/InWhenPresentTest.kt @@ -35,8 +35,8 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -56,8 +56,8 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -76,8 +76,8 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -96,8 +96,8 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -117,8 +117,8 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -139,8 +139,8 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -160,8 +160,8 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -181,7 +181,7 @@ class InWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/LikeNotLikeTest.kt b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt index 62d6ea859..55d899b65 100644 --- a/src/test/kotlin/nullability/test/LikeNotLikeTest.kt +++ b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt @@ -35,10 +35,8 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 34)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 34))) } @Test @@ -57,8 +55,8 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -78,10 +76,8 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 37)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 37))) } @Test @@ -100,8 +96,8 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -121,10 +117,8 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 35)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 35))) } @Test @@ -144,8 +138,8 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -166,10 +160,8 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 38)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 38))) } @Test @@ -189,7 +181,7 @@ class LikeNotLikeTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/NotBetweenTest.kt b/src/test/kotlin/nullability/test/NotBetweenTest.kt index f75ba3fc3..1e9704dac 100644 --- a/src/test/kotlin/nullability/test/NotBetweenTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenTest.kt @@ -35,10 +35,8 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 33)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 33))) } @Test @@ -57,10 +55,8 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 39)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 39))) } @Test @@ -79,13 +75,11 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(2) - val matchCount = compilerErrorReports.matchCount( + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( ExpectedErrorLocation(9, 33), ExpectedErrorLocation(9, 42) - ) - assertThat(matchCount).isEqualTo(2) + )) } @Test @@ -105,10 +99,8 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 39)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 39))) } @Test @@ -128,10 +120,8 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 41)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 41))) } @Test @@ -151,12 +141,10 @@ class NotBetweenTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(2) - val matchCount = compilerErrorReports.matchCount( + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( ExpectedErrorLocation(10, 39), ExpectedErrorLocation(10, 49) - ) - assertThat(matchCount).isEqualTo(2) + )) } } diff --git a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt index 84a3a5ffd..d24feb1ac 100644 --- a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt @@ -35,8 +35,8 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -55,8 +55,8 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -75,8 +75,8 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -96,8 +96,8 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -117,8 +117,8 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -138,7 +138,7 @@ class NotBetweenWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/NotInTest.kt b/src/test/kotlin/nullability/test/NotInTest.kt index 14b971529..36985bf56 100644 --- a/src/test/kotlin/nullability/test/NotInTest.kt +++ b/src/test/kotlin/nullability/test/NotInTest.kt @@ -35,10 +35,8 @@ class NotInTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(9, 31)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 31))) } @Test @@ -58,10 +56,8 @@ class NotInTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 28)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 28))) } @Test @@ -81,10 +77,8 @@ class NotInTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(10, 32)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 32))) } @Test @@ -105,9 +99,7 @@ class NotInTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).hasSize(1) - val matchCount = compilerErrorReports.matchCount(ExpectedErrorLocation(11, 29)) - assertThat(matchCount).isEqualTo(1) + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 29))) } } diff --git a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt index 2fa489a9c..48798be7a 100644 --- a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt @@ -35,8 +35,8 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -56,8 +56,8 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -76,8 +76,8 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -96,8 +96,8 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -117,8 +117,8 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -139,8 +139,8 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -160,8 +160,8 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } @Test @@ -181,7 +181,7 @@ class NotInWhenPresentTest { } """.trimIndent().lines() - val compilerErrorReports = compile(sourceLines) - assertThat(compilerErrorReports).isEmpty() + val compilerMessageCollector = compile(sourceLines) + assertThat(compilerMessageCollector.errors).isEmpty() } } From 6ce652d583e81fdee9db1ddb91d2cbe4cb70d1ee Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Tue, 14 Jun 2022 17:48:38 -0400 Subject: [PATCH 13/26] Refactor and simplify tests --- .../kotlin/nullability/test/BetweenTest.kt | 36 +++++++------- .../test/BetweenWhenPresentTest.kt | 36 +++++++------- .../nullability/test/CompilerUtilities.kt | 5 +- .../nullability/test/EqualNotEqualTest.kt | 48 +++++++++---------- src/test/kotlin/nullability/test/InTest.kt | 24 +++++----- .../nullability/test/InWhenPresentTest.kt | 48 +++++++++---------- .../nullability/test/LikeNotLikeTest.kt | 48 +++++++++---------- .../kotlin/nullability/test/NotBetweenTest.kt | 36 +++++++------- .../test/NotBetweenWhenPresentTest.kt | 36 +++++++------- src/test/kotlin/nullability/test/NotInTest.kt | 24 +++++----- .../nullability/test/NotInWhenPresentTest.kt | 48 +++++++++---------- 11 files changed, 195 insertions(+), 194 deletions(-) diff --git a/src/test/kotlin/nullability/test/BetweenTest.kt b/src/test/kotlin/nullability/test/BetweenTest.kt index 329b86a23..1d57261af 100644 --- a/src/test/kotlin/nullability/test/BetweenTest.kt +++ b/src/test/kotlin/nullability/test/BetweenTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class BetweenTest { @Test fun `Test That First Null Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -33,15 +33,15 @@ class BetweenTest { where { id isBetween null and 4 } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 30))) } @Test fun `Test That Second Null Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -53,15 +53,15 @@ class BetweenTest { where { id isBetween 4 and null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 36))) } @Test fun `Test That Both Null Causes Compile Errors`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -73,9 +73,9 @@ class BetweenTest { where { id isBetween null and null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( ExpectedErrorLocation(9, 30), ExpectedErrorLocation(9, 39) @@ -84,7 +84,7 @@ class BetweenTest { @Test fun `Test That First Null In Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -97,15 +97,15 @@ class BetweenTest { where { id (isBetween(null).and(4)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 36))) } @Test fun `Test That Second Null In Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -118,15 +118,15 @@ class BetweenTest { where { id (isBetween(4).and(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 38))) } @Test fun `Test That Both Null In Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -139,9 +139,9 @@ class BetweenTest { where { id (isBetween(null).and(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( ExpectedErrorLocation(10, 36), ExpectedErrorLocation(10, 46) diff --git a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt index 2ab936108..8785af800 100644 --- a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class BetweenWhenPresentTest { @Test fun `Test That First Null Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -33,15 +33,15 @@ class BetweenWhenPresentTest { where { id isBetweenWhenPresent null and 4 } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Second Null Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -53,15 +53,15 @@ class BetweenWhenPresentTest { where { id isBetweenWhenPresent 4 and null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Both Null Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -73,15 +73,15 @@ class BetweenWhenPresentTest { where { id isBetweenWhenPresent null and null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That First Null In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -94,15 +94,15 @@ class BetweenWhenPresentTest { where { id (isBetweenWhenPresent(null).and(4)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Second Null In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -115,15 +115,15 @@ class BetweenWhenPresentTest { where { id (isBetweenWhenPresent(4).and(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Both Null In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -136,9 +136,9 @@ class BetweenWhenPresentTest { where { id (isBetweenWhenPresent(null).and(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/CompilerUtilities.kt b/src/test/kotlin/nullability/test/CompilerUtilities.kt index 0f90d509a..3420acf43 100644 --- a/src/test/kotlin/nullability/test/CompilerUtilities.kt +++ b/src/test/kotlin/nullability/test/CompilerUtilities.kt @@ -26,10 +26,11 @@ import java.io.File /** * Compiles the source lines and returns any error reports generated by the compiler. */ -fun compile(sourceLines: List): CompilerErrorMessageCollector { +fun compile(source: String): CompilerErrorMessageCollector { val file: File = File.createTempFile("KotlinTest", ".kt") file.deleteOnExit() - file.writeText(sourceLines.joinToString(separator = System.lineSeparator())) + // normalize line endings and write to temp file + file.writeText(source.trimIndent().lines().joinToString(separator = System.lineSeparator())) val compilerArgs = K2JVMCompilerArguments().apply { freeArgs = listOf(file.path) diff --git a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt index 558507832..0c3dc7e52 100644 --- a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt +++ b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class EqualNotEqualTest { @Test fun `Test That Null Equal Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -33,15 +33,15 @@ class EqualNotEqualTest { where { firstName isEqualTo null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 37))) } @Test fun `Test That Null Equal When Present is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -53,15 +53,15 @@ class EqualNotEqualTest { where { firstName isEqualToWhenPresent null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null Not Equal Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -74,15 +74,15 @@ class EqualNotEqualTest { where { firstName isNotEqualTo null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 40))) } @Test fun `Test That Null Not Equal When Present is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -94,15 +94,15 @@ class EqualNotEqualTest { where { firstName isNotEqualToWhenPresent null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null Elements Equal Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -115,15 +115,15 @@ class EqualNotEqualTest { where { firstName (isEqualTo(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 38))) } @Test fun `Test That Null Elements Equal When Present is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -136,15 +136,15 @@ class EqualNotEqualTest { where { firstName (isEqualToWhenPresent(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null Elements Not Equal Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -158,15 +158,15 @@ class EqualNotEqualTest { where { firstName (isNotEqualTo(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 41))) } @Test fun `Test That Null Elements Not Equal When Present is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -179,9 +179,9 @@ class EqualNotEqualTest { where { firstName (isNotEqualToWhenPresent(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/InTest.kt b/src/test/kotlin/nullability/test/InTest.kt index 6fdcd8255..a3a434498 100644 --- a/src/test/kotlin/nullability/test/InTest.kt +++ b/src/test/kotlin/nullability/test/InTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class InTest { @Test fun `Test That Null In VarAgs Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -33,15 +33,15 @@ class InTest { where { id.isIn(4, null) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 28))) } @Test fun `Test That Null in List Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -54,15 +54,15 @@ class InTest { where { id isIn ids } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 25))) } @Test fun `Test That Null In VarArgs Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -75,15 +75,15 @@ class InTest { where { id (isIn(4, null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 29))) } @Test fun `Test That Null In List Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -97,9 +97,9 @@ class InTest { where { id (isIn(ids)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 26))) } } diff --git a/src/test/kotlin/nullability/test/InWhenPresentTest.kt b/src/test/kotlin/nullability/test/InWhenPresentTest.kt index 92a5eb1eb..dcc21b462 100644 --- a/src/test/kotlin/nullability/test/InWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/InWhenPresentTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class InWhenPresentTest { @Test fun `Test That Null In VarAgs Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -33,15 +33,15 @@ class InWhenPresentTest { where { id.isInWhenPresent(4, null) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null in List Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -54,15 +54,15 @@ class InWhenPresentTest { where { id isInWhenPresent ids } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Empty VarAgs Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -74,15 +74,15 @@ class InWhenPresentTest { where { id.isInWhenPresent() } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null List Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -94,15 +94,15 @@ class InWhenPresentTest { where { id.isInWhenPresent(null as List) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null In VarArgs Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -115,15 +115,15 @@ class InWhenPresentTest { where { id (isInWhenPresent(4, null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null In List Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -137,15 +137,15 @@ class InWhenPresentTest { where { id (isInWhenPresent(ids)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Empty VarAgs In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -158,15 +158,15 @@ class InWhenPresentTest { where { id (isInWhenPresent()) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null List In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -179,9 +179,9 @@ class InWhenPresentTest { where { id (isInWhenPresent(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/LikeNotLikeTest.kt b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt index 55d899b65..1c43e3d36 100644 --- a/src/test/kotlin/nullability/test/LikeNotLikeTest.kt +++ b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class LikeNotLikeTest { @Test fun `Test That Null Like Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -33,15 +33,15 @@ class LikeNotLikeTest { where { firstName isLike null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 34))) } @Test fun `Test That Null Like When Present is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -53,15 +53,15 @@ class LikeNotLikeTest { where { firstName isLikeWhenPresent null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null Not Like Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -74,15 +74,15 @@ class LikeNotLikeTest { where { firstName isNotLike null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 37))) } @Test fun `Test That Null Not Like When Present is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -94,15 +94,15 @@ class LikeNotLikeTest { where { firstName isNotLikeWhenPresent null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null Elements Like Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -115,15 +115,15 @@ class LikeNotLikeTest { where { firstName (isLike(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 35))) } @Test fun `Test That Null Elements Like When Present is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -136,15 +136,15 @@ class LikeNotLikeTest { where { firstName (isLikeWhenPresent(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null Elements Not Like Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -158,15 +158,15 @@ class LikeNotLikeTest { where { firstName (isNotLike(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 38))) } @Test fun `Test That Null Elements Not Like When Present is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.firstName @@ -179,9 +179,9 @@ class LikeNotLikeTest { where { firstName (isNotLikeWhenPresent(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/NotBetweenTest.kt b/src/test/kotlin/nullability/test/NotBetweenTest.kt index 1e9704dac..ace2601a2 100644 --- a/src/test/kotlin/nullability/test/NotBetweenTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class NotBetweenTest { @Test fun `Test That First Null Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -33,15 +33,15 @@ class NotBetweenTest { where { id isNotBetween null and 4 } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 33))) } @Test fun `Test That Second Null Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -53,15 +53,15 @@ class NotBetweenTest { where { id isNotBetween 4 and null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 39))) } @Test fun `Test That Both Null Causes Compile Errors`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -73,9 +73,9 @@ class NotBetweenTest { where { id isNotBetween null and null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( ExpectedErrorLocation(9, 33), ExpectedErrorLocation(9, 42) @@ -84,7 +84,7 @@ class NotBetweenTest { @Test fun `Test That First Null In Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -97,15 +97,15 @@ class NotBetweenTest { where { id (isNotBetween(null).and(4)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 39))) } @Test fun `Test That Second Null In Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -118,15 +118,15 @@ class NotBetweenTest { where { id (isNotBetween(4).and(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 41))) } @Test fun `Test That Both Null In Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -139,9 +139,9 @@ class NotBetweenTest { where { id (isNotBetween(null).and(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( ExpectedErrorLocation(10, 39), ExpectedErrorLocation(10, 49) diff --git a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt index d24feb1ac..391cf8cde 100644 --- a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class NotBetweenWhenPresentTest { @Test fun `Test That First Null Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -33,15 +33,15 @@ class NotBetweenWhenPresentTest { where { id isNotBetweenWhenPresent null and 4 } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Second Null Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -53,15 +53,15 @@ class NotBetweenWhenPresentTest { where { id isNotBetweenWhenPresent 4 and null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Both Null Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -73,15 +73,15 @@ class NotBetweenWhenPresentTest { where { id isNotBetweenWhenPresent null and null } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That First Null In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -94,15 +94,15 @@ class NotBetweenWhenPresentTest { where { id (isNotBetweenWhenPresent(null).and(4)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Second Null In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -115,15 +115,15 @@ class NotBetweenWhenPresentTest { where { id (isNotBetweenWhenPresent(4).and(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Both Null In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -136,9 +136,9 @@ class NotBetweenWhenPresentTest { where { id (isNotBetweenWhenPresent(null).and(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } } diff --git a/src/test/kotlin/nullability/test/NotInTest.kt b/src/test/kotlin/nullability/test/NotInTest.kt index 36985bf56..24f573223 100644 --- a/src/test/kotlin/nullability/test/NotInTest.kt +++ b/src/test/kotlin/nullability/test/NotInTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class NotInTest { @Test fun `Test That Null In VarAgs Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -33,15 +33,15 @@ class NotInTest { where { id.isNotIn(4, null) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 31))) } @Test fun `Test That Null in List Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -54,15 +54,15 @@ class NotInTest { where { id isNotIn ids } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 28))) } @Test fun `Test That Null In VarArgs Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -75,15 +75,15 @@ class NotInTest { where { id (isNotIn(4, null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 32))) } @Test fun `Test That Null In List Elements Method Causes Compile Error`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -97,9 +97,9 @@ class NotInTest { where { id (isNotIn(ids)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 29))) } } diff --git a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt index 48798be7a..f8b5eff59 100644 --- a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test class NotInWhenPresentTest { @Test fun `Test That Null In VarAgs Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -33,15 +33,15 @@ class NotInWhenPresentTest { where { id.isNotInWhenPresent(4, null) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null in List Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -54,15 +54,15 @@ class NotInWhenPresentTest { where { id isNotInWhenPresent ids } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Empty VarAgs Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -74,15 +74,15 @@ class NotInWhenPresentTest { where { id.isNotInWhenPresent() } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null List Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -94,15 +94,15 @@ class NotInWhenPresentTest { where { id.isNotInWhenPresent(null as List) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null In VarArgs Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -115,15 +115,15 @@ class NotInWhenPresentTest { where { id (isNotInWhenPresent(4, null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null In List Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -137,15 +137,15 @@ class NotInWhenPresentTest { where { id (isNotInWhenPresent(ids)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Empty VarAgs In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -158,15 +158,15 @@ class NotInWhenPresentTest { where { id (isNotInWhenPresent()) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } @Test fun `Test That Null List In Elements Method Is OK`() { - val sourceLines = """ + val source = """ package temp.kotlin.test import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id @@ -179,9 +179,9 @@ class NotInWhenPresentTest { where { id (isNotInWhenPresent(null)) } } } - """.trimIndent().lines() + """ - val compilerMessageCollector = compile(sourceLines) + val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errors).isEmpty() } } From 44f9eb50c9350f807332e5fb650fa8ea227a8381 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 Jun 2022 10:32:29 -0400 Subject: [PATCH 14/26] Refactor tests --- .../kotlin/nullability/test/BetweenTest.kt | 20 +++++++++---------- .../test/BetweenWhenPresentTest.kt | 12 +++++------ .../nullability/test/CompilerUtilities.kt | 17 ++++++++-------- .../nullability/test/EqualNotEqualTest.kt | 16 +++++++-------- src/test/kotlin/nullability/test/InTest.kt | 8 ++++---- .../nullability/test/InWhenPresentTest.kt | 16 +++++++-------- .../nullability/test/LikeNotLikeTest.kt | 16 +++++++-------- .../kotlin/nullability/test/NotBetweenTest.kt | 16 +++++++-------- .../test/NotBetweenWhenPresentTest.kt | 12 +++++------ src/test/kotlin/nullability/test/NotInTest.kt | 8 ++++---- .../nullability/test/NotInWhenPresentTest.kt | 16 +++++++-------- 11 files changed, 78 insertions(+), 79 deletions(-) diff --git a/src/test/kotlin/nullability/test/BetweenTest.kt b/src/test/kotlin/nullability/test/BetweenTest.kt index 1d57261af..31da32afa 100644 --- a/src/test/kotlin/nullability/test/BetweenTest.kt +++ b/src/test/kotlin/nullability/test/BetweenTest.kt @@ -36,7 +36,7 @@ class BetweenTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 30))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 30))) } @Test @@ -56,11 +56,11 @@ class BetweenTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 36))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 36))) } @Test - fun `Test That Both Null Causes Compile Errors`() { + fun `Test That Both Null Causes Two Compile Errors`() { val source = """ package temp.kotlin.test @@ -77,8 +77,8 @@ class BetweenTest { val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( - ExpectedErrorLocation(9, 30), - ExpectedErrorLocation(9, 39) + ErrorLocation(9, 30), + ErrorLocation(9, 39) )) } @@ -100,7 +100,7 @@ class BetweenTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 36))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 36))) } @Test @@ -121,11 +121,11 @@ class BetweenTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 38))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 38))) } @Test - fun `Test That Both Null In Elements Method Causes Compile Error`() { + fun `Test That Both Null In Elements Method Causes Two Compile Errors`() { val source = """ package temp.kotlin.test @@ -143,8 +143,8 @@ class BetweenTest { val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( - ExpectedErrorLocation(10, 36), - ExpectedErrorLocation(10, 46) + ErrorLocation(10, 36), + ErrorLocation(10, 46) )) } } diff --git a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt index 8785af800..f0ec0076b 100644 --- a/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/BetweenWhenPresentTest.kt @@ -36,7 +36,7 @@ class BetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -56,7 +56,7 @@ class BetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -76,7 +76,7 @@ class BetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -97,7 +97,7 @@ class BetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -118,7 +118,7 @@ class BetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -139,6 +139,6 @@ class BetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } } diff --git a/src/test/kotlin/nullability/test/CompilerUtilities.kt b/src/test/kotlin/nullability/test/CompilerUtilities.kt index 3420acf43..0e2266191 100644 --- a/src/test/kotlin/nullability/test/CompilerUtilities.kt +++ b/src/test/kotlin/nullability/test/CompilerUtilities.kt @@ -45,24 +45,23 @@ fun compile(source: String): CompilerErrorMessageCollector { } class CompilerErrorMessageCollector: MessageCollector { - val errors = mutableListOf() - override fun clear() = errors.clear() + val reports = mutableListOf() + override fun clear() = reports.clear() - override fun hasErrors() = errors.size > 0 + override fun hasErrors() = reports.any { it.severity.isError } override fun report( severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation? ) { - if (severity.isError) { - errors.add(CompilerErrorReport(severity, message, location)) - } + reports.add(CompilerErrorReport(severity, message, location)) } fun errorLocations() = - errors.mapNotNull { it.location } - .map { ExpectedErrorLocation(it.line, it.column) } + reports.filter { it.severity.isError } + .mapNotNull { it.location } + .map { ErrorLocation(it.line, it.column) } } data class CompilerErrorReport( @@ -70,4 +69,4 @@ data class CompilerErrorReport( val message: String, val location: CompilerMessageSourceLocation? ) -data class ExpectedErrorLocation(val line: Int, val column: Int) +data class ErrorLocation(val line: Int, val column: Int) diff --git a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt index 0c3dc7e52..27dadff36 100644 --- a/src/test/kotlin/nullability/test/EqualNotEqualTest.kt +++ b/src/test/kotlin/nullability/test/EqualNotEqualTest.kt @@ -36,7 +36,7 @@ class EqualNotEqualTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 37))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 37))) } @Test @@ -56,7 +56,7 @@ class EqualNotEqualTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -77,7 +77,7 @@ class EqualNotEqualTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 40))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 40))) } @Test @@ -97,7 +97,7 @@ class EqualNotEqualTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -118,7 +118,7 @@ class EqualNotEqualTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 38))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 38))) } @Test @@ -139,7 +139,7 @@ class EqualNotEqualTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -161,7 +161,7 @@ class EqualNotEqualTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 41))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(11, 41))) } @Test @@ -182,6 +182,6 @@ class EqualNotEqualTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } } diff --git a/src/test/kotlin/nullability/test/InTest.kt b/src/test/kotlin/nullability/test/InTest.kt index a3a434498..7010b53e7 100644 --- a/src/test/kotlin/nullability/test/InTest.kt +++ b/src/test/kotlin/nullability/test/InTest.kt @@ -36,7 +36,7 @@ class InTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 28))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 28))) } @Test @@ -57,7 +57,7 @@ class InTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 25))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 25))) } @Test @@ -78,7 +78,7 @@ class InTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 29))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 29))) } @Test @@ -100,6 +100,6 @@ class InTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 26))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(11, 26))) } } diff --git a/src/test/kotlin/nullability/test/InWhenPresentTest.kt b/src/test/kotlin/nullability/test/InWhenPresentTest.kt index dcc21b462..307e5255b 100644 --- a/src/test/kotlin/nullability/test/InWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/InWhenPresentTest.kt @@ -36,7 +36,7 @@ class InWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -57,7 +57,7 @@ class InWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -77,7 +77,7 @@ class InWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -97,7 +97,7 @@ class InWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -118,7 +118,7 @@ class InWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -140,7 +140,7 @@ class InWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -161,7 +161,7 @@ class InWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -182,6 +182,6 @@ class InWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } } diff --git a/src/test/kotlin/nullability/test/LikeNotLikeTest.kt b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt index 1c43e3d36..2b9de75b9 100644 --- a/src/test/kotlin/nullability/test/LikeNotLikeTest.kt +++ b/src/test/kotlin/nullability/test/LikeNotLikeTest.kt @@ -36,7 +36,7 @@ class LikeNotLikeTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 34))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 34))) } @Test @@ -56,7 +56,7 @@ class LikeNotLikeTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -77,7 +77,7 @@ class LikeNotLikeTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 37))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 37))) } @Test @@ -97,7 +97,7 @@ class LikeNotLikeTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -118,7 +118,7 @@ class LikeNotLikeTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 35))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 35))) } @Test @@ -139,7 +139,7 @@ class LikeNotLikeTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -161,7 +161,7 @@ class LikeNotLikeTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 38))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(11, 38))) } @Test @@ -182,6 +182,6 @@ class LikeNotLikeTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } } diff --git a/src/test/kotlin/nullability/test/NotBetweenTest.kt b/src/test/kotlin/nullability/test/NotBetweenTest.kt index ace2601a2..8bc76fcea 100644 --- a/src/test/kotlin/nullability/test/NotBetweenTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenTest.kt @@ -36,7 +36,7 @@ class NotBetweenTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 33))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 33))) } @Test @@ -56,7 +56,7 @@ class NotBetweenTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 39))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 39))) } @Test @@ -77,8 +77,8 @@ class NotBetweenTest { val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( - ExpectedErrorLocation(9, 33), - ExpectedErrorLocation(9, 42) + ErrorLocation(9, 33), + ErrorLocation(9, 42) )) } @@ -100,7 +100,7 @@ class NotBetweenTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 39))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 39))) } @Test @@ -121,7 +121,7 @@ class NotBetweenTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 41))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 41))) } @Test @@ -143,8 +143,8 @@ class NotBetweenTest { val compilerMessageCollector = compile(source) assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf( - ExpectedErrorLocation(10, 39), - ExpectedErrorLocation(10, 49) + ErrorLocation(10, 39), + ErrorLocation(10, 49) )) } } diff --git a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt index 391cf8cde..3faa85a6b 100644 --- a/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotBetweenWhenPresentTest.kt @@ -36,7 +36,7 @@ class NotBetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -56,7 +56,7 @@ class NotBetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -76,7 +76,7 @@ class NotBetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -97,7 +97,7 @@ class NotBetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -118,7 +118,7 @@ class NotBetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -139,6 +139,6 @@ class NotBetweenWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } } diff --git a/src/test/kotlin/nullability/test/NotInTest.kt b/src/test/kotlin/nullability/test/NotInTest.kt index 24f573223..f8e7d7ff3 100644 --- a/src/test/kotlin/nullability/test/NotInTest.kt +++ b/src/test/kotlin/nullability/test/NotInTest.kt @@ -36,7 +36,7 @@ class NotInTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(9, 31))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 31))) } @Test @@ -57,7 +57,7 @@ class NotInTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 28))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 28))) } @Test @@ -78,7 +78,7 @@ class NotInTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(10, 32))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 32))) } @Test @@ -100,6 +100,6 @@ class NotInTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ExpectedErrorLocation(11, 29))) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(11, 29))) } } diff --git a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt index f8b5eff59..99e57f43c 100644 --- a/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt +++ b/src/test/kotlin/nullability/test/NotInWhenPresentTest.kt @@ -36,7 +36,7 @@ class NotInWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -57,7 +57,7 @@ class NotInWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -77,7 +77,7 @@ class NotInWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -97,7 +97,7 @@ class NotInWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -118,7 +118,7 @@ class NotInWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -140,7 +140,7 @@ class NotInWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -161,7 +161,7 @@ class NotInWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } @Test @@ -182,6 +182,6 @@ class NotInWhenPresentTest { """ val compilerMessageCollector = compile(source) - assertThat(compilerMessageCollector.errors).isEmpty() + assertThat(compilerMessageCollector.hasErrors()).isFalse } } From 67d5f0f04c0f3c563d16c474131c49683a5ddd72 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 Jun 2022 12:03:43 -0400 Subject: [PATCH 15/26] Fix all the comparison functions --- .../util/kotlin/GroupingCriteriaCollector.kt | 16 +- .../sql/util/kotlin/elements/SqlElements.kt | 16 +- .../kotlin/nullability/test/ComparisonTest.kt | 513 ++++++++++++++++++ 3 files changed, 529 insertions(+), 16 deletions(-) create mode 100644 src/test/kotlin/nullability/test/ComparisonTest.kt diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt index 6687f56e3..5c3fdd697 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/GroupingCriteriaCollector.kt @@ -267,7 +267,7 @@ class GroupingCriteriaCollector { infix fun BindableColumn.isNotEqualToWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualToWhenPresent(value)) - infix fun BindableColumn.isGreaterThan(value: T) = + infix fun BindableColumn.isGreaterThan(value: T & Any) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThan(value)) infix fun BindableColumn<*>.isGreaterThan(subQuery: KotlinSubQueryBuilder.() -> Unit) = @@ -276,10 +276,10 @@ class GroupingCriteriaCollector { infix fun BindableColumn<*>.isGreaterThan(column: BasicColumn) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThan(column)) - infix fun BindableColumn.isGreaterThanWhenPresent(value: T?) = + infix fun BindableColumn.isGreaterThanWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanWhenPresent(value)) - infix fun BindableColumn.isGreaterThanOrEqualTo(value: T) = + infix fun BindableColumn.isGreaterThanOrEqualTo(value: T & Any) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanOrEqualTo(value)) infix fun BindableColumn<*>.isGreaterThanOrEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit) = @@ -288,10 +288,10 @@ class GroupingCriteriaCollector { infix fun BindableColumn<*>.isGreaterThanOrEqualTo(column: BasicColumn) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanOrEqualTo(column)) - infix fun BindableColumn.isGreaterThanOrEqualToWhenPresent(value: T?) = + infix fun BindableColumn.isGreaterThanOrEqualToWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanOrEqualToWhenPresent(value)) - infix fun BindableColumn.isLessThan(value: T) = + infix fun BindableColumn.isLessThan(value: T & Any) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThan(value)) infix fun BindableColumn<*>.isLessThan(subQuery: KotlinSubQueryBuilder.() -> Unit) = @@ -300,10 +300,10 @@ class GroupingCriteriaCollector { infix fun BindableColumn<*>.isLessThan(column: BasicColumn) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThan(column)) - infix fun BindableColumn.isLessThanWhenPresent(value: T?) = + infix fun BindableColumn.isLessThanWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanWhenPresent(value)) - infix fun BindableColumn.isLessThanOrEqualTo(value: T) = + infix fun BindableColumn.isLessThanOrEqualTo(value: T & Any) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualTo(value)) infix fun BindableColumn<*>.isLessThanOrEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit) = @@ -312,7 +312,7 @@ class GroupingCriteriaCollector { infix fun BindableColumn<*>.isLessThanOrEqualTo(column: BasicColumn) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualTo(column)) - infix fun BindableColumn.isLessThanOrEqualToWhenPresent(value: T?) = + infix fun BindableColumn.isLessThanOrEqualToWhenPresent(value: T?) = invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualToWhenPresent(value)) fun BindableColumn.isIn(vararg values: T & Any) = isIn(values.asList()) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt index 60dd689e2..6190275cb 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt @@ -200,16 +200,16 @@ fun isNotEqualTo(column: BasicColumn): IsNotEqualToColumn = SqlBuilder.is fun isNotEqualToWhenPresent(value: T?): IsNotEqualTo = SqlBuilder.isNotEqualToWhenPresent(value) -fun isGreaterThan(value: T): IsGreaterThan = SqlBuilder.isGreaterThan(value) +fun isGreaterThan(value: T & Any): IsGreaterThan = SqlBuilder.isGreaterThan(value) fun isGreaterThan(subQuery: KotlinSubQueryBuilder.() -> Unit): IsGreaterThanWithSubselect = SqlBuilder.isGreaterThan(KotlinSubQueryBuilder().apply(subQuery)) fun isGreaterThan(column: BasicColumn): IsGreaterThanColumn = SqlBuilder.isGreaterThan(column) -fun isGreaterThanWhenPresent(value: T?): IsGreaterThan = SqlBuilder.isGreaterThanWhenPresent(value) +fun isGreaterThanWhenPresent(value: T?): IsGreaterThan = SqlBuilder.isGreaterThanWhenPresent(value) -fun isGreaterThanOrEqualTo(value: T): IsGreaterThanOrEqualTo = SqlBuilder.isGreaterThanOrEqualTo(value) +fun isGreaterThanOrEqualTo(value: T & Any): IsGreaterThanOrEqualTo = SqlBuilder.isGreaterThanOrEqualTo(value) fun isGreaterThanOrEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit): IsGreaterThanOrEqualToWithSubselect = SqlBuilder.isGreaterThanOrEqualTo(KotlinSubQueryBuilder().apply(subQuery)) @@ -217,26 +217,26 @@ fun isGreaterThanOrEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit): IsGr fun isGreaterThanOrEqualTo(column: BasicColumn): IsGreaterThanOrEqualToColumn = SqlBuilder.isGreaterThanOrEqualTo(column) -fun isGreaterThanOrEqualToWhenPresent(value: T?): IsGreaterThanOrEqualTo = +fun isGreaterThanOrEqualToWhenPresent(value: T?): IsGreaterThanOrEqualTo = SqlBuilder.isGreaterThanOrEqualToWhenPresent(value) -fun isLessThan(value: T): IsLessThan = SqlBuilder.isLessThan(value) +fun isLessThan(value: T & Any): IsLessThan = SqlBuilder.isLessThan(value) fun isLessThan(subQuery: KotlinSubQueryBuilder.() -> Unit): IsLessThanWithSubselect = SqlBuilder.isLessThan(KotlinSubQueryBuilder().apply(subQuery)) fun isLessThan(column: BasicColumn): IsLessThanColumn = SqlBuilder.isLessThan(column) -fun isLessThanWhenPresent(value: T?): IsLessThan = SqlBuilder.isLessThanWhenPresent(value) +fun isLessThanWhenPresent(value: T?): IsLessThan = SqlBuilder.isLessThanWhenPresent(value) -fun isLessThanOrEqualTo(value: T): IsLessThanOrEqualTo = SqlBuilder.isLessThanOrEqualTo(value) +fun isLessThanOrEqualTo(value: T & Any): IsLessThanOrEqualTo = SqlBuilder.isLessThanOrEqualTo(value) fun isLessThanOrEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit): IsLessThanOrEqualToWithSubselect = SqlBuilder.isLessThanOrEqualTo(KotlinSubQueryBuilder().apply(subQuery)) fun isLessThanOrEqualTo(column: BasicColumn): IsLessThanOrEqualToColumn = SqlBuilder.isLessThanOrEqualTo(column) -fun isLessThanOrEqualToWhenPresent(value: T?): IsLessThanOrEqualTo = +fun isLessThanOrEqualToWhenPresent(value: T?): IsLessThanOrEqualTo = SqlBuilder.isLessThanOrEqualToWhenPresent(value) fun isIn(vararg values: T & Any): IsIn = isIn(values.asList()) diff --git a/src/test/kotlin/nullability/test/ComparisonTest.kt b/src/test/kotlin/nullability/test/ComparisonTest.kt new file mode 100644 index 000000000..3ca3cd088 --- /dev/null +++ b/src/test/kotlin/nullability/test/ComparisonTest.kt @@ -0,0 +1,513 @@ +/* + * Copyright 2016-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nullability.test + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class ComparisonTest { + @Test + fun `Test That Null In EqualTo Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isEqualTo null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 30))) + } + + @Test + fun `Test That Null In EqualToWhenPresent is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isEqualToWhenPresent null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In EqualTo Elements Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo + + fun testFunction() { + countFrom(person) { + where { id (isEqualTo(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 31))) + } + + @Test + fun `Test That Null In EqualToWhenPresent Elements is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isEqualToWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isEqualToWhenPresent(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In NotEqualTo Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isNotEqualTo null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 33))) + } + + @Test + fun `Test That Null In NotEqualToWhenPresent is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isNotEqualToWhenPresent null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In NotEqualTo Elements Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualTo + + fun testFunction() { + countFrom(person) { + where { id (isNotEqualTo(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 34))) + } + + @Test + fun `Test That Null In NotEqualToWhenPresent Elements is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isNotEqualToWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isNotEqualToWhenPresent(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In GreaterThan Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isGreaterThan null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 34))) + } + + @Test + fun `Test That Null In GreaterThanWhenPresent is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isGreaterThanWhenPresent null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In GreaterThan Elements Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThan + + fun testFunction() { + countFrom(person) { + where { id (isGreaterThan(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 35))) + } + + @Test + fun `Test That Null In GreaterThanWhenPresent Elements is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isGreaterThanWhenPresent(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In GreaterThanOrEqualTo Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isGreaterThanOrEqualTo null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 43))) + } + + @Test + fun `Test That Null In GreaterThanOrEqualToWhenPresent is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isGreaterThanOrEqualToWhenPresent null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In GreaterThanOrEqualTo Elements Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanOrEqualTo + + fun testFunction() { + countFrom(person) { + where { id (isGreaterThanOrEqualTo(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 44))) + } + + @Test + fun `Test That Null In GreaterThanOrEqualToWhenPresent Elements is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThanOrEqualToWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isGreaterThanOrEqualToWhenPresent(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In LessThan Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isLessThan null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 31))) + } + + @Test + fun `Test That Null In LessThanWhenPresent is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isLessThanWhenPresent null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In LessThan Elements Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isLessThan + + fun testFunction() { + countFrom(person) { + where { id (isLessThan(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 32))) + } + + @Test + fun `Test That Null In LessThanWhenPresent Elements is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isLessThanWhenPresent(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In LessThanOrEqualTo Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isLessThanOrEqualTo null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(9, 40))) + } + + @Test + fun `Test That Null In LessThanOrEqualToWhenPresent is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + + fun testFunction() { + countFrom(person) { + where { id isLessThanOrEqualToWhenPresent null } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } + + @Test + fun `Test That Null In LessThanOrEqualTo Elements Causes Compile Error`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualTo + + fun testFunction() { + countFrom(person) { + where { id (isLessThanOrEqualTo(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.errorLocations()).isEqualTo(listOf(ErrorLocation(10, 41))) + } + + @Test + fun `Test That Null In LessThanOrEqualToWhenPresent Elements is OK`() { + val source = """ + package temp.kotlin.test + + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id + import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person + import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom + import org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualToWhenPresent + + fun testFunction() { + countFrom(person) { + where { id (isLessThanOrEqualToWhenPresent(null)) } + } + } + """ + + val compilerMessageCollector = compile(source) + assertThat(compilerMessageCollector.hasErrors()).isFalse + } +} From 50d7cb6775d9b712aa1c28ca05520ef7635ad9e1 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 Jun 2022 13:14:02 -0400 Subject: [PATCH 16/26] Definitely not null for update builder --- .../mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt index 17933b69f..83f78c928 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt @@ -50,9 +50,9 @@ class KotlinUpdateBuilder(private val dsl: UpdateDSL) : set(column).equalToStringConstant(constant) } - infix fun equalTo(value: T): Unit = equalTo { value } + infix fun equalTo(value: T & Any): Unit = equalTo { value } - infix fun equalTo(value: () -> T): Unit = + infix fun equalTo(value: () -> T & Any): Unit = applyToDsl { set(column).equalTo(value) } From 64b38dc097f38f3aad479b398e376d866b656a2e Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 Jun 2022 13:19:33 -0400 Subject: [PATCH 17/26] Definitely not null for insert mappings --- .../util/kotlin/KotlinInsertColumnMapCompleters.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertColumnMapCompleters.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertColumnMapCompleters.kt index bd6012dae..cd2fa81d0 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertColumnMapCompleters.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertColumnMapCompleters.kt @@ -27,7 +27,7 @@ import org.mybatis.dynamic.sql.util.ValueOrNullMapping import org.mybatis.dynamic.sql.util.ValueWhenPresentMapping @MyBatisDslMarker -sealed class AbstractInsertColumnMapCompleter( +sealed class AbstractInsertColumnMapCompleter( internal val column: SqlColumn, internal val mappingConsumer: (AbstractColumnMapping) -> Unit) { @@ -38,7 +38,7 @@ sealed class AbstractInsertColumnMapCompleter( infix fun toStringConstant(constant: String) = mappingConsumer.invoke(StringConstantMapping.of(column, constant)) } -class MultiRowInsertColumnMapCompleter( +class MultiRowInsertColumnMapCompleter( column: SqlColumn, mappingConsumer: (AbstractColumnMapping) -> Unit) : AbstractInsertColumnMapCompleter(column, mappingConsumer) { @@ -46,7 +46,7 @@ class MultiRowInsertColumnMapCompleter( infix fun toProperty(property: String) = mappingConsumer.invoke(PropertyMapping.of(column, property)) } -class SingleRowInsertColumnMapCompleter( +class SingleRowInsertColumnMapCompleter( column: SqlColumn, mappingConsumer: (AbstractColumnMapping) -> Unit) : AbstractInsertColumnMapCompleter(column, mappingConsumer) { @@ -57,14 +57,14 @@ class SingleRowInsertColumnMapCompleter( mappingConsumer.invoke(PropertyWhenPresentMapping.of(column, property, valueSupplier)) } -class GeneralInsertColumnSetCompleter( +class GeneralInsertColumnSetCompleter( column: SqlColumn, mappingConsumer: (AbstractColumnMapping) -> Unit) : AbstractInsertColumnMapCompleter(column, mappingConsumer) { - infix fun toValue(value: T) = toValue { value } + infix fun toValue(value: T & Any) = toValue { value } - infix fun toValue(value: () -> T) = mappingConsumer.invoke(ValueMapping.of(column, value)) + infix fun toValue(value: () -> T & Any) = mappingConsumer.invoke(ValueMapping.of(column, value)) infix fun toValueOrNull(value: T?) = toValueOrNull { value } From 663b8af1f9d56eb3508cfa73f00a30d721098ef2 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 Jun 2022 14:01:25 -0400 Subject: [PATCH 18/26] Remove useless column bounds --- .../mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt | 2 +- .../dynamic/sql/util/kotlin/KotlinGeneralInsertBuilder.kt | 2 +- .../org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt | 2 +- .../dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt index 0f278cd17..72103d5ef 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt @@ -33,7 +33,7 @@ class KotlinBatchInsertBuilder (private val rows: Collection): Buildable map(column: SqlColumn) = MultiRowInsertColumnMapCompleter(column) { + fun map(column: SqlColumn) = MultiRowInsertColumnMapCompleter(column) { columnMappings.add(it) } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinGeneralInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinGeneralInsertBuilder.kt index b7d402bbf..4562680af 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinGeneralInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinGeneralInsertBuilder.kt @@ -29,7 +29,7 @@ class KotlinGeneralInsertBuilder(private val table: SqlTable) : Buildable() - fun set(column: SqlColumn) = GeneralInsertColumnSetCompleter(column) { + fun set(column: SqlColumn) = GeneralInsertColumnSetCompleter(column) { columnMappings.add(it) } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt index ca2bee86e..7e041a319 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt @@ -33,7 +33,7 @@ class KotlinInsertBuilder (private val row: T): Buildable> { this.table = table } - fun map(column: SqlColumn) = SingleRowInsertColumnMapCompleter(column) { + fun map(column: SqlColumn) = SingleRowInsertColumnMapCompleter(column) { columnMappings.add(it) } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt index 71f79f2a7..5bb83834d 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt @@ -33,7 +33,7 @@ class KotlinMultiRowInsertBuilder (private val rows: Collection): Buildabl this.table = table } - fun map(column: SqlColumn) = MultiRowInsertColumnMapCompleter(column) { + fun map(column: SqlColumn) = MultiRowInsertColumnMapCompleter(column) { columnMappings.add(it) } From 205cd21ef8bff13c6e338bf2bc891f87a2d5ab78 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sun, 19 Jun 2022 11:06:31 -0400 Subject: [PATCH 19/26] Better expression of non-nullability on insert methods --- .../DefaultInsertStatementProvider.java | 5 ++- .../render/InsertStatementProvider.java | 3 ++ .../util/kotlin/KotlinBatchInsertBuilder.kt | 2 +- .../sql/util/kotlin/KotlinInsertBuilder.kt | 2 +- .../kotlin/KotlinMultiRowInsertBuilder.kt | 2 +- .../kotlin/model/ModelBuilderFunctions.kt | 18 +++++--- .../kotlin/mybatis3/MapperSupportFunctions.kt | 45 ++++++++++++------- .../mybatis3/ProviderBuilderFunctions.kt | 6 +-- .../NamedParameterJdbcTemplateExtensions.kt | 40 ++++++++--------- .../kotlin/spring/ProviderBuilderFunctions.kt | 6 +-- 10 files changed, 77 insertions(+), 52 deletions(-) diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java b/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java index 9cdc67302..d330d362e 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package org.mybatis.dynamic.sql.insert.render; +import org.jetbrains.annotations.NotNull; + import java.util.Objects; public class DefaultInsertStatementProvider implements InsertStatementProvider { @@ -37,6 +39,7 @@ public T getRecord() { } @Override + @NotNull public T getRow() { return row; } diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java b/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java index 65d31882d..b5bd1d68c 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java @@ -15,6 +15,8 @@ */ package org.mybatis.dynamic.sql.insert.render; +import org.jetbrains.annotations.NotNull; + public interface InsertStatementProvider { /** * Return the row associated with this insert statement. @@ -30,6 +32,7 @@ public interface InsertStatementProvider { * * @return the row associated with this insert statement. */ + @NotNull T getRow(); /** diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt index 72103d5ef..a44256716 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt @@ -25,7 +25,7 @@ import org.mybatis.dynamic.sql.util.Buildable typealias KotlinBatchInsertCompleter = KotlinBatchInsertBuilder.() -> Unit @MyBatisDslMarker -class KotlinBatchInsertBuilder (private val rows: Collection): Buildable> { +class KotlinBatchInsertBuilder (private val rows: Collection): Buildable> { private var table: SqlTable? = null private val columnMappings = mutableListOf() diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt index 7e041a319..cb6089bd4 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt @@ -25,7 +25,7 @@ import org.mybatis.dynamic.sql.util.Buildable typealias KotlinInsertCompleter = KotlinInsertBuilder.() -> Unit @MyBatisDslMarker -class KotlinInsertBuilder (private val row: T): Buildable> { +class KotlinInsertBuilder (private val row: T & Any): Buildable> { private var table: SqlTable? = null private val columnMappings = mutableListOf() diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt index 5bb83834d..aef60d937 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt @@ -25,7 +25,7 @@ import org.mybatis.dynamic.sql.util.Buildable typealias KotlinMultiRowInsertCompleter = KotlinMultiRowInsertBuilder.() -> Unit @MyBatisDslMarker -class KotlinMultiRowInsertBuilder (private val rows: Collection): Buildable> { +class KotlinMultiRowInsertBuilder (private val rows: Collection): Buildable> { private var table: SqlTable? = null private val columnMappings = mutableListOf() diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt index 2e5216133..5bd629bbc 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt @@ -65,17 +65,23 @@ fun deleteFrom(table: SqlTable, completer: DeleteCompleter): DeleteModel = fun deleteFrom(table: SqlTable, tableAlias: String, completer: DeleteCompleter): DeleteModel = KotlinDeleteBuilder(SqlBuilder.deleteFrom(table, tableAlias)).apply(completer).build() -fun insert(row: T, completer: KotlinInsertCompleter): InsertModel = - KotlinInsertBuilder(row).apply(completer).build() +fun insert(row: T & Any, completer: KotlinInsertCompleter): InsertModel { + val f : KotlinInsertBuilder = KotlinInsertBuilder(row) + return f.apply(completer).build() +} -fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsertModel = - KotlinBatchInsertBuilder(rows).apply(completer).build() +fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsertModel { + val f: KotlinBatchInsertBuilder = KotlinBatchInsertBuilder(rows) + return f.apply(completer).build() +} fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInsertModel = KotlinGeneralInsertBuilder(table).apply(completer).build() -fun insertMultiple(rows: Collection, completer: KotlinMultiRowInsertCompleter): MultiRowInsertModel = - KotlinMultiRowInsertBuilder(rows).apply(completer).build() +fun insertMultiple(rows: Collection, completer: KotlinMultiRowInsertCompleter): MultiRowInsertModel { + val f: KotlinMultiRowInsertBuilder = KotlinMultiRowInsertBuilder(rows) + return f.apply(completer).build() +} fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelectModel = with(KotlinInsertSelectSubQueryBuilder().apply(completer)) { diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt index fa4643563..62a1897dd 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt @@ -19,6 +19,7 @@ package org.mybatis.dynamic.sql.util.kotlin.mybatis3 import org.mybatis.dynamic.sql.BasicColumn import org.mybatis.dynamic.sql.SqlTable import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider +import org.mybatis.dynamic.sql.insert.render.BatchInsert import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider @@ -65,14 +66,17 @@ fun deleteFrom(mapper: (DeleteStatementProvider) -> Int, table: SqlTable, comple fun insert( mapper: (InsertStatementProvider) -> Int, - row: T, + row: T & Any, table: SqlTable, completer: KotlinInsertCompleter -): Int = - insert(row) { +): Int { + val f : InsertStatementProvider = insert(row) { into(table) run(completer) - }.run(mapper) + } + + return f.run(mapper) +} /** * This function simply inserts all rows using the supplied mapper. It is up @@ -83,14 +87,17 @@ fun insert( */ fun insertBatch( mapper: (InsertStatementProvider) -> Int, - records: Collection, + records: Collection, table: SqlTable, completer: KotlinBatchInsertCompleter -): List = - insertBatch(records) { +): List { + val f: BatchInsert = insertBatch(records) { into(table) run(completer) - }.insertStatements().map(mapper) + } + + return f.insertStatements().map(mapper) +} fun insertInto( mapper: (GeneralInsertStatementProvider) -> Int, @@ -101,27 +108,33 @@ fun insertInto( fun insertMultiple( mapper: (MultiRowInsertStatementProvider) -> Int, - records: Collection, + records: Collection, table: SqlTable, completer: KotlinMultiRowInsertCompleter -): Int = - insertMultiple(records) { +): Int { + val f: MultiRowInsertStatementProvider = insertMultiple(records) { into(table) run(completer) - }.run(mapper) + } + + return f.run(mapper) +} fun insertMultipleWithGeneratedKeys( mapper: (String, List) -> Int, - records: Collection, + records: Collection, table: SqlTable, completer: KotlinMultiRowInsertCompleter -): Int = - insertMultiple(records) { +): Int { + val f: MultiRowInsertStatementProvider = insertMultiple(records) { into(table) run(completer) - }.run { + } + + return f.run { mapper(insertStatement, this.records) } +} fun insertSelect( mapper: (InsertSelectStatementProvider) -> Int, diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt index e58e7c707..2cdb7c0ec 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt @@ -68,17 +68,17 @@ fun deleteFrom(table: SqlTable, completer: DeleteCompleter): DeleteStatementProv fun deleteFrom(table: SqlTable, tableAlias: String, completer: DeleteCompleter): DeleteStatementProvider = deleteFrom(table, tableAlias, completer).render(RenderingStrategies.MYBATIS3) -fun insert(row: T, completer: KotlinInsertCompleter): InsertStatementProvider = +fun insert(row: T & Any, completer: KotlinInsertCompleter): InsertStatementProvider = insert(row, completer).render(RenderingStrategies.MYBATIS3) -fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsert = +fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsert = insertBatch(rows, completer).render(RenderingStrategies.MYBATIS3) fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInsertStatementProvider = insertInto(table, completer).render(RenderingStrategies.MYBATIS3) fun insertMultiple( - rows: Collection, + rows: Collection, completer: KotlinMultiRowInsertCompleter ): MultiRowInsertStatementProvider = insertMultiple(rows, completer).render(RenderingStrategies.MYBATIS3) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt index 20d1b4663..98cdaff2b 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt @@ -68,14 +68,14 @@ fun NamedParameterJdbcTemplate.deleteFrom(table: SqlTable, completer: DeleteComp fun NamedParameterJdbcTemplate.insertBatch(insertStatement: BatchInsert): IntArray = batchUpdate(insertStatement.insertStatementSQL, SqlParameterSourceUtils.createBatch(insertStatement.records)) -fun NamedParameterJdbcTemplate.insertBatch( - vararg records: T, +fun NamedParameterJdbcTemplate.insertBatch( + vararg records: T & Any, completer: KotlinBatchInsertCompleter ): IntArray = insertBatch(records.asList(), completer) -fun NamedParameterJdbcTemplate.insertBatch( - records: List, +fun NamedParameterJdbcTemplate.insertBatch( + records: List, completer: KotlinBatchInsertCompleter ): IntArray = insertBatch(org.mybatis.dynamic.sql.util.kotlin.spring.insertBatch(records, completer)) @@ -89,16 +89,16 @@ fun NamedParameterJdbcTemplate.insertBatch(records: List): BatchIns BatchInsertHelper(records, this) // single row insert -fun NamedParameterJdbcTemplate.insert(insertStatement: InsertStatementProvider): Int = +fun NamedParameterJdbcTemplate.insert(insertStatement: InsertStatementProvider): Int = update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.row)) -fun NamedParameterJdbcTemplate.insert( +fun NamedParameterJdbcTemplate.insert( insertStatement: InsertStatementProvider, keyHolder: KeyHolder ): Int = update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.row), keyHolder) -fun NamedParameterJdbcTemplate.insert(row: T, completer: KotlinInsertCompleter): Int = +fun NamedParameterJdbcTemplate.insert(row: T & Any, completer: KotlinInsertCompleter): Int = insert(org.mybatis.dynamic.sql.util.kotlin.spring.insert(row, completer)) @Deprecated("Please move the into phrase inside the lambda") @@ -119,14 +119,14 @@ fun NamedParameterJdbcTemplate.insertInto(table: SqlTable, completer: GeneralIns generalInsert(org.mybatis.dynamic.sql.util.kotlin.spring.insertInto(table, completer)) // multiple row insert -fun NamedParameterJdbcTemplate.insertMultiple( - vararg records: T - , completer: KotlinMultiRowInsertCompleter +fun NamedParameterJdbcTemplate.insertMultiple( + vararg records: T & Any, + completer: KotlinMultiRowInsertCompleter ): Int = insertMultiple(records.asList(), completer) -fun NamedParameterJdbcTemplate.insertMultiple( - records: List, +fun NamedParameterJdbcTemplate.insertMultiple( + records: List, completer: KotlinMultiRowInsertCompleter ): Int = insertMultiple(org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple(records, completer)) @@ -202,10 +202,10 @@ fun NamedParameterJdbcTemplate.selectList( ): List = query(selectStatement.selectStatement, selectStatement.parameters, rowMapper) -fun NamedParameterJdbcTemplate.selectList( +fun NamedParameterJdbcTemplate.selectList( selectStatement: SelectStatementProvider, - type: KClass -): List = + type: KClass +): List = queryForList(selectStatement.selectStatement, selectStatement.parameters, type.java) fun NamedParameterJdbcTemplate.selectOne( @@ -239,9 +239,9 @@ fun NamedParameterJdbcTemplate.selectOne( } @SuppressWarnings("SwallowedException") -fun NamedParameterJdbcTemplate.selectOne( +fun NamedParameterJdbcTemplate.selectOne( selectStatement: SelectStatementProvider, - type: KClass + type: KClass ): T? = try { queryForObject(selectStatement.selectStatement, selectStatement.parameters, type.java) } catch (e: EmptyResultDataAccessException) { @@ -284,17 +284,17 @@ class KeyHolderHelper(private val keyHolder: KeyHolder, private val template: Na fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): Int = template.generalInsert(org.mybatis.dynamic.sql.util.kotlin.spring.insertInto(table, completer), keyHolder) - fun insert(row: T, completer: KotlinInsertCompleter): Int = + fun insert(row: T & Any, completer: KotlinInsertCompleter): Int = template.insert(org.mybatis.dynamic.sql.util.kotlin.spring.insert(row, completer), keyHolder) @Deprecated("Please move the into phrase inside the lambda") fun insert(row: T): SingleRowInsertWithKeyHolderHelper = SingleRowInsertWithKeyHolderHelper(row, template, keyHolder) - fun insertMultiple(vararg records: T, completer: KotlinMultiRowInsertCompleter): Int = + fun insertMultiple(vararg records: T & Any, completer: KotlinMultiRowInsertCompleter): Int = insertMultiple(records.asList(), completer) - fun insertMultiple(records: List, completer: KotlinMultiRowInsertCompleter): Int = + fun insertMultiple(records: List, completer: KotlinMultiRowInsertCompleter): Int = template.insertMultiple(org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple(records, completer), keyHolder) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt index 7fcb6bd39..32b58dd13 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt @@ -68,17 +68,17 @@ fun deleteFrom(table: SqlTable, completer: DeleteCompleter): DeleteStatementProv fun deleteFrom(table: SqlTable, tableAlias: String, completer: DeleteCompleter): DeleteStatementProvider = deleteFrom(table, tableAlias, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) -fun insert(row: T, completer: KotlinInsertCompleter): InsertStatementProvider = +fun insert(row: T & Any, completer: KotlinInsertCompleter): InsertStatementProvider = insert(row, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) -fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsert = +fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsert = insertBatch(rows, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInsertStatementProvider = insertInto(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) fun insertMultiple( - rows: Collection, + rows: Collection, completer: KotlinMultiRowInsertCompleter ): MultiRowInsertStatementProvider = insertMultiple(rows, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) From b819973fe67a02f7719d777148afee57b2b11530 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 20 Jun 2022 07:48:57 -0400 Subject: [PATCH 20/26] Style updates and simplification --- .../kotlin/model/ModelBuilderFunctions.kt | 12 ++-- .../kotlin/mybatis3/MapperSupportFunctions.kt | 58 ++++++++----------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt index 5bd629bbc..0ea7d831f 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt @@ -66,21 +66,21 @@ fun deleteFrom(table: SqlTable, tableAlias: String, completer: DeleteCompleter): KotlinDeleteBuilder(SqlBuilder.deleteFrom(table, tableAlias)).apply(completer).build() fun insert(row: T & Any, completer: KotlinInsertCompleter): InsertModel { - val f : KotlinInsertBuilder = KotlinInsertBuilder(row) - return f.apply(completer).build() + val builder : KotlinInsertBuilder = KotlinInsertBuilder(row) + return builder.apply(completer).build() } fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsertModel { - val f: KotlinBatchInsertBuilder = KotlinBatchInsertBuilder(rows) - return f.apply(completer).build() + val builder: KotlinBatchInsertBuilder = KotlinBatchInsertBuilder(rows) + return builder.apply(completer).build() } fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInsertModel = KotlinGeneralInsertBuilder(table).apply(completer).build() fun insertMultiple(rows: Collection, completer: KotlinMultiRowInsertCompleter): MultiRowInsertModel { - val f: KotlinMultiRowInsertBuilder = KotlinMultiRowInsertBuilder(rows) - return f.apply(completer).build() + val builder: KotlinMultiRowInsertBuilder = KotlinMultiRowInsertBuilder(rows) + return builder.apply(completer).build() } fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelectModel = diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt index 62a1897dd..d13ca4a6f 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt @@ -42,10 +42,10 @@ fun count( table: SqlTable, completer: CountCompleter ): Long = - count(column) { + mapper(count(column) { from(table) run(completer) - }.run(mapper) + }) fun countDistinct( mapper: (SelectStatementProvider) -> Long, @@ -53,30 +53,27 @@ fun countDistinct( table: SqlTable, completer: CountCompleter ): Long = - countDistinct(column) { + mapper(countDistinct(column) { from(table) run(completer) - }.run(mapper) + }) fun countFrom(mapper: (SelectStatementProvider) -> Long, table: SqlTable, completer: CountCompleter): Long = - countFrom(table, completer).run(mapper) + mapper(countFrom(table, completer)) fun deleteFrom(mapper: (DeleteStatementProvider) -> Int, table: SqlTable, completer: DeleteCompleter): Int = - deleteFrom(table, completer).run(mapper) + mapper(deleteFrom(table, completer)) fun insert( mapper: (InsertStatementProvider) -> Int, row: T & Any, table: SqlTable, completer: KotlinInsertCompleter -): Int { - val f : InsertStatementProvider = insert(row) { +): Int = + mapper(insert(row) { into(table) run(completer) - } - - return f.run(mapper) -} + }) /** * This function simply inserts all rows using the supplied mapper. It is up @@ -91,12 +88,12 @@ fun insertBatch( table: SqlTable, completer: KotlinBatchInsertCompleter ): List { - val f: BatchInsert = insertBatch(records) { + val batchInsert: BatchInsert = insertBatch(records) { into(table) run(completer) } - return f.insertStatements().map(mapper) + return batchInsert.insertStatements().map(mapper) } fun insertInto( @@ -104,21 +101,18 @@ fun insertInto( table: SqlTable, completer: GeneralInsertCompleter ): Int = - insertInto(table, completer).run(mapper) + mapper(insertInto(table, completer)) fun insertMultiple( mapper: (MultiRowInsertStatementProvider) -> Int, records: Collection, table: SqlTable, completer: KotlinMultiRowInsertCompleter -): Int { - val f: MultiRowInsertStatementProvider = insertMultiple(records) { +): Int = + mapper(insertMultiple(records) { into(table) run(completer) - } - - return f.run(mapper) -} + }) fun insertMultipleWithGeneratedKeys( mapper: (String, List) -> Int, @@ -126,14 +120,12 @@ fun insertMultipleWithGeneratedKeys( table: SqlTable, completer: KotlinMultiRowInsertCompleter ): Int { - val f: MultiRowInsertStatementProvider = insertMultiple(records) { + val provider: MultiRowInsertStatementProvider = insertMultiple(records) { into(table) run(completer) } - return f.run { - mapper(insertStatement, this.records) - } + return mapper(provider.insertStatement, provider.records) } fun insertSelect( @@ -141,7 +133,7 @@ fun insertSelect( table: SqlTable, completer: InsertSelectCompleter ): Int = - insertSelect(table, completer).run(mapper) + mapper(insertSelect(table, completer)) fun selectDistinct( mapper: (SelectStatementProvider) -> List, @@ -149,10 +141,10 @@ fun selectDistinct( table: SqlTable, completer: SelectCompleter ): List = - selectDistinct(selectList) { + mapper(selectDistinct(selectList) { from(table) run(completer) - }.run(mapper) + }) fun selectList( mapper: (SelectStatementProvider) -> List, @@ -160,10 +152,10 @@ fun selectList( table: SqlTable, completer: SelectCompleter ): List = - select(selectList) { + mapper(select(selectList) { from(table) run(completer) - }.run(mapper) + }) fun selectOne( mapper: (SelectStatementProvider) -> T?, @@ -171,10 +163,10 @@ fun selectOne( table: SqlTable, completer: SelectCompleter ): T? = - select(selectList) { + mapper(select(selectList) { from(table) run(completer) - }.run(mapper) + }) fun update(mapper: (UpdateStatementProvider) -> Int, table: SqlTable, completer: UpdateCompleter): Int = - update(table, completer).run(mapper) + mapper(update(table, completer)) From 4edac4f4ebf184939eaa0792492244bb02b5d096 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 20 Jun 2022 14:45:00 -0400 Subject: [PATCH 21/26] Checkstyle updates --- src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java | 3 ++- .../sql/insert/render/DefaultInsertStatementProvider.java | 4 ++-- .../mybatis/dynamic/sql/update/render/SetPhraseVisitor.java | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java b/src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java index eba241267..4c06507b9 100644 --- a/src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java +++ b/src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java @@ -59,7 +59,8 @@ public R build() { return adapterFunction.apply(deleteModel); } - public static DeleteDSL deleteFrom(Function adapterFunction, SqlTable table, String tableAlias) { + public static DeleteDSL deleteFrom(Function adapterFunction, SqlTable table, + String tableAlias) { return new DeleteDSL<>(table, tableAlias, adapterFunction); } diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java b/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java index d330d362e..1fc9a54ae 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java @@ -15,10 +15,10 @@ */ package org.mybatis.dynamic.sql.insert.render; -import org.jetbrains.annotations.NotNull; - import java.util.Objects; +import org.jetbrains.annotations.NotNull; + public class DefaultInsertStatementProvider implements InsertStatementProvider { private final String insertStatement; // need to keep both row and record for now so we don't break diff --git a/src/main/java/org/mybatis/dynamic/sql/update/render/SetPhraseVisitor.java b/src/main/java/org/mybatis/dynamic/sql/update/render/SetPhraseVisitor.java index 0b2ef7359..de1937349 100644 --- a/src/main/java/org/mybatis/dynamic/sql/update/render/SetPhraseVisitor.java +++ b/src/main/java/org/mybatis/dynamic/sql/update/render/SetPhraseVisitor.java @@ -55,7 +55,8 @@ public SetPhraseVisitor(AtomicInteger sequence, RenderingStrategy renderingStrat @Override public Optional visit(NullMapping mapping) { - return FragmentAndParameters.withFragment(mapping.mapColumn(aliasedColumnNameFunction) + " = null") //$NON-NLS-1$ + return FragmentAndParameters + .withFragment(mapping.mapColumn(aliasedColumnNameFunction) + " = null") //$NON-NLS-1$ .buildOptional(); } From ca920a561af210d25639aea82eff1cae367e7556 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 20 Jun 2022 16:19:34 -0400 Subject: [PATCH 22/26] Correct nullability for insert methods --- .../util/kotlin/KotlinBatchInsertBuilder.kt | 2 +- .../sql/util/kotlin/KotlinInsertBuilder.kt | 2 +- .../kotlin/KotlinMultiRowInsertBuilder.kt | 2 +- .../kotlin/model/ModelBuilderFunctions.kt | 17 ++++----- .../kotlin/mybatis3/MapperSupportFunctions.kt | 35 ++++++++----------- .../mybatis3/ProviderBuilderFunctions.kt | 8 ++--- .../NamedParameterJdbcTemplateExtensions.kt | 24 ++++++------- .../kotlin/spring/ProviderBuilderFunctions.kt | 8 ++--- 8 files changed, 44 insertions(+), 54 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt index a44256716..84e066dfb 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBatchInsertBuilder.kt @@ -25,7 +25,7 @@ import org.mybatis.dynamic.sql.util.Buildable typealias KotlinBatchInsertCompleter = KotlinBatchInsertBuilder.() -> Unit @MyBatisDslMarker -class KotlinBatchInsertBuilder (private val rows: Collection): Buildable> { +class KotlinBatchInsertBuilder (private val rows: Collection): Buildable> { private var table: SqlTable? = null private val columnMappings = mutableListOf() diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt index cb6089bd4..fb7df5d38 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinInsertBuilder.kt @@ -25,7 +25,7 @@ import org.mybatis.dynamic.sql.util.Buildable typealias KotlinInsertCompleter = KotlinInsertBuilder.() -> Unit @MyBatisDslMarker -class KotlinInsertBuilder (private val row: T & Any): Buildable> { +class KotlinInsertBuilder (private val row: T): Buildable> { private var table: SqlTable? = null private val columnMappings = mutableListOf() diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt index aef60d937..3a7a48a7f 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinMultiRowInsertBuilder.kt @@ -25,7 +25,7 @@ import org.mybatis.dynamic.sql.util.Buildable typealias KotlinMultiRowInsertCompleter = KotlinMultiRowInsertBuilder.() -> Unit @MyBatisDslMarker -class KotlinMultiRowInsertBuilder (private val rows: Collection): Buildable> { +class KotlinMultiRowInsertBuilder (private val rows: Collection): Buildable> { private var table: SqlTable? = null private val columnMappings = mutableListOf() diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt index 0ea7d831f..cf2f962bd 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt @@ -65,23 +65,18 @@ fun deleteFrom(table: SqlTable, completer: DeleteCompleter): DeleteModel = fun deleteFrom(table: SqlTable, tableAlias: String, completer: DeleteCompleter): DeleteModel = KotlinDeleteBuilder(SqlBuilder.deleteFrom(table, tableAlias)).apply(completer).build() -fun insert(row: T & Any, completer: KotlinInsertCompleter): InsertModel { - val builder : KotlinInsertBuilder = KotlinInsertBuilder(row) - return builder.apply(completer).build() -} +fun insert(row: T, completer: KotlinInsertCompleter): InsertModel = + KotlinInsertBuilder(row).apply(completer).build() -fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsertModel { - val builder: KotlinBatchInsertBuilder = KotlinBatchInsertBuilder(rows) - return builder.apply(completer).build() +fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsertModel { + return KotlinBatchInsertBuilder(rows).apply(completer).build() } fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInsertModel = KotlinGeneralInsertBuilder(table).apply(completer).build() -fun insertMultiple(rows: Collection, completer: KotlinMultiRowInsertCompleter): MultiRowInsertModel { - val builder: KotlinMultiRowInsertBuilder = KotlinMultiRowInsertBuilder(rows) - return builder.apply(completer).build() -} +fun insertMultiple(rows: Collection, completer: KotlinMultiRowInsertCompleter): MultiRowInsertModel = + KotlinMultiRowInsertBuilder(rows).apply(completer).build() fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelectModel = with(KotlinInsertSelectSubQueryBuilder().apply(completer)) { diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt index d13ca4a6f..547d55230 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt @@ -19,7 +19,6 @@ package org.mybatis.dynamic.sql.util.kotlin.mybatis3 import org.mybatis.dynamic.sql.BasicColumn import org.mybatis.dynamic.sql.SqlTable import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider -import org.mybatis.dynamic.sql.insert.render.BatchInsert import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider @@ -64,9 +63,9 @@ fun countFrom(mapper: (SelectStatementProvider) -> Long, table: SqlTable, comple fun deleteFrom(mapper: (DeleteStatementProvider) -> Int, table: SqlTable, completer: DeleteCompleter): Int = mapper(deleteFrom(table, completer)) -fun insert( +fun insert( mapper: (InsertStatementProvider) -> Int, - row: T & Any, + row: T, table: SqlTable, completer: KotlinInsertCompleter ): Int = @@ -82,19 +81,16 @@ fun insert( * list will be [org.apache.ibatis.executor.BatchExecutor.BATCH_UPDATE_RETURN_VALUE]). * To retrieve update counts, execute [org.apache.ibatis.session.SqlSession.flushStatements]. */ -fun insertBatch( +fun insertBatch( mapper: (InsertStatementProvider) -> Int, - records: Collection, + records: Collection, table: SqlTable, completer: KotlinBatchInsertCompleter -): List { - val batchInsert: BatchInsert = insertBatch(records) { +): List = + insertBatch(records) { into(table) run(completer) - } - - return batchInsert.insertStatements().map(mapper) -} + }.insertStatements().map(mapper) fun insertInto( mapper: (GeneralInsertStatementProvider) -> Int, @@ -103,9 +99,9 @@ fun insertInto( ): Int = mapper(insertInto(table, completer)) -fun insertMultiple( +fun insertMultiple( mapper: (MultiRowInsertStatementProvider) -> Int, - records: Collection, + records: Collection, table: SqlTable, completer: KotlinMultiRowInsertCompleter ): Int = @@ -114,20 +110,19 @@ fun insertMultiple( run(completer) }) -fun insertMultipleWithGeneratedKeys( +fun insertMultipleWithGeneratedKeys( mapper: (String, List) -> Int, - records: Collection, + records: Collection, table: SqlTable, completer: KotlinMultiRowInsertCompleter -): Int { - val provider: MultiRowInsertStatementProvider = insertMultiple(records) { +): Int = + insertMultiple(records) { into(table) run(completer) + }.run { + mapper(insertStatement, this.records) } - return mapper(provider.insertStatement, provider.records) -} - fun insertSelect( mapper: (InsertSelectStatementProvider) -> Int, table: SqlTable, diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt index 2cdb7c0ec..2b1950b77 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt @@ -68,17 +68,17 @@ fun deleteFrom(table: SqlTable, completer: DeleteCompleter): DeleteStatementProv fun deleteFrom(table: SqlTable, tableAlias: String, completer: DeleteCompleter): DeleteStatementProvider = deleteFrom(table, tableAlias, completer).render(RenderingStrategies.MYBATIS3) -fun insert(row: T & Any, completer: KotlinInsertCompleter): InsertStatementProvider = +fun insert(row: T, completer: KotlinInsertCompleter): InsertStatementProvider = insert(row, completer).render(RenderingStrategies.MYBATIS3) -fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsert = +fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsert = insertBatch(rows, completer).render(RenderingStrategies.MYBATIS3) fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInsertStatementProvider = insertInto(table, completer).render(RenderingStrategies.MYBATIS3) -fun insertMultiple( - rows: Collection, +fun insertMultiple( + rows: Collection, completer: KotlinMultiRowInsertCompleter ): MultiRowInsertStatementProvider = insertMultiple(rows, completer).render(RenderingStrategies.MYBATIS3) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt index 98cdaff2b..a5c7bb679 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt @@ -68,14 +68,14 @@ fun NamedParameterJdbcTemplate.deleteFrom(table: SqlTable, completer: DeleteComp fun NamedParameterJdbcTemplate.insertBatch(insertStatement: BatchInsert): IntArray = batchUpdate(insertStatement.insertStatementSQL, SqlParameterSourceUtils.createBatch(insertStatement.records)) -fun NamedParameterJdbcTemplate.insertBatch( - vararg records: T & Any, +fun NamedParameterJdbcTemplate.insertBatch( + vararg records: T, completer: KotlinBatchInsertCompleter ): IntArray = insertBatch(records.asList(), completer) -fun NamedParameterJdbcTemplate.insertBatch( - records: List, +fun NamedParameterJdbcTemplate.insertBatch( + records: List, completer: KotlinBatchInsertCompleter ): IntArray = insertBatch(org.mybatis.dynamic.sql.util.kotlin.spring.insertBatch(records, completer)) @@ -98,7 +98,7 @@ fun NamedParameterJdbcTemplate.insert( ): Int = update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.row), keyHolder) -fun NamedParameterJdbcTemplate.insert(row: T & Any, completer: KotlinInsertCompleter): Int = +fun NamedParameterJdbcTemplate.insert(row: T, completer: KotlinInsertCompleter): Int = insert(org.mybatis.dynamic.sql.util.kotlin.spring.insert(row, completer)) @Deprecated("Please move the into phrase inside the lambda") @@ -119,14 +119,14 @@ fun NamedParameterJdbcTemplate.insertInto(table: SqlTable, completer: GeneralIns generalInsert(org.mybatis.dynamic.sql.util.kotlin.spring.insertInto(table, completer)) // multiple row insert -fun NamedParameterJdbcTemplate.insertMultiple( - vararg records: T & Any, +fun NamedParameterJdbcTemplate.insertMultiple( + vararg records: T, completer: KotlinMultiRowInsertCompleter ): Int = insertMultiple(records.asList(), completer) -fun NamedParameterJdbcTemplate.insertMultiple( - records: List, +fun NamedParameterJdbcTemplate.insertMultiple( + records: List, completer: KotlinMultiRowInsertCompleter ): Int = insertMultiple(org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple(records, completer)) @@ -284,17 +284,17 @@ class KeyHolderHelper(private val keyHolder: KeyHolder, private val template: Na fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): Int = template.generalInsert(org.mybatis.dynamic.sql.util.kotlin.spring.insertInto(table, completer), keyHolder) - fun insert(row: T & Any, completer: KotlinInsertCompleter): Int = + fun insert(row: T, completer: KotlinInsertCompleter): Int = template.insert(org.mybatis.dynamic.sql.util.kotlin.spring.insert(row, completer), keyHolder) @Deprecated("Please move the into phrase inside the lambda") fun insert(row: T): SingleRowInsertWithKeyHolderHelper = SingleRowInsertWithKeyHolderHelper(row, template, keyHolder) - fun insertMultiple(vararg records: T & Any, completer: KotlinMultiRowInsertCompleter): Int = + fun insertMultiple(vararg records: T, completer: KotlinMultiRowInsertCompleter): Int = insertMultiple(records.asList(), completer) - fun insertMultiple(records: List, completer: KotlinMultiRowInsertCompleter): Int = + fun insertMultiple(records: List, completer: KotlinMultiRowInsertCompleter): Int = template.insertMultiple(org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple(records, completer), keyHolder) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt index 32b58dd13..fcb70e746 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt @@ -68,17 +68,17 @@ fun deleteFrom(table: SqlTable, completer: DeleteCompleter): DeleteStatementProv fun deleteFrom(table: SqlTable, tableAlias: String, completer: DeleteCompleter): DeleteStatementProvider = deleteFrom(table, tableAlias, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) -fun insert(row: T & Any, completer: KotlinInsertCompleter): InsertStatementProvider = +fun insert(row: T, completer: KotlinInsertCompleter): InsertStatementProvider = insert(row, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) -fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsert = +fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsert = insertBatch(rows, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInsertStatementProvider = insertInto(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) -fun insertMultiple( - rows: Collection, +fun insertMultiple( + rows: Collection, completer: KotlinMultiRowInsertCompleter ): MultiRowInsertStatementProvider = insertMultiple(rows, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) From c62a1566610f0de14336330fc14f873bb867035a Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Tue, 21 Jun 2022 16:19:06 -0400 Subject: [PATCH 23/26] Style --- .../dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt index cf2f962bd..45478711e 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt @@ -68,9 +68,8 @@ fun deleteFrom(table: SqlTable, tableAlias: String, completer: DeleteCompleter): fun insert(row: T, completer: KotlinInsertCompleter): InsertModel = KotlinInsertBuilder(row).apply(completer).build() -fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsertModel { - return KotlinBatchInsertBuilder(rows).apply(completer).build() -} +fun insertBatch(rows: Collection, completer: KotlinBatchInsertCompleter): BatchInsertModel = + KotlinBatchInsertBuilder(rows).apply(completer).build() fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInsertModel = KotlinGeneralInsertBuilder(table).apply(completer).build() From cbeff50ac16433f994446239bf4b59c2fba6b2f9 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Tue, 21 Jun 2022 17:49:37 -0400 Subject: [PATCH 24/26] Better nullability specs --- .../kotlin/spring/NamedParameterJdbcTemplateExtensions.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt index a5c7bb679..6bf0ebe2b 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt @@ -202,9 +202,9 @@ fun NamedParameterJdbcTemplate.selectList( ): List = query(selectStatement.selectStatement, selectStatement.parameters, rowMapper) -fun NamedParameterJdbcTemplate.selectList( +fun NamedParameterJdbcTemplate.selectList( selectStatement: SelectStatementProvider, - type: KClass + type: KClass ): List = queryForList(selectStatement.selectStatement, selectStatement.parameters, type.java) @@ -239,9 +239,9 @@ fun NamedParameterJdbcTemplate.selectOne( } @SuppressWarnings("SwallowedException") -fun NamedParameterJdbcTemplate.selectOne( +fun NamedParameterJdbcTemplate.selectOne( selectStatement: SelectStatementProvider, - type: KClass + type: KClass ): T? = try { queryForObject(selectStatement.selectStatement, selectStatement.parameters, type.java) } catch (e: EmptyResultDataAccessException) { From 055d021319e510f07910130555205ccf17782a56 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 27 Jun 2022 17:07:16 -0400 Subject: [PATCH 25/26] Restore old pattern for running mappers --- .../kotlin/mybatis3/MapperSupportFunctions.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt index 547d55230..941be61af 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/MapperSupportFunctions.kt @@ -41,10 +41,10 @@ fun count( table: SqlTable, completer: CountCompleter ): Long = - mapper(count(column) { + count(column) { from(table) run(completer) - }) + }.run(mapper) fun countDistinct( mapper: (SelectStatementProvider) -> Long, @@ -52,16 +52,16 @@ fun countDistinct( table: SqlTable, completer: CountCompleter ): Long = - mapper(countDistinct(column) { + countDistinct(column) { from(table) run(completer) - }) + }.run(mapper) fun countFrom(mapper: (SelectStatementProvider) -> Long, table: SqlTable, completer: CountCompleter): Long = - mapper(countFrom(table, completer)) + countFrom(table, completer).run(mapper) fun deleteFrom(mapper: (DeleteStatementProvider) -> Int, table: SqlTable, completer: DeleteCompleter): Int = - mapper(deleteFrom(table, completer)) + deleteFrom(table, completer).run(mapper) fun insert( mapper: (InsertStatementProvider) -> Int, @@ -69,10 +69,10 @@ fun insert( table: SqlTable, completer: KotlinInsertCompleter ): Int = - mapper(insert(row) { + insert(row) { into(table) run(completer) - }) + }.run(mapper) /** * This function simply inserts all rows using the supplied mapper. It is up @@ -97,7 +97,7 @@ fun insertInto( table: SqlTable, completer: GeneralInsertCompleter ): Int = - mapper(insertInto(table, completer)) + insertInto(table, completer).run(mapper) fun insertMultiple( mapper: (MultiRowInsertStatementProvider) -> Int, @@ -105,10 +105,10 @@ fun insertMultiple( table: SqlTable, completer: KotlinMultiRowInsertCompleter ): Int = - mapper(insertMultiple(records) { + insertMultiple(records) { into(table) run(completer) - }) + }.run(mapper) fun insertMultipleWithGeneratedKeys( mapper: (String, List) -> Int, @@ -128,7 +128,7 @@ fun insertSelect( table: SqlTable, completer: InsertSelectCompleter ): Int = - mapper(insertSelect(table, completer)) + insertSelect(table, completer).run(mapper) fun selectDistinct( mapper: (SelectStatementProvider) -> List, @@ -136,10 +136,10 @@ fun selectDistinct( table: SqlTable, completer: SelectCompleter ): List = - mapper(selectDistinct(selectList) { + selectDistinct(selectList) { from(table) run(completer) - }) + }.run(mapper) fun selectList( mapper: (SelectStatementProvider) -> List, @@ -147,10 +147,10 @@ fun selectList( table: SqlTable, completer: SelectCompleter ): List = - mapper(select(selectList) { + select(selectList) { from(table) run(completer) - }) + }.run(mapper) fun selectOne( mapper: (SelectStatementProvider) -> T?, @@ -158,10 +158,10 @@ fun selectOne( table: SqlTable, completer: SelectCompleter ): T? = - mapper(select(selectList) { + select(selectList) { from(table) run(completer) - }) + }.run(mapper) fun update(mapper: (UpdateStatementProvider) -> Int, table: SqlTable, completer: UpdateCompleter): Int = - mapper(update(table, completer)) + update(table, completer).run(mapper) From ec771bdfc2e401d8d1428e99c41c22511aac2a04 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Mon, 27 Jun 2022 17:14:59 -0400 Subject: [PATCH 26/26] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc2cb462..21e7cb3aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles 2. Added the ability to specify a table alias on DELETE and UPDATE statements. This is especially useful when working with a sub-query with an exists or not exists condition. ([#489](https://github.com/mybatis/mybatis-dynamic-sql/pull/489)) +3. Updated the Kotlin DSL to use Kotlin 1.7's new "definitely non-null" types where appropriate. This helps us to more + accurately represent the nullable/non-nullable expectations for API method calls. + ([#496](https://github.com/mybatis/mybatis-dynamic-sql/pull/496)) ## Release 1.4.0 - March 3, 2022