Skip to content

Commit

Permalink
(Android) Get rid of some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
d4vidi committed Jul 15, 2019
1 parent 257c20d commit c7af1eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DetoxCrashHandler(private val wsClient: WebSocketClient) {
}

companion object {
val LOG_TAG = DetoxCrashHandler::class.java.simpleName!!
val LOG_TAG: String = DetoxCrashHandler::class.java.simpleName

const val APP_CRASH_ACTION_NAME = "AppWillTerminateWithError"
const val APP_CRASH_MESSAGE_ID = -10000L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TimingModuleReflected(reactContext: ReactContext) {
val timersQueue: PriorityQueue<Any>
get() = Reflect.on(nativeModule).field("mTimers").get()

val timersLock: Object
val timersLock: Any
get() = Reflect.on(nativeModule).field("mTimerGuard").get()

operator fun component1() = timersQueue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.wix.detox.espresso.matcher

import android.view.View
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import org.hamcrest.BaseMatcher
import org.hamcrest.Description

import org.hamcrest.Matcher
import org.hamcrest.Matchers.*
import org.hamcrest.Matchers.allOf
import org.hamcrest.TypeSafeMatcher

/*
* An extension of [androidx.test.espresso.matcher.ViewMatchers].
Expand All @@ -16,20 +16,29 @@ import org.hamcrest.Matchers.*
fun isOfClassName(className: String): Matcher<View> {
try {
val cls = Class.forName(className)
return allOf(isAssignableFrom(cls as Class<out View>?), withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))
return allOf(IsAssignableFromMatcher(cls), withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))
} catch (e: ClassNotFoundException) {
// empty
}

return object : BaseMatcher<View>() {
override fun matches(item: Any): Boolean {
return false
}

override fun matches(item: Any) = false
override fun describeTo(description: Description) {
description.appendText("Class $className not found on classpath. Are you using full class name?")
}
}
}

fun isMatchingAtIndex(index: Int, innerMatcher: Matcher<View>): Matcher<View> = ViewAtIndexMatcher(index, innerMatcher)

/**
* Same as [androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom], but accepts any class. Needed
* in order to avoid warning when passing 'any' class.
* [TypeSafeMatcher] does the View-class type matching for us.
*/
private class IsAssignableFromMatcher(private val clazz: Class<*>) : TypeSafeMatcher<View>() {
public override fun matchesSafely(view: View) = clazz.isAssignableFrom(view.javaClass)
override fun describeTo(description: Description) {
description.appendText("is assignable from class: $clazz")
}
}

0 comments on commit c7af1eb

Please sign in to comment.