Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add Boolean Conversion Support to JasyncRow #431

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

Merged
merged 3 commits into from
May 27, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add unit tests for Boolean type conversion in JasyncRow
  • Loading branch information
Sung-Heon committed May 18, 2025
commit 3922c34f12da2ff542e75e0b62ef577e6fb4c70c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.github.jasync.r2dbc.mysql

import com.github.jasync.sql.db.RowData
import io.mockk.every
import io.mockk.mockk
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

/**
* Unit tests for [JasyncRow].
*/
internal class JasyncRowTest {

@Test
fun testBooleanConversion() {
// Mock dependencies
val rowData = mockk<RowData>()
val metadata = mockk<JasyncMetadata>()

// Setup mock values for different types of data
every { rowData["boolTrue"] } returns true
every { rowData["boolFalse"] } returns false
every { rowData["numZero"] } returns 0
every { rowData["numOne"] } returns 1
every { rowData["stringTrue"] } returns "true"
every { rowData["stringFalse"] } returns "false"
every { rowData[0] } returns true
every { rowData[1] } returns 0
every { rowData[2] } returns "true"

val row = JasyncRow(rowData, metadata)

// Test conversion from Boolean to Boolean
assertTrue(row.get("boolTrue", java.lang.Boolean::class.java) as Boolean)
assertFalse(row.get("boolFalse", java.lang.Boolean::class.java) as Boolean)

// Test conversion from Number to Boolean
assertFalse(row.get("numZero", java.lang.Boolean::class.java) as Boolean)
assertTrue(row.get("numOne", java.lang.Boolean::class.java) as Boolean)

// Test conversion from String to Boolean
assertTrue(row.get("stringTrue", java.lang.Boolean::class.java) as Boolean)
assertFalse(row.get("stringFalse", java.lang.Boolean::class.java) as Boolean)

// Test conversion from various types using index
assertTrue(row.get(0, java.lang.Boolean::class.java) as Boolean)
assertFalse(row.get(1, java.lang.Boolean::class.java) as Boolean)
assertTrue(row.get(2, java.lang.Boolean::class.java) as Boolean)

// Test conversion to primitive boolean - using Boolean class in Kotlin
assertTrue(row.get("boolTrue", java.lang.Boolean::class.java) as Boolean)
assertFalse(row.get("boolFalse", java.lang.Boolean::class.java) as Boolean)
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.