Skip to content

Commit 411b639

Browse files
authored
Introduce ktfmt (#400)
* Introduce ktfmt * Introduce ktfmt * Update readme
1 parent 401794f commit 411b639

153 files changed

Lines changed: 3236 additions & 3412 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Depending on the Java requirements of the JUnit Framework version, these instrum
6363
that meet these requirements, however. These tests are ignored and their execution will be skipped on older devices.
6464

6565
- JUnit 5 requires Java 8 and is only supported by devices running Android 8.0 (API 26) or newer
66-
- JUnit 6 requires Java 17 and is only supported by devices running Android 15 (API 35) or newer
66+
- **(Coming soon)** JUnit 6 requires Java 17 and is only supported by devices running Android 15 (API 35) or newer
6767

6868
Before you can write instrumentation tests with JUnit Jupiter,
6969
make sure that your module is using the `androidx.test.runner.AndroidJUnitRunner`
@@ -120,9 +120,11 @@ dependencies {
120120
By default, the plugin will make sure to use a compatible version of the instrumentation test libraries
121121
when it sets up the artifacts automatically. However, it is possible to choose a custom version instead via its DSL:
122122

123+
```kotlin
123124
junitPlatform {
124125
instrumentationTests.version.set("1.9.0")
125126
}
127+
```
126128

127129
## Official Support
128130

README.md.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Depending on the Java requirements of the JUnit Framework version, these instrum
5858
that meet these requirements, however. These tests are ignored and their execution will be skipped on older devices.
5959

6060
- JUnit 5 requires Java 8 and is only supported by devices running Android 8.0 (API 26) or newer
61-
- JUnit 6 requires Java 17 and is only supported by devices running Android 15 (API 35) or newer
61+
- **(Coming soon)** JUnit 6 requires Java 17 and is only supported by devices running Android 15 (API 35) or newer
6262

6363
Before you can write instrumentation tests with JUnit Jupiter,
6464
make sure that your module is using the `androidx.test.runner.AndroidJUnitRunner`
@@ -115,9 +115,11 @@ dependencies {
115115
By default, the plugin will make sure to use a compatible version of the instrumentation test libraries
116116
when it sets up the artifacts automatically. However, it is possible to choose a custom version instead via its DSL:
117117

118+
```kotlin
118119
junitPlatform {
119120
instrumentationTests.version.set("${instrumentationVersion}")
120121
}
122+
```
121123

122124
## Official Support
123125

build-logic/gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ korte = "2.4.12"
1919
kotlin = "2.3.0"
2020
kotlinBinaryCompValidator = "0.17.0"
2121
kotlinCoroutines = "1.10.2"
22+
ktfmt = "0.25.0"
2223
mockitoCore = "5.16.0"
2324
mockitoKotlin = "5.4.0"
2425
nexusPublish = "2.0.0"
@@ -37,6 +38,7 @@ dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
3738
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
3839
kotlin-binarycompvalidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinBinaryCompValidator" }
3940
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
41+
ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" }
4042
publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublish" }
4143
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
4244

instrumentation/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import com.android.build.api.dsl.LibraryExtension
22
import com.android.build.gradle.BaseExtension
3+
import com.ncorti.ktfmt.gradle.KtfmtExtension
34
import extensions.capitalized
45
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
56
import org.gradle.api.tasks.testing.logging.TestLogEvent
@@ -17,6 +18,7 @@ plugins {
1718
alias(libs.plugins.dokka).apply(false)
1819
alias(libs.plugins.kotlin.android).apply(false)
1920
alias(libs.plugins.kotlin.jvm).apply(false)
21+
alias(libs.plugins.ktfmt).apply(false)
2022

2123
alias(libs.plugins.kotlin.binarycompvalidator)
2224
alias(libs.plugins.publish)
@@ -36,6 +38,12 @@ subprojects {
3638
val jvmTarget = JvmTarget.JVM_17
3739
val javaVersion = JavaVersion.toVersion(jvmTarget.target)
3840

41+
// Configure code formatting
42+
apply(plugin = "com.ncorti.ktfmt.gradle")
43+
configure<KtfmtExtension> {
44+
kotlinLangStyle()
45+
}
46+
3947
// Configure Kotlin
4048
plugins.withType<KotlinBasePlugin> {
4149
tasks.withType<KotlinCompilationTask<*>>().configureEach {

instrumentation/compose/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ android {
1515
"de.mannodermaus.junit5.AndroidJUnitFrameworkBuilder"
1616
}
1717

18-
buildFeatures {
19-
compose = true
20-
}
18+
buildFeatures { compose = true }
2119
}
2220

2321
junitPlatform {

instrumentation/compose/src/androidTest/java/de/mannodermaus/junit5/compose/ClassComposeExtensionTests.kt

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ import org.junit.jupiter.params.provider.ValueSource
1919
@ExtendWith(AndroidComposeExtension::class)
2020
class ClassComposeExtensionTests {
2121

22-
@ValueSource(
23-
strings = [
24-
"click me",
25-
"touch me",
26-
"jfc it actually works"
27-
]
28-
)
22+
@ValueSource(strings = ["click me", "touch me", "jfc it actually works"])
2923
@ParameterizedTest
3024
fun test(buttonLabel: String, extension: AndroidComposeExtension<ComponentActivity>) =
3125
extension.use {
@@ -34,9 +28,7 @@ class ClassComposeExtensionTests {
3428
var counter by remember { mutableStateOf(0) }
3529

3630
Text(text = "Clicked: $counter")
37-
Button(onClick = { counter++ }) {
38-
Text(text = buttonLabel)
39-
}
31+
Button(onClick = { counter++ }) { Text(text = buttonLabel) }
4032
}
4133
}
4234

@@ -46,24 +38,23 @@ class ClassComposeExtensionTests {
4638
}
4739

4840
@Test
49-
fun anotherTest(extension: ComposeExtension) = extension.use {
50-
setContent {
51-
Column {
52-
var showDetails by remember { mutableStateOf(false) }
41+
fun anotherTest(extension: ComposeExtension) =
42+
extension.use {
43+
setContent {
44+
Column {
45+
var showDetails by remember { mutableStateOf(false) }
5346

54-
Text("Hello world")
55-
if (showDetails) {
56-
Text("Extra details")
57-
}
47+
Text("Hello world")
48+
if (showDetails) {
49+
Text("Extra details")
50+
}
5851

59-
Button(onClick = { showDetails = !showDetails }) {
60-
Text("click")
52+
Button(onClick = { showDetails = !showDetails }) { Text("click") }
6153
}
6254
}
63-
}
6455

65-
onNodeWithText("Extra details").assertDoesNotExist()
66-
onNodeWithText("click").performClick()
67-
onNodeWithText("Extra details").assertIsDisplayed()
68-
}
56+
onNodeWithText("Extra details").assertDoesNotExist()
57+
onNodeWithText("click").performClick()
58+
onNodeWithText("Extra details").assertIsDisplayed()
59+
}
6960
}

instrumentation/compose/src/androidTest/java/de/mannodermaus/junit5/compose/ExistingActivityComposeExtensionTests.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,9 @@ class ExistingActivityComposeExtensionTests {
1919
@OptIn(ExperimentalTestApi::class)
2020
val extension = createAndroidComposeExtension<ExistingActivity>()
2121

22-
@BeforeAll
23-
fun beforeAll() = extension.use {
24-
onNodeWithText("click").performClick()
25-
}
22+
@BeforeAll fun beforeAll() = extension.use { onNodeWithText("click").performClick() }
2623

27-
@BeforeEach
28-
fun beforeEach() = extension.use {
29-
onNodeWithText("click").performClick()
30-
}
24+
@BeforeEach fun beforeEach() = extension.use { onNodeWithText("click").performClick() }
3125

32-
@Test
33-
fun test() = extension.use {
34-
onNodeWithText("Clicked: 2").assertIsDisplayed()
35-
}
26+
@Test fun test() = extension.use { onNodeWithText("Clicked: 2").assertIsDisplayed() }
3627
}

instrumentation/compose/src/androidTest/java/de/mannodermaus/junit5/compose/FieldComposeExtensionTests.kt

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,21 @@ class FieldComposeExtensionTests {
2222
@OptIn(ExperimentalTestApi::class)
2323
val extension = createComposeExtension()
2424

25-
@ValueSource(
26-
strings = [
27-
"click me",
28-
"touch me",
29-
"jfc it actually works"
30-
]
31-
)
25+
@ValueSource(strings = ["click me", "touch me", "jfc it actually works"])
3226
@ParameterizedTest
33-
fun test(buttonLabel: String) = extension.use {
34-
setContent {
35-
Column {
36-
var counter by remember { mutableStateOf(0) }
27+
fun test(buttonLabel: String) =
28+
extension.use {
29+
setContent {
30+
Column {
31+
var counter by remember { mutableStateOf(0) }
3732

38-
Text(text = "Clicked: $counter")
39-
Button(onClick = { counter++ }) {
40-
Text(text = buttonLabel)
33+
Text(text = "Clicked: $counter")
34+
Button(onClick = { counter++ }) { Text(text = buttonLabel) }
4135
}
4236
}
43-
}
4437

45-
onNodeWithText("Clicked: 0").assertIsDisplayed()
46-
onNodeWithText(buttonLabel).performClick()
47-
onNodeWithText("Clicked: 1").assertIsDisplayed()
48-
}
38+
onNodeWithText("Clicked: 0").assertIsDisplayed()
39+
onNodeWithText(buttonLabel).performClick()
40+
onNodeWithText("Clicked: 1").assertIsDisplayed()
41+
}
4942
}

instrumentation/compose/src/debug/java/de/mannodermaus/junit5/compose/ExistingActivity.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public class ExistingActivity : ComponentActivity() {
2020
var counter by remember { mutableIntStateOf(0) }
2121

2222
Text(text = "Clicked: $counter")
23-
Button(onClick = { counter++ }) {
24-
Text("click")
25-
}
23+
Button(onClick = { counter++ }) { Text("click") }
2624
}
2725
}
2826
}

0 commit comments

Comments
 (0)