Skip to content

Commit

Permalink
style: support
Browse files Browse the repository at this point in the history
  • Loading branch information
shouwn committed Sep 11, 2023
1 parent 50ea79d commit f73b1fe
Show file tree
Hide file tree
Showing 34 changed files with 1,456 additions and 1,299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class JpqlCoalesceSerializer : JpqlSerializer<JpqlCoalesce<*>> {
writer.write("COALESCE")

writer.writeParentheses {
writer.writeEach(part.expr) {
writer.writeEach(part.expr, separator = ", ") {
delegate.serialize(it, writer, context)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JpqlCoalesceSerializerTest : WithAssertions {
@MockK
private lateinit var serializer: JpqlRenderSerializer

private val expression1 = Expressions.nullValue<Int>()
private val expression1 = Expressions.value(1)
private val expression2 = Expressions.value(2)
private val expression3 = Expressions.value(3)

Expand All @@ -37,7 +37,11 @@ class JpqlCoalesceSerializerTest : WithAssertions {
@Test
fun serialize() {
// given
val coalesce = Expressions.coalesce(expression1, expression2, listOf(expression3))
val coalesce = Expressions.coalesce(
expression1,
expression2,
listOf(expression3),
)
val context = TestRenderContext(serializer)

// when
Expand All @@ -46,14 +50,11 @@ class JpqlCoalesceSerializerTest : WithAssertions {
// then
verifySequence {
writer.write("COALESCE")

writer.writeParentheses(any())

val expressions = listOf(expression1, expression2, expression3)
writer.writeEach(expressions, write = any())
expressions.forEach {
serializer.serialize(it, writer, context)
}
writer.writeEach(listOf(expression1, expression2, expression3), ", ", "", "", any())
serializer.serialize(expression1, writer, context)
serializer.serialize(expression2, writer, context)
serializer.serialize(expression3, writer, context)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ class JpqlEntityManagerUtilsTest : WithAssertions {
private lateinit var entityManager: EntityManager

@MockK
private lateinit var selectQuery: SelectQuery<String>
private lateinit var renderer: JpqlRenderer

@MockK
private lateinit var updateQuery: UpdateQuery<String>
private lateinit var context: RenderContext

@MockK
private lateinit var deleteQuery: DeleteQuery<String>
private lateinit var selectQuery1: SelectQuery<String>

@MockK
private lateinit var stringTypedQuery: TypedQuery<String>
private lateinit var updateQuery1: UpdateQuery<String>

@MockK
private lateinit var renderer: JpqlRenderer
private lateinit var deleteQuery1: DeleteQuery<String>

@MockK
private lateinit var context: RenderContext
private lateinit var stringTypedQuery1: TypedQuery<String>

private val renderedQuery1 = "query"
private val renderedParam1 = "queryParam1" to "queryParamValue1"
Expand All @@ -58,7 +58,7 @@ class JpqlEntityManagerUtilsTest : WithAssertions {
every { JpqlRendererHolder.get() } returns renderer

excludeRecords { JpqlRendererHolder.get() }
excludeRecords { stringTypedQuery.equals(any()) }
excludeRecords { stringTypedQuery1.equals(any()) }
}

@Test
Expand All @@ -67,22 +67,22 @@ class JpqlEntityManagerUtilsTest : WithAssertions {
val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2)))

every { renderer.render(any(), any()) } returns rendered1
every { selectQuery.returnType } returns String::class
every { entityManager.createQuery(any<String>(), any<Class<String>>()) } returns stringTypedQuery
every { stringTypedQuery.setParameter(any<String>(), any()) } returns stringTypedQuery
every { selectQuery1.returnType } returns String::class
every { entityManager.createQuery(any<String>(), any<Class<String>>()) } returns stringTypedQuery1
every { stringTypedQuery1.setParameter(any<String>(), any()) } returns stringTypedQuery1

// when
val actual = JpqlEntityManagerUtils.createQuery(entityManager, selectQuery, context)
val actual = JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, context)

// then
assertThat(actual).isEqualTo(stringTypedQuery)
assertThat(actual).isEqualTo(stringTypedQuery1)

verifySequence {
renderer.render(selectQuery, context)
selectQuery.returnType
renderer.render(selectQuery1, context)
selectQuery1.returnType
entityManager.createQuery(rendered1.query, String::class.java)
stringTypedQuery.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery.setParameter(renderedParam2.first, renderedParam2.second)
stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second)
}
}

Expand All @@ -92,23 +92,23 @@ class JpqlEntityManagerUtilsTest : WithAssertions {
val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2)))

every { renderer.render(any(), any(), any()) } returns rendered1
every { selectQuery.returnType } returns String::class
every { entityManager.createQuery(any<String>(), any<Class<String>>()) } returns stringTypedQuery
every { stringTypedQuery.setParameter(any<String>(), any()) } returns stringTypedQuery
every { selectQuery1.returnType } returns String::class
every { entityManager.createQuery(any<String>(), any<Class<String>>()) } returns stringTypedQuery1
every { stringTypedQuery1.setParameter(any<String>(), any()) } returns stringTypedQuery1

// when
val actual =
JpqlEntityManagerUtils.createQuery(entityManager, selectQuery, mapOf(queryParam1, queryParam2), context)
JpqlEntityManagerUtils.createQuery(entityManager, selectQuery1, mapOf(queryParam1, queryParam2), context)

// then
assertThat(actual).isEqualTo(stringTypedQuery)
assertThat(actual).isEqualTo(stringTypedQuery1)

verifySequence {
renderer.render(selectQuery, mapOf(queryParam1, queryParam2), context)
selectQuery.returnType
renderer.render(selectQuery1, mapOf(queryParam1, queryParam2), context)
selectQuery1.returnType
entityManager.createQuery(rendered1.query, String::class.java)
stringTypedQuery.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery.setParameter(renderedParam2.first, renderedParam2.second)
stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second)
}
}

Expand All @@ -118,20 +118,20 @@ class JpqlEntityManagerUtilsTest : WithAssertions {
val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2)))

every { renderer.render(any(), any()) } returns rendered1
every { entityManager.createQuery(any<String>()) } returns stringTypedQuery
every { stringTypedQuery.setParameter(any<String>(), any()) } returns stringTypedQuery
every { entityManager.createQuery(any<String>()) } returns stringTypedQuery1
every { stringTypedQuery1.setParameter(any<String>(), any()) } returns stringTypedQuery1

// when
val actual = JpqlEntityManagerUtils.createQuery(entityManager, updateQuery, context)
val actual = JpqlEntityManagerUtils.createQuery(entityManager, updateQuery1, context)

// then
assertThat(actual).isEqualTo(stringTypedQuery)
assertThat(actual).isEqualTo(stringTypedQuery1)

verifySequence {
renderer.render(updateQuery, context)
renderer.render(updateQuery1, context)
entityManager.createQuery(rendered1.query)
stringTypedQuery.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery.setParameter(renderedParam2.first, renderedParam2.second)
stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second)
}
}

Expand All @@ -141,21 +141,21 @@ class JpqlEntityManagerUtilsTest : WithAssertions {
val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2)))

every { renderer.render(any(), any(), any()) } returns rendered1
every { entityManager.createQuery(any<String>()) } returns stringTypedQuery
every { stringTypedQuery.setParameter(any<String>(), any()) } returns stringTypedQuery
every { entityManager.createQuery(any<String>()) } returns stringTypedQuery1
every { stringTypedQuery1.setParameter(any<String>(), any()) } returns stringTypedQuery1

// when
val actual =
JpqlEntityManagerUtils.createQuery(entityManager, updateQuery, mapOf(queryParam1, queryParam2), context)
JpqlEntityManagerUtils.createQuery(entityManager, updateQuery1, mapOf(queryParam1, queryParam2), context)

// then
assertThat(actual).isEqualTo(stringTypedQuery)
assertThat(actual).isEqualTo(stringTypedQuery1)

verifySequence {
renderer.render(updateQuery, mapOf(queryParam1, queryParam2), context)
renderer.render(updateQuery1, mapOf(queryParam1, queryParam2), context)
entityManager.createQuery(rendered1.query)
stringTypedQuery.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery.setParameter(renderedParam2.first, renderedParam2.second)
stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second)
}
}

Expand All @@ -165,20 +165,20 @@ class JpqlEntityManagerUtilsTest : WithAssertions {
val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2)))

every { renderer.render(any(), any()) } returns rendered1
every { entityManager.createQuery(any<String>()) } returns stringTypedQuery
every { stringTypedQuery.setParameter(any<String>(), any()) } returns stringTypedQuery
every { entityManager.createQuery(any<String>()) } returns stringTypedQuery1
every { stringTypedQuery1.setParameter(any<String>(), any()) } returns stringTypedQuery1

// when
val actual = JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery, context)
val actual = JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery1, context)

// then
assertThat(actual).isEqualTo(stringTypedQuery)
assertThat(actual).isEqualTo(stringTypedQuery1)

verifySequence {
renderer.render(deleteQuery, context)
renderer.render(deleteQuery1, context)
entityManager.createQuery(rendered1.query)
stringTypedQuery.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery.setParameter(renderedParam2.first, renderedParam2.second)
stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second)
}
}

Expand All @@ -188,21 +188,21 @@ class JpqlEntityManagerUtilsTest : WithAssertions {
val rendered1 = JpqlRendered(renderedQuery1, JpqlRenderedParams(mapOf(renderedParam1, renderedParam2)))

every { renderer.render(any(), any(), any()) } returns rendered1
every { entityManager.createQuery(any<String>()) } returns stringTypedQuery
every { stringTypedQuery.setParameter(any<String>(), any()) } returns stringTypedQuery
every { entityManager.createQuery(any<String>()) } returns stringTypedQuery1
every { stringTypedQuery1.setParameter(any<String>(), any()) } returns stringTypedQuery1

// when
val actual =
JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery, mapOf(queryParam1, queryParam2), context)
JpqlEntityManagerUtils.createQuery(entityManager, deleteQuery1, mapOf(queryParam1, queryParam2), context)

// then
assertThat(actual).isEqualTo(stringTypedQuery)
assertThat(actual).isEqualTo(stringTypedQuery1)

verifySequence {
renderer.render(deleteQuery, mapOf(queryParam1, queryParam2), context)
renderer.render(deleteQuery1, mapOf(queryParam1, queryParam2), context)
entityManager.createQuery(rendered1.query)
stringTypedQuery.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery.setParameter(renderedParam2.first, renderedParam2.second)
stringTypedQuery1.setParameter(renderedParam1.first, renderedParam1.second)
stringTypedQuery1.setParameter(renderedParam2.first, renderedParam2.second)
}
}
}
Loading

0 comments on commit f73b1fe

Please sign in to comment.