From f686ea572a55a9e605cf09c9510c3c3be6d27ea2 Mon Sep 17 00:00:00 2001 From: waahhh Date: Mon, 13 Nov 2023 20:17:27 +0900 Subject: [PATCH 1/2] fix(render): parentheses are not rendered, when only call writeParam() methods inside writeParentheses() --- .../kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriter.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriter.kt b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriter.kt index 7d085c832..7541d0b47 100644 --- a/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriter.kt +++ b/render/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriter.kt @@ -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 { From 48ee9209fbd07ef671d532703bb6ed262dcad894 Mon Sep 17 00:00:00 2001 From: waahhh Date: Mon, 13 Nov 2023 20:20:47 +0900 Subject: [PATCH 2/2] test(render): only call writeParam() methods inside writeParentheses() --- .../jpql/writer/impl/DefaultJpqlWriterTest.kt | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriterTest.kt b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriterTest.kt index 86fcb3843..5c642d0f1 100644 --- a/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriterTest.kt +++ b/render/jpql/src/test/kotlin/com/linecorp/kotlinjdsl/render/jpql/writer/impl/DefaultJpqlWriterTest.kt @@ -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