Skip to content

Commit e1e9c26

Browse files
committed
feat(java): add support for AssertJ and update JUnit detection logic
1 parent 1922f70 commit e1e9c26

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

java/src/main/kotlin/cc/unitmesh/idea/provider/JavaTestContextProvider.kt

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,22 @@ open class JavaTestContextProvider : ChatContextProvider {
108108
}
109109

110110
var rule = ""
111-
var hasJunit5 = false
112-
var hasJunit4 = false
113-
prepareLibraryData(project)?.forEach {
114-
if (it.groupId == "org.junit.jupiter") {
115-
hasJunit5 = true
116-
return@forEach
117-
}
118-
119-
if (it.groupId == "junit") {
120-
hasJunit4 = true
121-
return@forEach
111+
val libraryData = prepareLibraryData(project)
112+
libraryData?.forEach {
113+
when (it.groupId) {
114+
"org.assertj" -> {
115+
rule += "- This project uses AssertJ, you should import `org.assertj.core.api.Assertions` and use `assertThat` method."
116+
}
117+
"org.junit.jupiter" -> {
118+
rule +=
119+
"- This project uses JUnit 5, you should import `org.junit.jupiter.api.Test` and use `@Test` annotation."
120+
}
121+
"junit" -> {
122+
rule += "- This project uses JUnit 4, you should import `org.junit.Test` and use `@Test` annotation."
123+
}
122124
}
123125
}
124126

125-
if (hasJunit5) {
126-
rule =
127-
"- This project uses JUnit 5, you should import `org.junit.jupiter.api.Test` and use `@Test` annotation."
128-
} else if (hasJunit4) {
129-
rule = "- This project uses JUnit 4, you should import `org.junit.Test` and use `@Test` annotation."
130-
}
131-
132127
projectJunitCache[project] = rule
133128
return rule
134129
}

0 commit comments

Comments
 (0)