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 Malfunction - only call writeParam() methods inside writeParentheses() method #524

Merged
merged 2 commits into from
Nov 13, 2023
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 @@ -76,10 +76,12 @@ internal class DefaultJpqlWriter private constructor(

override fun writeParam(value: Any?) {
internal.writeParam(value)
nodes.add(Node.String())
}

override fun writeParam(name: String, value: Any?) {
internal.writeParam(name, value)
nodes.add(Node.String())
}

fun getQuery(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,115 @@ class DefaultJpqlWriterTest : WithAssertions {
assertThat(actualQuery).isEqualTo("(:param1 ($string1) :param2)")
}

@Test
fun `writeParentheses() prints a param inside parentheses, when there is the param with a value`() {
// when
sut.writeParentheses {
sut.writeParam(paramValue1)
}

val actualParam = sut.getParams()
val actualQuery = sut.getQuery()

println(actualParam)
println(actualQuery)
// then
assertThat(actualParam).containsEntry("param1", paramValue1)
assertThat(actualQuery).isEqualTo("(:param1)")
}

@Test
fun `writeParentheses() prints a param inside parentheses, when there is the param with a name and a value`() {
// when
sut.writeParentheses {
sut.writeParam("param1", paramValue1)
}

val actualParam = sut.getParams()
val actualQuery = sut.getQuery()

println(actualParam)
println(actualQuery)
// then
assertThat(actualParam).containsEntry("param1", paramValue1)
assertThat(actualQuery).isEqualTo("(:param1)")
}

@Test
fun `writeParentheses() prints all params inside parentheses, when there are params with a value`() {
// when
sut.writeParentheses {
sut.writeParam(paramValue1)
sut.writeParam(paramValue2)
sut.writeParam(paramValue3)
}

val actualParam = sut.getParams()
val actualQuery = sut.getQuery()

println(actualParam)
println(actualQuery)
// then
assertThat(actualParam).containsAllEntriesOf(
mapOf(
"param1" to paramValue1,
"param2" to paramValue2,
"param3" to paramValue3,
),
)
assertThat(actualQuery).isEqualTo("(:param1:param2:param3)")
}

@Test
fun `writeParentheses() prints all params inside parentheses, when there are the params with a name and a value`() {
// when
sut.writeParentheses {
sut.writeParam("param1", paramValue1)
sut.writeParam("param2", paramValue2)
sut.writeParam("param3", paramValue3)
}

val actualParam = sut.getParams()
val actualQuery = sut.getQuery()

println(actualParam)
println(actualQuery)
// then
assertThat(actualParam).containsAllEntriesOf(
mapOf(
"param1" to paramValue1,
"param2" to paramValue2,
"param3" to paramValue3,
),
)
assertThat(actualQuery).isEqualTo("(:param1:param2:param3)")
}

@Test
fun `writeParentheses() prints all params inside parentheses, when there are the params`() {
// when
sut.writeParentheses {
sut.writeParam(paramValue1)
sut.writeParam("param2", paramValue2)
sut.writeParam("param3", paramValue3)
}

val actualParam = sut.getParams()
val actualQuery = sut.getQuery()

println(actualParam)
println(actualQuery)
// then
assertThat(actualParam).containsAllEntriesOf(
mapOf(
"param1" to paramValue1,
"param2" to paramValue2,
"param3" to paramValue3,
),
)
assertThat(actualQuery).isEqualTo("(:param1:param2:param3)")
}

@Test
fun writeParam() {
// when
Expand Down
Loading