Skip to content

Commit

Permalink
Merge pull request #150 from appunite/ensure-ktlint-check
Browse files Browse the repository at this point in the history
LD-132 Fix code formatting
  • Loading branch information
jacek-marchwicki authored Oct 23, 2023
2 parents 48cf829 + 10019f9 commit a81ea7b
Show file tree
Hide file tree
Showing 77 changed files with 424 additions and 408 deletions.
1 change: 0 additions & 1 deletion .github/workflows/run-code-quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
# https://megalinter.github.io/configuration/
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KOTLIN_KTLINT_ARGUMENTS: "--ruleset=custom-ktlint-rules/build/libs/custom-ktlint-rules.jar"
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
# DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks

Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,29 @@ jobs:
- name: Ensure license headers are added
run: python "build-tools/check-license-headers.py"

verify-formatting:
name: Verify ktlint formatting
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare Android Environment
uses: ./.github/actions/prepare-android-env

- name: Run test
run: ./gradlew ktlintCheck

test-results:
name: Upload tests results
runs-on: ubuntu-20.04
if: always()
needs:
- android-tests
- unit-tests
- verify-formatting
- test-license-headers

steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ DISABLE_LINTERS:
- PYTHON_PYLINT
- PYTHON_PYRIGHT
- PYTHON_RUFF
- KOTLIN_KTLINT
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ abstract class AbsLoginScreenTest {
intended(
allOf(
hasAction(Intent.ACTION_VIEW),
hasData("https://github.com/login/oauth/authorize?client_id=91131449e417c7e29912&scope=repo"),
),
hasData("https://github.com/login/oauth/authorize?client_id=91131449e417c7e29912&scope=repo")
)
)
}

Expand All @@ -108,8 +108,8 @@ abstract class AbsLoginScreenTest {
intended(
allOf(
hasAction(Intent.ACTION_VIEW),
hasData("https://github.com/login/oauth/authorize?client_id=91131449e417c7e29912&scope=repo"),
),
hasData("https://github.com/login/oauth/authorize?client_id=91131449e417c7e29912&scope=repo")
)
)
}

Expand All @@ -136,10 +136,10 @@ abstract class AbsLoginScreenTest {
hasComponent(
allOf(
hasPackageName("com.miui.securitycenter"),
hasClassName("com.miui.permcenter.permissions.PermissionsEditorActivity"),
),
),
),
hasClassName("com.miui.permcenter.permissions.PermissionsEditorActivity")
)
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ abstract class AbsWalkThroughAppTest : UniversalWalkThroughAppTest() {
ActivityScenario.launch<MainActivity>(
Intent(
Intent.ACTION_VIEW,
Uri.parse("loudius://callback?code=example_code"),
Uri.parse("loudius://callback?code=example_code")
).apply {
setPackage(integrationTestRule.composeTestRule.activity.packageName)
},
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.junit.runners.model.Statement

class IntegrationTestRule(
testClass: Any,
testActivity: Class<out ComponentActivity> = TestActivity::class.java,
testActivity: Class<out ComponentActivity> = TestActivity::class.java
) : TestRule {

val composeTestRule = createAndroidComposeRule(testActivity).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Request(
val headers: Headers,
val method: String,
val url: HttpUrl,
val body: Buffer,
val body: Buffer
) {
override fun toString(): String =
"Request(method=$method, url=$url, headers=${headers.joinToString(separator = ",") { (key, value) -> "$key: $value" }})"
Expand Down Expand Up @@ -73,7 +73,7 @@ class MockWebServerRule : TestRule {
buildList {
add(e)
addAll(dispatcher.errors)
},
}
)
}
} finally {
Expand All @@ -100,7 +100,7 @@ private class UrlOverrideInterceptor(private val baseUrl: HttpUrl) : Interceptor
.build()
return chain.proceed(
request.newBuilder().url(newUrl)
.addHeader("X-Test-Original-Url", request.url.toString()).build(),
.addHeader("X-Test-Original-Url", request.url.toString()).build()
)
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ private class MockDispatcher : Dispatcher() {
).toHttpUrl(),
headers = request.headers.newBuilder().removeAll("X-Test-Original-Url").build(),
method = request.method ?: throw Exception("Nullable method in the request"),
body = request.body,
body = request.body
)
} catch (e: Exception) {
throw Exception("Request: $request, is incorrect", e)
Expand All @@ -155,7 +155,7 @@ private class MockDispatcher : Dispatcher() {
}
throw MultipleFailuresError(
"Request: ${mockRequest.method} ${mockRequest.url}, " + if (assertionErrors.isEmpty()) "there are no mocks" else "no mock is matching the request",
assertionErrors,
assertionErrors
)
}
}
Expand All @@ -176,7 +176,7 @@ class MultipleFailuresError(val heading: String, val failures: List<Throwable>)
0 -> "no failures"
1 -> "failure"
else -> "failures"
},
}
)
append(")")
append("\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Register {
"token_type": "bearer",
"scope": "repo"
}
""".trimIndent(),
""".trimIndent()
)
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ object Register {
"issue_url": "https://api.github.com/repos/owner/repo/issues/1",
"author_association": "COLLABORATOR"
}
""".trimIndent(),
""".trimIndent()
)
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ object Register {
],
"teams": []
}
""",
"""
)
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ object Register {
}
]
}
""",
"""
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class KeyGroupingKtTest {
listOf(
mockKeyEvent(1),
mockKeyEvent(2),
mockKeyEvent(3),
),
mockKeyEvent(3)
)
)
expectThat(grouped)
.containsExactly(
KeyTypeEvent(listOf(1, 2, 3), 0),
KeyTypeEvent(listOf(1, 2, 3), 0)
)
}

Expand All @@ -53,12 +53,12 @@ class KeyGroupingKtTest {
mockKeyEvent(1, action = KeyEvent.ACTION_DOWN),
mockKeyEvent(1, action = KeyEvent.ACTION_UP),
mockKeyEvent(2, action = KeyEvent.ACTION_DOWN),
mockKeyEvent(2, action = KeyEvent.ACTION_UP),
),
mockKeyEvent(2, action = KeyEvent.ACTION_UP)
)
)
expectThat(grouped)
.containsExactly(
KeyTypeEvent(listOf(1, 2), 0),
KeyTypeEvent(listOf(1, 2), 0)
)
}

Expand All @@ -68,14 +68,14 @@ class KeyGroupingKtTest {
listOf(
mockKeyEvent(1, metaState = 1),
mockKeyEvent(2, metaState = 2),
mockKeyEvent(3, metaState = 3),
),
mockKeyEvent(3, metaState = 3)
)
)
expectThat(grouped)
.containsExactly(
KeyTypeEvent(listOf(1), 1),
KeyTypeEvent(listOf(2), 2),
KeyTypeEvent(listOf(3), 3),
KeyTypeEvent(listOf(3), 3)
)
}

Expand All @@ -87,21 +87,21 @@ class KeyGroupingKtTest {
mockKeyEvent(2, metaState = 1),
mockKeyEvent(3, metaState = 2),
mockKeyEvent(4, metaState = 2),
mockKeyEvent(5, metaState = 1),
),
mockKeyEvent(5, metaState = 1)
)
)
expectThat(grouped)
.containsExactly(
KeyTypeEvent(listOf(1, 2), 1),
KeyTypeEvent(listOf(3, 4), 2),
KeyTypeEvent(listOf(5), 1),
KeyTypeEvent(listOf(5), 1)
)
}

private fun mockKeyEvent(
keyCode: Int,
metaState: Int = 0,
action: Int = KeyEvent.ACTION_UP,
action: Int = KeyEvent.ACTION_UP
): KeyEvent = mockk<KeyEvent> {
every { getKeyCode() } returns keyCode
every { getAction() } returns action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class MockWebServerRuleTest {
.contains("An test exception occurred, but we also found some not mocked requests")
expectThat(it).isA<MultipleFailuresError>().get(MultipleFailuresError::failures)
.first().isA<CustomException>()
},
}
)

executeRequest("https://example.com/not_mocked")
Expand All @@ -139,7 +139,7 @@ class MockWebServerRuleTest {
.contains("Request: GET https://example.com/not_mocked, there are no mocks")
get(MultipleFailuresError::failures).isEmpty()
}
},
}
)

executeRequest("https://example.com/not_mocked")
Expand Down Expand Up @@ -177,7 +177,7 @@ class MockWebServerRuleTest {
message.isNotNull().contains("found \"/not_mocked\"")
}
}
},
}
)

executeRequest("https://example.com/not_mocked")
Expand Down Expand Up @@ -233,7 +233,7 @@ class MockWebServerRuleTest {
val slot = executeRequestAndGetMockedArgumentRequest {
it.method(
"POST",
"Request body".toRequestBody(),
"Request body".toRequestBody()
)
}

Expand All @@ -248,29 +248,29 @@ class MockWebServerRuleTest {
expectedException.expect(
matcher<Any> {
expectThat(it).isA<CustomException>()
},
}
)

throw CustomException
}

private fun executeRequest(
url: String,
builder: (okhttp3.Request.Builder) -> okhttp3.Request.Builder = { it },
builder: (okhttp3.Request.Builder) -> okhttp3.Request.Builder = { it }
): Response {
val client = OkHttpClient.Builder()
.addInterceptor(TestInterceptor)
.build()
val request = builder(
okhttp3.Request.Builder()
.url(url),
.url(url)
)
.build()
return client.newCall(request).execute()
}

private fun executeRequestAndGetMockedArgumentRequest(
requestBuilder: (okhttp3.Request.Builder) -> okhttp3.Request.Builder = { it },
requestBuilder: (okhttp3.Request.Builder) -> okhttp3.Request.Builder = { it }
): CapturingSlot<Request> {
val slot = slot<Request>()
val mock = mockk<ResponseGenerator> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class End2EndWalkThroughAppTest : UniversalWalkThroughAppTest() {
automatorTestRule.device.ensure(
hasAnyOfObjects(
By.text("Accept & continue"),
By.text("Username or email address"),
),
By.text("Username or email address")
)
)
}

Expand Down Expand Up @@ -102,7 +102,7 @@ class End2EndWalkThroughAppTest : UniversalWalkThroughAppTest() {

description("Wait for return to the app") {
automatorTestRule.device.waitAndFind(
By.pkg(InstrumentationRegistry.getInstrumentation().targetContext.packageName),
By.pkg(InstrumentationRegistry.getInstrumentation().targetContext.packageName)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun UiDevice.type(text: String) {
.forEach {
pressKeyCodes(
it.keyCodes.toIntArray(),
it.metaState,
it.metaState
)
}
waitForIdle()
Expand All @@ -73,7 +73,7 @@ fun UiDevice.type(text: String) {
* ```
*/
fun UiDevice.waitAndFind(
selector: BySelector,
selector: BySelector
): UiObject2 {
ensure(Until.hasObject(selector))

Expand All @@ -93,7 +93,7 @@ fun UiDevice.waitAndFind(
*/
fun UiDevice.ensure(
condition: Condition<in UiDevice, Boolean>,
timeout: Long = 30_000L,
timeout: Long = 30_000L
) {
val result = wait(condition, timeout) ?: throw AssertionError("Error in condition")
if (!result) {
Expand Down
Loading

0 comments on commit a81ea7b

Please sign in to comment.