Uri¶
some-android includes a resolver for android.net.Uri.
Once some-android is on your test classpath, some<Uri>() works without custom factories or custom resolvers.
Android-only feature
UriStrategy is part of some-android. It is not available from some-core.
Basic usage¶
The generated value is a parseable Uri with a scheme, host, and path. Depending on the active strategy, it may also include a query string or fragment.
Uri strategy¶
Use UriStrategy when the URI scheme matters for the code you are testing.
| Strategy | Default | What it generates | Good for |
|---|---|---|---|
UriStrategy.Random |
Yes | Randomly chooses content://, file://, or https:// |
General tests that only need a valid Uri |
UriStrategy.Content |
No | Only content://... URIs |
ContentResolver, providers, and content URIs |
UriStrategy.File |
No | Only file://... URIs |
File URI handling |
UriStrategy.Url |
No | Only https://... URIs with a domain-like host |
Web links and URL-style inputs |
Configure it per call¶
import android.net.Uri
import dev.appoutlet.some.android.strategy.UriStrategy
import dev.appoutlet.some.some
val uri = some<Uri> {
strategy(UriStrategy.Url)
}
Configure it once and reuse it¶
import android.net.Uri
import dev.appoutlet.some.android.strategy.UriStrategy
import dev.appoutlet.some.someSetup
val some = someSetup {
strategy(UriStrategy.Content)
}
val avatarUri: Uri = some()
val documentUri: Uri = some()
What the resolver generates¶
- A scheme controlled by
UriStrategy - A non-empty host
- At least one path segment
- An optional query string
- An optional fragment
When you use UriStrategy.Url, the host is generated in a domain-like format such as example.ab.
Picking the right strategy¶
- Use
UriStrategy.Randomwhen your test only needs a validUri - Use
UriStrategy.Contentwhen your code branches oncontentURIs - Use
UriStrategy.Filewhen your code expects file URIs - Use
UriStrategy.Urlwhen your code validates or handleshttpslinks
Examples¶
If your test cares about the scheme, prefer an explicit strategy instead of asserting against the default random output.
See Android for installation and the list of Android-specific supported types.