Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error occurs generating test #123

Closed
iptton opened this issue Mar 29, 2024 · 0 comments
Closed

error occurs generating test #123

iptton opened this issue Mar 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@iptton
Copy link
Collaborator

iptton commented Mar 29, 2024

Describe the bug

To Reproduce
Steps to reproduce the behavior:

  1. open a class
  2. right click select generate test action
  3. see error panel in right corner

Additional context

java.lang.Throwable: Failed to find PsiClass in the source file: KtFile: LLMProviderTest.kt, code: ```java
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner

@RunWith(MockitoJUnitRunner::class)
class LLMProviderTest {

    private lateinit var llmProvider: LLMProvider

    @Test
    fun `should return default timeout value when accessed`() {
        // Given
        llmProvider = Mockito.mock(LLMProvider::class.java)

        // When
        val timeout = llmProvider.defaultTimeout

        // Then
        org.junit.Assert.assertEquals(600, timeout)
    }

    @Test
    fun `should return prompt text from prompt function`() {
        // Given
        val promptText = "Hello, how can I help you?"
        llmProvider = Mockito.mock(LLMProvider::class.java)
        Mockito.`when`<llmProvider.prompt(promptText)).thenReturn("Help with something")

        // When
        val result = llmProvider.prompt(promptText)

        // Then
        org.junit.Assert.assertEquals("Help with something", result)
    }

    @Test
    fun `should emit prompt text when streaming with system prompt and keep history is true`() {
        // Given
        val promptText = "What do you need?"
        val systemPrompt = "System: Are you sure?"
        llmProvider = Mockito.mock(LLMProvider::class.java)
        Mockito.`when`<llmProvider.prompt(Mockito.anyString())).thenReturn("I need assistance")

        // When
        val testSubscriber = llmProvider.stream(promptText, systemPrompt, true).test()
        val emittedValue = testSubscriber.values().first()

        // Then
        org.junit.Assert.assertEquals("I need assistance", emittedValue)
    }

    @Test
    fun `should not emit any value when streaming with system prompt and keep history is false`() {
        // Given
        val promptText = "What's up?"
        llmProvider = Mockito.mock(LLMProvider::class.java)

        // When
        val testSubscriber = llmProvider.stream(promptText, "System: Is this urgent?", false).test()

        // Then
        testSubscriber.assertNoValues()
    }
}

	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:376)
	at cc.unitmesh.kotlin.provider.KotlinCodeModifier$insertMethod$1$rootElement$1.invoke(KotlinCodeModifier.kt:53)
	at cc.unitmesh.kotlin.provider.KotlinCodeModifier$insertMethod$1$rootElement$1.invoke(KotlinCodeModifier.kt:49)
	at com.intellij.openapi.application.ActionsKt.runReadAction$lambda$3(actions.kt:31)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:894)
	at com.intellij.openapi.application.ActionsKt.runReadAction(actions.kt:31)
	at cc.unitmesh.kotlin.provider.KotlinCodeModifier.insertMethod$lambda$2(KotlinCodeModifier.kt:49)
	at com.intellij.util.concurrency.ContextRunnable.run(ContextRunnable.java:27)
	at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
	at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:22)
	at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:843)
	at com.intellij.openapi.application.impl.ApplicationImpl$4.run(ApplicationImpl.java:463)
	at com.intellij.openapi.application.impl.RwLockHolder.runWithEnabledImplicitRead(RwLockHolder.kt:75)
	at com.intellij.openapi.application.impl.RwLockHolder.runWithImplicitRead(RwLockHolder.kt:67)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWithImplicitRead(ApplicationImpl.java:1436)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:82)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:124)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:44)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:792)
	at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
	at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:733)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:761)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:695)
	at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$12(IdeEventQueue.kt:589)
	at com.intellij.openapi.application.impl.RwLockHolder.runWithoutImplicitRead(RwLockHolder.kt:44)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:589)
	at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:72)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:355)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:354)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:793)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:354)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:349)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1014)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
	at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1014)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$7(IdeEventQueue.kt:349)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:848)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:391)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

@phodal phodal added the bug Something isn't working label Mar 29, 2024
jialiu-github pushed a commit to jialiu-github/auto-dev that referenced this issue Apr 8, 2024
phodal added a commit that referenced this issue Apr 8, 2024
fix: psi element text should not be null #123
@phodal phodal closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants