Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render false condition for in condition if the compare values is empty #704

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class JpqlInSerializer : JpqlSerializer<JpqlIn<*>> {
val delegate = context.getValue(JpqlRenderSerializer)

if (IterableUtils.isEmpty(part.compareValues)) {
return
}

delegate.serialize(part.value, writer, context)
writer.write("0 = 1")
} else {
delegate.serialize(part.value, writer, context)

writer.write(" ")
writer.write("IN")
writer.write(" ")
writer.write(" ")
writer.write("IN")
writer.write(" ")

writer.writeParentheses {
writer.writeEach(part.compareValues, separator = ", ") {
delegate.serialize(it, writer, context)
writer.writeParentheses {
writer.writeEach(part.compareValues, separator = ", ") {
delegate.serialize(it, writer, context)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class JpqlNotInSerializer : JpqlSerializer<JpqlNotIn<*>> {
val delegate = context.getValue(JpqlRenderSerializer)

if (IterableUtils.isEmpty(part.compareValues)) {
return
}

delegate.serialize(part.value, writer, context)
writer.write("0 = 1")
} else {
delegate.serialize(part.value, writer, context)

writer.write(" ")
writer.write("NOT IN")
writer.write(" ")
writer.write(" ")
writer.write("NOT IN")
writer.write(" ")

writer.writeParentheses {
writer.writeEach(part.compareValues, separator = ", ") {
delegate.serialize(it, writer, context)
writer.writeParentheses {
writer.writeEach(part.compareValues, separator = ", ") {
delegate.serialize(it, writer, context)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializerTest
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
import io.mockk.called
import io.mockk.impl.annotations.MockK
import io.mockk.verifySequence
import org.assertj.core.api.WithAssertions
Expand Down Expand Up @@ -73,7 +72,7 @@ class JpqlInSerializerTest : WithAssertions {
}

@Test
fun `serialize() draws nothing, when the compareValues is empty`() {
fun `serialize() draws 0 = 1, when the compareValues is empty`() {
// Given
val part = Predicates.`in`(
expression1,
Expand All @@ -86,7 +85,7 @@ class JpqlInSerializerTest : WithAssertions {

// Then
verifySequence {
writer wasNot called
writer.write("0 = 1")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.linecorp.kotlinjdsl.render.jpql.entity.book.Book
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlRenderSerializer
import com.linecorp.kotlinjdsl.render.jpql.serializer.JpqlSerializerTest
import com.linecorp.kotlinjdsl.render.jpql.writer.JpqlWriter
import io.mockk.called
import io.mockk.impl.annotations.MockK
import io.mockk.verifySequence
import org.assertj.core.api.WithAssertions
Expand Down Expand Up @@ -73,7 +72,7 @@ class JpqlNotInSerializerTest : WithAssertions {
}

@Test
fun `serialize() draws nothing, when the compareValues is empty`() {
fun `serialize() draws 0 = 1, when the compareValues is empty`() {
// Given
val part = Predicates.notIn(
expression1,
Expand All @@ -86,7 +85,7 @@ class JpqlNotInSerializerTest : WithAssertions {

// Then
verifySequence {
writer wasNot called
writer.write("0 = 1")
}
}
}