Fix some tests
This commit is contained in:
parent
fc77dd153c
commit
015140fbf0
4 changed files with 16 additions and 33 deletions
|
@ -1,41 +1,28 @@
|
|||
package com.nytimes.android.sample
|
||||
|
||||
import com.nytimes.android.external.store3.base.Fetcher
|
||||
import com.nytimes.android.external.store3.base.impl.BarCode
|
||||
import com.nytimes.android.external.store3.base.impl.Store
|
||||
import com.nytimes.android.external.store3.base.impl.StoreBuilder
|
||||
import junit.framework.Assert.assertEquals
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class StoreIntegrationTest {
|
||||
|
||||
lateinit var store: Store<String, BarCode>
|
||||
val atomicInt = AtomicInteger(0)
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
store = StoreBuilder.barcode<String>()
|
||||
.fetcher(fetcher = object : Fetcher<String, BarCode> {
|
||||
override suspend fun fetch(key: BarCode): String {
|
||||
return atomicInt.incrementAndGet().toString()
|
||||
}
|
||||
})
|
||||
.open()
|
||||
}
|
||||
private val atomicInt = AtomicInteger(0)
|
||||
|
||||
private val store: Store<String, BarCode> = StoreBuilder.barcode<String>()
|
||||
.fetcher { atomicInt.incrementAndGet().toString() }
|
||||
.open()
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testRepeatedGet() {
|
||||
val barcode = BarCode.empty()
|
||||
runBlocking {
|
||||
val first = store.get(barcode)
|
||||
val same = store.fresh(barcode)
|
||||
val first = store.fresh(barcode)
|
||||
val same = store.get(barcode)
|
||||
assertEquals(first, same)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class SourceDiskDaoStoreTest {
|
|||
.open()
|
||||
|
||||
val foo = Foo()
|
||||
foo.bar = barCode.getKey()
|
||||
foo.bar = barCode.key
|
||||
|
||||
val sourceData = Gson().toJson(foo)
|
||||
val source = source(sourceData)
|
||||
|
|
|
@ -31,7 +31,7 @@ class StoreNetworkBeforeStaleTest {
|
|||
@Test
|
||||
fun networkBeforeDiskWhenStale() = runBlocking<Unit> {
|
||||
whenever(fetcher.fetch(barCode))
|
||||
.thenThrow(Exception())
|
||||
.thenThrow(RuntimeException())
|
||||
whenever(persister.read(barCode))
|
||||
.thenReturn(disk1) //get should return from disk
|
||||
whenever(persister.getRecordState(barCode)).thenReturn(RecordState.STALE)
|
||||
|
|
|
@ -6,18 +6,14 @@ import com.nytimes.android.external.store3.base.impl.StoreBuilder
|
|||
import kotlinx.coroutines.runBlocking
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.fail
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class NoNetworkTest {
|
||||
private lateinit var store: Store<Any, BarCode>
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
store = StoreBuilder.barcode<Any>()
|
||||
.fetcher { throw EXCEPTION }
|
||||
.open()
|
||||
}
|
||||
private val store: Store<Any, BarCode> = StoreBuilder.barcode<Any>()
|
||||
.fetcher {
|
||||
throw EXCEPTION
|
||||
}
|
||||
.open()
|
||||
|
||||
@Test
|
||||
fun testNoNetwork() = runBlocking<Unit> {
|
||||
|
@ -25,7 +21,7 @@ class NoNetworkTest {
|
|||
store.get(BarCode("test", "test"))
|
||||
fail("Exception not thrown")
|
||||
} catch (e: Exception) {
|
||||
assertThat(e).isEqualTo(EXCEPTION)
|
||||
assertThat(e.message).isEqualTo(EXCEPTION.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +34,6 @@ class NoNetworkTest {
|
|||
// }
|
||||
|
||||
companion object {
|
||||
private val EXCEPTION = RuntimeException()
|
||||
private val EXCEPTION = RuntimeException("abc")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue