@@ -8,14 +8,15 @@ import android.content.Context
8
8
import android.util.AttributeSet
9
9
import mozilla.components.concept.engine.webextension.WebExtension
10
10
import org.json.JSONObject
11
- import org.junit.Assert.fail
11
+ import org.junit.Assert.assertNotNull
12
+ import org.junit.Assert.assertTrue
12
13
import org.junit.Test
13
14
import java.lang.UnsupportedOperationException
14
15
15
16
class EngineTest {
16
17
17
18
@Test
18
- fun `throws exception if webextensions not supported` () {
19
+ fun `invokes error callback if webextensions not supported` () {
19
20
val engine = object : Engine {
20
21
override fun createView (context : Context , attrs : AttributeSet ? ): EngineView {
21
22
throw NotImplementedError (" Not needed for test" )
@@ -41,32 +42,9 @@ class EngineTest {
41
42
get() = throw NotImplementedError (" Not needed for test" )
42
43
}
43
44
44
- try {
45
- engine.installWebExtension(WebExtension (" my-ext" , " resource://path" ))
46
- fail(" Expected UnsupportedOperationException" )
47
- } catch (_: UnsupportedOperationException ) {
48
- // expected
49
- }
50
-
51
- try {
52
- engine.installWebExtension(WebExtension (" my-ext" , " resource://path" )) { _, _ -> }
53
- fail(" Expected UnsupportedOperationException" )
54
- } catch (_: UnsupportedOperationException ) {
55
- // expected
56
- }
57
-
58
- try {
59
- engine.installWebExtension(WebExtension (" my-ext" , " resource://path" ), onSuccess = { })
60
- fail(" Expected UnsupportedOperationException" )
61
- } catch (_: UnsupportedOperationException ) {
62
- // expected
63
- }
64
-
65
- try {
66
- engine.installWebExtension(WebExtension (" my-ext" , " resource://path" ), onSuccess = { }) { _, _ -> }
67
- fail(" Expected UnsupportedOperationException" )
68
- } catch (_: UnsupportedOperationException ) {
69
- // expected
70
- }
45
+ var exception: Throwable ? = null
46
+ engine.installWebExtension(WebExtension (" my-ext" , " resource://path" ), onError = { _, e -> exception = e })
47
+ assertNotNull(exception)
48
+ assertTrue(exception is UnsupportedOperationException )
71
49
}
72
50
}
0 commit comments