Commit 2b196833 authored by levimatheri's avatar levimatheri
Browse files

Closes #6369: Add ThrowProperty to support-test

parent febac9aa
......@@ -8,6 +8,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.browser.session.Session
import mozilla.components.concept.toolbar.AutocompleteDelegate
import mozilla.components.concept.toolbar.Toolbar
import mozilla.components.support.test.ThrowProperty
import mozilla.components.support.test.mock
import org.junit.Assert.assertEquals
import org.junit.Test
......@@ -15,8 +16,6 @@ import org.junit.runner.RunWith
import org.mockito.Mockito
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
@RunWith(AndroidJUnit4::class)
class CustomTabSessionTitleObserverTest {
......@@ -86,12 +85,4 @@ class CustomTabSessionTitleObserverTest {
override fun displayMode() = Unit
override fun editMode() = Unit
}
private class ThrowProperty<T> : ReadWriteProperty<Any, T> {
override fun getValue(thisRef: Any, property: KProperty<*>): T =
throw UnsupportedOperationException("Cannot get $property")
override fun setValue(thisRef: Any, property: KProperty<*>, value: T) =
throw UnsupportedOperationException("Cannot set $property")
}
}
package mozilla.components.support.test
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
/**
* A [ReadWriteProperty] implementation for creating stub properties.
*/
class ThrowProperty<T> : ReadWriteProperty<Any, T> {
override fun getValue(thisRef: Any, property: KProperty<*>): T =
throw UnsupportedOperationException("Cannot get $property")
override fun setValue(thisRef: Any, property: KProperty<*>, value: T) =
throw UnsupportedOperationException("Cannot set $property")
}
package mozilla.components.support.test.robolectric.mozilla.components.support.test
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.support.test.ThrowProperty
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ThrowPropertyTest {
private val testProperty = "test"
@Test(expected = UnsupportedOperationException::class)
fun `exception thrown when get value is called`() {
val throwProperty = ThrowProperty<String>()
throwProperty.getValue(testProperty, ::testProperty)
}
@Test(expected = UnsupportedOperationException::class)
fun `exception thrown when set value is called`() {
val throwProperty = ThrowProperty<String>()
throwProperty.setValue(testProperty, ::testProperty, "test1")
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment