File tree Expand file tree Collapse file tree 3 files changed +41
-6
lines changed
concept/engine/src/test/java/mozilla/components/concept/engine/manifest
main/java/mozilla/components/support/test/file
test/java/mozilla/components/support/test/file Expand file tree Collapse file tree 3 files changed +41
-6
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package mozilla.components.concept.engine.manifest
7
7
import android.graphics.Color
8
8
import android.graphics.Color.rgb
9
9
import androidx.test.ext.junit.runners.AndroidJUnit4
10
+ import mozilla.components.support.test.file.loadResourceAsString
10
11
import org.json.JSONObject
11
12
import org.junit.Assert.assertEquals
12
13
import org.junit.Assert.assertFalse
@@ -580,12 +581,7 @@ class WebAppManifestParserTest {
580
581
}
581
582
582
583
private fun loadManifestAsString (fileName : String ): String =
583
- javaClass.getResourceAsStream(" /manifests/$fileName " )!!
584
- .bufferedReader().use {
585
- it.readText()
586
- }.also {
587
- assertNotNull(it)
588
- }
584
+ loadResourceAsString(" /manifests/$fileName " )
589
585
590
586
private fun loadManifest (fileName : String ): JSONObject =
591
587
JSONObject (loadManifestAsString(fileName))
Original file line number Diff line number Diff line change
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
+
5
+ package mozilla.components.support.test.file
6
+
7
+ import org.junit.Assert
8
+
9
+ /* *
10
+ * Loads a file from the resources folder and return its content as a string object.
11
+ * @param path The path where the file is located
12
+ */
13
+ fun Any.loadResourceAsString (path : String ): String {
14
+ return javaClass.getResourceAsStream(path)!! .bufferedReader().use {
15
+ it.readText()
16
+ }.also {
17
+ Assert .assertNotNull(it)
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
+
5
+ package mozilla.components.support.test.robolectric.mozilla.components.support.test.file
6
+
7
+ import androidx.test.ext.junit.runners.AndroidJUnit4
8
+ import mozilla.components.support.test.file.loadResourceAsString
9
+ import org.junit.Assert.assertEquals
10
+ import org.junit.Test
11
+ import org.junit.runner.RunWith
12
+
13
+ @RunWith(AndroidJUnit4 ::class )
14
+ class ResourcesTest {
15
+
16
+ @Test
17
+ fun getProvidedAppContext () {
18
+ assertEquals(" 42" , loadResourceAsString(" /example_file.txt" ))
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments