void () { final String testName = getTestName(true); final PsiFile file = myFixture.configureByFile(testName + ".groovy"); UsefulTestCase.assertInstanceOf(file, GroovyFile.class); GrTopStatement[] statements = ((GroovyFile)file).getTopStatements(); final StringBuilder builder = new StringBuilder(); CodeBlockGenerator generator = new CodeBlockGenerator(builder, new ExpressionContext(getProject(), GroovyFile.EMPTY_ARRAY)); for (GrTopStatement statement : statements) { statement.accept(generator); builder.append("\n"); } final PsiFile result = createLightFile(testName + ".java", JavaLanguage.INSTANCE, builder.toString()); PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting(); final String text = result.getText(); UsefulTestCase.assertSameLinesWithFile(Path.of(getTestDataPath(), testName + ".java").toString(), text); }