Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc35593d

Browse files
committed
fix: handle ApplicationManager null in test environments
- Add null check in AutoDevSettingsState.getInstance() to return default instance when ApplicationManager is not available- Add try-catch blocks in AutoDevAppScope.scope() and workerScope() with fallback CoroutineScope instances- Remove@ignore annotation from LLMProvider2Test.shouldWorkWithJson as the test now passes- Fixes 'Cannot invoke Application.getService() because ApplicationManager.getApplication() is null' error in unit tests
1 parente323739 commitc35593d

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

‎core/src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
6565
val language:String get()= getInstance().fetchLocalLanguage()
6666

6767
fungetInstance():AutoDevSettingsState {
68-
returnApplicationManager.getApplication().getService(AutoDevSettingsState::class.java).state
68+
val application=ApplicationManager.getApplication()
69+
returnif (application!=null) {
70+
application.getService(AutoDevSettingsState::class.java).state
71+
}else {
72+
// Return a default instance for testing environments where ApplicationManager is not available
73+
AutoDevSettingsState()
74+
}
6975
}
7076
}
7177
}

‎core/src/main/kotlin/cc/unitmesh/devti/util/AutoDevCoroutineScope.kt‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,25 @@ class AutoDevAppScope: Disposable {
2424
}
2525

2626
companionobject {
27-
funscope():CoroutineScope= service<AutoDevAppScope>().coroutineScope
28-
funworkerScope():CoroutineScope= service<AutoDevAppScope>().workerScope
27+
funscope():CoroutineScope {
28+
returntry {
29+
service<AutoDevAppScope>().coroutineScope
30+
}catch (e:Exception) {
31+
// Fallback for testing environments where ApplicationManager is not available
32+
CoroutineScope(SupervisorJob()+CoroutineExceptionHandler { _, throwable->
33+
logger<AutoDevAppScope>().error(throwable)
34+
})
35+
}
36+
}
37+
38+
funworkerScope():CoroutineScope {
39+
returntry {
40+
service<AutoDevAppScope>().workerScope
41+
}catch (e:Exception) {
42+
// Fallback for testing environments where ApplicationManager is not available
43+
CoroutineScope(SupervisorJob()+ workerThread)
44+
}
45+
}
2946
}
3047
}
3148

‎core/src/test/kotlin/cc/unitmesh/devti/llm2/LLMProvider2Test.kt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class LLMProvider2Test {
3939
mockWebServer.shutdown()
4040
}
4141

42-
@Ignore("Cannot invoke\"com.intellij.openapi.application.Application.getService(java.lang.Class)\" because the return value of\"com.intellij.openapi.application.ApplicationManager.getApplication()\" is null")
4342
@Test
4443
funshouldWorkWithJson()= runBlocking {
4544
val mockResponse=MockResponse()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp