mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-113758 Create Specifications when creating tests
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
void setup() {
|
||||
${BODY}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<html>
|
||||
<body>
|
||||
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
|
||||
<tr>
|
||||
<td colspan="3"><font face="verdana" size="-1">
|
||||
This is a template used to create a setup() method in Spock test class.
|
||||
</font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
|
||||
<tr>
|
||||
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${NAME}</i></b></font></nobr></td>
|
||||
<td width="10"> </td>
|
||||
<td valign="top"><font face="verdana" size="-1">name of the created method.</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${BODY}</i></b></font></nobr></td>
|
||||
<td width="10"> </td>
|
||||
<td valign="top"><font face="verdana" size="-1">generated method body.</font></td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,3 @@
|
||||
def "${NAME}"() {
|
||||
${BODY}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<html>
|
||||
<body>
|
||||
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
|
||||
<tr>
|
||||
<td colspan="3"><font face="verdana" size="-1">
|
||||
This is a template used to create a test method in Spock test class.
|
||||
</font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
|
||||
<tr>
|
||||
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${NAME}</i></b></font></nobr></td>
|
||||
<td width="10"> </td>
|
||||
<td valign="top"><font face="verdana" size="-1">name of the created method.</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${BODY}</i></b></font></nobr></td>
|
||||
<td width="10"> </td>
|
||||
<td valign="top"><font face="verdana" size="-1">generated method body.</font></td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,3 @@
|
||||
void cleanup() {
|
||||
${BODY}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<html>
|
||||
<body>
|
||||
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
|
||||
<tr>
|
||||
<td colspan="3"><font face="verdana" size="-1">
|
||||
This is a template used to create a cleanup() method in Spock test class.
|
||||
</font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
|
||||
<tr>
|
||||
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${NAME}</i></b></font></nobr></td>
|
||||
<td width="10"> </td>
|
||||
<td valign="top"><font face="verdana" size="-1">name of the created method.</font></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${BODY}</i></b></font></nobr></td>
|
||||
<td width="10"> </td>
|
||||
<td valign="top"><font face="verdana" size="-1">generated method body.</font></td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -209,6 +209,8 @@
|
||||
implementationClass="org.jetbrains.plugins.groovy.findUsages.GrFileItemPresentationProvider"/>
|
||||
|
||||
<testFramework implementation="org.jetbrains.plugins.groovy.testIntegration.GroovyTestFramework" order="first"/>
|
||||
<testFramework implementation="org.jetbrains.plugins.groovy.spock.SpockTestFramework" order="first"/>
|
||||
|
||||
<testCreator language="Groovy" implementationClass="com.intellij.testIntegration.JavaTestCreator"/>
|
||||
<testGenerator language="Groovy" implementationClass="org.jetbrains.plugins.groovy.testIntegration.GroovyTestGenerator"/>
|
||||
<constructorBodyGenerator language="Groovy"
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.spock;
|
||||
|
||||
import com.intellij.execution.junit.JUnitUtil;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
|
||||
import org.jetbrains.plugins.groovy.testIntegration.GroovyTestFramework;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class SpockTestFramework extends GroovyTestFramework {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Spock";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getLibraryPath() {
|
||||
try {
|
||||
return PathUtil.getJarPathForClass(Class.forName(getMarkerClassFQName()));
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getDefaultSuperClass() {
|
||||
return SpockUtils.SPEC_CLASS_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() {
|
||||
return new FileTemplateDescriptor("Spock SetUp Method.groovy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor() {
|
||||
return new FileTemplateDescriptor("Spock cleanup Method.groovy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
|
||||
return new FileTemplateDescriptor("Spock Test Method.groovy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTestMethod(PsiElement element) {
|
||||
if (!(element instanceof PsiMethod)) return false;
|
||||
|
||||
return GroovyPsiManager.isInheritorCached(((PsiMethod)element).getContainingClass(), SpockUtils.SPEC_CLASS_NAME)
|
||||
&& JUnitUtil.getTestMethod(element) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMarkerClassFQName() {
|
||||
return SpockUtils.SPEC_CLASS_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTestClass(PsiClass clazz, boolean canBePotential) {
|
||||
return clazz.getLanguage() == GroovyFileType.GROOVY_LANGUAGE
|
||||
&& GroovyPsiManager.isInheritorCached(clazz, SpockUtils.SPEC_CLASS_NAME);
|
||||
}
|
||||
|
||||
private PsiMethod findSpecificMethod(@NotNull PsiClass clazz, String methodName) {
|
||||
if (!isTestClass(clazz, false)) return null;
|
||||
|
||||
for (PsiMethod method : clazz.findMethodsByName(methodName, false)) {
|
||||
if (method.getParameterList().getParametersCount() == 0) return method;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected PsiMethod findSetUpMethod(@NotNull PsiClass clazz) {
|
||||
return findSpecificMethod(clazz, "setup");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected PsiMethod findTearDownMethod(@NotNull PsiClass clazz) {
|
||||
return findSpecificMethod(clazz, "cleanup");
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getMnemonic() {
|
||||
return 'S';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user