File tree 3 files changed +9
-22
lines changed
app/src/androidTest/java/com/mitteloupe/whoami/localstore
architecture/instrumentation-test/src/main/java/com/mitteloupe/whoami/test 3 files changed +9
-22
lines changed Original file line number Diff line number Diff line change 1
1
package com.mitteloupe.whoami.localstore
2
2
3
3
import com.mitteloupe.whoami.datasource.local.LocalStoreKey.KEY_HISTORY_RECORDS
4
- import com.mitteloupe.whoami.test.asset.assetReader
4
+ import com.mitteloupe.whoami.test.asset.getAssetAsString
5
5
import com.mitteloupe.whoami.test.localstore.KeyValueStore
6
6
7
7
const val KEY_VALUE_SAVED_HISTORY = " Saved history"
@@ -15,5 +15,5 @@ class AppKeyValueStore : KeyValueStore() {
15
15
(KEY_HISTORY_RECORDS to assetAsString(" localstore/history_no_records.json" ))
16
16
)
17
17
18
- private fun assetAsString (assetName : String ) = assetReader. getAssetAsString(assetName)
18
+ private fun assetAsString (assetName : String ) = getAssetAsString(assetName)
19
19
}
Original file line number Diff line number Diff line change @@ -2,25 +2,12 @@ package com.mitteloupe.whoami.test.asset
2
2
3
3
import androidx.test.platform.app.InstrumentationRegistry
4
4
import java.io.InputStream
5
- import java.io.InputStreamReader
6
5
7
- val assetReader = AssetReader ()
8
-
9
- class AssetReader {
10
- fun getAssetAsString (name : String ): String =
11
- javaClass.classLoader!! .getResourceAsStream(" assets/$name " ).use { stream ->
12
- InputStreamReader (stream).use { reader ->
13
- reader.readText()
14
- }
15
- }
16
- }
6
+ fun getAssetAsString (name : String ): String =
7
+ processAssetStream(name) { stream -> stream.bufferedReader().readText() }
17
8
18
9
fun <OUTPUT > processAssetStream (
19
10
filename : String ,
20
- performOnStream : (inputString: InputStream ) -> OUTPUT
21
- ): OUTPUT {
22
- val stream = InstrumentationRegistry .getInstrumentation().context.assets.open(filename)
23
- val result = performOnStream(stream)
24
- stream.close()
25
- return result
26
- }
11
+ performOnStream : (inputStream: InputStream ) -> OUTPUT
12
+ ): OUTPUT = InstrumentationRegistry .getInstrumentation().context.assets.open(filename)
13
+ .use { stream -> performOnStream(stream) }
Original file line number Diff line number Diff line change 1
1
package com.mitteloupe.whoami.test.server.response
2
2
3
- import com.mitteloupe.whoami.test.asset.assetReader
3
+ import com.mitteloupe.whoami.test.asset.getAssetAsString
4
4
import com.mitteloupe.whoami.test.server.MockResponse
5
5
6
6
data class SimpleResponseFactory (
@@ -12,7 +12,7 @@ data class SimpleResponseFactory(
12
12
if (bodyFileName == null ) {
13
13
" "
14
14
} else {
15
- assetReader. getAssetAsString(bodyFileName)
15
+ getAssetAsString(bodyFileName)
16
16
}
17
17
}
18
18
You can’t perform that action at this time.
0 commit comments