Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
2b196833
Commit
2b196833
authored
Mar 24, 2020
by
levimatheri
Browse files
Closes #6369: Add ThrowProperty to support-test
parent
febac9aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
components/feature/customtabs/src/test/java/mozilla/components/feature/customtabs/feature/CustomTabSessionTitleObserverTest.kt
View file @
2b196833
...
...
@@ -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"
)
}
}
components/support/test/src/main/java/mozilla/components/support/test/ThrowProperty.kt
0 → 100644
View file @
2b196833
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"
)
}
components/support/test/src/test/java/mozilla/components/support/test/ThrowPropertyTest.kt
0 → 100644
View file @
2b196833
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment