mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Ensure Fake classes must be named using Fake and the interface it fakes is detecting error by adding failing cases.
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2024 New Vector Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
* Please see LICENSE in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.tests.konsist.failures
|
||||||
|
|
||||||
|
// Make test `Fake classes must be named using Fake and the interface it fakes` fails
|
||||||
|
|
||||||
|
interface MyInterface
|
||||||
|
|
||||||
|
// This class should be named FakeMyInterface
|
||||||
|
class FakeWrongClassName : MyInterface
|
||||||
|
|
||||||
|
class MyClass {
|
||||||
|
interface MyFactory
|
||||||
|
}
|
||||||
|
|
||||||
|
// This class should be named FakeMyClassMyFactory
|
||||||
|
class FakeWrongClassSubInterfaceName : MyClass.MyFactory
|
||||||
+13
-1
@@ -73,6 +73,11 @@ class KonsistClassNameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `Fake classes must be named using Fake and the interface it fakes`() {
|
fun `Fake classes must be named using Fake and the interface it fakes`() {
|
||||||
|
var failingCases = 0
|
||||||
|
val failingCasesList = listOf(
|
||||||
|
"FakeWrongClassName",
|
||||||
|
"FakeWrongClassSubInterfaceName",
|
||||||
|
)
|
||||||
Konsist.scopeFromProject()
|
Konsist.scopeFromProject()
|
||||||
.classes()
|
.classes()
|
||||||
.withNameContaining("Fake")
|
.withNameContaining("Fake")
|
||||||
@@ -84,7 +89,7 @@ class KonsistClassNameTest {
|
|||||||
val interfaceName = it.name
|
val interfaceName = it.name
|
||||||
.replace("FakeRust", "")
|
.replace("FakeRust", "")
|
||||||
.replace("Fake", "")
|
.replace("Fake", "")
|
||||||
(it.name.startsWith("Fake") || it.name.startsWith("FakeRust")) &&
|
val result = (it.name.startsWith("Fake") || it.name.startsWith("FakeRust")) &&
|
||||||
it.parents().any { parent ->
|
it.parents().any { parent ->
|
||||||
// Workaround to get the parent name. For instance:
|
// Workaround to get the parent name. For instance:
|
||||||
// parent.name used to return `UserListPresenter.Factory` but is now returning `Factory`.
|
// parent.name used to return `UserListPresenter.Factory` but is now returning `Factory`.
|
||||||
@@ -93,7 +98,14 @@ class KonsistClassNameTest {
|
|||||||
val parentName = parent.fullyQualifiedName!!.substringAfter("$packageName.").replace(".", "")
|
val parentName = parent.fullyQualifiedName!!.substringAfter("$packageName.").replace(".", "")
|
||||||
parentName == interfaceName
|
parentName == interfaceName
|
||||||
}
|
}
|
||||||
|
if (!result && it.name in failingCasesList) {
|
||||||
|
failingCases++
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
assertThat(failingCases).isEqualTo(failingCasesList.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user