Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

## [Unreleased]
### Added
NA

### Changed
- remove the annoying inspector for unittest check during writing the unittest, reason: inspector is for something that can be fast fixed, but the unittest check is not, so remove it to avoid the confusion.

## 1.0.0 - 2024-10-12
### Initial Release
Expand Down Expand Up @@ -105,3 +108,7 @@
- Tool window:
- Update the tool window to show the test case scan result on completion.
- Move all tool window into one multi-tab tool window.

## 1.0.14 - 2025-06-08
- remove the annoying inspector for unittest check during writing the unittest, reason: inspector is for something that can be fast fixed, but the unittest check is not, so remove it to avoid the confusion.
- add the support to Junit 5 from version 5.7.0 to 5.13.0.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pluginName = TestCraft-Pro
pluginRepositoryUrl = https://github.com/jaksonlin/testcraft-pro
# SemVer format -> https://semver.org

pluginVersion = 1.0.13
pluginVersion = 1.0.14


# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
Expand Down
Binary file added lib/apiguardian-api-1.1.2.jar
Binary file not shown.
Binary file added lib/junit-platform-launcher-1.12.2.jar
Binary file not shown.
Binary file added lib/junit-platform-launcher-1.13.0.jar
Binary file not shown.
Binary file added lib/junit-platform-launcher-1.9.2.jar
Binary file not shown.
Binary file added lib/pitest-junit5-plugin-1.2.2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.github.jaksonlin.testcraft.application.actions;

import com.github.jaksonlin.testcraft.infrastructure.commands.testscan.UnittestFileBatchScanCommand;

Check warning on line 3 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.github.jaksonlin.testcraft.infrastructure.commands.testscan.UnittestFileBatchScanCommand;`
import com.github.jaksonlin.testcraft.infrastructure.services.business.RunHistoryManagerService;

Check warning on line 4 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.github.jaksonlin.testcraft.infrastructure.services.business.RunHistoryManagerService;`
import com.github.jaksonlin.testcraft.infrastructure.services.config.InvalidTestCaseConfigService;

Check warning on line 5 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.github.jaksonlin.testcraft.infrastructure.services.config.InvalidTestCaseConfigService;`
import com.github.jaksonlin.testcraft.infrastructure.services.system.I18nService;

Check warning on line 6 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.github.jaksonlin.testcraft.infrastructure.services.system.I18nService;`
import com.intellij.openapi.actionSystem.AnActionEvent;

Check warning on line 7 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.actionSystem.AnActionEvent;`
import com.intellij.openapi.actionSystem.DataContext;

Check warning on line 8 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.actionSystem.DataContext;`
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;

Check warning on line 9 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.actionSystem.impl.SimpleDataContext;`
import com.intellij.openapi.application.ApplicationManager;

Check warning on line 10 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.application.ApplicationManager;`
import com.intellij.openapi.project.Project;

Check warning on line 11 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.project.Project;`
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.changes.CommitContext;
import com.intellij.openapi.vcs.checkin.CheckinHandler;
import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory;
import com.intellij.openapi.vfs.VirtualFile;

Check warning on line 16 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.vfs.VirtualFile;`
import com.intellij.psi.PsiFile;

Check warning on line 17 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.psi.PsiFile;`
import com.intellij.psi.PsiManager;

Check warning on line 18 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.psi.PsiManager;`
import com.intellij.openapi.ui.Messages;

Check warning on line 19 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.ui.Messages;`
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

Check warning on line 22 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.ArrayList;`
import java.util.Collection;

Check warning on line 23 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.Collection;`
import java.util.List;

Check warning on line 24 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.List;`
import java.util.concurrent.CompletableFuture;

Check warning on line 25 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.concurrent.CompletableFuture;`
import java.util.concurrent.ExecutionException;

Check warning on line 26 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.concurrent.ExecutionException;`
import java.util.concurrent.TimeUnit;

Check warning on line 27 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.concurrent.TimeUnit;`
import java.util.concurrent.TimeoutException;

Check warning on line 28 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.concurrent.TimeoutException;`

public class PreCommitValidationAction extends CheckinHandlerFactory {
@Override
public @NotNull CheckinHandler createHandler(@NotNull CheckinProjectPanel checkinProjectPanel, @NotNull CommitContext commitContext) {
return null;

Check warning on line 33 in src/main/java/com/github/jaksonlin/testcraft/application/actions/PreCommitValidationAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

`null` is returned by the method declared as @NotNull
}
// private final InvalidTestCaseConfigService invalidTestCaseConfigService;
// private final RunHistoryManagerService runHistoryManager;
//
// public PreCommitValidationAction() {
// this.invalidTestCaseConfigService = ApplicationManager.getApplication().getService(InvalidTestCaseConfigService.class);
// this.runHistoryManager = RunHistoryManagerService.getInstance();
// }
//
// @Override
// public @NotNull CheckinHandler createHandler(@NotNull CheckinProjectPanel checkinProjectPanel, @NotNull CommitContext commitContext) {
//
// return new CheckinHandler() {
// @Override
// public ReturnResult beforeCheckin() {
// try {
// if (!invalidTestCaseConfigService.isEnable()) {
// return ReturnResult.COMMIT;
// }
//
// Project project = checkinProjectPanel.getProject();
// if (project == null) {
// return ReturnResult.COMMIT;
// }
//
// Collection<VirtualFile> files = checkinProjectPanel.getVirtualFiles();
// if (files == null || files.isEmpty()) {
// return ReturnResult.COMMIT;
// }
//
// // Collect test files
// List<PsiFile> testFiles = new ArrayList<>();
// PsiManager psiManager = PsiManager.getInstance(project);
// for (VirtualFile file : files) {
// if (file.getName().endsWith("Test.java")) {
// PsiFile psiFile = psiManager.findFile(file);
// if (psiFile != null) {
// testFiles.add(psiFile);
// }
// }
// }
//
// if (!testFiles.isEmpty()) {
// // Create a simple data context for the action event
// DataContext dataContext = SimpleDataContext.getProjectContext(project);
// AnActionEvent actionEvent = AnActionEvent.createFromDataContext(
// "PreCommitValidation",
// null,
// dataContext
// );
//
// // Run validation on all test files
// UnittestFileBatchScanCommand scanCommand = new UnittestFileBatchScanCommand(project, actionEvent);
//
// // Create a CompletableFuture to handle the validation result
// CompletableFuture<Boolean> validationFuture = new CompletableFuture<>();
//
// // Add a listener to handle the validation result
//// scanCommand.setOnValidationCompleteListener(hasInvalidTests -> {
//// validationFuture.complete(hasInvalidTests);
//// });
//
// // Execute the validation
// scanCommand.execute();
//
// try {
// // Wait for validation to complete with a timeout
// boolean hasInvalidTests = validationFuture.get(30, TimeUnit.SECONDS);
//
// if (hasInvalidTests) {
// // Show error message and block commit
// Messages.showErrorDialog(
// project,
// I18nService.getInstance().message("testscan.commit_blocked_message"),
// I18nService.getInstance().message("testscan.test_case_validation_results")
// );
//
// return ReturnResult.CANCEL;
// }
// } catch (InterruptedException | ExecutionException | TimeoutException ex) {
// // Handle timeout or other errors
// Messages.showErrorDialog(
// project,
// I18nService.getInstance().message("testscan.validation_timeout_message"),
// I18nService.getInstance().message("testscan.test_case_validation_results")
// );
// return ReturnResult.CANCEL;
// }
// }
//
// return ReturnResult.COMMIT;
// } catch (Exception e) {
// // Handle any unexpected errors
// Project project = checkinProjectPanel.getProject();
// if (project != null) {
// Messages.showErrorDialog(
// project,
// "An unexpected error occurred during pre-commit validation: " + e.getMessage(),
// "Pre-commit Validation Error"
// );
// }
// return ReturnResult.COMMIT;
// }
// }
// };
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ public class PitestContext {
private String workingDirectory;
private String methodsToMutate;
private String mutatorGroup;
private Boolean isJunit5;
private String javaVersion;

public String getJavaVersion() {
return javaVersion;
}

public void setJavaVersion(String javaVersion) {
this.javaVersion = javaVersion;
}

public Boolean getIsJunit5() {
return isJunit5;
}

public void setIsJunit5(Boolean isJunit5) {
this.isJunit5 = isJunit5;
}

public String getMutatorGroup() {
return mutatorGroup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.jaksonlin.testcraft.infrastructure.commands.pitest;

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -28,21 +30,29 @@ public void execute() {
}

private List<String> getTargetClassMethods() {
ClassFileInfo classFileInfo = javaFileProcessor.getFullyQualifiedName(getContext().getTargetClassFilePath());
List<String> methods = classFileInfo.getMethods();
ItemSelectionComponent<String> itemSelectionComponent = new ItemSelectionComponent<String>(getProject(), "Select the methods to mutate");
itemSelectionComponent.setItems(methods);
AtomicReference<List<String>> result = new AtomicReference<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
itemSelectionComponent.showDialog();
result.set(itemSelectionComponent.getSelectedItems());
}, ModalityState.defaultModalityState());


// format into QualifiedClassName::methodName
return result.get().stream()
.map(method -> classFileInfo.getFullyQualifiedName() + "::" + method)
.collect(Collectors.toList());
try {
Optional<ClassFileInfo> classFileInfo = javaFileProcessor.getFullyQualifiedName(getContext().getTargetClassFilePath());
if (!classFileInfo.isPresent()) {
showError("Cannot get fully qualified name for target class");
throw new IllegalStateException("Cannot get fully qualified name for target class");
}
List<String> methods = classFileInfo.get().getMethods();
ItemSelectionComponent<String> itemSelectionComponent = new ItemSelectionComponent<String>(getProject(), "Select the methods to mutate");
itemSelectionComponent.setItems(methods);
AtomicReference<List<String>> result = new AtomicReference<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
itemSelectionComponent.showDialog();
result.set(itemSelectionComponent.getSelectedItems());
}, ModalityState.defaultModalityState());
// format into QualifiedClassName::methodName
return result.get().stream()
.map(method -> classFileInfo.get().getFullyQualifiedName() + "::" + method)
.collect(Collectors.toList());
} catch(IOException ex){
showError("Error getting fully qualified name for target class: " + ex.getMessage());
throw new IllegalStateException("Error getting fully qualified name for target class", ex);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.github.jaksonlin.testcraft.util.TargetClassInfo;
import com.github.jaksonlin.testcraft.util.JavaFileProcessor;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

public class MultiTargetClassCheckCommand extends PitestCommand {
Expand All @@ -25,7 +27,7 @@
public void execute() {
List<String> targetClassFilePaths = getMultiTargetClass();
if (targetClassFilePaths == null || targetClassFilePaths.isEmpty()) {
return;

Check warning on line 30 in src/main/java/com/github/jaksonlin/testcraft/infrastructure/commands/pitest/MultiTargetClassCheckCommand.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unnecessary 'return' statement

`return` is unnecessary as the last statement in a 'void' method
}
//getContext().setTargetClassFilePaths(targetClassFilePaths);
}
Expand All @@ -47,15 +49,20 @@
showError("Cannot find target class file");
throw new IllegalStateException("Cannot find target class file");
}
ClassFileInfo classInfo = javaFileProcessor.getFullyQualifiedName(targetClassInfo.getFile().toString());
try {
Optional<ClassFileInfo> classInfo = javaFileProcessor.getFullyQualifiedName(targetClassInfo.getFile().toString());

if (classInfo == null) {
showError("Cannot get fully qualified name for target class");
throw new IllegalStateException("Cannot get fully qualified name for target class");
if (!classInfo.isPresent()) {
showError("Cannot get fully qualified name for target class");
throw new IllegalStateException("Cannot get fully qualified name for target class");
}
List<String> fullyQualifiedNames = new ArrayList<>();
fullyQualifiedNames.add(classInfo.get().getFullyQualifiedName());
return fullyQualifiedNames;
} catch (IOException e) {
showError("Error getting fully qualified name for target class: " + e.getMessage());
throw new IllegalStateException("Error getting fully qualified name for target class", e);
}
List<String> fullyQualifiedNames = new ArrayList<>();
fullyQualifiedNames.add(classInfo.getFullyQualifiedName());
return fullyQualifiedNames;
}

private String displayCandidateClass(String classCandidateName) {
Expand Down
Loading
Loading