Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw specific exceptions based on the method and configuration #7

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
432c96c
add specific type to any()
zhangfj88 Mar 18, 2024
19dc74a
add specific type to any()
zhangfj88 Mar 19, 2024
cf99b7e
Merge branch 'master' into zfj_task
zhangfj88 Mar 20, 2024
fce645a
Merge pull request #1 from zhangfj88/zfj_task
zhangfj88 Mar 20, 2024
3e7b2dc
add specific type to any()
zhangfj88 Mar 20, 2024
2edd29f
add specific type to any()
zhangfj88 Mar 20, 2024
dc23b0f
Merge pull request #2 from zhangfj88/zfj_task
zhangfj88 Mar 20, 2024
0efb82c
test generator: avoid mocking field that is initialized inline and it…
yaronyam Mar 20, 2024
246dfdd
add user check dialog
huangliang992 Mar 25, 2024
87befe8
add user check dialog
huangliang992 Mar 25, 2024
e17994d
Throw specific exceptions based on the method under test
zhangfj88 Mar 25, 2024
8cba2c5
Throw specific exceptions based on the method under test
zhangfj88 Mar 25, 2024
488e926
add user check dialog
huangliang992 Mar 25, 2024
3cb7ef0
Throw specific exceptions based on the method under test
zhangfj88 Mar 25, 2024
2cb44c9
add a setting to open check dialog
huangliang992 Mar 25, 2024
bf4b602
test generator: avoid mocking field that is initialized inline - appl…
yaronyam Mar 25, 2024
1671e0b
Add a UI setting as "declare specific test method thrown exception ty…
zhangfj88 Mar 26, 2024
810722a
update
huangliang992 Mar 26, 2024
f7e1248
test generator: avoid mocking field that is initialized inline. fix UT
yaronyam Mar 26, 2024
ece9a92
update
huangliang992 Mar 26, 2024
a596d62
update
huangliang992 Mar 26, 2024
9716098
update
huangliang992 Mar 26, 2024
835ed7d
test generator: avoid mocking field that is initialized inline. fix U…
yaronyam Mar 26, 2024
cada609
add specific type to Mockito argument matcher any(),and work for arr…
zhangfj88 Mar 26, 2024
f7ab68e
Merge pull request #4 from zhangfj88/zfj_task
zhangfj88 Mar 26, 2024
a12d370
add specific type to Mockito argument matcher any(),and work for arr…
zhangfj88 Mar 26, 2024
e8e5e65
Merge pull request #5 from zhangfj88/zfj_task
zhangfj88 Mar 26, 2024
04e4561
testme popup - replace powermock icon
yaronyam Mar 26, 2024
1bd80de
Merge pull request #30 from wrdv/feature/do_not_mock_inline_init_field
yaronyam Mar 26, 2024
530a959
version bump v6.3.0
yaronyam Mar 26, 2024
6c1f6be
Merge branch 'master' of https://github.com/huangliang992/testme-idea…
huangliang992 Mar 27, 2024
cecc9a5
update
huangliang992 Mar 28, 2024
cbced16
Merge branch 'master' into zfj_task
zhangfj88 Mar 28, 2024
08b0634
add specific type to Mockito argument matcher any(),and work for arr…
zhangfj88 Mar 28, 2024
70cc517
add specific type to Mockito argument matcher any-- remove unused method
zhangfj88 Mar 28, 2024
7517edc
Merge pull request #6 from zhangfj88/zfj_task
zhangfj88 Mar 28, 2024
c33c108
Merge pull request #27 from huangliang992/feature/add-specific-type-t…
yaronyam Mar 28, 2024
d812b31
add fileTemplateCustomization integrationTest
huangliang992 Mar 29, 2024
f25d16b
add fileTemplateCustomization integrationTest
huangliang992 Mar 29, 2024
b624ce5
Merge branch 'wrdv:master' into feature/add-user-select-dialog
huangliang992 Mar 29, 2024
98ec861
add fileTemplateCustomization integrationTest
huangliang992 Mar 29, 2024
b7ac9e1
add fileTemplateCustomization integrationTest
huangliang992 Mar 29, 2024
68e6fd3
add fileTemplateCustomization integrationTest
huangliang992 Mar 29, 2024
59c7491
Merge pull request #28 from huangliang992/feature/add-user-select-dialog
yaronyam Mar 29, 2024
6942652
file template customization bug fix
huangliang992 Apr 1, 2024
439bd06
test modify
huangliang992 Apr 1, 2024
ac5d5e8
Merge pull request #31 from huangliang992/feature/add-user-select-dialog
yaronyam Apr 1, 2024
86a47ab
Throw specific exceptions based on the method and configuration
zhangfj88 Apr 3, 2024
0579e4f
Throw specific exceptions based on the method and configuration
zhangfj88 Apr 3, 2024
f92797c
Merge branch 'master' into add-exception-on-actual
zhangfj88 Apr 3, 2024
ce60478
Throw specific exceptions based on the method and configuration
zhangfj88 Apr 3, 2024
3385ccf
Throw specific exceptions based on the method and configuration
zhangfj88 Apr 3, 2024
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'com.weirddev.testme'
version = 6.2.0
version = 6.3.0

#jvmTargetVersion = 1.8
jvmTargetVersion = 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.weirddev.testme.intellij.template.FileTemplateConfig;
import com.weirddev.testme.intellij.template.TemplateRegistry;
import com.weirddev.testme.intellij.template.context.Language;
import com.weirddev.testme.intellij.ui.customizedialog.FileTemplateCustomization;

import java.util.ArrayList;
import java.util.List;

public class TestMeGeneratorJunit4PowerMockTest extends TestMeGeneratorTestBase {

Expand Down Expand Up @@ -39,4 +43,15 @@ public void testRenderInternalMethodCallStubsIgnored() {
doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState()));
}

public void testFileTemplateCustomization() {
final TestMeConfig testMeConfig = new TestMeConfig();
testMeConfig.setOpenCustomizeTestDialog(true);
final FileTemplateConfig fileTemplateConfig = new FileTemplateConfig(testMeConfig);
List<String> selectedFieldNameList = List.of("result", "techFighter");
List<String> selectedMethodIdList = List.of("com.example.services.impl.Foo#fight(com.example.foes.Fire,java.lang.String)");
final FileTemplateCustomization customization =
new FileTemplateCustomization(selectedFieldNameList, selectedMethodIdList, true);
doTest(fileTemplateConfig, customization);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.weirddev.testme.intellij.template.FileTemplateConfig;
import com.weirddev.testme.intellij.template.TemplateRegistry;
import com.weirddev.testme.intellij.template.context.Language;
import com.weirddev.testme.intellij.ui.customizedialog.FileTemplateCustomization;

import java.util.ArrayList;
import java.util.List;

/**
* Date: 10/20/2016
Expand Down Expand Up @@ -192,6 +196,17 @@ public void testMockFieldsInDiWithCtor() {
doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState()));
}

public void testFileTemplateCustomization() {
final TestMeConfig testMeConfig = new TestMeConfig();
testMeConfig.setOpenCustomizeTestDialog(true);
final FileTemplateConfig fileTemplateConfig = new FileTemplateConfig(testMeConfig);
List<String> selectedFieldNameList = List.of("result", "techFighter");
List<String> selectedMethodIdList = List.of("com.example.services.impl.Foo#fight(com.example.foes.Fire,java.lang.String)");
final FileTemplateCustomization customization =
new FileTemplateCustomization(selectedFieldNameList, selectedMethodIdList, true);
doTest(fileTemplateConfig, customization);
}

//todo TC - use static init method when constructor not available

// TODO TC different test target dir
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.weirddev.testme.intellij.generator;

import com.weirddev.testme.intellij.configuration.TestMeConfig;
import com.weirddev.testme.intellij.configuration.TestMeConfigPersistent;
import com.weirddev.testme.intellij.template.FileTemplateConfig;
import com.weirddev.testme.intellij.template.TemplateRegistry;
import com.weirddev.testme.intellij.template.context.Language;
import com.weirddev.testme.intellij.ui.customizedialog.FileTemplateCustomization;

import java.util.ArrayList;
import java.util.List;

/**
* Date: 13/12/2016
Expand Down Expand Up @@ -48,4 +53,15 @@ public void testMockFieldsInDiWithSetter() {
public void testMockFieldsInDiWithCtor() {
doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState()));
}

public void testFileTemplateCustomization() {
final TestMeConfig testMeConfig = new TestMeConfig();
testMeConfig.setOpenCustomizeTestDialog(true);
final FileTemplateConfig fileTemplateConfig = new FileTemplateConfig(testMeConfig);
List<String> selectedFieldNameList = List.of("result", "techFighter");
List<String> selectedMethodIdList = List.of("com.example.services.impl.Foo#fight(com.example.foes.Fire,java.lang.String)");
final FileTemplateCustomization customization =
new FileTemplateCustomization(selectedFieldNameList, selectedMethodIdList, true);
doTest(fileTemplateConfig, customization);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.LightProjectDescriptor;
import com.weirddev.testme.intellij.configuration.TestMeConfig;
import com.weirddev.testme.intellij.template.FileTemplateConfig;
import com.weirddev.testme.intellij.template.TemplateRegistry;
import com.weirddev.testme.intellij.template.context.Language;
import com.weirddev.testme.intellij.ui.customizedialog.FileTemplateCustomization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.weirddev.testme.intellij.generator;

import com.weirddev.testme.intellij.configuration.TestMeConfig;
import com.weirddev.testme.intellij.configuration.TestMeConfigPersistent;
import com.weirddev.testme.intellij.template.FileTemplateConfig;
import com.weirddev.testme.intellij.template.TemplateRegistry;
import com.weirddev.testme.intellij.template.context.Language;
import com.weirddev.testme.intellij.ui.customizedialog.FileTemplateCustomization;

import java.util.ArrayList;
import java.util.List;

/**
* Date: 24/02/2017
Expand Down Expand Up @@ -41,4 +46,15 @@ public void testMockFieldsInDiWithSetter() {
public void testMockFieldsInDiWithCtor() {
doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState()));
}

public void testFileTemplateCustomization() {
final TestMeConfig testMeConfig = new TestMeConfig();
testMeConfig.setOpenCustomizeTestDialog(true);
final FileTemplateConfig fileTemplateConfig = new FileTemplateConfig(testMeConfig);
List<String> selectedFieldNameList = List.of("result", "techFighter");
List<String> selectedMethodIdList = List.of("com.example.services.impl.Foo#fight(com.example.foes.Fire,java.lang.String)");
final FileTemplateCustomization customization =
new FileTemplateCustomization(selectedFieldNameList, selectedMethodIdList, true);
doTest(fileTemplateConfig, customization);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import com.weirddev.testme.intellij.template.FileTemplateConfig;
import com.weirddev.testme.intellij.template.FileTemplateContext;
import com.weirddev.testme.intellij.template.context.Language;
import com.weirddev.testme.intellij.ui.customizedialog.FileTemplateCustomization;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;

import java.util.GregorianCalendar;
import java.util.Map;
import java.util.Properties;
import java.util.*;

/**
* Date: 13/12/2016
Expand Down Expand Up @@ -78,6 +77,10 @@ protected void doTest(FileTemplateConfig fileTemplateConfig) {
doTest("com.example.services.impl", "Foo", "FooTest", fileTemplateConfig);
}

protected void doTest(FileTemplateConfig fileTemplateConfig, FileTemplateCustomization fileTemplateCustomization) {
doTest("com.example.services.impl", "Foo", "FooTest", fileTemplateConfig, fileTemplateCustomization);
}

protected void doTest(final String packageName, String testSubjectClassName, final String expectedTestClassName, final boolean reformatCode, final boolean optimizeImports, final boolean replaceFqn, final boolean ignoreUnusedProperties, final int minPercentOfExcessiveSettersToPreferDefaultCtor, boolean stubMockMethodCallsReturnValues) {
final TestMeConfig testMeConfig = new TestMeConfig();
testMeConfig.setGenerateTestsForInheritedMethods(true);
Expand All @@ -97,7 +100,13 @@ protected void doTest(final String packageName, String testSubjectClassName, fin
doTest(packageName, testSubjectClassName, expectedTestClassName, fileTemplateConfig);
}

protected void doTest(final String packageName, String testSubjectClassName, final String expectedTestClassName, final FileTemplateConfig fileTemplateConfig) {
protected void doTest(final String packageName, String testSubjectClassName, final String expectedTestClassName,
final FileTemplateConfig fileTemplateConfig) {
doTest(packageName, testSubjectClassName, expectedTestClassName, fileTemplateConfig, null);
}

protected void doTest(final String packageName, String testSubjectClassName, final String expectedTestClassName,
final FileTemplateConfig fileTemplateConfig, final FileTemplateCustomization fileTemplateCustomization) {
if (!testEnabled) {
System.out.println(expectedTestClassExtension+ " idea plugin disabled. Skipping test");
return;
Expand All @@ -106,17 +115,21 @@ protected void doTest(final String packageName, String testSubjectClassName, fin
final PsiDirectory srcDir = fooClass.getContainingFile().getContainingDirectory();
final PsiPackage targetPackage = JavaDirectoryService.getInstance().getPackage(srcDir);

FileTemplateCustomization customization = null != fileTemplateCustomization ? fileTemplateCustomization
: new FileTemplateCustomization(new ArrayList<>(), new ArrayList<>(), false);

CommandProcessor.getInstance().executeCommand(getProject(), () -> {
myFixture.openFileInEditor(fooClass.getContainingFile().getVirtualFile());

PsiElement result = new TestMeGenerator(new TestClassElementsLocator(), testTemplateContextBuilder,new CodeRefactorUtil()).generateTest(new FileTemplateContext(new FileTemplateDescriptor(templateFilename), language, getProject(),
expectedTestClassName,
targetPackage,
getModule(),
getModule(),
srcDir,
fooClass,
fileTemplateConfig));
expectedTestClassName,
targetPackage,
getModule(),
getModule(),
srcDir,
fooClass,
fileTemplateConfig,
customization));
System.out.println("result:"+result);
verifyGeneratedTest(packageName, expectedTestClassName);
}, CodeInsightBundle.message("intention.create.test"), this);
Expand Down Expand Up @@ -157,7 +170,7 @@ public void setUp() throws Exception {
ignoreTrailingWhitespaces = false;
}
// @Override //relevant when JavaCodeInsightFixtureTestCase is used
// protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception {
// moduleBuilder.addJdk(new File(System.getProperty("java.home")).getParentContainerClass());
// }
// protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception {
// moduleBuilder.addJdk(new File(System.getProperty("java.home")).getParentContainerClass());
// }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.weirddev.testme.intellij.generator;

import com.weirddev.testme.intellij.configuration.TestMeConfig;
import com.weirddev.testme.intellij.configuration.TestMeConfigPersistent;
import com.weirddev.testme.intellij.template.FileTemplateConfig;
import com.weirddev.testme.intellij.template.TemplateRegistry;
import com.weirddev.testme.intellij.template.context.Language;
import com.weirddev.testme.intellij.ui.customizedialog.FileTemplateCustomization;

import java.util.ArrayList;
import java.util.List;

/**
* Date: 23/05/2017
Expand Down Expand Up @@ -49,4 +54,15 @@ public void testMockFieldsInDiWithCtor() {
doTest(new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState()));
}

public void testFileTemplateCustomization() {
final TestMeConfig testMeConfig = new TestMeConfig();
testMeConfig.setOpenCustomizeTestDialog(true);
final FileTemplateConfig fileTemplateConfig = new FileTemplateConfig(testMeConfig);
List<String> selectedFieldNameList = List.of("result", "techFighter");
List<String> selectedMethodIdList = List.of("com.example.services.impl.Foo#fight(com.example.foes.Fire,java.lang.String)");
final FileTemplateCustomization customization =
new FileTemplateCustomization(selectedFieldNameList, selectedMethodIdList, true);
doTest(fileTemplateConfig, customization);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.weirddev.testme.intellij.template.FileTemplateConfig;
import com.weirddev.testme.intellij.template.FileTemplateContext;
import com.weirddev.testme.intellij.template.TemplateDescriptor;
import com.weirddev.testme.intellij.ui.customizedialog.CustomizeTestDialog;
import com.weirddev.testme.intellij.ui.customizedialog.FileTemplateCustomization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
Expand Down Expand Up @@ -107,23 +109,42 @@ public void invoke(@NotNull final Project project, Editor editor, @NotNull PsiEl
}
LOG.debug("targetDirectory:"+targetDirectory.getVirtualFile().getUrl());
final ClassNameSelection classNameSelection = generatedClassNameResolver.resolveClassName(project, targetDirectory, srcClass, templateDescriptor);
if (classNameSelection.getUserDecision() != ClassNameSelection.UserDecision.Abort) {
final Module finalTestModule = testModule;
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {
testMeGenerator.generateTest(
new FileTemplateContext(
new FileTemplateDescriptor(templateDescriptor.getFilename()),templateDescriptor.getLanguage(),project, classNameSelection.getClassName(), srcPackage, srcModule, finalTestModule,targetDirectory, srcClass,
new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState())
)
);
}
}, "TestMe Generate Test", this);
if (classNameSelection.getUserDecision().equals(ClassNameSelection.UserDecision.Abort)) {
return;
}

FileTemplateConfig fileTemplateConfig = new FileTemplateConfig(TestMeConfigPersistent.getInstance().getState());
final Module finalTestModule = testModule;
boolean openUserCheckDialog = TestMeConfigPersistent.getInstance().getState().isOpenCustomizeTestDialog();
FileTemplateContext fileTemplateContext = new FileTemplateContext(
new FileTemplateDescriptor(templateDescriptor.getFilename()), templateDescriptor.getLanguage(), project,
classNameSelection.getClassName(), srcPackage, srcModule, finalTestModule, targetDirectory, srcClass,
fileTemplateConfig, new FileTemplateCustomization(new ArrayList<>(), new ArrayList<>(), openUserCheckDialog));
if (openUserCheckDialog) {
// create filed and method check dialog
final CustomizeTestDialog dialog = createTestMeDialog(project, srcClass, fileTemplateContext);
// if not ok button selected the return
if (dialog.isModal() && !dialog.showAndGet()) {
return;
}
}

CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {
testMeGenerator.generateTest(fileTemplateContext);
}
}, "TestMe Generate Test", this);
LOG.debug("End CreateTestMeAction.invoke");
}

/**
* create user check dialog to decide fields to mock and methods to test
*/
private CustomizeTestDialog createTestMeDialog(Project project, PsiClass srcClass, FileTemplateContext fileTemplateContext) {
return new CustomizeTestDialog(project, "Select fields/methods to be mocked/tested", srcClass, fileTemplateContext);
}

/**
* @see CreateTestAction#computeSuitableTestRootUrls
*/
Expand All @@ -150,7 +171,7 @@ private static List<SourceFolder> suitableTestSourceFolders(@NotNull Module modu
return sourceFolders;
}
/**
* @see JavaProjectRootsUtil#isForGeneratedSources(com.intellij.openapi.roots.SourceFolder)
* @see JavaProjectRootsUtil#isForGeneratedSources(SourceFolder)
*/
private static boolean isForGeneratedSources(SourceFolder sourceFolder) {
JavaSourceRootProperties properties = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
Expand Down
Loading