Skip to content

Commit 546fa6c

Browse files
committed
Inline test assertion suspend functions
See: #1 (comment)
1 parent d5fd3a9 commit 546fa6c

File tree

2 files changed

+13
-33
lines changed

2 files changed

+13
-33
lines changed

src/test/kotlin/com/github/michaelbull/jdbc/ConnectionTest.kt

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ import org.junit.jupiter.api.Test
1515
import java.sql.Connection
1616
import java.sql.SQLException
1717
import javax.sql.DataSource
18-
import kotlin.coroutines.coroutineContext
1918

2019
@ExperimentalCoroutinesApi
2120
class ConnectionTest {
2221

23-
private val openConnection = mockk<Connection>("OpenConnection", relaxed = true).apply {
22+
private val openConnection = mockk<Connection>("OpenConnection", relaxed = true) {
2423
every { isClosed } returns false
2524
}
2625

27-
private val closedConnection = mockk<Connection>("ClosedConnection", relaxed = true).apply {
26+
private val closedConnection = mockk<Connection>("ClosedConnection", relaxed = true) {
2827
every { isClosed } returns true
2928
}
3029

@@ -38,7 +37,7 @@ class ConnectionTest {
3837

3938
runBlockingTest(context) {
4039
withConnection {
41-
assertConnectionNotNull()
40+
assertNotNull(coroutineContext.connection)
4241
}
4342
}
4443
}
@@ -50,8 +49,8 @@ class ConnectionTest {
5049

5150
runBlockingTest(context) {
5251
withConnection {
53-
assertConnectionNotNull()
54-
assertConnectionNotEquals(coroutineConnection)
52+
assertNotNull(coroutineContext.connection)
53+
assertNotEquals(coroutineConnection, coroutineContext.connection)
5554
}
5655
}
5756
}
@@ -65,7 +64,7 @@ class ConnectionTest {
6564

6665
runBlockingTest(context) {
6766
withConnection {
68-
assertConnectionNotEquals(coroutineConnection)
67+
assertNotEquals(coroutineConnection, coroutineContext.connection)
6968
}
7069
}
7170
}
@@ -77,7 +76,7 @@ class ConnectionTest {
7776

7877
runBlockingTest(context) {
7978
withConnection {
80-
assertConnectionEquals(coroutineConnection)
79+
assertEquals(coroutineConnection, coroutineContext.connection)
8180
}
8281
}
8382
}
@@ -116,16 +115,4 @@ class ConnectionTest {
116115

117116
verify(exactly = 0) { openConnection.close() }
118117
}
119-
120-
private suspend fun assertConnectionNotNull() {
121-
assertNotNull(coroutineContext.connection)
122-
}
123-
124-
private suspend fun assertConnectionEquals(expected: Connection) {
125-
assertEquals(expected, coroutineContext.connection)
126-
}
127-
128-
private suspend fun assertConnectionNotEquals(unexpected: Connection) {
129-
assertNotEquals(unexpected, coroutineContext.connection)
130-
}
131118
}

src/test/kotlin/com/github/michaelbull/jdbc/TransactionTest.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ import org.junit.jupiter.api.Test
1515
import org.junit.jupiter.api.assertThrows
1616
import java.sql.Connection
1717
import javax.sql.DataSource
18-
import kotlin.coroutines.coroutineContext
1918

2019
@ExperimentalCoroutinesApi
2120
class TransactionTest {
2221

23-
private val openConnection = mockk<Connection>("OpenConnection", relaxed = true).apply {
22+
private val openConnection = mockk<Connection>("OpenConnection", relaxed = true) {
2423
every { isClosed } returns false
2524
}
2625

27-
private val dataSource = mockk<DataSource>(relaxed = true).apply {
26+
private val dataSource = mockk<DataSource>(relaxed = true) {
2827
every { connection } returns openConnection
2928
}
3029

@@ -41,7 +40,8 @@ class TransactionTest {
4140
fun `transaction should add new transaction to context if absent`() {
4241
runBlockingTest(CoroutineDataSource(dataSource)) {
4342
transaction {
44-
assertTransactionNotNull()
43+
assertNotNull(coroutineContext.transaction)
44+
Unit
4545
}
4646
}
4747
}
@@ -77,7 +77,8 @@ class TransactionTest {
7777

7878
runBlockingTest(context) {
7979
transaction {
80-
assertTransactionEquals(transaction)
80+
assertEquals(transaction, coroutineContext.transaction)
81+
Unit
8182
}
8283
}
8384
}
@@ -149,12 +150,4 @@ class TransactionTest {
149150
}
150151
}
151152
}
152-
153-
private suspend fun assertTransactionNotNull() {
154-
assertNotNull(coroutineContext.transaction)
155-
}
156-
157-
private suspend fun assertTransactionEquals(expected: CoroutineTransaction) {
158-
assertEquals(expected, coroutineContext.transaction)
159-
}
160153
}

0 commit comments

Comments
 (0)