I want to write a test that checks if a property I...
# announcements
a
I want to write a test that checks if a property I have is a certain type. The property is a sealed class, so I want to write something like:
fun assertNetworkStateType(clazz: Class<*>) { assertTrue(networkState is clazz) }
so that I can call it like
assertNetworkStateType(NetworkState.Loading)
but I can't quite figure out what the type of that parameter would be.
d
If I understand you might want an inline function with a
reified
type parameter:
Copy code
inline fun <reified T> assertNetworkStateType(obj: Any?) = assertTrue(obj is T)
a
and how would I call that?
ah I see
assertNetworkStateType<NetworkState.Loading>()
works. Thank you. 🙂
I'm all the sudden less convinced this is the way I really want to do it, but at least now I know if I ever come across a more appropriate use case.
d
Then you should explain what exactly you want 😉