use of com.intellij.testIntegration.JavaTestFramework in project intellij-community by JetBrains.
the class CreateTestDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints constr = new GridBagConstraints();
constr.fill = GridBagConstraints.HORIZONTAL;
constr.anchor = GridBagConstraints.WEST;
int gridy = 1;
constr.insets = insets(4);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
final JLabel libLabel = new JLabel(CodeInsightBundle.message("intention.create.test.dialog.testing.library"));
libLabel.setLabelFor(myLibrariesCombo);
panel.add(libLabel, constr);
constr.gridx = 1;
constr.weightx = 1;
constr.gridwidth = GridBagConstraints.REMAINDER;
panel.add(myLibrariesCombo, constr);
myFixLibraryPanel = new JPanel(new BorderLayout());
myFixLibraryLabel = new JLabel();
myFixLibraryLabel.setIcon(AllIcons.Actions.IntentionBulb);
myFixLibraryPanel.add(myFixLibraryLabel, BorderLayout.CENTER);
myFixLibraryPanel.add(myFixLibraryButton, BorderLayout.EAST);
constr.insets = insets(1);
constr.gridy = gridy++;
constr.gridx = 0;
panel.add(myFixLibraryPanel, constr);
constr.gridheight = 1;
constr.insets = insets(6);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
constr.gridwidth = 1;
panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.class.name")), constr);
myTargetClassNameField = new EditorTextField(suggestTestClassName(myTargetClass));
myTargetClassNameField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
getOKAction().setEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(getClassName()));
}
});
constr.gridx = 1;
constr.weightx = 1;
panel.add(myTargetClassNameField, constr);
constr.insets = insets(1);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.super.class")), constr);
mySuperClassField = new ReferenceEditorComboWithBrowseButton(new MyChooseSuperClassAction(), null, myProject, true, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE, RECENT_SUPERS_KEY);
mySuperClassField.setMinimumSize(mySuperClassField.getPreferredSize());
constr.gridx = 1;
constr.weightx = 1;
panel.add(mySuperClassField, constr);
constr.insets = insets(1);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
panel.add(new JLabel(CodeInsightBundle.message("dialog.create.class.destination.package.label")), constr);
constr.gridx = 1;
constr.weightx = 1;
String targetPackageName = myTargetPackage != null ? myTargetPackage.getQualifiedName() : "";
myTargetPackageField = new PackageNameReferenceEditorCombo(targetPackageName, myProject, RECENTS_KEY, CodeInsightBundle.message("dialog.create.class.package.chooser.title"));
new AnAction() {
public void actionPerformed(AnActionEvent e) {
myTargetPackageField.getButton().doClick();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myTargetPackageField.getChildComponent());
JPanel targetPackagePanel = new JPanel(new BorderLayout());
targetPackagePanel.add(myTargetPackageField, BorderLayout.CENTER);
panel.add(targetPackagePanel, constr);
constr.insets = insets(6);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.generate")), constr);
constr.gridx = 1;
constr.weightx = 1;
panel.add(myGenerateBeforeBox, constr);
constr.insets = insets(1);
constr.gridy = gridy++;
panel.add(myGenerateAfterBox, constr);
constr.insets = insets(6);
constr.gridy = gridy++;
constr.gridx = 0;
constr.weightx = 0;
final JLabel membersLabel = new JLabel(CodeInsightBundle.message("intention.create.test.dialog.select.methods"));
membersLabel.setLabelFor(myMethodsTable);
panel.add(membersLabel, constr);
constr.gridx = 1;
constr.weightx = 1;
panel.add(myShowInheritedMethodsBox, constr);
constr.insets = insets(1, 8);
constr.gridy = gridy++;
constr.gridx = 0;
constr.gridwidth = GridBagConstraints.REMAINDER;
constr.fill = GridBagConstraints.BOTH;
constr.weighty = 1;
panel.add(ScrollPaneFactory.createScrollPane(myMethodsTable), constr);
myLibrariesCombo.setRenderer(new ListCellRendererWrapper<TestFramework>() {
@Override
public void customize(JList list, TestFramework value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(value.getName());
setIcon(value.getIcon());
}
}
});
final boolean hasTestRoots = !ModuleRootManager.getInstance(myTargetModule).getSourceRoots(JavaModuleSourceRootTypes.TESTS).isEmpty();
final List<TestFramework> attachedLibraries = new ArrayList<>();
final String defaultLibrary = getDefaultLibraryName();
TestFramework defaultDescriptor = null;
final DefaultComboBoxModel model = (DefaultComboBoxModel) myLibrariesCombo.getModel();
final List<TestFramework> descriptors = new ArrayList<>();
descriptors.addAll(Arrays.asList(Extensions.getExtensions(TestFramework.EXTENSION_NAME)));
descriptors.sort((d1, d2) -> Comparing.compare(d1.getName(), d2.getName()));
for (final TestFramework descriptor : descriptors) {
model.addElement(descriptor);
if (hasTestRoots && descriptor.isLibraryAttached(myTargetModule)) {
attachedLibraries.add(descriptor);
if (defaultLibrary == null) {
defaultDescriptor = descriptor;
}
}
if (Comparing.equal(defaultLibrary, descriptor.getName())) {
defaultDescriptor = descriptor;
}
}
myLibrariesCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Object selectedItem = myLibrariesCombo.getSelectedItem();
if (selectedItem != null) {
final DumbService dumbService = DumbService.getInstance(myProject);
dumbService.setAlternativeResolveEnabled(true);
try {
onLibrarySelected((TestFramework) selectedItem);
} finally {
dumbService.setAlternativeResolveEnabled(false);
}
}
}
});
if (defaultDescriptor != null && (attachedLibraries.contains(defaultDescriptor) || attachedLibraries.isEmpty())) {
myLibrariesCombo.setSelectedItem(defaultDescriptor);
} else {
myLibrariesCombo.setSelectedIndex(0);
}
myFixLibraryButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mySelectedFramework instanceof JavaTestFramework) {
((JavaTestFramework) mySelectedFramework).setupLibrary(myTargetModule);
} else {
OrderEntryFix.addJarToRoots(mySelectedFramework.getLibraryPath(), myTargetModule, null);
}
myFixLibraryPanel.setVisible(false);
}
});
myShowInheritedMethodsBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateMethodsTable();
}
});
restoreShowInheritedMembersStatus();
updateMethodsTable();
return panel;
}
use of com.intellij.testIntegration.JavaTestFramework in project intellij-community by JetBrains.
the class MoveInitializerToSetUpMethodAction method isAvailable.
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
final boolean isAvailable = super.isAvailable(project, editor, element) && TestIntegrationUtils.isTest(element);
if (isAvailable) {
final PsiField field = PsiTreeUtil.getParentOfType(element, PsiField.class);
LOG.assertTrue(field != null);
final PsiClass aClass = field.getContainingClass();
LOG.assertTrue(aClass != null);
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
for (TestFramework framework : Extensions.getExtensions(TestFramework.EXTENSION_NAME)) {
if (framework instanceof JavaTestFramework && framework.isTestClass(aClass)) {
try {
((JavaTestFramework) framework).createSetUpPatternMethod(elementFactory);
return true;
} catch (Exception e) {
return false;
}
}
}
return true;
}
return false;
}
Aggregations