From 29db0a15678468a3ac9e1abfe54cce8011578fde Mon Sep 17 00:00:00 2001 From: matt-ramotar Date: Sun, 17 Nov 2024 14:28:25 -0500 Subject: [PATCH] Run gradlew ktlintFormat Signed-off-by: matt-ramotar --- .../store/store5/FetcherResponseTests.kt | 105 +++++---- .../store/store5/FlowStoreTests.kt | 200 +++++++++--------- .../store/store5/HotFlowStoreTests.kt | 85 ++++---- .../store/store5/MapIndexedTests.kt | 13 +- .../store/store5/SourceOfTruthErrorsTests.kt | 89 ++++---- .../store5/SourceOfTruthWithBarrierTests.kt | 36 ++-- .../store5/StreamWithoutSourceOfTruthTests.kt | 8 +- .../store/store5/UpdaterTests.kt | 56 ++--- 8 files changed, 293 insertions(+), 299 deletions(-) diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FetcherResponseTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FetcherResponseTests.kt index d2ff4f37..bc1ad503 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FetcherResponseTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FetcherResponseTests.kt @@ -34,37 +34,37 @@ class FetcherResponseTests { } @Test - fun givenAFetcherThatEmitsErrorAndDataWhenSteamingThenItCanEmitValueAfterAnError() = testScope.runTest { - val exception = RuntimeException("first error") - val store = - StoreBuilder.from( - fetcher = - Fetcher.ofResultFlow { key: Int -> - flowOf( - FetcherResult.Error.Exception(exception), - FetcherResult.Data("$key"), - ) - }, - ).buildWithTestScope() - - store.stream(StoreReadRequest.fresh(1)).test { - assertEquals( - StoreReadResponse.Loading(StoreReadResponseOrigin.Fetcher()), - awaitItem() - ) - - assertEquals( - StoreReadResponse.Error.Exception(exception, StoreReadResponseOrigin.Fetcher()), - awaitItem() - ) - - assertEquals( - StoreReadResponse.Data("1", StoreReadResponseOrigin.Fetcher()), - awaitItem() - ) - } + fun givenAFetcherThatEmitsErrorAndDataWhenSteamingThenItCanEmitValueAfterAnError() = + testScope.runTest { + val exception = RuntimeException("first error") + val store = + StoreBuilder.from( + fetcher = + Fetcher.ofResultFlow { key: Int -> + flowOf( + FetcherResult.Error.Exception(exception), + FetcherResult.Data("$key"), + ) + }, + ).buildWithTestScope() - } + store.stream(StoreReadRequest.fresh(1)).test { + assertEquals( + StoreReadResponse.Loading(StoreReadResponseOrigin.Fetcher()), + awaitItem(), + ) + + assertEquals( + StoreReadResponse.Error.Exception(exception, StoreReadResponseOrigin.Fetcher()), + awaitItem(), + ) + + assertEquals( + StoreReadResponse.Data("1", StoreReadResponseOrigin.Fetcher()), + awaitItem(), + ) + } + } @Test fun givenTransformerWhenRawValueThenUnwrappedValueReturnedAndValueIsCached() = @@ -79,7 +79,7 @@ class FetcherResponseTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -87,7 +87,7 @@ class FetcherResponseTests { value = 9, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -97,7 +97,7 @@ class FetcherResponseTests { value = 9, origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) } } @@ -125,7 +125,7 @@ class FetcherResponseTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -133,7 +133,7 @@ class FetcherResponseTests { message = "zero", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -142,7 +142,7 @@ class FetcherResponseTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -150,7 +150,7 @@ class FetcherResponseTests { value = 1, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -180,7 +180,7 @@ class FetcherResponseTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -188,7 +188,7 @@ class FetcherResponseTests { error = e, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -197,7 +197,7 @@ class FetcherResponseTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -205,7 +205,7 @@ class FetcherResponseTests { value = 1, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -228,13 +228,12 @@ class FetcherResponseTests { .from(fetcher = fetcher) .buildWithTestScope() - pipeline.stream(StoreReadRequest.fresh(3)).test { assertEquals( StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -242,7 +241,7 @@ class FetcherResponseTests { error = e, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -251,7 +250,7 @@ class FetcherResponseTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -259,7 +258,7 @@ class FetcherResponseTests { value = 1, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -274,17 +273,17 @@ class FetcherResponseTests { val store = StoreBuilder.from( fetcher = - Fetcher.ofResultFlow { _: Int -> - flowOf( - FetcherResult.Error.Custom(customError), - ) - }, + Fetcher.ofResultFlow { _: Int -> + flowOf( + FetcherResult.Error.Custom(customError), + ) + }, ).buildWithTestScope() store.stream(StoreReadRequest.fresh(1)).test { assertEquals( StoreReadResponse.Loading(origin = StoreReadResponseOrigin.Fetcher()), - awaitItem() + awaitItem(), ) assertEquals( @@ -292,7 +291,7 @@ class FetcherResponseTests { error = customError, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FlowStoreTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FlowStoreTests.kt index c8cc67e8..f377ef45 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FlowStoreTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FlowStoreTests.kt @@ -129,7 +129,7 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -137,7 +137,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -147,7 +147,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) // note that we still get the data from persister as well as we don't listen to @@ -159,7 +159,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) } @@ -168,7 +168,7 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -176,7 +176,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -186,7 +186,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -194,7 +194,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) } } @@ -220,7 +220,7 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -228,7 +228,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -238,7 +238,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -246,14 +246,14 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) assertEquals( Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -261,7 +261,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -283,7 +283,7 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -291,25 +291,24 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } - pipeline.stream(StoreReadRequest.cached(3, refresh = true)).test { assertEquals( Data( value = "three-1", origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) assertEquals( Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -317,7 +316,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -334,13 +333,12 @@ class FlowStoreTests { StoreBuilder.from(fetcher = fetcher) .buildWithTestScope() - pipeline.stream(StoreReadRequest.skipMemory(3, refresh = false)).test { assertEquals( Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -348,7 +346,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -357,7 +355,7 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -365,7 +363,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -388,13 +386,12 @@ class FlowStoreTests { .disableCache() .buildWithTestScope() - pipeline.stream(StoreReadRequest.fresh(3)).test { assertEquals( Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -402,7 +399,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -410,7 +407,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -420,14 +417,14 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) assertEquals( Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -435,7 +432,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -443,7 +440,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -475,7 +472,7 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -483,7 +480,7 @@ class FlowStoreTests { value = "local-1", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -491,7 +488,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -503,14 +500,14 @@ class FlowStoreTests { val pipeline = StoreBuilder.from( fetcher = - Fetcher.ofFlow { - flow { - delay(10) - emit("three-1") - delay(10) - emit("three-2") - } - }, + Fetcher.ofFlow { + flow { + delay(10) + emit("three-1") + delay(10) + emit("three-2") + } + }, sourceOfTruth = persister.asSourceOfTruth(), ) .disableCache() @@ -528,7 +525,7 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -536,7 +533,7 @@ class FlowStoreTests { value = "local-1", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -544,7 +541,7 @@ class FlowStoreTests { value = "three-1", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -552,7 +549,7 @@ class FlowStoreTests { value = "local-2", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -560,7 +557,7 @@ class FlowStoreTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -590,7 +587,7 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -598,7 +595,7 @@ class FlowStoreTests { error = exception, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -606,24 +603,24 @@ class FlowStoreTests { value = "local-1", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) } pipeline.stream(StoreReadRequest.cached(key = 3, refresh = true)).test { - assertEquals( - Data( - value = "local-1", - origin = StoreReadResponseOrigin.SourceOfTruth, - ), - awaitItem() - ) + assertEquals( + Data( + value = "local-1", + origin = StoreReadResponseOrigin.SourceOfTruth, + ), + awaitItem(), + ) assertEquals( Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -631,7 +628,7 @@ class FlowStoreTests { error = exception, origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -656,14 +653,14 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.NoNewData( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -671,7 +668,7 @@ class FlowStoreTests { value = "local-1", origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -679,7 +676,7 @@ class FlowStoreTests { value = "local-1", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) } } @@ -699,14 +696,13 @@ class FlowStoreTests { val firstFetch = pipeline.fresh(3) // prime the cache assertEquals("local-1", firstFetch) - pipeline.stream(StoreReadRequest.cached(3, refresh = true)).test { assertEquals( Data( value = "local-1", origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -714,21 +710,21 @@ class FlowStoreTests { value = "local-1", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) assertEquals( Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.NoNewData( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -740,13 +736,13 @@ class FlowStoreTests { val pipeline = StoreBuilder.from( fetcher = - Fetcher.ofFlow { - if (createCount++ == 0) { - flowOf("remote-1") - } else { - flowOf() - } - }, + Fetcher.ofFlow { + if (createCount++ == 0) { + flowOf("remote-1") + } else { + flowOf() + } + }, ) .buildWithTestScope() @@ -758,14 +754,14 @@ class FlowStoreTests { Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.NoNewData( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -773,7 +769,7 @@ class FlowStoreTests { value = "remote-1", origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) } } @@ -785,13 +781,13 @@ class FlowStoreTests { val pipeline = StoreBuilder.from( fetcher = - Fetcher.ofFlow { - if (createCount++ == 0) { - flowOf("remote-1") - } else { - flowOf() - } - }, + Fetcher.ofFlow { + if (createCount++ == 0) { + flowOf("remote-1") + } else { + flowOf() + } + }, ) .buildWithTestScope() @@ -804,21 +800,21 @@ class FlowStoreTests { value = "remote-1", origin = StoreReadResponseOrigin.Cache, ), - awaitItem() + awaitItem(), ) assertEquals( Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.NoNewData( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -953,7 +949,7 @@ class FlowStoreTests { } @Test - fun givenCacheAndNoSourceOfTruthWhen3CachedStreamsWithRefreshAnd1stHasSlowCollectionThen1stStreamsGets3FetchUpdatesAndOtherStreamsGetCacheResultAndFetchResult() = + fun testSlowFirstCollectorGetsAllFetchUpdatesOthersGetCacheAndLatestFetchResult() = testScope.runTest { val fetcher = FakeFetcher( @@ -983,37 +979,35 @@ class FlowStoreTests { fetcher1Collected, ) - pipeline.stream(StoreReadRequest.cached(3, refresh = true)).test { assertEquals( Data(origin = StoreReadResponseOrigin.Cache, value = "three-1"), - awaitItem() + awaitItem(), ) assertEquals( Loading(origin = StoreReadResponseOrigin.Fetcher()), - awaitItem() + awaitItem(), ) assertEquals( Data(origin = StoreReadResponseOrigin.Fetcher(), value = "three-2"), - awaitItem() + awaitItem(), ) - } pipeline.stream(StoreReadRequest.cached(3, refresh = true)).test { assertEquals( Data(origin = StoreReadResponseOrigin.Cache, value = "three-2"), - awaitItem() + awaitItem(), ) assertEquals( Loading(origin = StoreReadResponseOrigin.Fetcher()), - awaitItem() + awaitItem(), ) assertEquals( Data(origin = StoreReadResponseOrigin.Fetcher(), value = "three-3"), - awaitItem() + awaitItem(), ) } @@ -1032,7 +1026,7 @@ class FlowStoreTests { } @Test - fun givenCacheAndNoSourceOfTruthWhen2CachedStreamsWithRefreshThenFirstStreamsGets2FetchUpdatesAnd2ndStreamGetsCacheResultAndFetchResult() = + fun testFirstStreamGetsTwoFetchUpdatesSecondGetsCacheAndFetchResult() = testScope.runTest { val fetcher = FakeFetcher( @@ -1062,17 +1056,17 @@ class FlowStoreTests { pipeline.stream(StoreReadRequest.cached(3, refresh = true)).test { assertEquals( Data(origin = StoreReadResponseOrigin.Cache, value = "three-1"), - awaitItem() + awaitItem(), ) assertEquals( Loading(origin = StoreReadResponseOrigin.Fetcher()), - awaitItem() + awaitItem(), ) assertEquals( Data(origin = StoreReadResponseOrigin.Fetcher(), value = "three-2"), - awaitItem() + awaitItem(), ) } diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/HotFlowStoreTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/HotFlowStoreTests.kt index 04e12117..7d3c2e64 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/HotFlowStoreTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/HotFlowStoreTests.kt @@ -30,53 +30,54 @@ class HotFlowStoreTests { .scope(testScope) .build() - val job = launch { - pipeline.stream(StoreReadRequest.cached(3, refresh = false)).test { - assertEquals( - StoreReadResponse.Loading( - origin = StoreReadResponseOrigin.Fetcher(), - ), - awaitItem() - ) + val job = + launch { + pipeline.stream(StoreReadRequest.cached(3, refresh = false)).test { + assertEquals( + StoreReadResponse.Loading( + origin = StoreReadResponseOrigin.Fetcher(), + ), + awaitItem(), + ) - assertEquals( - StoreReadResponse.Data( - value = "three-1", - origin = StoreReadResponseOrigin.Fetcher(), - ), - awaitItem() - ) - } + assertEquals( + StoreReadResponse.Data( + value = "three-1", + origin = StoreReadResponseOrigin.Fetcher(), + ), + awaitItem(), + ) + } - pipeline.stream( - StoreReadRequest.cached(3, refresh = false), - ).test { - assertEquals( - StoreReadResponse.Data( - value = "three-1", - origin = StoreReadResponseOrigin.Cache, - ), - awaitItem() - ) - } + pipeline.stream( + StoreReadRequest.cached(3, refresh = false), + ).test { + assertEquals( + StoreReadResponse.Data( + value = "three-1", + origin = StoreReadResponseOrigin.Cache, + ), + awaitItem(), + ) + } - pipeline.stream(StoreReadRequest.fresh(3)).test { - assertEquals( - StoreReadResponse.Loading( - origin = StoreReadResponseOrigin.Fetcher(), - ), - awaitItem() - ) + pipeline.stream(StoreReadRequest.fresh(3)).test { + assertEquals( + StoreReadResponse.Loading( + origin = StoreReadResponseOrigin.Fetcher(), + ), + awaitItem(), + ) - assertEquals( - StoreReadResponse.Data( - value = "three-2", - origin = StoreReadResponseOrigin.Fetcher(), - ), - awaitItem() - ) + assertEquals( + StoreReadResponse.Data( + value = "three-2", + origin = StoreReadResponseOrigin.Fetcher(), + ), + awaitItem(), + ) + } } - } job.cancel() } diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/MapIndexedTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/MapIndexedTests.kt index ccedcc96..da4527c7 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/MapIndexedTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/MapIndexedTests.kt @@ -12,11 +12,12 @@ class MapIndexedTests { private val scope = TestScope() @Test - fun mapIndexed() = scope.runTest { - flowOf(5, 6).mapIndexed { index, value -> index to value }.test { - assertEquals(0 to 5, awaitItem()) - assertEquals(1 to 6, awaitItem()) - awaitComplete() + fun mapIndexed() = + scope.runTest { + flowOf(5, 6).mapIndexed { index, value -> index to value }.test { + assertEquals(0 to 5, awaitItem()) + assertEquals(1 to 6, awaitItem()) + awaitComplete() + } } - } } diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/SourceOfTruthErrorsTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/SourceOfTruthErrorsTests.kt index 1253340f..79808aaf 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/SourceOfTruthErrorsTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/SourceOfTruthErrorsTests.kt @@ -46,23 +46,22 @@ class SourceOfTruthErrorsTests { } pipeline.stream(StoreReadRequest.fresh(3)).test { - assertEquals( StoreReadResponse.Loading(StoreReadResponseOrigin.Fetcher()), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.Error.Exception( error = - WriteException( - key = 3, - value = "a", - cause = TestException("i fail"), - ), + WriteException( + key = 3, + value = "a", + cause = TestException("i fail"), + ), origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) } } @@ -93,13 +92,13 @@ class SourceOfTruthErrorsTests { assertEquals( StoreReadResponse.Error.Exception( error = - ReadException( - key = 3, - cause = TestException("null"), - ), + ReadException( + key = 3, + cause = TestException("null"), + ), origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) // after disk fails, we should still invoke fetcher @@ -107,7 +106,7 @@ class SourceOfTruthErrorsTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) // and after fetcher writes the value, it will trigger another read which will also @@ -115,13 +114,13 @@ class SourceOfTruthErrorsTests { assertEquals( StoreReadResponse.Error.Exception( error = - ReadException( - key = 3, - cause = TestException("a"), - ), + ReadException( + key = 3, + cause = TestException("a"), + ), origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) } } @@ -154,19 +153,19 @@ class SourceOfTruthErrorsTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.Error.Exception( error = - WriteException( - key = 3, - value = "a", - cause = TestException("a"), - ), + WriteException( + key = 3, + value = "a", + cause = TestException("a"), + ), origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -174,20 +173,20 @@ class SourceOfTruthErrorsTests { value = "b", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.Error.Exception( error = - WriteException( - key = 3, - value = "c", - cause = TestException("c"), - ), + WriteException( + key = 3, + value = "c", + cause = TestException("c"), + ), origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) // disk flow will restart after a failed write (because we stopped it before the @@ -197,7 +196,7 @@ class SourceOfTruthErrorsTests { value = "b", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) assertEquals( @@ -205,7 +204,7 @@ class SourceOfTruthErrorsTests { value = "d", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -319,7 +318,7 @@ class SourceOfTruthErrorsTests { value = "b", origin = StoreReadResponseOrigin.SourceOfTruth, ), - awaitItem() + awaitItem(), ) // don't receive the write exception because technically it started before we @@ -328,7 +327,7 @@ class SourceOfTruthErrorsTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -336,7 +335,7 @@ class SourceOfTruthErrorsTests { value = "d", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -414,19 +413,19 @@ class SourceOfTruthErrorsTests { StoreReadResponse.Error.Exception( origin = StoreReadResponseOrigin.SourceOfTruth, error = - ReadException( - key = 3, - cause = TestException("first read"), - ), + ReadException( + key = 3, + cause = TestException("first read"), + ), ), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -434,7 +433,7 @@ class SourceOfTruthErrorsTests { value = "a", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/SourceOfTruthWithBarrierTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/SourceOfTruthWithBarrierTests.kt index 9d138d48..656f9b91 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/SourceOfTruthWithBarrierTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/SourceOfTruthWithBarrierTests.kt @@ -153,12 +153,12 @@ class SourceOfTruthWithBarrierTests { StoreReadResponse.Error.Exception( origin = StoreReadResponseOrigin.SourceOfTruth, error = - ReadException( - key = 1, - cause = exception, - ), + ReadException( + key = 1, + cause = exception, + ), ), - awaitItem() + awaitItem(), ) } } @@ -188,10 +188,10 @@ class SourceOfTruthWithBarrierTests { StoreReadResponse.Error.Exception( origin = StoreReadResponseOrigin.SourceOfTruth, error = - ReadException( - key = 1, - cause = exception, - ), + ReadException( + key = 1, + cause = exception, + ), ), collected.first(), ) @@ -205,10 +205,10 @@ class SourceOfTruthWithBarrierTests { StoreReadResponse.Error.Exception( origin = StoreReadResponseOrigin.SourceOfTruth, error = - ReadException( - key = 1, - cause = exception, - ), + ReadException( + key = 1, + cause = exception, + ), ), StoreReadResponse.Data( // this is fetcher since we are using the write API @@ -254,11 +254,11 @@ class SourceOfTruthWithBarrierTests { StoreReadResponse.Error.Exception( origin = StoreReadResponseOrigin.SourceOfTruth, error = - WriteException( - key = 1, - value = failValue, - cause = exception, - ), + WriteException( + key = 1, + value = failValue, + cause = exception, + ), ), StoreReadResponse.Data( origin = StoreReadResponseOrigin.SourceOfTruth, diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/StreamWithoutSourceOfTruthTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/StreamWithoutSourceOfTruthTests.kt index 47f3541f..a9a81c1b 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/StreamWithoutSourceOfTruthTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/StreamWithoutSourceOfTruthTests.kt @@ -42,7 +42,7 @@ class StreamWithoutSourceOfTruthTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -50,7 +50,7 @@ class StreamWithoutSourceOfTruthTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -97,7 +97,7 @@ class StreamWithoutSourceOfTruthTests { StoreReadResponse.Loading( origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) assertEquals( @@ -105,7 +105,7 @@ class StreamWithoutSourceOfTruthTests { value = "three-2", origin = StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/UpdaterTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/UpdaterTests.kt index a50e4bcd..d7898fee 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/UpdaterTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/UpdaterTests.kt @@ -63,12 +63,12 @@ class UpdaterTests { MutableStoreBuilder.from( fetcher = Fetcher.of { key -> api.get(key, ttl = ttl) }, sourceOfTruth = - SourceOfTruth.of( - nonFlowReader = { key -> notes.get(key) }, - writer = { key, sot: InputNote -> notes.put(key, sot) }, - delete = { key -> notes.clear(key) }, - deleteAll = { notes.clear() }, - ), + SourceOfTruth.of( + nonFlowReader = { key -> notes.get(key) }, + writer = { key, sot: InputNote -> notes.put(key, sot) }, + delete = { key -> notes.clear(key) }, + deleteAll = { notes.clear() }, + ), converter = converter, ) .validator(validator) @@ -85,7 +85,7 @@ class UpdaterTests { stream.test { assertEquals( StoreReadResponse.Loading(origin = StoreReadResponseOrigin.Fetcher()), - awaitItem() + awaitItem(), ) assertEquals( @@ -93,7 +93,7 @@ class UpdaterTests { OutputNote(NoteData.Single(Notes.One), ttl = ttl), StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -176,12 +176,12 @@ class UpdaterTests { MutableStoreBuilder.from( fetcher = Fetcher.of { key -> api.get(key, ttl = ttl) }, sourceOfTruth = - SourceOfTruth.of( - nonFlowReader = { key -> notes.get(key) }, - writer = { key, sot: InputNote -> notes.put(key, sot) }, - delete = { key -> notes.clear(key) }, - deleteAll = { notes.clear() }, - ), + SourceOfTruth.of( + nonFlowReader = { key -> notes.get(key) }, + writer = { key, sot: InputNote -> notes.put(key, sot) }, + delete = { key -> notes.clear(key) }, + deleteAll = { notes.clear() }, + ), converter = converter, ) .validator(validator) @@ -198,7 +198,7 @@ class UpdaterTests { stream.test { assertEquals( StoreReadResponse.Loading(origin = StoreReadResponseOrigin.Fetcher()), - awaitItem() + awaitItem(), ) assertEquals( @@ -206,7 +206,7 @@ class UpdaterTests { OutputNote(NoteData.Single(Notes.One), ttl = ttl), StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } @@ -222,14 +222,14 @@ class UpdaterTests { cachedStream.test { assertEquals( StoreReadResponse.Loading(origin = StoreReadResponseOrigin.Fetcher(name = null)), - awaitItem() + awaitItem(), ) assertEquals( StoreReadResponse.Data( OutputNote(NoteData.Single(Notes.One), ttl = ttl), StoreReadResponseOrigin.Fetcher(), ), - awaitItem() + awaitItem(), ) } } @@ -251,17 +251,17 @@ class UpdaterTests { val store = MutableStoreBuilder.from( fetcher = - Fetcher.ofFlow { key -> - val network = api.get(key) - flow { emit(network) } - }, + Fetcher.ofFlow { key -> + val network = api.get(key) + flow { emit(network) } + }, sourceOfTruth = - SourceOfTruth.of( - nonFlowReader = { key -> notes.get(key) }, - writer = { key, sot -> notes.put(key, sot) }, - delete = { key -> notes.clear(key) }, - deleteAll = { notes.clear() }, - ), + SourceOfTruth.of( + nonFlowReader = { key -> notes.get(key) }, + writer = { key, sot -> notes.put(key, sot) }, + delete = { key -> notes.clear(key) }, + deleteAll = { notes.clear() }, + ), converter, ) .validator(validator)