Skip to content

Commit

Permalink
Merge pull request #524 from waahhh/fix/malfunction-write-param-method
Browse files Browse the repository at this point in the history
Fix Malfunction - only call writeParam() methods inside writeParentheses() method
  • Loading branch information
shouwn authored Nov 13, 2023
2 parents 5902e86 + 48ee920 commit ff14081
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
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

0 comments on commit ff14081

Please sign in to comment.