Testing module creation with custom ModuleType

Answered

Hi.

 

I have created a plugin with a custom ModuleType and want to implement automatic testing for it.

When a new project with the ModuleType is created, there are some folders and files created.

The thing I want to test is that all the files and folders are created correctly.

I am currently struggling with setting up the TestProject.

public class ProjectCreationTest extends TestCase {
protected JavaCodeInsightTestFixture myFixture;
protected Module myModule;

@Override
protected void setUp() throws Exception {
super.setUp();
final TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = JavaTestFixtureFactory.createFixtureBuilder(getName());
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
myFixture.setTestDataPath(getTestDataPath());
myFixture.setUp();
final AtomicReference<ModuleManager> moduleManager = new AtomicReference<ModuleManager>();
ReadAction.run(() -> moduleManager.set(ModuleManagerImpl.getInstance(projectBuilder.getFixture().getProject())));

WriteAction.run(()-> myModule = moduleManager.get().newModule(projectBuilder.getFixture().getProject().getBasePath()+"/module/","MARVIN_MODULE"));
System.out.println(myModule.getModuleTypeName());
}

private ModuleFixture newModule(TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder, String contentRoot) throws Exception {
final JavaModuleFixtureBuilder firstProjectBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
firstProjectBuilder.setLanguageLevel(LanguageLevel.JDK_1_7);
String tempDirPath = myFixture.getTempDirPath();

// Create a new content root for each module, and create a directory for it manually
String contentRootPath = tempDirPath + "/" + contentRoot;
new File(contentRootPath).mkdir();

// Call the builder
ModuleFixture moduleFixture = firstProjectBuilder
.addContentRoot(contentRootPath)
.getFixture();

return moduleFixture;
}

public String getTestDataPath(){
return Thread.currentThread().getContextClassLoader().getResource("testData/").getPath();
}
}

When I am running this code I get the following error.

EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@45b7757d
Current thread: Thread[Test worker,5,main] 1679554036
Write thread (volatile): Thread[AWT-EventQueue-0,6,main] 1611457063com.intellij.openapi.diagnostic.Attachment@7ba2a0cf
com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@45b7757d
Current thread: Thread[Test worker,5,main] 1679554036
Write thread (volatile): Thread[AWT-EventQueue-0,6,main] 1611457063com.intellij.openapi.diagnostic.Attachment@7ba2a0cf
at com.intellij.openapi.application.impl.ApplicationImpl.assertIsWriteThread(ApplicationImpl.java:1068)
at com.intellij.openapi.application.impl.ApplicationImpl.startWrite(ApplicationImpl.java:1154)
at com.intellij.openapi.application.impl.ApplicationImpl.access$300(ApplicationImpl.java:61)
at com.intellij.openapi.application.impl.ApplicationImpl$WriteAccessToken.<init>(ApplicationImpl.java:1223)
at com.intellij.openapi.application.impl.ApplicationImpl.acquireWriteActionLock(ApplicationImpl.java:1215)
at com.intellij.openapi.application.WriteAction.start(WriteAction.java:92)
at com.intellij.openapi.application.WriteAction.run(WriteAction.java:100)
at ProjectCreationTest.setUp(ProjectCreationTest.java:37)
at junit.framework.TestCase.runBare(TestCase.java:139)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:119)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:834)

Can somebody please help me to find the cause of my Problem ?

Or are there examples that achieve the same goal ?

1 comment
Comment actions Permalink

Sorry this got lost.

Please use default base classes for tests (https://plugins.jetbrains.com/docs/intellij/tests-and-fixtures.html), see org.jetbrains.plugins.javaFX.JavaFxModuleBuilderTest as sample.

0

Please sign in to leave a comment.