Skip to content

Commit

Permalink
MBS-8436 enable kotlin warnings as errors (#638)
Browse files Browse the repository at this point in the history
* MBS-8436 enable kotlin warnings as errors

* MBS-8436 fix test warnings
  • Loading branch information
dsvoronin authored Nov 17, 2020
1 parent fd323b1 commit 4204954
Show file tree
Hide file tree
Showing 54 changed files with 152 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ abstract class InHouseInstrumentationTestRunner :
)
}

private fun validateEnvironment(runEnvironment: TestRunEnvironment.RunEnvironment) {
private fun validateEnvironment(@Suppress("UNUSED_PARAMETER") runEnvironment: TestRunEnvironment.RunEnvironment) {
//todo validate
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal fun Context.checkPlayServices() {
}
}

@Suppress("DEPRECATION")
internal val Context.playServicesOnDeviceVersion: Int
get() = packageManager.getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0).versionCode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.test.fixtures.TestAnnotation1
import com.test.fixtures.TestAnnotation2
import com.test.fixtures.TestAnnotation3
import com.test.fixtures.TestAnnotation4
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.hasSize
import org.junit.Assert.assertThat
import org.junit.jupiter.api.Test
import ru.avito.util.matcher.containsValueWithType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.avito.android.runner.annotation.resolver.MethodStringRepresentation.R
import com.avito.android.runner.annotation.resolver.MethodStringRepresentation.Resolution.ParseError
import com.test.fixtures.ClassWithMethod
import org.hamcrest.CoreMatchers.equalTo
import org.junit.Assert.assertThat
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Test

class MethodStringRepresentationTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface TestLifecycleListener {
//do nothing
}

fun afterTestStop(result: ReportState.Initialized.Started) {
fun afterTestStop(state: ReportState.Initialized.Started) {
//do nothing
}

Expand Down Expand Up @@ -55,8 +55,8 @@ object TestLifecycleNotifier : TestLifecycleListener {
listeners.forEach { it.afterTestUpdate(state) }
}

override fun afterTestStop(result: ReportState.Initialized.Started) {
listeners.forEach { it.afterTestStop(result) }
override fun afterTestStop(state: ReportState.Initialized.Started) {
listeners.forEach { it.afterTestStop(state) }
}

override fun beforeTestWrite(state: ReportState.Initialized.Started) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ class VideoCapturerImpl(
return binary.absolutePath
}

fun File.createOrClear() {
private fun File.createOrClear() {
if (exists()) {
writer().use { it.write("") }
} else {
parentFile.mkdirs()
parentFile?.mkdirs()
createNewFile()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import com.avito.android.test.internal.Cache
import com.avito.android.test.internal.SQLiteDB
import com.avito.android.test.internal.SharedPreferences
import com.avito.android.test.page_object.KeyboardElement
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.not
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue

/**
* Abstraction of android phone from user's perspective
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class ChecksImpl(private val driver: ChecksDriver) : Checks,
}

override fun isLeftOf(matcher: Matcher<View>) {
driver.check(PositionAssertions.isLeftOf(matcher))
driver.check(PositionAssertions.isCompletelyLeftOf(matcher))
}

override fun isRightOf(matcher: Matcher<View>) {
driver.check(PositionAssertions.isRightOf(matcher))
driver.check(PositionAssertions.isCompletelyRightOf(matcher))
}

override fun isLeftAlignedWith(matcher: Matcher<View>) {
Expand All @@ -104,11 +104,11 @@ class ChecksImpl(private val driver: ChecksDriver) : Checks,
}

override fun isAbove(matcher: Matcher<View>) {
driver.check(PositionAssertions.isAbove(matcher))
driver.check(PositionAssertions.isCompletelyAbove(matcher))
}

override fun isBelow(matcher: Matcher<View>) {
driver.check(PositionAssertions.isBelow(matcher))
driver.check(PositionAssertions.isCompletelyBelow(matcher))
}

override fun isBottomAlignedWith(matcher: Matcher<View>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import com.avito.android.test.interceptor.AssertionInterceptor
import com.avito.android.test.waitForCheck
import org.hamcrest.Matcher

@Deprecated("todo use InteractionContext")
/**
* use interactionContext instead
*/
class OnViewChecksDriver(private val matcher: Matcher<View>) : ChecksDriver {

private val interaction: ViewInteraction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.avito.android.test.internal

import android.content.Context
import com.avito.android.waiter.waitFor
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.`is`
import org.junit.Assert
import java.io.File

internal class Cache(private val appContext: Context) {
Expand All @@ -12,7 +12,7 @@ internal class Cache(private val appContext: Context) {
val cacheDir = appContext.cacheDir
if (cacheDir.list() != null) {
waitFor(frequencyMs = DELETE_FREQUENCY_MS, timeoutMs = DELETE_TIMEOUT_MS) {
Assert.assertThat(
assertThat(
"Can't delete ${cacheDir.path}",
deleteRecursive(cacheDir),
`is`(true)
Expand All @@ -29,7 +29,7 @@ internal class Cache(private val appContext: Context) {
if (directory.isDirectory) {
directory.list()?.forEach { content ->
waitFor(frequencyMs = DELETE_FREQUENCY_MS, timeoutMs = DELETE_TIMEOUT_MS) {
Assert.assertThat(
assertThat(
"Can't delete file $content in ${directory.path}",
deleteRecursive(File(directory, content), *excludes),
`is`(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.avito.android.test.internal

import android.content.Context
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.`is`
import org.junit.Assert

internal class SQLiteDB(private val appContext: Context) {

Expand All @@ -16,7 +16,7 @@ internal class SQLiteDB(private val appContext: Context) {
appContext.deleteDatabase(database)

val exists = databasePath.exists()
Assert.assertThat("db exist not anymore at $databasePath", exists, `is`(false))
assertThat("db exist not anymore at $databasePath", exists, `is`(false))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import android.widget.ImageView
import androidx.test.espresso.matcher.BoundedMatcher
import org.hamcrest.Description

class ImageShownMatcher :
BoundedMatcher<View, ImageView>(ImageView::class.java) {
class ImageShownMatcher : BoundedMatcher<View, ImageView>(ImageView::class.java) {

override fun describeTo(description: Description) {
description.appendText("with shown image: ")
}

@Suppress("DEPRECATION")
override fun matchesSafely(layout: ImageView): Boolean {
layout.isDrawingCacheEnabled = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import android.view.View
import org.hamcrest.Description
import org.hamcrest.TypeSafeMatcher

@Deprecated("Used to refactor PageObjectElement matcher constructor")
/**
* Used to refactor PageObjectElement matcher constructor
*/
class NoViewMatcher : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText(
" If you see this description: you use legacy PageObjectElement constructor; " +
"It is forbidden for now, because it doesn't respect interaction context"
"It is forbidden for now, because it doesn't respect interaction context"
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package com.avito.android.test.page_object

import androidx.test.espresso.assertion.ViewAssertions
import android.view.View
import com.avito.android.test.InteractionContext
import com.avito.android.test.checks.Checks
import com.avito.android.test.checks.ChecksDriver
import com.avito.android.test.checks.ChecksImpl
import com.avito.android.test.checks.OnViewChecksDriver
import com.avito.android.test.matcher.BottomSheetCollapsedMatcher
import com.avito.android.test.matcher.BottomSheetExpandedMatcher
import org.hamcrest.Matcher

open class BottomSheetElement(matcher: Matcher<View>) : ViewElement(matcher) {
open class BottomSheetElement(interactionContext: InteractionContext) : ViewElement(interactionContext) {

override val checks = ElementChecks()
override val checks = ElementChecks(interactionContext)

inner class ElementChecks(
private val drivenChecks: ChecksDriver = OnViewChecksDriver(matcher)
) : Checks by ChecksImpl(drivenChecks) {
inner class ElementChecks(private val drivenChecks: ChecksDriver) : Checks by ChecksImpl(drivenChecks) {

fun isExpanded() {
drivenChecks.check(ViewAssertions.matches(BottomSheetExpandedMatcher()))
Expand All @@ -25,6 +21,5 @@ open class BottomSheetElement(matcher: Matcher<View>) : ViewElement(matcher) {
fun isCollapsed() {
drivenChecks.check(ViewAssertions.matches(BottomSheetCollapsedMatcher()))
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import android.view.View
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.platform.app.InstrumentationRegistry
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.`is`
import org.junit.Assert

class KeyboardElement : PageObject() {

Expand Down Expand Up @@ -70,7 +70,7 @@ class KeyboardElement : PageObject() {
if (get(content) == null) {
throw RuntimeException(
"Can't check keyboard position. Because View::mAttachInfo is null." +
" Did you rotate screen in test before this check?"
" Did you rotate screen in test before this check?"
)
}
}
Expand All @@ -82,7 +82,7 @@ class KeyboardElement : PageObject() {
threshold = (activityHeight - minimalKeyboardHeight).toInt()
}

Assert.assertThat(
assertThat(
generateErrorMessage(
displayed = isOpen,
activityEffectiveHeight = activityEffectiveHeight,
Expand All @@ -107,7 +107,7 @@ class KeyboardElement : PageObject() {
}
val sizes =
" actualEffectiveHeight: $activityEffectiveHeight " +
"thresholdEffectiveHeight: $threshold"
"thresholdEffectiveHeight: $threshold"

"(keyboard $status on the screen.${if (withSizes) sizes else ""})"
}
Expand All @@ -116,7 +116,7 @@ class KeyboardElement : PageObject() {
val expected = "Expected:"

return "${getStatusMessage(!displayed, true)} $doesNotMatch" +
" $expected ${getStatusMessage(displayed, false)}"
" $expected ${getStatusMessage(displayed, false)}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ open class ListElement(interactionContext: InteractionContext) : ViewElement(int
/**
* Hide parent method [PageObject.element]
*/
protected inline fun <reified T : PageObjectElement> element(matcher: Matcher<View>): T =
protected inline fun <reified T : PageObjectElement> element(@Suppress("UNUSED_PARAMETER") matcher: Matcher<View>): T =
throw RuntimeException("Use listElement(Matcher<View>) instead of element(Matcher<View>)")

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import com.avito.android.test.action.Actions
import com.avito.android.test.checks.Checks
import org.hamcrest.Matcher


// TODO: hide or deprecate private api
abstract class PageObjectElement : PageObject(), Actions {
@Deprecated("Don't use this matcher directly. Make child interaction context instead.")
/**
* Don't use this matcher directly. Make child interaction context instead.
*/
abstract val matcher: Matcher<View>
abstract val actions: Actions
abstract val checks: Checks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ open class ViewElement : PageObjectElement, Actions {
override val actions: Actions
override val checks: Checks

// TODO: make this constructor private and remove matcher
@Deprecated("Don't use this constructor. It leads to actions and checks in a wrong screen. " +
"Inside [PageObject] use [element] to create an instance with child interaction context. " +
"From custom class use ViewElement(interactionContext)")
/**
* TODO: make this constructor private and remove matcher
* Don't use this constructor. It leads to actions and checks in a wrong screen. " +
"Inside [PageObject] use [element] to create an instance with child interaction context. " +
"From custom class use ViewElement(interactionContext)
*/
constructor(
matcher: Matcher<View>,
interactionContext: InteractionContext = SimpleInteractionContext(matcher),
Expand Down Expand Up @@ -53,7 +55,8 @@ open class ViewElement : PageObjectElement, Actions {

override fun scrollTo() = actions.scrollTo()

override fun swipe(direction: SwipeDirection, speed: Swiper, precision: PrecisionDescriber) = actions.swipe(direction, speed, precision)
override fun swipe(direction: SwipeDirection, speed: Swiper, precision: PrecisionDescriber) =
actions.swipe(direction, speed, precision)

override fun read(allowBlank: Boolean) = actions.read(allowBlank)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ open class ViewPagerElement(
/**
* Hide parent method [PageObject.element]
*/
protected inline fun <reified T : PageObjectElement> element(matcher: Matcher<View>): T =
protected inline fun <reified T : PageObjectElement> element(@Suppress("UNUSED_PARAMETER") matcher: Matcher<View>): T =
throw RuntimeException(
"Use currentPageElement(Matcher<View>) instead for getting page of view pager" +
"and then use element(Matcher<View>) for getting child"
"and then use element(Matcher<View>) for getting child"
)

/**
Expand All @@ -53,7 +53,7 @@ open class ViewPagerElement(
protected inline fun <reified T : PageObjectElement> element(): T =
throw RuntimeException(
"Use currentPageElement(Matcher<View>) instead for getting page of view pager" +
"and then use element(Matcher<View>) for getting child"
"and then use element(Matcher<View>) for getting child"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal fun <T> Any.getFieldByReflection(fieldName: String): T =
internal fun Any.getFieldByReflectionWithAnyField(fieldName: String): Any =
this::class.java.getDeclaredField(fieldName)
.also { it.isAccessible = true }
.get(this)
.get(this)!!

internal fun Any.executeMethod(method: String, vararg arguments: Any?) =
javaClass.methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.avito.android.test.maps.provider.GoogleMapProvider
import com.avito.android.test.waitFor
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.model.LatLng
import org.junit.Assert
import org.hamcrest.MatcherAssert.assertThat

interface GoogleMapActions {
fun movePinTo(position: LatLng)
Expand All @@ -27,7 +27,7 @@ class GoogleMapActionsImpl(

waitFor(timeoutMs = timeoutMs) {
UiThreadStatement.runOnUiThread {
Assert.assertThat(
assertThat(
map.cameraPosition.target,
hasTheSameCoordinatesAs(position)
)
Expand Down
Loading

0 comments on commit 4204954

Please sign in to comment.