Skip to content

Commit

Permalink
Silence warning
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxnlai committed May 29, 2021
1 parent c0fe0a9 commit 39a686d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import app.cash.tempest2.musiclibrary.AsyncMusicDb
import app.cash.tempest2.musiclibrary.PlaylistInfo
import app.cash.tempest2.musiclibrary.testDb
import app.cash.tempest2.testing.asyncLogicalDb
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
Expand All @@ -37,7 +36,7 @@ class AsyncLogicalDbBatchTest {
private val musicTable by lazy { musicDb.music }

@Test
fun batchLoad() = runBlocking {
fun batchLoad() = runBlockingTest {
val albumTracks = listOf(
AlbumTrack("ALBUM_1", 1, "dreamin'", Duration.parse("PT3M28S")),
AlbumTrack("ALBUM_1", 2, "what you do to me", Duration.parse("PT3M24S")),
Expand All @@ -64,7 +63,7 @@ class AsyncLogicalDbBatchTest {
}

@Test
fun batchLoadMultipleTables() = runBlocking {
fun batchLoadMultipleTables() = runBlockingTest {
val albumTracks = listOf(
AlbumTrack("ALBUM_1", 1, "dreamin'", Duration.parse("PT3M28S")),
AlbumTrack("ALBUM_1", 2, "what you do to me", Duration.parse("PT3M24S")),
Expand All @@ -91,7 +90,7 @@ class AsyncLogicalDbBatchTest {
}

@Test
fun batchLoadAfterBatchWrite() = runBlocking {
fun batchLoadAfterBatchWrite() = runBlockingTest {
val albumTracks = listOf(
AlbumTrack("ALBUM_1", 1, "dreamin'", Duration.parse("PT3M28S")),
AlbumTrack("ALBUM_1", 2, "what you do to me", Duration.parse("PT3M24S")),
Expand All @@ -109,7 +108,7 @@ class AsyncLogicalDbBatchTest {
}

@Test
fun batchLoadAfterBatchDelete() = runBlocking {
fun batchLoadAfterBatchDelete() = runBlockingTest {
val t1 = AlbumTrack("ALBUM_1", 1, "dreamin'", Duration.parse("PT3M28S"))
val t2 = AlbumTrack("ALBUM_1", 2, "what you do to me", Duration.parse("PT3M24S"))
val t3 = AlbumTrack("ALBUM_1", 3, "too slow", Duration.parse("PT2M27S"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import app.cash.tempest2.musiclibrary.AsyncMusicDb
import app.cash.tempest2.musiclibrary.PlaylistInfo
import app.cash.tempest2.musiclibrary.testDb
import app.cash.tempest2.testing.asyncLogicalDb
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.Test
Expand All @@ -41,7 +40,7 @@ class AsyncLogicalDbTransactionTest {
private val musicTable by lazy { musicDb.music }

@Test
fun transactionLoad() = runBlocking {
fun transactionLoad() = runBlockingTest {
val albumTracks = listOf(
AlbumTrack(
"ALBUM_1",
Expand Down Expand Up @@ -83,7 +82,7 @@ class AsyncLogicalDbTransactionTest {
}

@Test
fun transactionLoadAfterTransactionWrite() = runBlocking {
fun transactionLoadAfterTransactionWrite() = runBlockingTest {
val albumTracks = listOf(
AlbumTrack(
"ALBUM_1",
Expand Down Expand Up @@ -127,7 +126,7 @@ class AsyncLogicalDbTransactionTest {
}

@Test
fun conditionalUpdateInTransactionWrite() = runBlocking {
fun conditionalUpdateInTransactionWrite() = runBlockingTest {
val playlistInfoV1 =
PlaylistInfo("PLAYLIST_1", "WFH Music", emptyList())
musicTable.playlistInfo.save(playlistInfoV1)
Expand Down Expand Up @@ -162,7 +161,7 @@ class AsyncLogicalDbTransactionTest {
}

@Test
fun conditionalUpdateFailureInTransactionWrite() = runBlocking {
fun conditionalUpdateFailureInTransactionWrite() = runBlockingTest {
val playlistInfoV1 =
PlaylistInfo("PLAYLIST_1", "WFH Music", emptyList())
musicTable.playlistInfo.save(playlistInfoV1)
Expand Down Expand Up @@ -191,7 +190,7 @@ class AsyncLogicalDbTransactionTest {

assertThatExceptionOfType(TransactionCanceledException::class.java)
.isThrownBy {
runBlocking {
runBlockingTest {
musicDb.transactionWrite(writeTransaction)
}
}
Expand All @@ -204,7 +203,7 @@ class AsyncLogicalDbTransactionTest {
}

@Test
fun conditionCheckInTransactionWrite() = runBlocking {
fun conditionCheckInTransactionWrite() = runBlockingTest {
val playlistInfoV1 =
PlaylistInfo("PLAYLIST_1", "WFH Music", emptyList())
musicTable.playlistInfo.save(playlistInfoV1)
Expand Down Expand Up @@ -238,7 +237,7 @@ class AsyncLogicalDbTransactionTest {
}

@Test
fun conditionCheckFailureInTransactionWrite() = runBlocking {
fun conditionCheckFailureInTransactionWrite() = runBlockingTest {
val playlistInfoV1 =
PlaylistInfo("PLAYLIST_1", "WFH Music", emptyList())
musicTable.playlistInfo.save(playlistInfoV1)
Expand All @@ -261,7 +260,7 @@ class AsyncLogicalDbTransactionTest {

assertThatExceptionOfType(TransactionCanceledException::class.java)
.isThrownBy {
runBlocking {
runBlockingTest {
musicDb.transactionWrite(writeTransaction)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import app.cash.tempest2.musiclibrary.givenAlbums
import app.cash.tempest2.musiclibrary.testDb
import app.cash.tempest2.musiclibrary.trackTitles
import app.cash.tempest2.testing.asyncLogicalDb
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
Expand All @@ -46,7 +45,7 @@ class DynamoDbAsyncQueryableTest {
private val musicTable by lazy { db.asyncLogicalDb<AsyncMusicDb>().music }

@Test
fun primaryIndexBetween() = runBlocking {
fun primaryIndexBetween() = runBlockingTest {
musicTable.givenAlbums(AFTER_HOURS_EP)

val page1 = musicTable.albumTracks.query(
Expand Down Expand Up @@ -78,7 +77,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun primaryIndexBeginsWith() = runBlocking {
fun primaryIndexBeginsWith() = runBlockingTest {
musicTable.givenAlbums(AFTER_HOURS_EP)

val page1 = musicTable.albumTracks.query(
Expand All @@ -95,7 +94,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun primaryIndexFilter() = runBlocking {
fun primaryIndexFilter() = runBlockingTest {
musicTable.givenAlbums(AFTER_HOURS_EP)

val page1 = musicTable.albumTracks.query(
Expand All @@ -111,7 +110,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun primaryIndexPagination() = runBlocking {
fun primaryIndexPagination() = runBlockingTest {
musicTable.givenAlbums(AFTER_HOURS_EP)

val page1 = musicTable.albumTracks.query(
Expand Down Expand Up @@ -139,7 +138,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun primaryIndexDesc() = runBlocking {
fun primaryIndexDesc() = runBlockingTest {
musicTable.givenAlbums(AFTER_HOURS_EP)

val page = musicTable.albumTracks.query(
Expand All @@ -151,7 +150,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun primaryIndexDescPagination() = runBlocking {
fun primaryIndexDescPagination() = runBlockingTest {
musicTable.givenAlbums(AFTER_HOURS_EP)

val page1 = musicTable.albumTracks.query(
Expand Down Expand Up @@ -182,7 +181,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun localSecondaryIndex() = runBlocking {
fun localSecondaryIndex() = runBlockingTest {
musicTable.givenAlbums(AFTER_HOURS_EP)
val expectedTrackTitles = AFTER_HOURS_EP.trackTitles.sorted()

Expand All @@ -194,7 +193,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun localSecondaryIndexPagination() = runBlocking {
fun localSecondaryIndexPagination() = runBlockingTest {
musicTable.givenAlbums(AFTER_HOURS_EP)
val expectedTrackTitles = AFTER_HOURS_EP.trackTitles.sorted()

Expand Down Expand Up @@ -223,7 +222,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun globalSecondaryIndex() = runBlocking {
fun globalSecondaryIndex() = runBlockingTest {
musicTable.givenAlbums(
THE_DARK_SIDE_OF_THE_MOON,
THE_WALL,
Expand Down Expand Up @@ -252,7 +251,7 @@ class DynamoDbAsyncQueryableTest {
}

@Test
fun globalSecondaryIndexPagination() = runBlocking {
fun globalSecondaryIndexPagination() = runBlockingTest {
musicTable.givenAlbums(
WHAT_YOU_DO_TO_ME_SINGLE,
AFTER_HOURS_EP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import app.cash.tempest2.musiclibrary.givenAlbums
import app.cash.tempest2.musiclibrary.testDb
import app.cash.tempest2.musiclibrary.trackTitles
import app.cash.tempest2.testing.asyncLogicalDb
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
Expand All @@ -44,7 +43,7 @@ class DynamoDbAsyncScannableTest {
private val musicTable by lazy { db.asyncLogicalDb<AsyncMusicDb>().music }

@Test
fun primaryIndex() = runBlocking {
fun primaryIndex() = runBlockingTest {
musicTable.givenAlbums(
THE_DARK_SIDE_OF_THE_MOON,
THE_WALL,
Expand All @@ -65,7 +64,7 @@ class DynamoDbAsyncScannableTest {
}

@Test
fun localSecondaryIndex() = runBlocking {
fun localSecondaryIndex() = runBlockingTest {
musicTable.givenAlbums(THE_WALL)
val expectedTrackTitles = THE_WALL.trackTitles.sorted()

Expand All @@ -84,7 +83,7 @@ class DynamoDbAsyncScannableTest {
}

@Test
fun localSecondaryIndexWithFilter() = runBlocking {
fun localSecondaryIndexWithFilter() = runBlockingTest {
musicTable.givenAlbums(THE_WALL)
val expectedTrackTitles = THE_WALL.tracks
.filter { it.run_length > Duration.ofMinutes(3) }
Expand All @@ -100,7 +99,7 @@ class DynamoDbAsyncScannableTest {
}

@Test
fun globalSecondaryIndex() = runBlocking {
fun globalSecondaryIndex() = runBlockingTest {
musicTable.givenAlbums(
THE_DARK_SIDE_OF_THE_MOON,
THE_WALL,
Expand All @@ -122,7 +121,7 @@ class DynamoDbAsyncScannableTest {
}

@Test
fun globalSecondaryIndexWithFilter() = runBlocking {
fun globalSecondaryIndexWithFilter() = runBlockingTest {
musicTable.givenAlbums(
THE_DARK_SIDE_OF_THE_MOON,
THE_WALL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import app.cash.tempest2.musiclibrary.AsyncMusicDb
import app.cash.tempest2.musiclibrary.PlaylistInfo
import app.cash.tempest2.musiclibrary.testDb
import app.cash.tempest2.testing.asyncLogicalDb
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.Test
Expand All @@ -41,7 +40,7 @@ class DynamoDbAsyncViewTest {
private val musicTable by lazy { db.asyncLogicalDb<AsyncMusicDb>().music }

@Test
fun loadAfterSave() = runBlocking {
fun loadAfterSave() = runBlockingTest {
val albumInfo = AlbumInfo(
"ALBUM_1",
"after hours - EP",
Expand All @@ -61,7 +60,7 @@ class DynamoDbAsyncViewTest {
}

@Test
fun saveIfNotExist() = runBlocking {
fun saveIfNotExist() = runBlockingTest {
val albumInfo = AlbumInfo(
"ALBUM_1",
"after hours - EP",
Expand All @@ -74,14 +73,14 @@ class DynamoDbAsyncViewTest {
// This fails because the album info already exists.
assertThatExceptionOfType(ConditionalCheckFailedException::class.java)
.isThrownBy {
runBlocking {
runBlockingTest {
musicTable.albumInfo.save(albumInfo, ifNotExist())
}
}
}

@Test
fun optimisticLocking() = runBlocking {
fun optimisticLocking() = runBlockingTest {
val playlistInfoV1 = PlaylistInfo(
"PLAYLIST_1",
"WFH Music",
Expand All @@ -108,7 +107,7 @@ class DynamoDbAsyncViewTest {
// This fails because playlist_size is already 1.
assertThatExceptionOfType(ConditionalCheckFailedException::class.java)
.isThrownBy {
runBlocking {
runBlockingTest {
musicTable.playlistInfo.save(
playlistInfoV2,
ifPlaylistVersionIs(playlistInfoV1.playlist_version)
Expand All @@ -118,7 +117,7 @@ class DynamoDbAsyncViewTest {
}

@Test
fun delete() = runBlocking {
fun delete() = runBlockingTest {
val albumInfo = AlbumInfo(
"ALBUM_1",
"after hours - EP",
Expand Down
9 changes: 9 additions & 0 deletions tempest2/src/test/kotlin/app/cash/tempest2/TestUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package app.cash.tempest2

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking

// Exist to silence Intellij warning "Junit test should return Unit".
fun runBlockingTest(block: suspend CoroutineScope.() -> Unit) {
runBlocking(block = block)
}

0 comments on commit 39a686d

Please sign in to comment.