Skip to content

Commit

Permalink
1.10-unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
starcwang committed Apr 2, 2021
1 parent e141452 commit 8c3f0d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
// all versions https://data.services.jetbrains.com/products?fields=code,name,releases.downloads,releases.version,releases.build,releases.type&code=DG,PS,DL,MPS,MPSIIP,RDCPPP,WS,AC,IIC,IIE,GO,CL,PCD,PCC,RD,PCE,IIU,RM,PCP
intellij {
// plugins 'java'
version '2019.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.stream.Collectors;

import com.google.common.collect.Maps;
import com.intellij.codeInsight.navigation.NavigationUtil;
import com.intellij.ide.fileTemplates.FileTemplateUtil;
import com.intellij.ide.fileTemplates.impl.CustomFileTemplate;
import com.intellij.openapi.actionSystem.AnAction;
Expand All @@ -21,13 +22,17 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaDirectoryService;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.impl.source.PsiJavaFileImpl;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.refactoring.util.classMembers.MemberInfo;
import com.intellij.util.ResourceUtil;
import com.star.easygenerate.dialog.CreateUnitTestDialog;
Expand Down Expand Up @@ -83,6 +88,14 @@ public void actionPerformed(AnActionEvent e) {
} catch (Exception exception) {
LOGGER.error("create template error:", exception);
}

// 跳转到类上
String tgtClassName = ((PsiJavaFileImpl)dialog.getTargetClass().getParent()).getPackageName() + "." + dialog.getClassName();
PsiClass testClass = JavaPsiFacade.getInstance(project).findClass(tgtClassName, GlobalSearchScope.allScope(project));
if (testClass == null) {
return;
}
NavigationUtil.activateFileWithPsiElement(testClass, true);
}

/**
Expand Down Expand Up @@ -162,7 +175,7 @@ private Map<String, Object> getParamMap(PsiJavaFile psiJavaFile, CreateUnitTestD
params.put("user", System.getProperty("user.name"));
params.put("date", LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
params.put("className", className);
params.put("package", dialog.getTargetDirectory().getName());
params.put("package", ((PsiJavaFileImpl)dialog.getTargetClass().getParent()).getPackageName());
params.put("instanceName", StringUtils.substring(className, 0, 1).toLowerCase() + StringUtils.substring(className, 1));
params.put("testClassName", dialog.getClassName());
params.put("fieldList", fields);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/template/unit-test.vm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ${field.packageName};
#end

/**
* {@link ${package}.${className}}的单元测试类
* {@link ${className}}的单元测试类
*
* @author ${user}
* @date ${date}
Expand Down

0 comments on commit 8c3f0d4

Please sign in to comment.