Skip to content

Commit

Permalink
fix: render false condition for in condition if the compare values is…
Browse files Browse the repository at this point in the history
… empty
  • Loading branch information
shouwn committed May 4, 2024
1 parent a33bf96 commit 25ce71b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
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")
}
}
}

0 comments on commit 25ce71b

Please sign in to comment.