Nathan Kleinschmidt
09/22/2022, 2:55 PMArchie
09/23/2022, 7:44 AMfun someFunctionInsideActivity() {
val intent = try {
packageManager.getLaunchIntentForPackage("some.app.id")
} catch (e: Exception) {
Intent(
Intent.ACTION_VIEW,
Uri.parse(webSiteUrl)
)
}
startActivity(intent)
}
I want to write Espresso
test for both scenario. I was wondering if its possible to Mock the return of packageManager.getLaunchIntentForPackage(...)
so that I could test both scenario in test.
Any ideas? Any other way of testing this would be appreciated.
Thanks in advance.Slackbot
09/23/2022, 8:08 AMMichael Pohl
09/23/2022, 12:39 PMclass SomeFragment: Fragment() {
val myVal: SomeClass by lazy {
SomeClass { requireContext().packageName }
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
myVal.runLambda()
}
}
class SomeClass(
private val willBeRunSomeTimeInTheFuture: () -> String) {
fun runLambda() {
Thread.sleep(1000)
println(willBeRunSomeTimeInTheFuture())
}
}
Trying to wrap my head around if I have to worry when using requireContext
in a lambda that might get executed at a point the fragment is potentially already gone again, and what to do about it. If this is problematic (happy to hear why exactly), would a WeakReference
be enough to mitigate this, like below?
WeakReference(requireContext()).get()?.packageName ?: ""
Or do I completely misunderstand something here?
Let me know if this example or my question is not sufficient to understand the problem.Ahmed Sellami
09/23/2022, 1:40 PMsuspend fun <T> wrapNetworkCall(call: () -> T) : NetworkResult<T> {
return try {
NetworkResult.Success(call())
} catch (e: HttpException) {
if (e.code() == 400)
NetworkResult.BadRequestError(e)
else NetworkResult.Error(e)
}
}
coroutineScope.launch {
val result = wrapNetworkCall {
Api.retrofitService.getCurrent() // Suspension functions can be called only within coroutine body
}
}
Lilly
09/23/2022, 5:19 PMfun <T : ResponsePacket> subscribe(..) : Flow<T> {
val packet = ResponsePacket()
emit(packet as T)
println("what is T: ${packet.javaClass}") // prints ResponsePacket
}
caller side:
dao.subscribe<ParameterResponsePacket>()
The IDE marks the packet as smart casted (green background) but it isn't actually. Any ideas whats is wrong?Animesh Vashistha
09/24/2022, 11:10 AMAnimesh Vashistha
09/24/2022, 11:11 AMAnimesh Vashistha
09/24/2022, 11:11 AMaridder
09/24/2022, 12:13 PMbuild.gradle.kts
which works:Amit
09/24/2022, 4:27 PMJakub Neukirch
09/26/2022, 10:22 AMjannis
09/26/2022, 12:20 PMjared
09/26/2022, 3:13 PMSlackbot
09/27/2022, 12:30 PMnuhkoca
09/27/2022, 12:44 PMAhmed Sellami
09/27/2022, 1:07 PMShreyas Patil
09/28/2022, 7:44 AMCiaran Sloan
09/28/2022, 10:34 AMScaffold
API for that. The content
lambda receives a PaddingValues
which you can use to retrieve the padding of both top and bottom bars which are provided to the Scaffold
Sky
09/28/2022, 11:56 AMMuhammad Junaid
09/28/2022, 7:33 PMMuhammad Junaid
09/28/2022, 7:53 PMMilo
09/28/2022, 9:11 PMAshish Gautam
09/29/2022, 6:39 AMdave08
09/29/2022, 11:33 AMSlackbot
09/29/2022, 1:18 PMMichael Job
09/29/2022, 3:20 PMprivate val modelScope = CoroutineScope(SupervisorJob() + <http://Dispatchers.IO|Dispatchers.IO>)
fun loadImageBitmap(id: Int) {
if (currentId == id) {
return
}
currentId = id
modelScope.coroutineContext.cancelChildren().also { print(".") }
//cancel all requests before the current one - prints a dot each just for demonstrating
modelScope.launch { //Coroutine #1
delay(500) //simulate longer http request
println("\njob ${this.coroutineContext.job.hashCode()} gets Image $id")
currentImage = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
URL("$baseUrl$id-1.jpg").openStream()
}
.buffered()
.use(::loadImageBitmap) // loads image
}
}
Brandon Howard
09/29/2022, 5:41 PMval isDebuggable = 0 != applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE
I tried using BuildConfig.DEBUG
but thats always falseMuhammad Junaid
09/29/2022, 9:02 PMPabitra Ranjan Sahu
09/30/2022, 9:32 AMPabitra Ranjan Sahu
09/30/2022, 9:32 AM