Skip to content

Commit

Permalink
Enable and fix Detekt naming and formatting rules (#642)
Browse files Browse the repository at this point in the history
* detekt: enable and fix MatchingDeclarationName rule

explain why InvalidPackageDeclaration blocked

* detekt: enable ConstructorParameterNaming

* detekt: enable ClassNaming

* detekt: enable and fix VariableNaming

* detekt: enable and fix FinalNewline

enable formatting options (add required dependency)

* detekt: enable and fix NoMultipleSpaces

* detekt: enable and fix NoSemicolons

* detekt: enable and fix NoTrailingSpaces

* detekt: enable and fix NoUnusedImports

* detekt: enable and fix NoWildcardImports

* detekt: remove unused autoCorrect directives

* detekt: explain why Indentation rule blocked and some fixes

* detekt: enable NoEmptyClassBody rule

* detekt: enable and fix NoConsecutiveBlankLines rule

* detekt: enable and fix SpacingAroundColon rule

* detekt: enable and fix SpacingAroundComma rule

* detekt: enable and fix SpacingAroundCurly rule

* detekt: enable and fix SpacingAroundDot rule

* detekt: enable and fix SpacingAroundDoubleColon rule

* detekt: enable and fix SpacingAroundKeyword rule

* detekt: enable and fix SpacingAroundOperators rule

* detekt: enable and fix SpacingAroundParens rule

* detekt: enable and fix SpacingAroundRangeOperator rule

* detekt: enable and fix SpacingBetweenDeclarationsWithAnnotations rule

* detekt: enable and fix SpacingBetweenDeclarationsWithComments rule

* detekt: enable and fix StringTemplate rule

* detekt: enable and fix CommentSpacing rule

* detekt: enable and fix ArgumentListWrapping rule

* detekt: explain disabling ChainWrapping rule

* detekt: enable and fix ImportOrdering rule

* detekt: enable ModifierOrdering rule

* detekt: enable and fix MultiLineIfElse rule

* detekt: enable and fix NoBlankLineBeforeRbrace rule

* detekt: enable NoLineBreakAfterElse rule

* detekt: enable NoLineBreakBeforeAssignment rule

* detekt: enable and fix ParameterListWrapping rule

* detekt: finish with formatting for now

* detekt

* pr fixes

* fix dependencies resolution
  • Loading branch information
dsvoronin authored Nov 20, 2020
1 parent ec0dc8e commit 7caea75
Show file tree
Hide file tree
Showing 385 changed files with 1,229 additions and 1,198 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.avito.android.test

//see TestMinimized.md
// see TestMinimized.md

/**
* An analog of [androidx.annotation.Keep]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,5 @@ class SnackbarRule() : SimpleRule(), SnackbarAsserts {
// look at snackbar.setText
private val Snackbar.text: String
get() = view.findViewById<TextView>(google_R.id.snackbar_text).text.toString()

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StatsdHttpTracker(private val statsd: StatsDSender) : HttpTracker {
val urlKey = convertUrlToMetricKey(response.request.url)

statsd.send(
"test.http.${urlKey}",
"test.http.$urlKey",
CountMetric(response.code.toString())
)
statsd.send(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.test.rule.ActivityTestRule
import com.avito.android.test.Intents.stubEverything

internal class ActivityRule<T : Activity>(aClass: Class<T>) : ActivityTestRule<T>(
aClass,
/*initialTouchMode*/ true,
/*launchActivity*/ false
aClass,
true, // initialTouchMode
false // launchActivity
) {

override fun afterActivityLaunched() {
Expand All @@ -21,4 +21,4 @@ internal class ActivityRule<T : Activity>(aClass: Class<T>) : ActivityTestRule<T
super.afterActivityFinished()
Intents.release()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import java.util.concurrent.TimeUnit

@SuppressLint("LogNotTimber")
internal fun createReportHttpClient(): OkHttpClient {
val retryInterceptor = RetryInterceptor(allowedMethods = listOf("GET", "POST"),
val retryInterceptor = RetryInterceptor(
allowedMethods = listOf("GET", "POST"),
logger = object : Logger {
override fun debug(msg: String) {
Log.v("ReportViewerHttp", msg)
Expand All @@ -27,12 +28,15 @@ internal fun createReportHttpClient(): OkHttpClient {
override fun warn(msg: String, error: Throwable?) {
Log.v("ReportViewerHttp", msg, error)
}
})
val httpLoggingInterceptor = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger {
override fun log(message: String) {
Log.v("ReportViewerHttp", message)
}
}).apply {
)
val httpLoggingInterceptor = HttpLoggingInterceptor(
object : HttpLoggingInterceptor.Logger {
override fun log(message: String) {
Log.v("ReportViewerHttp", message)
}
}
).apply {
level = HttpLoggingInterceptor.Level.BASIC
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ abstract class InHouseInstrumentationTestRunner :
}

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

private fun initTestCase(runEnvironment: TestRunEnvironment.RunEnvironment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class SentryErrorsReporter(
override fun reportError(error: Throwable) {
sentry.sendException(error)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fun provideEnvironment(
buildCommit = argumentsProvider.getMandatoryArgument("buildCommit"),
testMetadata = argumentsProvider.getMandatorySerializableArgument(TEST_METADATA_KEY) as TestMetadata,
networkType = argumentsProvider.getMandatorySerializableArgument(NETWORKING_TYPE_KEY) as NetworkingType,
//todo url'ы не обязательные параметры
// todo url'ы не обязательные параметры
apiUrl = provideApiUrl(
argumentsProvider = argumentsProvider,
apiUrlParameterKey = apiUrlParameterKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.avito.android.runner.annotation.resolver

import java.lang.reflect.Method


object Annotations {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ object MethodStringRepresentation {
}

fun parseString(stringRepresentation: String): Resolution {
if (stringRepresentation.trim().isEmpty())
return Resolution.ParseError(
"Method string representation is empty string"
)
if (stringRepresentation.trim().isEmpty()) {
return Resolution.ParseError("Method string representation is empty string")
}

val testTargetString = stringRepresentation.split("#")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AnnotationResolversBasedMetadataInjector(
when (val switchResolution = annotationResolver.resolve(fullyQualifiedTestName)) {
is TestMetadataResolver.Resolution.ReplaceString -> {
instrumentationArguments.putString(
annotationResolver.key, //TODO: protect against accidental collision in keys
annotationResolver.key, // TODO: protect against accidental collision in keys
switchResolution.replacement
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.avito.android.test
import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import androidx.test.platform.app.InstrumentationRegistry
import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import com.avito.android.runner.checkPlayServices
import com.avito.android.test.util.getCurrentActivity
import org.junit.rules.TestRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ class DeviceSettingsChecker(private val context: Context) {
)
if (warnings.isNotEmpty()) {
// TODO: Try to fix them of fail MBS-7355
Log.e("UITestRunner", "=== ERROR=== \n" +
"Emulator has incorrect settings which cause flakiness:\n" +
warnings.joinToString(separator = "") { "- $it\n" } +
"\nSee https://avito-tech.github.io/avito-android/docs/ci/containers/#android-emulator-images"
Log.e(
"UITestRunner",
"=== ERROR=== \n" +
"Emulator has incorrect settings which cause flakiness:\n" +
warnings.joinToString(separator = "") { "- $it\n" } +
"\nSee https://avito-tech.github.io/avito-android/docs/ci/containers/#android-emulator-images"
)
}
}
Expand All @@ -44,7 +46,13 @@ class DeviceSettingsChecker(private val context: Context) {
}

private fun checkTransitionAnimationScale(): String? {
return if (Settings.Global.getFloat(context.contentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE, 1f) > 0) {
return if (
Settings.Global.getFloat(
context.contentResolver,
Settings.Global.TRANSITION_ANIMATION_SCALE,
1f
) > 0
) {
"Transition animation scale must be turned off"
} else {
null
Expand All @@ -66,5 +74,4 @@ class DeviceSettingsChecker(private val context: Context) {
null
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class MethodStringRepresentationTest {
@Test
fun `parseString - resolution method - for class#method string`() {
assertResolution(
"com.test.fixtures.ClassWithMethod#method", Method(
"com.test.fixtures.ClassWithMethod#method",
Method(
ClassWithMethod::class.java,
ClassWithMethod::class.java.getMethod("method")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.avito.android.runner

interface Context {
val errorsReporter: ErrorsReporter
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.avito.android.runner

class DefaultTestInstrumentationContext(
override val errorsReporter: ErrorsReporter
) : Context
) : Context
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.avito.android.runner

interface ErrorsReporter {
fun reportError(error: Throwable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class InstrumentationDelegate(
fun beforeOnStart() {
systemDialogsManager.closeSystemDialogs()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class LogErrorsReporter(
override fun reportError(error: Throwable) {
Log.e(tag, "ERROR", error)
}
}
}
12 changes: 7 additions & 5 deletions subprojects/android-test/test-library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ android {
}
}

dependencies(delegateClosureOf<DependencyHandler> {
dependencies(
delegateClosureOf<DependencyHandler> {

implementation(Dependencies.appcompat)
implementation(Dependencies.appcompat)

androidTestImplementation(project(":android-test:ui-testing-core"))
androidTestUtil(Dependencies.AndroidTest.orchestrator)
})
androidTestImplementation(project(":android-test:ui-testing-core"))
androidTestUtil(Dependencies.AndroidTest.orchestrator)
}
)
2 changes: 1 addition & 1 deletion subprojects/android-test/test-report/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
implementation(Dependencies.kotson)
implementation(Dependencies.funktionaleTry)
implementation(Dependencies.okhttp)
implementation(Dependencies.sentryAndroid) //todo use common:sentry
implementation(Dependencies.sentryAndroid) // todo use common:sentry

testImplementation(project(":common:junit-utils"))
testImplementation(project(":common:logger-test-fixtures"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.avito.android.test.report
import android.os.Bundle
import java.io.Serializable

//TODO: consider of using as a wrapper above "bundle" to protect from collisions, empty values, ...
// TODO: consider of using as a wrapper above "bundle" to protect from collisions, empty values, ...
interface ArgsProvider {

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ class BundleArgsProvider(
val result: String? = bundle.getString(name)
if (result == null || result.isBlank()) {
throw ReporterException(
"$name is a mandatory argument; all values=${bundle}"
"$name is a mandatory argument; all values=$bundle"
)
} else {
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class ReportImplementation(
TestLifecycleListener by TestLifecycleNotifier,
PreconditionLifecycleListener by PreconditionLifecycleNotifier {


/**
* Entries that occurred before first step/precondition
*/
Expand All @@ -73,7 +72,6 @@ class ReportImplementation(
override val isFirstStepOrPrecondition: Boolean
get() = state.isFirstStepOrPrecondition


@Synchronized
override fun initTestCase(testMetadata: TestMetadata) = methodExecutionTracing("initTestCase") {
checkStateIs<ReportState.Nothing>()
Expand Down Expand Up @@ -279,7 +277,6 @@ class ReportImplementation(
futureUploads.add(html)
}


@Synchronized
override fun addComment(comment: String) {
addEntry(Entry.Comment(comment, timeProvider.nowInSeconds()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import com.avito.filestorage.RemoteStorage
import com.avito.http.isPlaintext
import com.github.salomonbrys.kotson.fromJson
import com.google.gson.GsonBuilder
import okhttp3.*
import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.Interceptor
import okhttp3.MediaType
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import okhttp3.internal.http.promisesBody
import okio.Buffer
import java.nio.charset.Charset
Expand Down Expand Up @@ -90,11 +96,7 @@ class ReportViewerHttpInterceptor(
while (requestHeadersIndex < requestHeadersCount) {
val name = headers.name(requestHeadersIndex)
// Skip headers from the request body as they are explicitly logged above.
if (!"Content-Type".equals(name, ignoreCase = true) && !"Content-Length".equals(
name,
ignoreCase = true
)
) {
if (!"Content-Type".equals(name, ignoreCase = true) && !"Content-Length".equals(name, ignoreCase = true)) {
result.appendln(name + ": " + headers.value(requestHeadersIndex))
}
requestHeadersIndex++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,4 @@ class ReportViewerWebsocketReporter(private val reportProvider: ReportProvider)
class RpcRequest(val id: String, val method: String, override val prettyJson: String) : OutgoingMessage()
class Unknown(override val prettyJson: String) : OutgoingMessage()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inline fun <T : DataSet> dataSet(
) {
report.updateTestCase {
dataSet = value
//todo почему -1 это вообще валидное значение? попробовать использовать unsigned тип данных
// todo почему -1 это вообще валидное значение? попробовать использовать unsigned тип данных
require(testMetadata.dataSetNumber != null && testMetadata.dataSetNumber != -1) {
"Please specify @DataSetNumber(Int) for test ${testMetadata.className}.${testMetadata.methodName}"
}
Expand Down Expand Up @@ -185,9 +185,11 @@ class StepException(
fun data(isPrecondition: Boolean, action: String, assertion: String?): String {
return "${slug(isPrecondition).capitalize()}:\n${action.prependIndent()}"
.let {
if (assertion != null)
if (assertion != null) {
"$it\nПроверка:\n${assertion.prependIndent()}"
else it
} else {
it
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ import com.avito.report.model.Incident
interface TestLifecycleListener {

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

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

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

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

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

fun testWriteError(error: Throwable) {
//do nothing
// do nothing
}

fun afterIncident(incident: Incident) {
//do nothing
// do nothing
}

fun screenshotUploadError(error: Throwable) {
//do nothing
// do nothing
}
}

Expand Down
Loading

0 comments on commit 7caea75

Please sign in to comment.