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: Failed to find PsiClass in the source file #156

Closed
jialiu-github opened this issue Apr 22, 2024 · 1 comment
Closed

Error: Failed to find PsiClass in the source file #156

jialiu-github opened this issue Apr 22, 2024 · 1 comment

Comments

@jialiu-github
Copy link
Contributor

java.lang.Throwable: Failed to find PsiClass in the source file: PsiJavaFile:MonitorControllerTest.java, code: @SpringBootTest
@AutoConfigureMockMvc
class MonitorControllerTest {

@Autowired
private MockMvc mockMvc;

@MockBean
private MonitorService monitorService;

@Test
void shouldSaveStepNumbers() throws Exception {
    // Given
    List<StepNumberDTO> stepNumbers = new ArrayList<>();
    StepNumberDTO stepNumber1 = new StepNumberDTO(1L, 100, UUID.randomUUID(), LocalDate.now());
    StepNumberDTO stepNumber2 = new StepNumberDTO(2L, 200, UUID.randomUUID(), LocalDate.now());
    stepNumbers.add(stepNumber1);
    stepNumbers.add(stepNumber2);

    // When
    mockMvc.perform(post("/monitor/stepNumber")
            .contentType(MediaType.APPLICATION_JSON)
            .content(new ObjectMapper().writeValueAsString(stepNumbers)))
            .andExpect(status().isCreated());

    // Then
    verify(monitorService, times(1)).saveStepNumbers(stepNumbers);
}

@Test
void shouldGetStepNumbers() throws Exception {
    // Given
    List<StepNumberDTO> stepNumbers = new ArrayList<>();
    StepNumberDTO stepNumber1 = new StepNumberDTO(1L, 100, UUID.randomUUID(), LocalDate.now());
    StepNumberDTO stepNumber2 = new StepNumberDTO(2L, 200, UUID.randomUUID(), LocalDate.now());
    stepNumbers.add(stepNumber1);
    stepNumbers.add(stepNumber2);

    when(monitorService.getStepNumbers()).thenReturn(stepNumbers);

    // When
    mockMvc.perform(get("/monitor/stepNumber"))
            .andExpect(status().isOk())
            .andExpect(content().json(new ObjectMapper().writeValueAsString(stepNumbers)));

    // Then
    verify(monitorService, times(1)).getStepNumbers();
}

}
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:376)
at cc.unitmesh.idea.context.JavaCodeModifier$insertMethod$rootElement$1.invoke(JavaCodeModifier.kt:83)
at cc.unitmesh.idea.context.JavaCodeModifier$insertMethod$rootElement$1.invoke(JavaCodeModifier.kt:79)
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.idea.context.JavaCodeModifier.insertMethod(JavaCodeModifier.kt:79)
at cc.unitmesh.idea.context.JavaCodeModifier.insertTestCode(JavaCodeModifier.kt:74)
at cc.unitmesh.devti.intentions.action.task.TestCodeGenTask.writeTestToFile(TestCodeGenTask.kt:158)
at cc.unitmesh.devti.intentions.action.task.TestCodeGenTask.access$writeTestToFile(TestCodeGenTask.kt:32)
at cc.unitmesh.devti.intentions.action.task.TestCodeGenTask$writeTestToFile$1.invokeSuspend(TestCodeGenTask.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at cc.unitmesh.devti.intentions.action.task.TestCodeGenTask.run(TestCodeGenTask.kt:124)
at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:434)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:132)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$5(CoreProgressManager.java:484)
at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:248)
at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:73)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:192)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:610)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:685)
at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:641)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:609)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:78)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:179)
at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:73)
at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$5(ProgressRunner.java:248)
at com.intellij.openapi.progress.impl.ProgressRunner$ProgressRunnable.run(ProgressRunner.java:498)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
at java.base/java.lang.Thread.run(Thread.java:840)

@jialiu-github
Copy link
Contributor Author

LLM Response not include package or imports inform when generate a new test file:

 val isClassStarted = trimCode.startsWith("import") || trimCode.startsWith("package")

jialiu-github added a commit to jialiu-github/auto-dev that referenced this issue Apr 22, 2024
phodal added a commit that referenced this issue Apr 22, 2024
fix: change prompts to fix issue #156, but this is not the best way #156
@phodal phodal closed this as completed Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants