Skip to content

Commit

Permalink
test(render): only call writeParam() methods inside writeParentheses()
Browse files Browse the repository at this point in the history
  • Loading branch information
waahhh committed Nov 13, 2023
1 parent f686ea5 commit 48ee920
Showing 1 changed file with 109 additions and 0 deletions.
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 48ee920

Please sign in to comment.