From 66092ea830c1f3c6b3d0eaa5ef1ab701eb5a2e1e Mon Sep 17 00:00:00 2001 From: Emmanuel Chebbi Date: Thu, 5 Mar 2020 23:08:19 +0100 Subject: [PATCH 01/50] Improve current PIT launch tab --- .../pitclipse/launch/ui/PitArgumentsTab.java | 129 +++++++++++++----- .../launch/ui/PitLaunchUiActivator.java | 6 + 2 files changed, 104 insertions(+), 31 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index 9e31dbf1..f159ef1a 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -17,27 +17,36 @@ package org.pitest.pitclipse.launch.ui; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ui.JavaElementLabelProvider; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; +import org.osgi.framework.Bundle; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; +import java.net.URL; + import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; @@ -46,18 +55,20 @@ import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_FROM_PIT; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATION_TESTS_RUN_IN_PARALLEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.USE_INCREMENTAL_ANALYSIS; +import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; -import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; /** * Tab allowing to configure a PIT analyze. */ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab { private static final int NUMBER_OF_COLUMNS = 3; + + private Image icon; private Text testClassText; private Text projectText; @@ -70,6 +81,22 @@ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab { private Text excludedClassesText; private Text excludedMethodsText; private Text avoidCallsTo; + + @Override + public Image getImage() { + Bundle bundle = Platform.getBundle(PitLaunchUiActivator.PLUGIN_ID); + Path path = new Path("icons/pit.gif"); + URL iconURL = FileLocator.find(bundle, path, null); + icon = ImageDescriptor.createFromURL(iconURL).createImage(); + return icon; + } + + @Override + public void dispose() { + if (icon != null) { + icon.dispose(); + } + } public void initializeFrom(ILaunchConfiguration config) { projectText.setText(getAttributeFromConfig(config, ATTR_PROJECT_NAME, "")); @@ -125,43 +152,61 @@ public void createControl(Composite parent) { createSpacer(comp); createProjectWidgets(font, comp); createSpacer(comp); - createTestClassWidgets(font, comp); + createMutationScopeWidgets(font, comp); createSpacer(comp); - createTestDirWidgets(font, comp); + createFilters(font, comp); createSpacer(comp); createPreferences(font, comp); } + + private void createMutationScopeWidgets(Font font, Composite comp) { + Group group = new Group(comp, SWT.NONE); + group.setText(" Mutation Scope "); + group.setFont(font); + GridData groupGrid = new GridData(FILL_HORIZONTAL); + groupGrid.horizontalSpan = NUMBER_OF_COLUMNS; + group.setLayoutData(groupGrid); + GridLayout groupLayout = new GridLayout(2, false); + group.setLayout(groupLayout); + + createTestClassWidgets(font, group, groupLayout.numColumns); + createSpacer(group); + createTestDirWidgets(font, group, groupLayout.numColumns); + } private void createProjectWidgets(Font font, Composite comp) { Label projectLabel = new Label(comp, SWT.NONE); - projectLabel.setText("Project to mutate:"); - GridData gd = new GridData(FILL_HORIZONTAL); + projectLabel.setText("Project to mutate: "); + GridData gd = new GridData(); gd.horizontalSpan = 1; projectLabel.setLayoutData(gd); projectLabel.setFont(font); gd = new GridData(FILL_HORIZONTAL); - gd.horizontalSpan = NUMBER_OF_COLUMNS; + gd.horizontalSpan = NUMBER_OF_COLUMNS - 1; projectText = new Text(comp, SWT.SINGLE | SWT.BORDER); projectText.setLayoutData(gd); projectText.addModifyListener(new UpdateOnModifyListener()); } - private void createTestClassWidgets(Font font, Composite comp) { + private void createTestClassWidgets(Font font, Composite comp, int columnsInParent) { testClassRadioButton = createTestRadioButton(comp, "Run mutations from a unit test"); + GridData testClassGrid = new GridData(FILL_HORIZONTAL); + testClassGrid.horizontalSpan = columnsInParent; + testClassRadioButton.setLayoutData(testClassGrid); Label testClassLabel = new Label(comp, SWT.NONE); testClassLabel.setText("Test Class:"); - GridData labelGrid = new GridData(FILL_HORIZONTAL); + GridData labelGrid = new GridData(); labelGrid.horizontalIndent = 25; - labelGrid.horizontalSpan = NUMBER_OF_COLUMNS; + labelGrid.horizontalSpan = 1; testClassLabel.setLayoutData(labelGrid); testClassLabel.setFont(font); GridData textGrid = new GridData(FILL_HORIZONTAL); - textGrid.horizontalSpan = NUMBER_OF_COLUMNS; - textGrid.horizontalIndent = 25; + textGrid.horizontalSpan = columnsInParent - 1; + textGrid.grabExcessHorizontalSpace = true; testClassText = new Text(comp, SWT.SINGLE | SWT.BORDER); testClassText.setLayoutData(textGrid); testClassText.addModifyListener(new UpdateOnModifyListener()); @@ -174,61 +219,83 @@ private Button createTestRadioButton(Composite comp, String label) { return button; } - private void createTestDirWidgets(Font font, Composite comp) { + private void createTestDirWidgets(Font font, Composite comp, int columnsInParent) { testDirectoryRadioButton = createTestRadioButton(comp, "Run mutations against a package or directory"); - - GridData labelGrid = new GridData(FILL_HORIZONTAL); + GridData testDirGrid = new GridData(FILL_HORIZONTAL); + testDirGrid.horizontalSpan = columnsInParent; + testDirectoryRadioButton.setLayoutData(testDirGrid); + + GridData labelGrid = new GridData(); labelGrid.horizontalIndent = 25; - labelGrid.horizontalSpan = NUMBER_OF_COLUMNS; + labelGrid.horizontalSpan = 1; Label testDirectoryLabel = new Label(comp, SWT.NONE); testDirectoryLabel.setText("Directory:"); testDirectoryLabel.setLayoutData(labelGrid); testDirectoryLabel.setFont(font); GridData textGrid = new GridData(FILL_HORIZONTAL); - textGrid.horizontalSpan = NUMBER_OF_COLUMNS; - textGrid.horizontalIndent = 25; + textGrid.horizontalSpan = columnsInParent - 1; testDirText = new Text(comp, SWT.SINGLE | SWT.BORDER); testDirText.setLayoutData(textGrid); testDirText.addModifyListener(new UpdateOnModifyListener()); } - private void createPreferences(Font font, Composite comp) { - runInParallel = createNewCheckBox(font, comp, + private void createFilters(Font font, Composite comp) { + Group group = new Group(comp, SWT.NONE); + group.setText(" Filters "); + group.setFont(font); + GridData groupGrid = new GridData(FILL_HORIZONTAL); + groupGrid.horizontalSpan = NUMBER_OF_COLUMNS; + group.setLayoutData(groupGrid); + GridLayout groupLayout = new GridLayout(1, false); + group.setLayout(groupLayout); + + runInParallel = createNewCheckBox(font, group, groupLayout.numColumns, MUTATION_TESTS_RUN_IN_PARALLEL); - incrementalAnalysis = createNewCheckBox(font, comp, + incrementalAnalysis = createNewCheckBox(font, group, groupLayout.numColumns, USE_INCREMENTAL_ANALYSIS); - excludedClassesText = createTextPreference(font, comp, + } + + private void createPreferences(Font font, Composite comp) { + Group misc = new Group(comp, SWT.NONE); + misc.setText(" Preferences "); + misc.setFont(font); + GridData miscGrid = new GridData(FILL_HORIZONTAL); + miscGrid.horizontalSpan = NUMBER_OF_COLUMNS; + misc.setLayoutData(miscGrid); + GridLayout miscLayout = new GridLayout(2, false); + misc.setLayout(miscLayout); + + excludedClassesText = createTextPreference(font, misc, miscLayout.numColumns, EXCLUDE_CLASSES_FROM_PIT); - excludedMethodsText = createTextPreference(font, comp, + excludedMethodsText = createTextPreference(font, misc, miscLayout.numColumns, EXCLUDE_METHODS_FROM_PIT); - avoidCallsTo = createTextPreference(font, comp, AVOID_CALLS_FROM_PIT); + avoidCallsTo = createTextPreference(font, misc, miscLayout.numColumns, + AVOID_CALLS_FROM_PIT); } - private Text createTextPreference(Font font, Composite comp, String label) { - GridData labelGrid = new GridData(FILL_HORIZONTAL); - labelGrid.horizontalIndent = 25; - labelGrid.horizontalSpan = NUMBER_OF_COLUMNS; + private Text createTextPreference(Font font, Composite comp, int columnsInParent, String label) { + GridData labelGrid = new GridData(); + labelGrid.horizontalSpan = 1; Label testDirectoryLabel = new Label(comp, SWT.NONE); testDirectoryLabel.setText(label); testDirectoryLabel.setLayoutData(labelGrid); testDirectoryLabel.setFont(font); GridData textGrid = new GridData(FILL_HORIZONTAL); - textGrid.horizontalSpan = NUMBER_OF_COLUMNS; - textGrid.horizontalIndent = 25; + textGrid.horizontalSpan = columnsInParent - 1; Text textBox = new Text(comp, SWT.SINGLE | SWT.BORDER); textBox.setLayoutData(textGrid); textBox.addModifyListener(new UpdateOnModifyListener()); return textBox; } - private Button createNewCheckBox(Font font, Composite comp, String label) { + private Button createNewCheckBox(Font font, Composite comp, int columnsInParent, String label) { Button checkBox = new Button(comp, SWT.CHECK); checkBox.setText(label); GridData labelGrid = new GridData(FILL_HORIZONTAL); - labelGrid.horizontalSpan = NUMBER_OF_COLUMNS; + labelGrid.horizontalSpan = columnsInParent - 1; checkBox.setLayoutData(labelGrid); checkBox.setFont(font); return checkBox; diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchUiActivator.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchUiActivator.java index 2c23a05a..2955c3c0 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchUiActivator.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchUiActivator.java @@ -24,6 +24,8 @@ public class PitLaunchUiActivator extends AbstractUIPlugin { + public static String PLUGIN_ID = "org.pitest.pitclipse.launch.ui"; + private static PitLaunchUiActivator plugin; @Override @@ -31,6 +33,10 @@ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } + + public static PitLaunchUiActivator getInstance() { + return plugin; + } public static Shell getActiveWorkbenchShell() { IWorkbenchWindow workBenchWindow = getActiveWorkbenchWindow(); From 077377bd1c74626d2a5f951776dbfb50f15861a4 Mon Sep 17 00:00:00 2001 From: Emmanuel Chebbi Date: Thu, 5 Mar 2020 23:15:53 +0100 Subject: [PATCH 02/50] draft 'Mutators' page --- .../ui/PitLaunchConfigurationTabGroup.java | 1 + .../pitclipse/launch/ui/PitMutatorsTab.java | 400 ++++++++++++++++++ 2 files changed, 401 insertions(+) create mode 100644 bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchConfigurationTabGroup.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchConfigurationTabGroup.java index 2310f0ea..ed99ae22 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchConfigurationTabGroup.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchConfigurationTabGroup.java @@ -32,6 +32,7 @@ public class PitLaunchConfigurationTabGroup extends AbstractLaunchConfigurationT public void createTabs(ILaunchConfigurationDialog dialog, String mode) { final ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new PitArgumentsTab(), + new PitMutatorsTab(), new JavaArgumentsTab(), new JavaJRETab(), new JavaClasspathTab(), diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java new file mode 100644 index 00000000..4ad86e59 --- /dev/null +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -0,0 +1,400 @@ +/******************************************************************************* + * Copyright 2012-2019 Phil Glover and contributors + * + * 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.pitest.pitclipse.launch.ui; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.ui.JavaElementLabelProvider; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.osgi.framework.Bundle; +import org.pitest.pitclipse.core.PitCoreActivator; +import org.pitest.pitclipse.runner.config.PitConfiguration; + +import java.net.URL; + +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; +import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_FROM_PIT; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_FROM_PIT; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_FROM_PIT; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATION_TESTS_RUN_IN_PARALLEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.USE_INCREMENTAL_ANALYSIS; +import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; + +/** + * Tab allowing to configure a PIT analyze. + */ +public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { + private static final int NUMBER_OF_COLUMNS = 3; + + private Image icon; + + private Text testClassText; + private Text projectText; + private Button testClassRadioButton; + private Button testDirectoryRadioButton; + private Text testDirText; + private String containerId; + private Button runInParallel; + private Button incrementalAnalysis; + private Text excludedClassesText; + private Text excludedMethodsText; + private Text avoidCallsTo; + + @Override + public String getName() { + return "Mutators"; + } + + @Override + public Image getImage() { + Bundle bundle = Platform.getBundle(PitLaunchUiActivator.PLUGIN_ID); + Path path = new Path("icons/pit.gif"); + URL iconURL = FileLocator.find(bundle, path, null); + icon = ImageDescriptor.createFromURL(iconURL).createImage(); + return icon; + } + + @Override + public void dispose() { + if (icon != null) { + icon.dispose(); + } + } + + public void initializeFrom(ILaunchConfiguration config) { + projectText.setText(getAttributeFromConfig(config, ATTR_PROJECT_NAME, "")); + String testClass = getAttributeFromConfig(config, ATTR_MAIN_TYPE_NAME, ""); + containerId = getAttributeFromConfig(config, ATTR_TEST_CONTAINER, ""); + testClassText.setText(testClass); + if (testClass.length() == 0 && containerId.length() > 0) { + testClassText.setText(""); + IJavaElement containerElement = JavaCore.create(containerId); + testDirText.setText(new JavaElementLabelProvider().getText(containerElement)); + testClassRadioButton.setSelection(false); + testDirectoryRadioButton.setSelection(true); + } else { + testClassText.setText(testClass); + testDirText.setText(""); + testClassRadioButton.setSelection(true); + testDirectoryRadioButton.setSelection(false); + } + initialiseWithPreferenceDefaults(config); + testModeChanged(); + } + + private void initialiseWithPreferenceDefaults(ILaunchConfiguration config) { + PitConfiguration preferences = PitCoreActivator.getDefault() + .getConfiguration(); + runInParallel.setSelection(Boolean + .valueOf(getBooleanAttributeFromConfig(config, + ATTR_TEST_IN_PARALLEL, + preferences.isParallelExecution()))); + incrementalAnalysis.setSelection(Boolean + .valueOf(getBooleanAttributeFromConfig(config, + ATTR_TEST_INCREMENTALLY, + preferences.isIncrementalAnalysis()))); + excludedClassesText.setText(getAttributeFromConfig(config, + ATTR_EXCLUDE_CLASSES, preferences.getExcludedClasses())); + excludedMethodsText.setText(getAttributeFromConfig(config, + ATTR_EXCLUDE_METHODS, preferences.getExcludedMethods())); + avoidCallsTo.setText(getAttributeFromConfig(config, + ATTR_AVOID_CALLS_TO, preferences.getExcludedMethods())); + } + + public void createControl(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + setControl(comp); + GridLayout topLayout = new GridLayout(); + topLayout.verticalSpacing = 0; + topLayout.numColumns = NUMBER_OF_COLUMNS; + comp.setLayout(topLayout); + + Font font = parent.getFont(); + comp.setFont(font); + + createSpacer(comp); + createProjectWidgets(font, comp); + createSpacer(comp); + createMutationScopeWidgets(font, comp); + createSpacer(comp); + createFilters(font, comp); + createSpacer(comp); + createPreferences(font, comp); + } + + private void createMutationScopeWidgets(Font font, Composite comp) { + Group group = new Group(comp, SWT.NONE); + group.setText(" Mutation Scope "); + group.setFont(font); + GridData groupGrid = new GridData(FILL_HORIZONTAL); + groupGrid.horizontalSpan = NUMBER_OF_COLUMNS; + group.setLayoutData(groupGrid); + GridLayout groupLayout = new GridLayout(2, false); + group.setLayout(groupLayout); + + createTestClassWidgets(font, group, groupLayout.numColumns); + createSpacer(group); + createTestDirWidgets(font, group, groupLayout.numColumns); + } + + private void createProjectWidgets(Font font, Composite comp) { + Label projectLabel = new Label(comp, SWT.NONE); + projectLabel.setText("Project to mutate: "); + GridData gd = new GridData(); + gd.horizontalSpan = 1; + projectLabel.setLayoutData(gd); + projectLabel.setFont(font); + + gd = new GridData(FILL_HORIZONTAL); + gd.horizontalSpan = NUMBER_OF_COLUMNS - 1; + projectText = new Text(comp, SWT.SINGLE | SWT.BORDER); + projectText.setLayoutData(gd); + projectText.addModifyListener(new UpdateOnModifyListener()); + } + + private void createTestClassWidgets(Font font, Composite comp, int columnsInParent) { + testClassRadioButton = createTestRadioButton(comp, + "Run mutations from a unit test"); + GridData testClassGrid = new GridData(FILL_HORIZONTAL); + testClassGrid.horizontalSpan = columnsInParent; + testClassRadioButton.setLayoutData(testClassGrid); + + Label testClassLabel = new Label(comp, SWT.NONE); + testClassLabel.setText("Test Class:"); + GridData labelGrid = new GridData(); + labelGrid.horizontalIndent = 25; + labelGrid.horizontalSpan = 1; + testClassLabel.setLayoutData(labelGrid); + testClassLabel.setFont(font); + + GridData textGrid = new GridData(FILL_HORIZONTAL); + textGrid.horizontalSpan = columnsInParent - 1; + textGrid.grabExcessHorizontalSpace = true; + testClassText = new Text(comp, SWT.SINGLE | SWT.BORDER); + testClassText.setLayoutData(textGrid); + testClassText.addModifyListener(new UpdateOnModifyListener()); + } + + private Button createTestRadioButton(Composite comp, String label) { + Button button = new Button(comp, SWT.RADIO); + button.setText(label); + button.addSelectionListener(new ButtonSelectionAdapter(button)); + return button; + } + + private void createTestDirWidgets(Font font, Composite comp, int columnsInParent) { + testDirectoryRadioButton = createTestRadioButton(comp, + "Run mutations against a package or directory"); + GridData testDirGrid = new GridData(FILL_HORIZONTAL); + testDirGrid.horizontalSpan = columnsInParent; + testDirectoryRadioButton.setLayoutData(testDirGrid); + + GridData labelGrid = new GridData(); + labelGrid.horizontalIndent = 25; + labelGrid.horizontalSpan = 1; + Label testDirectoryLabel = new Label(comp, SWT.NONE); + testDirectoryLabel.setText("Directory:"); + testDirectoryLabel.setLayoutData(labelGrid); + testDirectoryLabel.setFont(font); + + GridData textGrid = new GridData(FILL_HORIZONTAL); + textGrid.horizontalSpan = columnsInParent - 1; + testDirText = new Text(comp, SWT.SINGLE | SWT.BORDER); + testDirText.setLayoutData(textGrid); + testDirText.addModifyListener(new UpdateOnModifyListener()); + } + + private void createFilters(Font font, Composite comp) { + Group group = new Group(comp, SWT.NONE); + group.setText(" Filters "); + group.setFont(font); + GridData groupGrid = new GridData(FILL_HORIZONTAL); + groupGrid.horizontalSpan = NUMBER_OF_COLUMNS; + group.setLayoutData(groupGrid); + GridLayout groupLayout = new GridLayout(1, false); + group.setLayout(groupLayout); + + runInParallel = createNewCheckBox(font, group, groupLayout.numColumns, + MUTATION_TESTS_RUN_IN_PARALLEL); + incrementalAnalysis = createNewCheckBox(font, group, groupLayout.numColumns, + USE_INCREMENTAL_ANALYSIS); + } + + private void createPreferences(Font font, Composite comp) { + Group misc = new Group(comp, SWT.NONE); + misc.setText(" Preferences "); + misc.setFont(font); + GridData miscGrid = new GridData(FILL_HORIZONTAL); + miscGrid.horizontalSpan = NUMBER_OF_COLUMNS; + misc.setLayoutData(miscGrid); + GridLayout miscLayout = new GridLayout(2, false); + misc.setLayout(miscLayout); + + excludedClassesText = createTextPreference(font, misc, miscLayout.numColumns, + EXCLUDE_CLASSES_FROM_PIT); + excludedMethodsText = createTextPreference(font, misc, miscLayout.numColumns, + EXCLUDE_METHODS_FROM_PIT); + avoidCallsTo = createTextPreference(font, misc, miscLayout.numColumns, + AVOID_CALLS_FROM_PIT); + } + + private Text createTextPreference(Font font, Composite comp, int columnsInParent, String label) { + GridData labelGrid = new GridData(); + labelGrid.horizontalSpan = 1; + Label testDirectoryLabel = new Label(comp, SWT.NONE); + testDirectoryLabel.setText(label); + testDirectoryLabel.setLayoutData(labelGrid); + testDirectoryLabel.setFont(font); + + GridData textGrid = new GridData(FILL_HORIZONTAL); + textGrid.horizontalSpan = columnsInParent - 1; + Text textBox = new Text(comp, SWT.SINGLE | SWT.BORDER); + textBox.setLayoutData(textGrid); + textBox.addModifyListener(new UpdateOnModifyListener()); + return textBox; + } + + private Button createNewCheckBox(Font font, Composite comp, int columnsInParent, String label) { + Button checkBox = new Button(comp, SWT.CHECK); + checkBox.setText(label); + GridData labelGrid = new GridData(FILL_HORIZONTAL); + labelGrid.horizontalSpan = columnsInParent - 1; + checkBox.setLayoutData(labelGrid); + checkBox.setFont(font); + return checkBox; + } + + public void performApply(ILaunchConfigurationWorkingCopy workingCopy) { + workingCopy.setAttribute(ATTR_PROJECT_NAME, projectText.getText() + .trim()); + if (testClassRadioButton.getSelection()) { + workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, testClassText.getText().trim()); + workingCopy.setAttribute(ATTR_TEST_CONTAINER, ""); + } else { + workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, ""); + workingCopy.setAttribute(ATTR_TEST_CONTAINER, containerId); + } + workingCopy.setAttribute(ATTR_TEST_IN_PARALLEL, + runInParallel.getSelection()); + workingCopy.setAttribute(ATTR_TEST_INCREMENTALLY, + incrementalAnalysis.getSelection()); + workingCopy.setAttribute(ATTR_EXCLUDE_CLASSES, + excludedClassesText.getText()); + workingCopy.setAttribute(ATTR_EXCLUDE_METHODS, + excludedMethodsText.getText()); + workingCopy.setAttribute(ATTR_AVOID_CALLS_TO, avoidCallsTo.getText()); + try { + PitMigrationDelegate.mapResources(workingCopy); + } catch (CoreException ce) { + setErrorMessage(ce.getStatus().getMessage()); + } + } + + public void setDefaults(ILaunchConfigurationWorkingCopy workingCopy) { + /* + * IJavaElement javaElement = getContext(); if (javaElement != null) { + * initializeJavaProject(javaElement, workingCopy); } else { + * workingCopy.setAttribute( + * IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); } + */ + } + + public String getAttributeFromConfig(ILaunchConfiguration config, + String attribute, String defaultValue) { + String result = defaultValue; + try { + result = config.getAttribute(attribute, defaultValue); + } catch (CoreException e) { + // Swallowed + } + return result; + } + + public boolean getBooleanAttributeFromConfig(ILaunchConfiguration config, + String attribute, boolean defaultValue) { + boolean result = defaultValue; + try { + result = config.getAttribute(attribute, defaultValue); + } catch (CoreException e) { + // Swallowed + } + return result; + } + + private void createSpacer(Composite comp) { + Label label = new Label(comp, SWT.NONE); + GridData gd = new GridData(); + gd.horizontalSpan = 3; + label.setLayoutData(gd); + } + + private void testModeChanged() { + boolean isSingleTestMode = testClassRadioButton.getSelection(); + testClassText.setEnabled(isSingleTestMode); + testDirText.setEnabled(!isSingleTestMode); + updateLaunchConfigurationDialog(); + } + + private class ButtonSelectionAdapter extends SelectionAdapter { + private final Button button; + + private ButtonSelectionAdapter(Button button) { + this.button = button; + } + + @Override + public void widgetSelected(SelectionEvent e) { + if (button.getSelection()) { + testModeChanged(); + } + } + } + + private final class UpdateOnModifyListener implements ModifyListener { + public void modifyText(ModifyEvent evt) { + updateLaunchConfigurationDialog(); + } + } +} From 47cbbaed97c7c20192929725626c9bdc8dcf32ee Mon Sep 17 00:00:00 2001 From: Emmanuel Chebbi Date: Fri, 6 Mar 2020 19:11:11 +0100 Subject: [PATCH 03/50] Rename PitMutators as MutatorGroups --- .../core/{PitMutators.java => MutatorGroups.java} | 4 ++-- .../pitest/pitclipse/core/PitCoreActivator.java | 4 ++-- .../preferences/ui/PitMutatorsPreferencePage.java | 4 ++-- .../pageobjects/PitPreferenceSelector.java | 15 ++++++++------- .../ui/behaviours/pageobjects/WindowsMenu.java | 6 +++--- .../ui/behaviours/steps/PreferencesSteps.java | 8 ++++---- 6 files changed, 21 insertions(+), 20 deletions(-) rename bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/{PitMutators.java => MutatorGroups.java} (93%) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitMutators.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java similarity index 93% rename from bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitMutators.java rename to bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java index cceb0d1b..38a088c7 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitMutators.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java @@ -16,7 +16,7 @@ package org.pitest.pitclipse.core; -public enum PitMutators { +public enum MutatorGroups { DEFAULTS("defaultMutators", "&Default Mutators"), STRONGER("strongerMutators", "&Stronger Mutators"), @@ -25,7 +25,7 @@ public enum PitMutators { private final String label; private final String id; - private PitMutators(String id, String label) { + private MutatorGroups(String id, String label) { this.id = id; this.label = label; } diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index 5d8d3e5d..b7f39189 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -284,7 +284,7 @@ public PitConfiguration getConfiguration() { break; } } - for (PitMutators mutatorMode : PitMutators.values()) { + for (MutatorGroups mutatorMode : MutatorGroups.values()) { if (mutatorMode.getId().equals(mutators)) { builder.withMutators(mutatorMode.toString()); break; @@ -297,7 +297,7 @@ public void setExecutionMode(PitExecutionMode pitExecutionMode) { getPreferenceStore().setValue(PIT_EXECUTION_MODE, pitExecutionMode.getId()); } - public void setMutators(PitMutators mutators) { + public void setMutators(MutatorGroups mutators) { getPreferenceStore().setValue(PIT_MUTATORS, mutators.getId()); } } diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java index 6dd684e8..1341c0b2 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java @@ -21,7 +21,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.pitest.pitclipse.core.PitCoreActivator; -import org.pitest.pitclipse.core.PitMutators; +import org.pitest.pitclipse.core.MutatorGroups; import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_MUTATORS; @@ -39,7 +39,7 @@ public void createFieldEditors() { } private void createExecutionModeRadioButtons() { - PitMutators[] values = PitMutators.values(); + MutatorGroups[] values = MutatorGroups.values(); String[][] mutatorValues = new String[values.length][2]; for (int i = 0; i < values.length; i++) { mutatorValues[i] = new String[] { values[i].getLabel(), values[i].getId() }; diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java index 923fee48..a72a2c44 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java @@ -21,7 +21,8 @@ import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.pitest.pitclipse.core.PitMutators; +import org.pitest.pitclipse.core.PitCoreActivator; +import org.pitest.pitclipse.core.MutatorGroups; import org.pitest.pitclipse.runner.config.PitExecutionMode; import java.io.Closeable; @@ -124,7 +125,7 @@ public void setAvoidCallsTo(String avoidCallsTo) { setTextFor(AVOID_CALLS_TO_LABEL).to(avoidCallsTo); } - public PitMutators getMutators() { + public MutatorGroups getMutators() { return getSelectedMutators().from(MUTATORS_LABEL); } @@ -263,17 +264,17 @@ public Boolean getPreference(String label) { }); } - private PreferenceGetterBuilder getSelectedMutators() { - return new PreferenceGetterBuilder(new PreferenceGetter() { + private PreferenceGetterBuilder getSelectedMutators() { + return new PreferenceGetterBuilder(new PreferenceGetter() { @Override - public PitMutators getPreference(String label) { + public MutatorGroups getPreference(String label) { expandPitMutatorPreferences(); - for (PitMutators mutator : PitMutators.values()) { + for (MutatorGroups mutator : MutatorGroups.values()) { if (bot.radio(mutator.getLabel()).isSelected()) { return mutator; } } - return PitMutators.DEFAULTS; + return MutatorGroups.DEFAULTS; } }); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java index 4a9024e2..af4ed4cd 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java @@ -25,7 +25,7 @@ import org.eclipse.swtbot.swt.finder.waits.Conditions; import org.eclipse.ui.dialogs.PreferencesUtil; import org.pitest.pitclipse.core.PitCoreActivator; -import org.pitest.pitclipse.core.PitMutators; +import org.pitest.pitclipse.core.MutatorGroups; import org.pitest.pitclipse.runner.config.PitExecutionMode; public class WindowsMenu { @@ -155,11 +155,11 @@ public void openPitMutationsView() { viewSelector.selectView("PIT", "PIT Mutations"); } - public PitMutators getMutators() { + public MutatorGroups getMutators() { return openPreferences().andThen().getMutators(); } - public void setMutators(PitMutators mutators) { + public void setMutators(MutatorGroups mutators) { PitCoreActivator.getDefault().setMutators(mutators); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java index 46a97e5f..033b27a0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java @@ -21,7 +21,7 @@ import cucumber.api.java.en.When; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; -import org.pitest.pitclipse.core.PitMutators; +import org.pitest.pitclipse.core.MutatorGroups; import org.pitest.pitclipse.runner.config.PitExecutionMode; import java.math.BigDecimal; @@ -33,8 +33,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.pitest.pitclipse.core.PitMutators.ALL; -import static org.pitest.pitclipse.core.PitMutators.STRONGER; +import static org.pitest.pitclipse.core.MutatorGroups.ALL; +import static org.pitest.pitclipse.core.MutatorGroups.STRONGER; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_MUTATORS; import static org.pitest.pitclipse.runner.config.PitExecutionMode.PROJECT_ISOLATION; @@ -149,7 +149,7 @@ public void setAvoidCalls(String avoidCallsTo) { @Then("the default mutators preference is selected") public void defaultMutators() { - PitMutators selectedMutators = PAGES.getWindowsMenu().getMutators(); + MutatorGroups selectedMutators = PAGES.getWindowsMenu().getMutators(); assertThat(selectedMutators.toString(), is(equalTo(DEFAULT_MUTATORS))); } From cc74e3b686d6c28c0e0daea19e7bbcfd4954e5ab Mon Sep 17 00:00:00 2001 From: Emmanuel Chebbi Date: Fri, 6 Mar 2020 20:25:02 +0100 Subject: [PATCH 04/50] Allow to disable checkstyle rules with SuppressWarnings annotation --- checkstyle.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/checkstyle.xml b/checkstyle.xml index ecdf0687..37d79034 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -141,4 +141,8 @@ + + + + From c44b7f9da373831e2305c586573525e9dbf441e0 Mon Sep 17 00:00:00 2001 From: Emmanuel Chebbi Date: Fri, 6 Mar 2020 20:25:16 +0100 Subject: [PATCH 05/50] Create Mutators enum --- .../org/pitest/pitclipse/core/Mutators.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java new file mode 100644 index 00000000..d5e98618 --- /dev/null +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java @@ -0,0 +1,67 @@ +package org.pitest.pitclipse.core; + +@SuppressWarnings("checkstyle:LineLength") +public enum Mutators { + + CONDITIONALS_BOUNDARY("CONDITIONALS_BOUNDARY", "Conditionals Boundary", "Replaces the relational operators <, <=, >, >=", true), + INCREMENTS("INCREMENTS", "Increments", "Mutates increments, decrements and assignment increments and decrements of local variables (stack variables). Replaces increments with decrements and vice versa", true), + INVERT_NEGS("INVERT_NEGS", "Invert Negatives", "Inverts negation of integer and floating point numbers", true), + MATH("MATH", "Math", "Replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation", true), + NEGATE_CONDITIONALS("NEGATE_CONDITIONALS", "Negate Conditionals", "Mutates all conditionals found", true), + RETURN_VALS("RETURN_VALS", "Return Values", "Mutates the return values of method calls. Depending on the return type of the method another mutation is used", true), + VOID_METHOD_CALLS("VOID_METHOD_CALLS", "Void Method Call", "Removes method calls to void methods", true), + CONSTRUCTOR_CALLS("CONSTRUCTOR_CALLS", "Constructor Call", "Replaces constructor calls with null values", false), + EMPTY_RETURNS("EMPTY_RETURNS", "Empty Returns", "Replaces return values with an 'empty' value", false), + FALSE_RETURNS("FALSE_RETURNS", "False Returns", "Replaces primitive and boxed boolean return values with false", false), + INLINE_CONSTS("INLINE_CONSTS", "Inline Constant", "Mutates inline constants. An inline constant is a literal value assigned to a non-final variable", false), + NULL_RETURNS("NULL_RETURNS", "Null Returns", "Replaces return values with null. Method that can be mutated by the EMPTY_RETURNS mutator or that are directly annotated with NotNull are not mutated", false), + NON_VOID_METHOD_CALLS("NON_VOID_METHOD_CALLS", "Non Void Method Call", "Removes method calls to non void methods. Their return value is replaced by the Java Default Value for that specific type", false), + PRIMITIVE_RETURNS("PRIMITIVE_RETURNS", "Primite Returns", "Replaces int, short, long, char, float and double return values with 0", false), + REMOVE_CONDITIONALS("REMOVE_CONDITIONALS", "Remove Conditionals", "Removes all conditionals statements such that the guarded statements always execute", false), + REMOVE_INCREMENTS("REMOVE_INCREMENTS", "Remove Increments", "Removes local variable increments", false), + TRUE_RETURNS("TRUE_RETURNS", "True Returns", "Replaces primitive and boxed boolean return values with true", false), + EXPERIMENTAL_ARGUMENT_PROPAGATION("EXPERIMENTAL_ARGUMENT_PROPAGATION", "Experimentation Argument Propagation", "Replaces method call with one of its parameters of matching type", false), + EXPERIMENTAL_BIG_INTEGER("EXPERIMENTAL_BIG_INTEGER", "Experimental Big Integer", "Swaps big integer methods", false), + EXPERIMENTAL_NAKED_RECEIVER("EXPERIMENTAL_NAKED_RECEIVER", "Experimental Naked Receiver", "Replaces method call with a naked receiver", false), + EXPERIMENTAL_MEMBER_VARIABLE("EXPERIMENTAL_MEMBER_VARIABLE", "Experimental Member Variable", "Removes assignments to member variables. Can even remove assignments to final members. The members will be initialized with their Java Default Value", false), + EXPERIMENTAL_SWITCH_MUTATOR("EXPERIMENTAL_SWITCH", "Experimental Switch", "Finds the first label within a switch statement that differs from the default label. Mutates the switch statement by replacing the default label (wherever it is used) with this label. ALl the other labels are replaced by the default one", false), + ABS("ABS", "Negation", "Replaces any use of a numeric variable (local variable, field, array cell) with its negation", false), + AOR("AOR", "Arithmetic Operator Replacement", "Like the Math mutator, replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation", false), + AOD("AOD", "Arithmetic Operator Deletion", "Replaces an arithmetic operation with one of its members", false), + CRCR("CRCR", "Constant Replacement", "Like the Inline Constant mutator, mutates inline constant", false), + OBBN("OBBN", "Bitwise Operator", "Mutates bitwise and (&) and or (|)", false), + ROR("ROR", "Relational Operator Replacement", "Replaces a relational operator with another one", false), + UOI("UOI", "Unary Operator Insertion", "Inserts a unary operator (increment or decrement) to a variable call. Affects local variables, array variables, fields and parameters", false); + + private final String id; + + private final String name; + + private final String description; + + private final boolean activeByDefault; + + private Mutators(String id, String name, String description, boolean activeByDefault) { + this.id = id; + this.name = name; + this.description = description; + this.activeByDefault = activeByDefault; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public boolean isActiveByDefault() { + return activeByDefault; + } + +} From 1a23396b68d71a3132164f396e9a49304714f845 Mon Sep 17 00:00:00 2001 From: Emmanuel Chebbi Date: Wed, 11 Mar 2020 08:56:16 +0100 Subject: [PATCH 06/50] the table shows the mutators --- .../pitclipse/core/PitCoreActivator.java | 4 + .../launch/ui/LambdaLabelProvider.java | 27 +++ .../pitclipse/launch/ui/PitMutatorsTab.java | 172 ++++++++++++------ .../config/LaunchConfigurationWrapper.java | 2 + 4 files changed, 150 insertions(+), 55 deletions(-) create mode 100644 bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/LambdaLabelProvider.java diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index b7f39189..d0317608 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -300,4 +300,8 @@ public void setExecutionMode(PitExecutionMode pitExecutionMode) { public void setMutators(MutatorGroups mutators) { getPreferenceStore().setValue(PIT_MUTATORS, mutators.getId()); } + + public String getDefaultMutators() { + return getPreferenceStore().getString(PIT_MUTATORS); + } } diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/LambdaLabelProvider.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/LambdaLabelProvider.java new file mode 100644 index 00000000..45d734e5 --- /dev/null +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/LambdaLabelProvider.java @@ -0,0 +1,27 @@ +package org.pitest.pitclipse.launch.ui; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +import java.util.function.Function; + +class LambdaLabelProvider extends ColumnLabelProvider { + + private final Function labelProvider; + + public LambdaLabelProvider(Function labelProvider) { + super(); + this.labelProvider = labelProvider; + } + + @Override + @SuppressWarnings("unchecked") + public String getText(Object element) { + try { + return labelProvider.apply((T) element); + } + catch (ClassCastException e) { + return ""; + } + } + +} \ No newline at end of file diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 4ad86e59..b50e0260 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -23,10 +23,11 @@ import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.ui.JavaElementLabelProvider; +import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -42,20 +43,19 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.osgi.framework.Bundle; +import org.pitest.pitclipse.core.MutatorGroups; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; import java.net.URL; -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_FROM_PIT; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_FROM_PIT; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_FROM_PIT; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATION_TESTS_RUN_IN_PARALLEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.USE_INCREMENTAL_ANALYSIS; -import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; @@ -66,7 +66,7 @@ * Tab allowing to configure a PIT analyze. */ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { - private static final int NUMBER_OF_COLUMNS = 3; + private static final int NUMBER_OF_COLUMNS = MutatorGroups.values().length + 2; private Image icon; @@ -82,6 +82,8 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private Text excludedMethodsText; private Text avoidCallsTo; + private CheckboxTableViewer mutatorsTable; + @Override public String getName() { return "Mutators"; @@ -104,24 +106,24 @@ public void dispose() { } public void initializeFrom(ILaunchConfiguration config) { - projectText.setText(getAttributeFromConfig(config, ATTR_PROJECT_NAME, "")); - String testClass = getAttributeFromConfig(config, ATTR_MAIN_TYPE_NAME, ""); - containerId = getAttributeFromConfig(config, ATTR_TEST_CONTAINER, ""); - testClassText.setText(testClass); - if (testClass.length() == 0 && containerId.length() > 0) { - testClassText.setText(""); - IJavaElement containerElement = JavaCore.create(containerId); - testDirText.setText(new JavaElementLabelProvider().getText(containerElement)); - testClassRadioButton.setSelection(false); - testDirectoryRadioButton.setSelection(true); - } else { - testClassText.setText(testClass); - testDirText.setText(""); - testClassRadioButton.setSelection(true); - testDirectoryRadioButton.setSelection(false); - } - initialiseWithPreferenceDefaults(config); - testModeChanged(); +// projectText.setText(getAttributeFromConfig(config, ATTR_PROJECT_NAME, "")); +// String testClass = getAttributeFromConfig(config, ATTR_MAIN_TYPE_NAME, ""); +// containerId = getAttributeFromConfig(config, ATTR_TEST_CONTAINER, ""); +// testClassText.setText(testClass); +// if (testClass.length() == 0 && containerId.length() > 0) { +// testClassText.setText(""); +// IJavaElement containerElement = JavaCore.create(containerId); +// testDirText.setText(new JavaElementLabelProvider().getText(containerElement)); +// testClassRadioButton.setSelection(false); +// testDirectoryRadioButton.setSelection(true); +// } else { +// testClassText.setText(testClass); +// testDirText.setText(""); +// testClassRadioButton.setSelection(true); +// testDirectoryRadioButton.setSelection(false); +// } +// initialiseWithPreferenceDefaults(config); +// testModeChanged(); } private void initialiseWithPreferenceDefaults(ILaunchConfiguration config) { @@ -155,13 +157,73 @@ public void createControl(Composite parent) { comp.setFont(font); createSpacer(comp); - createProjectWidgets(font, comp); - createSpacer(comp); - createMutationScopeWidgets(font, comp); - createSpacer(comp); - createFilters(font, comp); + createMutatorGroupsWidgets(font, comp); createSpacer(comp); - createPreferences(font, comp); + createMutatorsWidgets(comp); + } + + private void createMutatorGroupsWidgets(Font font, Composite group) { +// Group group = new Group(comp, SWT.NONE); +// group.setFont(font); +// group.setText(" Mutator Groups "); +// GridDataFactory.fillDefaults().grab(true, false).span(NUMBER_OF_COLUMNS, 1).applyTo(group); +// GridLayoutFactory.fillDefaults().margins(8, 8).numColumns(MutatorGroups.values().length).applyTo(group); + + Label mutateWith = new Label(group, SWT.NONE); + mutateWith.setFont(font); + mutateWith.setText("Mutate with: "); + + boolean selected = false; + + for (MutatorGroups mutatorGroup : MutatorGroups.values()) { + Button mutatorGroupButton = new Button(group, SWT.RADIO); + mutatorGroupButton.setText(mutatorGroup.getLabel()); + + if (mutatorGroup == MutatorGroups.DEFAULTS) { + mutatorGroupButton.setSelection(true); + selected = true; + } + } + Button customMutatorsButton = new Button(group, SWT.RADIO); + customMutatorsButton.setText("Mutators selected below"); + if (!selected) { + customMutatorsButton.setSelection(true); + } + } + + /** + * Creates a group containing a table showing available Execution Hooks. Execution Hooks are found from extension points. + * Each execution hook provide a checkbox that can be used to activate / deactivate the hook. + */ + private void createMutatorsWidgets(Composite parent) { + mutatorsTable = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + mutatorsTable.getTable().setHeaderVisible(true); + mutatorsTable.setContentProvider(new ArrayContentProvider()); + GridDataFactory.swtDefaults().grab(false, false).span(NUMBER_OF_COLUMNS, 1).applyTo(mutatorsTable.getTable()); + + TableViewerColumn colName = new TableViewerColumn(mutatorsTable, SWT.FILL | SWT.H_SCROLL | SWT.V_SCROLL); + colName.getColumn().setText("Name"); + colName.setLabelProvider(new LambdaLabelProvider(Mutators::getName)); + + TableViewerColumn colDescription = new TableViewerColumn(mutatorsTable, SWT.FILL | SWT.H_SCROLL | SWT.V_SCROLL); + colDescription.getColumn().setText("Description"); + colDescription.setLabelProvider(new LambdaLabelProvider(Mutators::getDescription)); + + mutatorsTable.setInput(Mutators.values()); + + // Init checked state based on whether the hook is activated by default + for (Mutators mutator : Mutators.values()) { + if (mutator.isActiveByDefault()) { + mutatorsTable.setChecked(mutator, true); + } + } + colName.getColumn().pack(); + colDescription.getColumn().pack(); + + mutatorsTable.getTable().setEnabled(true); + + // Dirty the tab when a hook is activated / deactivated + mutatorsTable.addCheckStateListener(event -> setDirty(true)); } private void createMutationScopeWidgets(Font font, Composite comp) { @@ -307,29 +369,29 @@ private Button createNewCheckBox(Font font, Composite comp, int columnsInParent, } public void performApply(ILaunchConfigurationWorkingCopy workingCopy) { - workingCopy.setAttribute(ATTR_PROJECT_NAME, projectText.getText() - .trim()); - if (testClassRadioButton.getSelection()) { - workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, testClassText.getText().trim()); - workingCopy.setAttribute(ATTR_TEST_CONTAINER, ""); - } else { - workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, ""); - workingCopy.setAttribute(ATTR_TEST_CONTAINER, containerId); - } - workingCopy.setAttribute(ATTR_TEST_IN_PARALLEL, - runInParallel.getSelection()); - workingCopy.setAttribute(ATTR_TEST_INCREMENTALLY, - incrementalAnalysis.getSelection()); - workingCopy.setAttribute(ATTR_EXCLUDE_CLASSES, - excludedClassesText.getText()); - workingCopy.setAttribute(ATTR_EXCLUDE_METHODS, - excludedMethodsText.getText()); - workingCopy.setAttribute(ATTR_AVOID_CALLS_TO, avoidCallsTo.getText()); - try { - PitMigrationDelegate.mapResources(workingCopy); - } catch (CoreException ce) { - setErrorMessage(ce.getStatus().getMessage()); - } +// workingCopy.setAttribute(ATTR_PROJECT_NAME, projectText.getText() +// .trim()); +// if (testClassRadioButton.getSelection()) { +// workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, testClassText.getText().trim()); +// workingCopy.setAttribute(ATTR_TEST_CONTAINER, ""); +// } else { +// workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, ""); +// workingCopy.setAttribute(ATTR_TEST_CONTAINER, containerId); +// } +// workingCopy.setAttribute(ATTR_TEST_IN_PARALLEL, +// runInParallel.getSelection()); +// workingCopy.setAttribute(ATTR_TEST_INCREMENTALLY, +// incrementalAnalysis.getSelection()); +// workingCopy.setAttribute(ATTR_EXCLUDE_CLASSES, +// excludedClassesText.getText()); +// workingCopy.setAttribute(ATTR_EXCLUDE_METHODS, +// excludedMethodsText.getText()); +// workingCopy.setAttribute(ATTR_AVOID_CALLS_TO, avoidCallsTo.getText()); +// try { +// PitMigrationDelegate.mapResources(workingCopy); +// } catch (CoreException ce) { +// setErrorMessage(ce.getStatus().getMessage()); +// } } public void setDefaults(ILaunchConfigurationWorkingCopy workingCopy) { @@ -366,7 +428,7 @@ public boolean getBooleanAttributeFromConfig(ILaunchConfiguration config, private void createSpacer(Composite comp) { Label label = new Label(comp, SWT.NONE); GridData gd = new GridData(); - gd.horizontalSpan = 3; + gd.horizontalSpan = NUMBER_OF_COLUMNS; label.setLayoutData(gd); } diff --git a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java index c77516e1..c944f538 100644 --- a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java +++ b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java @@ -125,6 +125,8 @@ public PitOptions.PitOptionsBuilder getPitOptionsBuilder() throws CoreException List mutators = getMutators(); int timeout = pitConfiguration.getTimeout(); BigDecimal timeoutFactor = pitConfiguration.getTimeoutFactor(); + + PitOptionsBuilder builder = PitOptions.builder().withClassesToMutate(classPath) .withSourceDirectories(sourceDirs).withReportDirectory(reportDir).withThreads(threadCount) From b39f16c5f2f3c8395afb8140947b38cbc2c0b245 Mon Sep 17 00:00:00 2001 From: Emmanuel Chebbi Date: Tue, 23 Jun 2020 19:53:18 +0200 Subject: [PATCH 07/50] [WIP] Show the description of mutators --- .../pitest/pitclipse/core/MutatorGroups.java | 14 +++- .../pitclipse/launch/ui/PitMutatorsTab.java | 77 +++++++++++++++++-- 2 files changed, 82 insertions(+), 9 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java index 38a088c7..5b4b6353 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java @@ -18,16 +18,18 @@ public enum MutatorGroups { - DEFAULTS("defaultMutators", "&Default Mutators"), - STRONGER("strongerMutators", "&Stronger Mutators"), - ALL("allMutators", "&All Mutators"); + DEFAULTS("defaultMutators", "&Default Mutators", ""), + STRONGER("strongerMutators", "&Stronger Mutators", ""), + ALL("allMutators", "&All Mutators", ""); private final String label; private final String id; + private final String description; - private MutatorGroups(String id, String label) { + private MutatorGroups(String id, String label, String description) { this.id = id; this.label = label; + this.description = description; } public String getLabel() { @@ -37,4 +39,8 @@ public String getLabel() { public String getId() { return id; } + + public String getDescription() { + return description; + } } diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index b50e0260..942cc331 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -29,6 +29,8 @@ import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; @@ -37,6 +39,7 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; @@ -50,6 +53,7 @@ import java.net.URL; +import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_FROM_PIT; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_FROM_PIT; @@ -84,6 +88,8 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private CheckboxTableViewer mutatorsTable; + private Button customMutatorsButton; + @Override public String getName() { return "Mutators"; @@ -106,6 +112,7 @@ public void dispose() { } public void initializeFrom(ILaunchConfiguration config) { + System.out.println("PitMutatorsTab.initializeFrom()"); // projectText.setText(getAttributeFromConfig(config, ATTR_PROJECT_NAME, "")); // String testClass = getAttributeFromConfig(config, ATTR_MAIN_TYPE_NAME, ""); // containerId = getAttributeFromConfig(config, ATTR_TEST_CONTAINER, ""); @@ -156,10 +163,47 @@ public void createControl(Composite parent) { Font font = parent.getFont(); comp.setFont(font); + createDescription(comp); + addSeparator(comp); createSpacer(comp); createMutatorGroupsWidgets(font, comp); createSpacer(comp); createMutatorsWidgets(comp); + + disableTableIfUnused(); + setDirty(false); + } + + private void createDescription(Composite parent) { + String description = " Select the mutators used to alter the code. See the documentation on Pitest.org"; + String link = "https://pitest.org/quickstart/mutators/"; + int linkStartIndex = description.indexOf("See"); + int linkLength = description.indexOf("Pitest") + "Pitest.org".length() - description.indexOf("See"); + + StyledText styledText = new StyledText(parent, SWT.NONE); + styledText.setText(description); + styledText.setBackground(parent.getBackground()); + styledText.setMarginColor(parent.getBackground()); + + GridDataFactory.fillDefaults().span(NUMBER_OF_COLUMNS, 1).applyTo(styledText); + styledText.setLeftMargin(0); + + StyleRange style = new StyleRange(); + style.underline = true; + style.underlineStyle = SWT.UNDERLINE_LINK; + style.start = linkStartIndex; + style.length = linkLength; + styledText.setStyleRange(style); + + styledText.addListener(SWT.MouseDown, event -> { + int clickOffset = styledText.getCaretOffset(); + if (linkStartIndex <= clickOffset && clickOffset < linkStartIndex + linkLength) { + // Open the documentation with external browser + Program.launch(link); + } + }); + styledText.setBottomMargin(5); + styledText.setToolTipText(link); } private void createMutatorGroupsWidgets(Font font, Composite group) { @@ -173,24 +217,37 @@ private void createMutatorGroupsWidgets(Font font, Composite group) { mutateWith.setFont(font); mutateWith.setText("Mutate with: "); - boolean selected = false; + boolean aMutatorGroupIsSelected = false; for (MutatorGroups mutatorGroup : MutatorGroups.values()) { Button mutatorGroupButton = new Button(group, SWT.RADIO); mutatorGroupButton.setText(mutatorGroup.getLabel()); + mutatorGroupButton.addSelectionListener(widgetSelectedAdapter(event -> { + disableTableIfUnused(); + setDirty(); + })); if (mutatorGroup == MutatorGroups.DEFAULTS) { mutatorGroupButton.setSelection(true); - selected = true; + aMutatorGroupIsSelected = true; } } - Button customMutatorsButton = new Button(group, SWT.RADIO); + customMutatorsButton = new Button(group, SWT.RADIO); customMutatorsButton.setText("Mutators selected below"); - if (!selected) { + customMutatorsButton.addSelectionListener(widgetSelectedAdapter(event -> { + disableTableIfUnused(); + setDirty(); + })); + if (!aMutatorGroupIsSelected) { customMutatorsButton.setSelection(true); } } + private void setDirty() { +// setDirty(true); + updateLaunchConfigurationDialog(); + } + /** * Creates a group containing a table showing available Execution Hooks. Execution Hooks are found from extension points. * Each execution hook provide a checkbox that can be used to activate / deactivate the hook. @@ -223,7 +280,11 @@ private void createMutatorsWidgets(Composite parent) { mutatorsTable.getTable().setEnabled(true); // Dirty the tab when a hook is activated / deactivated - mutatorsTable.addCheckStateListener(event -> setDirty(true)); + mutatorsTable.addCheckStateListener(event -> setDirty()); + } + + private void disableTableIfUnused() { + mutatorsTable.getTable().setEnabled(customMutatorsButton.getSelection()); } private void createMutationScopeWidgets(Font font, Composite comp) { @@ -367,8 +428,14 @@ private Button createNewCheckBox(Font font, Composite comp, int columnsInParent, checkBox.setFont(font); return checkBox; } + + protected static void addSeparator(Composite parent) { + Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); + GridDataFactory.fillDefaults().span(NUMBER_OF_COLUMNS, 1).applyTo(separator); + } public void performApply(ILaunchConfigurationWorkingCopy workingCopy) { + System.out.println("PitMutatorsTab.performApply()"); // workingCopy.setAttribute(ATTR_PROJECT_NAME, projectText.getText() // .trim()); // if (testClassRadioButton.getSelection()) { From d5a6a9cd7b0a5568912bd70e490734b3babe1106 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Tue, 20 Jul 2021 17:11:20 +0200 Subject: [PATCH 08/50] Fixed failing tests Added fields for text, that it can be used in tests --- .../pitest/pitclipse/core/MutatorGroups.java | 6 ++-- .../pitclipse/launch/ui/PitArgumentsTab.java | 33 +++++++++++-------- .../pageobjects/RunConfigurationSelector.java | 14 ++++---- .../ui/tests/PitclipseOptionsTest.java | 7 ++-- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java index 5b4b6353..6518012a 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java @@ -18,9 +18,9 @@ public enum MutatorGroups { - DEFAULTS("defaultMutators", "&Default Mutators", ""), - STRONGER("strongerMutators", "&Stronger Mutators", ""), - ALL("allMutators", "&All Mutators", ""); + DEFAULTS("DEFAULT", "&Default Mutators", ""), + STRONGER("STRONGER", "&Stronger Mutators", ""), + ALL("ALL", "&All Mutators", ""); private final String label; private final String id; diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index f159ef1a..b4ff2047 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -63,11 +63,18 @@ import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; /** - * Tab allowing to configure a PIT analyze. + * Tab allowing to configure a PIT analyze. */ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab { private static final int NUMBER_OF_COLUMNS = 3; - + public static final String TEST_CLASS_RADIO_TEXT = "Run mutations from a unit test"; + public static final String TEST_CLASS_TEXT = "Test Class:"; + public static final String TEST_DIR_RADIO_TEXT = "Run mutations against a package or directory"; + public static final String TEST_DIR_TEXT = "Directory:"; + public static final String FILTERS_GROUP_TEXT = " Filters "; + public static final String SCOPE_GROUP_TEXT = " Mutation Scope "; + public static final String PROJECT_TEXT = "Project to mutate: "; + private Image icon; private Text testClassText; @@ -158,17 +165,17 @@ public void createControl(Composite parent) { createSpacer(comp); createPreferences(font, comp); } - + private void createMutationScopeWidgets(Font font, Composite comp) { Group group = new Group(comp, SWT.NONE); - group.setText(" Mutation Scope "); + group.setText(SCOPE_GROUP_TEXT); group.setFont(font); GridData groupGrid = new GridData(FILL_HORIZONTAL); groupGrid.horizontalSpan = NUMBER_OF_COLUMNS; group.setLayoutData(groupGrid); GridLayout groupLayout = new GridLayout(2, false); group.setLayout(groupLayout); - + createTestClassWidgets(font, group, groupLayout.numColumns); createSpacer(group); createTestDirWidgets(font, group, groupLayout.numColumns); @@ -176,7 +183,7 @@ private void createMutationScopeWidgets(Font font, Composite comp) { private void createProjectWidgets(Font font, Composite comp) { Label projectLabel = new Label(comp, SWT.NONE); - projectLabel.setText("Project to mutate: "); + projectLabel.setText(PROJECT_TEXT); GridData gd = new GridData(); gd.horizontalSpan = 1; projectLabel.setLayoutData(gd); @@ -190,14 +197,13 @@ private void createProjectWidgets(Font font, Composite comp) { } private void createTestClassWidgets(Font font, Composite comp, int columnsInParent) { - testClassRadioButton = createTestRadioButton(comp, - "Run mutations from a unit test"); + testClassRadioButton = createTestRadioButton(comp, TEST_CLASS_RADIO_TEXT); GridData testClassGrid = new GridData(FILL_HORIZONTAL); testClassGrid.horizontalSpan = columnsInParent; testClassRadioButton.setLayoutData(testClassGrid); Label testClassLabel = new Label(comp, SWT.NONE); - testClassLabel.setText("Test Class:"); + testClassLabel.setText(TEST_CLASS_TEXT); GridData labelGrid = new GridData(); labelGrid.horizontalIndent = 25; labelGrid.horizontalSpan = 1; @@ -220,17 +226,16 @@ private Button createTestRadioButton(Composite comp, String label) { } private void createTestDirWidgets(Font font, Composite comp, int columnsInParent) { - testDirectoryRadioButton = createTestRadioButton(comp, - "Run mutations against a package or directory"); + testDirectoryRadioButton = createTestRadioButton(comp, TEST_DIR_RADIO_TEXT); GridData testDirGrid = new GridData(FILL_HORIZONTAL); testDirGrid.horizontalSpan = columnsInParent; testDirectoryRadioButton.setLayoutData(testDirGrid); - + GridData labelGrid = new GridData(); labelGrid.horizontalIndent = 25; labelGrid.horizontalSpan = 1; Label testDirectoryLabel = new Label(comp, SWT.NONE); - testDirectoryLabel.setText("Directory:"); + testDirectoryLabel.setText(TEST_DIR_TEXT); testDirectoryLabel.setLayoutData(labelGrid); testDirectoryLabel.setFont(font); @@ -243,7 +248,7 @@ private void createTestDirWidgets(Font font, Composite comp, int columnsInParent private void createFilters(Font font, Composite comp) { Group group = new Group(comp, SWT.NONE); - group.setText(" Filters "); + group.setText(FILTERS_GROUP_TEXT); group.setFont(font); GridData groupGrid = new GridData(FILL_HORIZONTAL); groupGrid.horizontalSpan = NUMBER_OF_COLUMNS; diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index 030674e2..b543ee32 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -21,6 +21,8 @@ import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.pitest.pitclipse.core.preferences.PitPreferences; +import org.pitest.pitclipse.launch.ui.PitArgumentsTab; import org.pitest.pitclipse.ui.behaviours.pageobjects.PitRunConfiguration.Builder; import java.util.List; @@ -59,12 +61,12 @@ public List getConfigurations() { private PitRunConfiguration getPitConfiguration(SWTBotTreeItem treeItem) { String name = treeItem.getText(); - String project = bot.textWithLabel("Project to mutate:").getText(); - boolean runInParallel = bot.checkBox("Mutation tests run in parallel").isChecked(); - boolean incrementalAnalysis = bot.checkBox("Use incremental analysis").isChecked(); - String excludedClasses = bot.textWithLabel("Excluded classes (e.g.*IntTest)").getText(); - String excludedMethods = bot.textWithLabel("Excluded methods (e.g.*toString*)").getText(); - String avoidCallsTo = bot.textWithLabel("Avoid calls to").getText(); + String project = bot.textWithLabel(PitArgumentsTab.PROJECT_TEXT).getText(); + boolean runInParallel = bot.checkBox(PitPreferences.MUTATION_TESTS_RUN_IN_PARALLEL).isChecked(); + boolean incrementalAnalysis = bot.checkBox(PitPreferences.USE_INCREMENTAL_ANALYSIS).isChecked(); + String excludedClasses = bot.textWithLabel(PitPreferences.EXCLUDE_CLASSES_FROM_PIT).getText(); + String excludedMethods = bot.textWithLabel(PitPreferences.EXCLUDE_METHODS_FROM_PIT).getText(); + String avoidCallsTo = bot.textWithLabel(PitPreferences.AVOID_CALLS_FROM_PIT).getText(); return new Builder().withName(name).withProjects(project).withRunInParallel(runInParallel) .withIncrementalAnalysis(incrementalAnalysis).withExcludedClasses(excludedClasses) .withExcludedMethods(excludedMethods).withAvoidCallsTo(avoidCallsTo).build(); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 51b06b85..c5229ec5 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.pitest.pitclipse.core.PitMutators.STRONGER; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_MUTATORS; import static org.pitest.pitclipse.runner.config.PitExecutionMode.PROJECT_ISOLATION; @@ -18,8 +17,8 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.pitest.pitclipse.core.MutatorGroups; import org.pitest.pitclipse.core.PitCoreActivator; -import org.pitest.pitclipse.core.PitMutators; import org.pitest.pitclipse.core.preferences.PitPreferences; import org.pitest.pitclipse.runner.config.PitConfiguration; import org.pitest.pitclipse.ui.behaviours.pageobjects.PitPreferenceSelector; @@ -84,7 +83,7 @@ public void useDefaultMutators() throws CoreException { @Test public void useStrongerMutators() throws CoreException { // now set STRONGER mutators - PAGES.getWindowsMenu().setMutators(STRONGER); + PAGES.getWindowsMenu().setMutators(MutatorGroups.STRONGER); try { runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); coverageReportGenerated(2, 80, 0); @@ -99,7 +98,7 @@ public void useStrongerMutators() throws CoreException { "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f"); } finally { // it's crucial to reset it to the default or we break other tests - PAGES.getWindowsMenu().setMutators(PitMutators.DEFAULTS); + PAGES.getWindowsMenu().setMutators(MutatorGroups.DEFAULTS); } } From 0d7daeeee427ece657251b3cf3ab7fe60e4a432b Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Wed, 21 Jul 2021 15:08:18 +0200 Subject: [PATCH 09/50] Added old defaults to groups --- .../src/org/pitest/pitclipse/core/MutatorGroups.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java index 6518012a..794d452c 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java @@ -17,8 +17,8 @@ package org.pitest.pitclipse.core; public enum MutatorGroups { - - DEFAULTS("DEFAULT", "&Default Mutators", ""), + OLDDEFAULTS("OLD_DEFAULTS", "&Old default Mutators", ""), + DEFAULTS("DEFAULTS", "&Default Mutators", ""), STRONGER("STRONGER", "&Stronger Mutators", ""), ALL("ALL", "&All Mutators", ""); From 936377e27f3f3f46aa13e01531926f8b8e22d6c1 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Wed, 21 Jul 2021 15:09:33 +0200 Subject: [PATCH 10/50] Working mutations tab --- .../META-INF/MANIFEST.MF | 3 +- .../pitclipse/launch/ui/PitArgumentsTab.java | 4 +- .../pitclipse/launch/ui/PitMutatorsTab.java | 539 ++++++------------ .../config/LaunchConfigurationWrapper.java | 11 +- .../runner/config/PitConfiguration.java | 1 - .../pageobjects/PitPreferenceSelector.java | 1 - 6 files changed, 176 insertions(+), 383 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF b/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF index 38e7c3e2..d97cd33a 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF +++ b/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.1,4.0.0)", org.pitest.pitclipse.launch, org.eclipse.jface;bundle-version="[3.11.1,4.0.0)", org.eclipse.ui.workbench;bundle-version="[3.107.1,4.0.0)", - org.eclipse.jdt.debug.ui;bundle-version="[3.7.101,4.0.0)" + org.eclipse.jdt.debug.ui;bundle-version="[3.7.101,4.0.0)", + org.pitest;bundle-version="1.6.7" Import-Package: com.google.common.collect;version="21.0.0" Export-Package: org.pitest.pitclipse.launch.ui diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index b4ff2047..98d9a7fc 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -345,7 +345,7 @@ public void setDefaults(ILaunchConfigurationWorkingCopy workingCopy) { */ } - public String getAttributeFromConfig(ILaunchConfiguration config, + public static String getAttributeFromConfig(ILaunchConfiguration config, String attribute, String defaultValue) { String result = defaultValue; try { @@ -356,7 +356,7 @@ public String getAttributeFromConfig(ILaunchConfiguration config, return result; } - public boolean getBooleanAttributeFromConfig(ILaunchConfiguration config, + public static boolean getBooleanAttributeFromConfig(ILaunchConfiguration config, String attribute, boolean defaultValue) { boolean result = defaultValue; try { diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 942cc331..20b957dc 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -24,15 +24,12 @@ import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; @@ -42,9 +39,8 @@ import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Link; import org.osgi.framework.Bundle; import org.pitest.pitclipse.core.MutatorGroups; import org.pitest.pitclipse.core.Mutators; @@ -52,49 +48,37 @@ import org.pitest.pitclipse.runner.config.PitConfiguration; import java.net.URL; +import java.util.Arrays; +import java.util.Iterator; +import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_MUTATORS; import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; -import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATION_TESTS_RUN_IN_PARALLEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.USE_INCREMENTAL_ANALYSIS; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; /** - * Tab allowing to configure a PIT analyze. + * Tab allowing to configure a PIT analyze. */ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private static final int NUMBER_OF_COLUMNS = MutatorGroups.values().length + 2; - + private static final String CUSTOM_MUTATOR_RADIO_TEXT = "Mutators selected below"; + private static final String CUSTOM_MUTATOR_RADIO_DATA = "CUSTOM"; + private static final String MUTATOR_LINK_TEXT = "See the documentation on Pitest.org"; + private static final String DESCRIPTION_TEXT = "Select the mutators used to alter the code."; + private static final String MUTATOR_LINK = "https://pitest.org/quickstart/mutators/"; private Image icon; - - private Text testClassText; - private Text projectText; - private Button testClassRadioButton; - private Button testDirectoryRadioButton; - private Text testDirText; - private String containerId; - private Button runInParallel; - private Button incrementalAnalysis; - private Text excludedClassesText; - private Text excludedMethodsText; - private Text avoidCallsTo; - + private String mutators; private CheckboxTableViewer mutatorsTable; - private Button customMutatorsButton; + private Button[] groupButtons; + private Composite mainComp; + private Label descriptionLabel; + private Composite grouopComposite; + private Label mutateWithLabel; @Override public String getName() { return "Mutators"; } - + @Override public Image getImage() { Bundle bundle = Platform.getBundle(PitLaunchUiActivator.PLUGIN_ID); @@ -103,7 +87,7 @@ public Image getImage() { icon = ImageDescriptor.createFromURL(iconURL).createImage(); return icon; } - + @Override public void dispose() { if (icon != null) { @@ -112,353 +96,175 @@ public void dispose() { } public void initializeFrom(ILaunchConfiguration config) { - System.out.println("PitMutatorsTab.initializeFrom()"); -// projectText.setText(getAttributeFromConfig(config, ATTR_PROJECT_NAME, "")); -// String testClass = getAttributeFromConfig(config, ATTR_MAIN_TYPE_NAME, ""); -// containerId = getAttributeFromConfig(config, ATTR_TEST_CONTAINER, ""); -// testClassText.setText(testClass); -// if (testClass.length() == 0 && containerId.length() > 0) { -// testClassText.setText(""); -// IJavaElement containerElement = JavaCore.create(containerId); -// testDirText.setText(new JavaElementLabelProvider().getText(containerElement)); -// testClassRadioButton.setSelection(false); -// testDirectoryRadioButton.setSelection(true); -// } else { -// testClassText.setText(testClass); -// testDirText.setText(""); -// testClassRadioButton.setSelection(true); -// testDirectoryRadioButton.setSelection(false); -// } -// initialiseWithPreferenceDefaults(config); -// testModeChanged(); - } + PitConfiguration preferences = PitCoreActivator.getDefault().getConfiguration(); + mutators = PitArgumentsTab.getAttributeFromConfig(config, PIT_MUTATORS, preferences.getMutators()); + System.out.println(mutators); + if (!updateSelectionOfGroup(mutators)) { + // no selection was made, because no match of data + // select custom mutators button + customMutatorsButton.setSelection(true); + // TODO: select mutators which are set + } - private void initialiseWithPreferenceDefaults(ILaunchConfiguration config) { - PitConfiguration preferences = PitCoreActivator.getDefault() - .getConfiguration(); - runInParallel.setSelection(Boolean - .valueOf(getBooleanAttributeFromConfig(config, - ATTR_TEST_IN_PARALLEL, - preferences.isParallelExecution()))); - incrementalAnalysis.setSelection(Boolean - .valueOf(getBooleanAttributeFromConfig(config, - ATTR_TEST_INCREMENTALLY, - preferences.isIncrementalAnalysis()))); - excludedClassesText.setText(getAttributeFromConfig(config, - ATTR_EXCLUDE_CLASSES, preferences.getExcludedClasses())); - excludedMethodsText.setText(getAttributeFromConfig(config, - ATTR_EXCLUDE_METHODS, preferences.getExcludedMethods())); - avoidCallsTo.setText(getAttributeFromConfig(config, - ATTR_AVOID_CALLS_TO, preferences.getExcludedMethods())); } public void createControl(Composite parent) { - Composite comp = new Composite(parent, SWT.NONE); - setControl(comp); + mainComp = new Composite(parent, SWT.NONE); + setControl(mainComp); GridLayout topLayout = new GridLayout(); topLayout.verticalSpacing = 0; topLayout.numColumns = NUMBER_OF_COLUMNS; - comp.setLayout(topLayout); + mainComp.setLayout(topLayout); Font font = parent.getFont(); - comp.setFont(font); - - createDescription(comp); - addSeparator(comp); - createSpacer(comp); - createMutatorGroupsWidgets(font, comp); - createSpacer(comp); - createMutatorsWidgets(comp); - + mainComp.setFont(font); + + createDescription(mainComp); + addSeparator(mainComp); + createSpacer(mainComp); + createMutatorGroupsWidgets(font, mainComp); + createSpacer(mainComp); + createMutatorsWidgets(mainComp); + disableTableIfUnused(); setDirty(false); } - + + /** + * Creates an description what mutants are and prvides a link to the + * documentation of pitest.org + * @param parent where to add the description + */ private void createDescription(Composite parent) { - String description = " Select the mutators used to alter the code. See the documentation on Pitest.org"; - String link = "https://pitest.org/quickstart/mutators/"; - int linkStartIndex = description.indexOf("See"); - int linkLength = description.indexOf("Pitest") + "Pitest.org".length() - description.indexOf("See"); - - StyledText styledText = new StyledText(parent, SWT.NONE); - styledText.setText(description); - styledText.setBackground(parent.getBackground()); - styledText.setMarginColor(parent.getBackground()); - - GridDataFactory.fillDefaults().span(NUMBER_OF_COLUMNS, 1).applyTo(styledText); - styledText.setLeftMargin(0); - - StyleRange style = new StyleRange(); - style.underline = true; - style.underlineStyle = SWT.UNDERLINE_LINK; - style.start = linkStartIndex; - style.length = linkLength; - styledText.setStyleRange(style); - - styledText.addListener(SWT.MouseDown, event -> { - int clickOffset = styledText.getCaretOffset(); - if (linkStartIndex <= clickOffset && clickOffset < linkStartIndex + linkLength) { - // Open the documentation with external browser - Program.launch(link); + descriptionLabel = new Label(parent, SWT.NONE); + descriptionLabel.setText(DESCRIPTION_TEXT); + GridDataFactory.swtDefaults().indent(5, 0).applyTo(descriptionLabel); + Link link = new Link(parent, SWT.NONE); + link.setText("" + MUTATOR_LINK_TEXT + ""); + link.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Program.launch(MUTATOR_LINK); } + }); - styledText.setBottomMargin(5); - styledText.setToolTipText(link); } - - private void createMutatorGroupsWidgets(Font font, Composite group) { -// Group group = new Group(comp, SWT.NONE); -// group.setFont(font); -// group.setText(" Mutator Groups "); -// GridDataFactory.fillDefaults().grab(true, false).span(NUMBER_OF_COLUMNS, 1).applyTo(group); -// GridLayoutFactory.fillDefaults().margins(8, 8).numColumns(MutatorGroups.values().length).applyTo(group); - - Label mutateWith = new Label(group, SWT.NONE); - mutateWith.setFont(font); - mutateWith.setText("Mutate with: "); - - boolean aMutatorGroupIsSelected = false; - + + /** + * Creates an radio Button for each group present in MutatorGroups and adds one + * for custom selection of mutants + * @param font which is used for text + * @param parent where to add the widget + */ + private void createMutatorGroupsWidgets(Font font, Composite parent) { + // add own composite to group options closer together + grouopComposite = new Composite(parent, SWT.NONE); + GridDataFactory.swtDefaults().span(NUMBER_OF_COLUMNS, 1).applyTo(grouopComposite); + GridLayoutFactory.swtDefaults().numColumns(NUMBER_OF_COLUMNS).applyTo(grouopComposite); + mutateWithLabel = new Label(grouopComposite, SWT.NONE); + mutateWithLabel.setFont(font); + mutateWithLabel.setText("Mutate with: "); + GridDataFactory.swtDefaults().applyTo(mutateWithLabel); + + groupButtons = new Button[MutatorGroups.values().length]; + int i = 0; for (MutatorGroups mutatorGroup : MutatorGroups.values()) { - Button mutatorGroupButton = new Button(group, SWT.RADIO); - mutatorGroupButton.setText(mutatorGroup.getLabel()); - mutatorGroupButton.addSelectionListener(widgetSelectedAdapter(event -> { - disableTableIfUnused(); - setDirty(); + Button button = new Button(grouopComposite, SWT.RADIO); + button.setText(mutatorGroup.getLabel()); + button.setData(mutatorGroup.getId()); + button.setFont(font); + button.addSelectionListener(widgetSelectedAdapter(event -> { + final String old = mutators; + mutators = (String) event.widget.getData(); + if (((Button) event.widget).getSelection() && !old.equals(mutators)) { + updateLaunchConfigurationDialog(); + disableTableIfUnused(); + } })); - - if (mutatorGroup == MutatorGroups.DEFAULTS) { - mutatorGroupButton.setSelection(true); - aMutatorGroupIsSelected = true; - } + groupButtons[i++] = button; + GridDataFactory.swtDefaults().applyTo(button); } - customMutatorsButton = new Button(group, SWT.RADIO); - customMutatorsButton.setText("Mutators selected below"); + customMutatorsButton = new Button(grouopComposite, SWT.RADIO); + customMutatorsButton.setText(CUSTOM_MUTATOR_RADIO_TEXT); + customMutatorsButton.setData(CUSTOM_MUTATOR_RADIO_DATA); + customMutatorsButton.setFont(font); customMutatorsButton.addSelectionListener(widgetSelectedAdapter(event -> { - disableTableIfUnused(); - setDirty(); + final String old = mutators; + mutators = (String) event.widget.getData(); + if (!old.equals(mutators)) { + updateLaunchConfigurationDialog(); + disableTableIfUnused(); + } })); - if (!aMutatorGroupIsSelected) { - customMutatorsButton.setSelection(true); - } + GridDataFactory.swtDefaults().applyTo(customMutatorsButton); } - - private void setDirty() { -// setDirty(true); - updateLaunchConfigurationDialog(); - } - + /** - * Creates a group containing a table showing available Execution Hooks. Execution Hooks are found from extension points. - * Each execution hook provide a checkbox that can be used to activate / deactivate the hook. + * Creates a group containing a table showing available Execution Hooks. + * Execution Hooks are found from extension points. Each execution hook provide + * a checkbox that can be used to activate / deactivate the hook. */ private void createMutatorsWidgets(Composite parent) { mutatorsTable = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); mutatorsTable.getTable().setHeaderVisible(true); mutatorsTable.setContentProvider(new ArrayContentProvider()); GridDataFactory.swtDefaults().grab(false, false).span(NUMBER_OF_COLUMNS, 1).applyTo(mutatorsTable.getTable()); - + TableViewerColumn colName = new TableViewerColumn(mutatorsTable, SWT.FILL | SWT.H_SCROLL | SWT.V_SCROLL); colName.getColumn().setText("Name"); colName.setLabelProvider(new LambdaLabelProvider(Mutators::getName)); - + TableViewerColumn colDescription = new TableViewerColumn(mutatorsTable, SWT.FILL | SWT.H_SCROLL | SWT.V_SCROLL); colDescription.getColumn().setText("Description"); colDescription.setLabelProvider(new LambdaLabelProvider(Mutators::getDescription)); - + mutatorsTable.setInput(Mutators.values()); - - // Init checked state based on whether the hook is activated by default - for (Mutators mutator : Mutators.values()) { - if (mutator.isActiveByDefault()) { - mutatorsTable.setChecked(mutator, true); - } - } + colName.getColumn().pack(); colDescription.getColumn().pack(); - - mutatorsTable.getTable().setEnabled(true); - - // Dirty the tab when a hook is activated / deactivated - mutatorsTable.addCheckStateListener(event -> setDirty()); - } - - private void disableTableIfUnused() { - mutatorsTable.getTable().setEnabled(customMutatorsButton.getSelection()); - } - - private void createMutationScopeWidgets(Font font, Composite comp) { - Group group = new Group(comp, SWT.NONE); - group.setText(" Mutation Scope "); - group.setFont(font); - GridData groupGrid = new GridData(FILL_HORIZONTAL); - groupGrid.horizontalSpan = NUMBER_OF_COLUMNS; - group.setLayoutData(groupGrid); - GridLayout groupLayout = new GridLayout(2, false); - group.setLayout(groupLayout); - - createTestClassWidgets(font, group, groupLayout.numColumns); - createSpacer(group); - createTestDirWidgets(font, group, groupLayout.numColumns); - } - private void createProjectWidgets(Font font, Composite comp) { - Label projectLabel = new Label(comp, SWT.NONE); - projectLabel.setText("Project to mutate: "); - GridData gd = new GridData(); - gd.horizontalSpan = 1; - projectLabel.setLayoutData(gd); - projectLabel.setFont(font); - - gd = new GridData(FILL_HORIZONTAL); - gd.horizontalSpan = NUMBER_OF_COLUMNS - 1; - projectText = new Text(comp, SWT.SINGLE | SWT.BORDER); - projectText.setLayoutData(gd); - projectText.addModifyListener(new UpdateOnModifyListener()); - } - - private void createTestClassWidgets(Font font, Composite comp, int columnsInParent) { - testClassRadioButton = createTestRadioButton(comp, - "Run mutations from a unit test"); - GridData testClassGrid = new GridData(FILL_HORIZONTAL); - testClassGrid.horizontalSpan = columnsInParent; - testClassRadioButton.setLayoutData(testClassGrid); - - Label testClassLabel = new Label(comp, SWT.NONE); - testClassLabel.setText("Test Class:"); - GridData labelGrid = new GridData(); - labelGrid.horizontalIndent = 25; - labelGrid.horizontalSpan = 1; - testClassLabel.setLayoutData(labelGrid); - testClassLabel.setFont(font); - - GridData textGrid = new GridData(FILL_HORIZONTAL); - textGrid.horizontalSpan = columnsInParent - 1; - textGrid.grabExcessHorizontalSpace = true; - testClassText = new Text(comp, SWT.SINGLE | SWT.BORDER); - testClassText.setLayoutData(textGrid); - testClassText.addModifyListener(new UpdateOnModifyListener()); - } - - private Button createTestRadioButton(Composite comp, String label) { - Button button = new Button(comp, SWT.RADIO); - button.setText(label); - button.addSelectionListener(new ButtonSelectionAdapter(button)); - return button; - } - - private void createTestDirWidgets(Font font, Composite comp, int columnsInParent) { - testDirectoryRadioButton = createTestRadioButton(comp, - "Run mutations against a package or directory"); - GridData testDirGrid = new GridData(FILL_HORIZONTAL); - testDirGrid.horizontalSpan = columnsInParent; - testDirectoryRadioButton.setLayoutData(testDirGrid); - - GridData labelGrid = new GridData(); - labelGrid.horizontalIndent = 25; - labelGrid.horizontalSpan = 1; - Label testDirectoryLabel = new Label(comp, SWT.NONE); - testDirectoryLabel.setText("Directory:"); - testDirectoryLabel.setLayoutData(labelGrid); - testDirectoryLabel.setFont(font); - - GridData textGrid = new GridData(FILL_HORIZONTAL); - textGrid.horizontalSpan = columnsInParent - 1; - testDirText = new Text(comp, SWT.SINGLE | SWT.BORDER); - testDirText.setLayoutData(textGrid); - testDirText.addModifyListener(new UpdateOnModifyListener()); - } + mutatorsTable.getTable().setEnabled(true); - private void createFilters(Font font, Composite comp) { - Group group = new Group(comp, SWT.NONE); - group.setText(" Filters "); - group.setFont(font); - GridData groupGrid = new GridData(FILL_HORIZONTAL); - groupGrid.horizontalSpan = NUMBER_OF_COLUMNS; - group.setLayoutData(groupGrid); - GridLayout groupLayout = new GridLayout(1, false); - group.setLayout(groupLayout); - - runInParallel = createNewCheckBox(font, group, groupLayout.numColumns, - MUTATION_TESTS_RUN_IN_PARALLEL); - incrementalAnalysis = createNewCheckBox(font, group, groupLayout.numColumns, - USE_INCREMENTAL_ANALYSIS); - } - - private void createPreferences(Font font, Composite comp) { - Group misc = new Group(comp, SWT.NONE); - misc.setText(" Preferences "); - misc.setFont(font); - GridData miscGrid = new GridData(FILL_HORIZONTAL); - miscGrid.horizontalSpan = NUMBER_OF_COLUMNS; - misc.setLayoutData(miscGrid); - GridLayout miscLayout = new GridLayout(2, false); - misc.setLayout(miscLayout); - - excludedClassesText = createTextPreference(font, misc, miscLayout.numColumns, - EXCLUDE_CLASSES_FROM_PIT); - excludedMethodsText = createTextPreference(font, misc, miscLayout.numColumns, - EXCLUDE_METHODS_FROM_PIT); - avoidCallsTo = createTextPreference(font, misc, miscLayout.numColumns, - AVOID_CALLS_FROM_PIT); + // Update the tab when a hook is activated / deactivated + mutatorsTable.addCheckStateListener(event -> updateLaunchConfigurationDialog()); } - private Text createTextPreference(Font font, Composite comp, int columnsInParent, String label) { - GridData labelGrid = new GridData(); - labelGrid.horizontalSpan = 1; - Label testDirectoryLabel = new Label(comp, SWT.NONE); - testDirectoryLabel.setText(label); - testDirectoryLabel.setLayoutData(labelGrid); - testDirectoryLabel.setFont(font); - - GridData textGrid = new GridData(FILL_HORIZONTAL); - textGrid.horizontalSpan = columnsInParent - 1; - Text textBox = new Text(comp, SWT.SINGLE | SWT.BORDER); - textBox.setLayoutData(textGrid); - textBox.addModifyListener(new UpdateOnModifyListener()); - return textBox; + private void disableTableIfUnused() { + mutatorsTable.getTable().setEnabled(customMutatorsButton.getSelection()); } - private Button createNewCheckBox(Font font, Composite comp, int columnsInParent, String label) { - Button checkBox = new Button(comp, SWT.CHECK); - checkBox.setText(label); - GridData labelGrid = new GridData(FILL_HORIZONTAL); - labelGrid.horizontalSpan = columnsInParent - 1; - checkBox.setLayoutData(labelGrid); - checkBox.setFont(font); - return checkBox; - } - protected static void addSeparator(Composite parent) { Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); GridDataFactory.fillDefaults().span(NUMBER_OF_COLUMNS, 1).applyTo(separator); } - public void performApply(ILaunchConfigurationWorkingCopy workingCopy) { - System.out.println("PitMutatorsTab.performApply()"); -// workingCopy.setAttribute(ATTR_PROJECT_NAME, projectText.getText() -// .trim()); -// if (testClassRadioButton.getSelection()) { -// workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, testClassText.getText().trim()); -// workingCopy.setAttribute(ATTR_TEST_CONTAINER, ""); -// } else { -// workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, ""); -// workingCopy.setAttribute(ATTR_TEST_CONTAINER, containerId); -// } -// workingCopy.setAttribute(ATTR_TEST_IN_PARALLEL, -// runInParallel.getSelection()); -// workingCopy.setAttribute(ATTR_TEST_INCREMENTALLY, -// incrementalAnalysis.getSelection()); -// workingCopy.setAttribute(ATTR_EXCLUDE_CLASSES, -// excludedClassesText.getText()); -// workingCopy.setAttribute(ATTR_EXCLUDE_METHODS, -// excludedMethodsText.getText()); -// workingCopy.setAttribute(ATTR_AVOID_CALLS_TO, avoidCallsTo.getText()); -// try { -// PitMigrationDelegate.mapResources(workingCopy); -// } catch (CoreException ce) { -// setErrorMessage(ce.getStatus().getMessage()); -// } + public void performApply(ILaunchConfigurationWorkingCopy config) { + config.setAttribute(PIT_MUTATORS, getMutators()); + try { + PitMigrationDelegate.mapResources(config); + } catch (CoreException ce) { + setErrorMessage(ce.getStatus().getMessage()); + } + } + + /** + * Returns the mutators as a String and if individual mutators are used, + * mutators are separated with commas + * @return mutators as string + */ + private String getMutators() { + if (isBasicMutatorGroup()) { + return mutators; + } + StringBuilder sb = new StringBuilder(); + Iterator iterator = Arrays.asList(mutatorsTable.getCheckedElements()).iterator(); + while (iterator.hasNext()) { + sb.append(((Mutators) iterator.next()).getId()); + if (iterator.hasNext()) { + sb.append(','); + } + } + return sb.toString(); } public void setDefaults(ILaunchConfigurationWorkingCopy workingCopy) { @@ -470,28 +276,6 @@ public void setDefaults(ILaunchConfigurationWorkingCopy workingCopy) { */ } - public String getAttributeFromConfig(ILaunchConfiguration config, - String attribute, String defaultValue) { - String result = defaultValue; - try { - result = config.getAttribute(attribute, defaultValue); - } catch (CoreException e) { - // Swallowed - } - return result; - } - - public boolean getBooleanAttributeFromConfig(ILaunchConfiguration config, - String attribute, boolean defaultValue) { - boolean result = defaultValue; - try { - result = config.getAttribute(attribute, defaultValue); - } catch (CoreException e) { - // Swallowed - } - return result; - } - private void createSpacer(Composite comp) { Label label = new Label(comp, SWT.NONE); GridData gd = new GridData(); @@ -499,31 +283,34 @@ private void createSpacer(Composite comp) { label.setLayoutData(gd); } - private void testModeChanged() { - boolean isSingleTestMode = testClassRadioButton.getSelection(); - testClassText.setEnabled(isSingleTestMode); - testDirText.setEnabled(!isSingleTestMode); - updateLaunchConfigurationDialog(); - } - - private class ButtonSelectionAdapter extends SelectionAdapter { - private final Button button; - - private ButtonSelectionAdapter(Button button) { - this.button = button; + /** + * Selects the button that conforms to the given value. + * @param selectedValue the selected value + * @param buttons array of buttons to select one + * @return true, if a button was selected + */ + private boolean updateSelectionOfGroup(String value) { + if (groupButtons == null || value == null) { + return false; } - - @Override - public void widgetSelected(SelectionEvent e) { - if (button.getSelection()) { - testModeChanged(); + boolean found = false; + for (Button button : groupButtons) { + boolean selection = false; + if (((String) button.getData()).equals(value)) { + selection = true; + found = true; } + button.setSelection(selection); } + + return found; } - private final class UpdateOnModifyListener implements ModifyListener { - public void modifyText(ModifyEvent evt) { - updateLaunchConfigurationDialog(); - } + /** + * @return true, if one of the groups from PIT is selected.
+ * false, if individual mutators are selected. + */ + private boolean isBasicMutatorGroup() { + return !customMutatorsButton.getSelection(); } } diff --git a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java index c944f538..0f39ea83 100644 --- a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java +++ b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java @@ -41,6 +41,7 @@ import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; +import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_MUTATORS; import static org.pitest.pitclipse.core.PitCoreActivator.getDefault; public class LaunchConfigurationWrapper { @@ -262,7 +263,13 @@ public List getMutatedProjects() throws CoreException { return projectFinder.getProjects(this); } - private List getMutators() { - return ImmutableList.of(pitConfiguration.getMutators()); + private List getMutators() throws CoreException { + final String mutators; + if (launchConfig.hasAttribute(PIT_MUTATORS)) { + mutators = launchConfig.getAttribute(PIT_MUTATORS, ""); + } else { + mutators = pitConfiguration.getMutators(); + } + return ImmutableList.of(mutators); } } diff --git a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java index 57da7c4d..bc4985ad 100644 --- a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java +++ b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java @@ -120,7 +120,6 @@ public Builder withTimeout(int timeout) { this.timeout = timeout; return this; } - public PitConfiguration build() { return new PitConfiguration(executionMode, parallelExecution, incrementalAnalysis, excludedClasses, excludedMethods, avoidCallsTo, mutators, timeout, timeoutFactor); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java index a72a2c44..1fe00ebe 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java @@ -21,7 +21,6 @@ import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.core.MutatorGroups; import org.pitest.pitclipse.runner.config.PitExecutionMode; From f687a7f3ca9ba5c61a39e4afbfea7e23cbb59c5c Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Wed, 21 Jul 2021 17:03:09 +0200 Subject: [PATCH 11/50] Unified Strings of preference page We used almost the same Strings in the tests as in the creation of the preferences itself. Now all are using the same Strings. Show always the Package Explorer when selecting something to be sure. (Sped up the tests locally for me a lot.) --- .../pitclipse/core/PitCoreActivator.java | 22 ++++----- .../core/preferences/PitPreferences.java | 38 +++++++++------ .../preferences/PreferenceInitializer.java | 8 ++-- .../pitclipse/launch/ui/PitArgumentsTab.java | 20 ++++---- .../pitclipse/launch/ui/PitMutatorsTab.java | 6 +-- .../config/LaunchConfigurationWrapper.java | 6 +-- .../ui/PitMutatorsPreferencePage.java | 8 ++-- .../preferences/ui/PitPreferencePage.java | 34 ++++---------- .../pageobjects/PackageExplorer.java | 1 + .../pageobjects/PitPreferenceSelector.java | 46 +++++++++---------- .../pageobjects/RunConfigurationSelector.java | 10 ++-- .../tests/PitclipseMultipleProjectsTest.java | 2 +- .../ui/tests/PitclipseOptionsTest.java | 4 +- 13 files changed, 103 insertions(+), 102 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index d0317608..8c65e21f 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -37,12 +37,12 @@ import static com.google.common.io.Files.createParentDirs; import static com.google.common.io.Files.createTempDir; import static org.eclipse.core.runtime.FileLocator.getBundleFile; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS; import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_EXECUTION_MODE; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_SCOPE; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_FACTOR; @@ -259,13 +259,13 @@ public File getHistoryFile() { public PitConfiguration getConfiguration() { IPreferenceStore preferenceStore = getPreferenceStore(); - String executionMode = preferenceStore.getString(PIT_EXECUTION_MODE); - String mutators = preferenceStore.getString(PIT_MUTATORS); + String executionMode = preferenceStore.getString(EXECUTION_SCOPE); + String mutators = preferenceStore.getString(MUTATORS); boolean parallelRun = preferenceStore.getBoolean(RUN_IN_PARALLEL); boolean incrementalAnalysis = preferenceStore.getBoolean(INCREMENTAL_ANALYSIS); String excludedClasses = preferenceStore.getString(EXCLUDED_CLASSES); - String excludedMethods = preferenceStore.getString(EXCLUDED_METHODS); - String avoidCallsTo = preferenceStore.getString(AVOID_CALLS_TO); + String excludedMethods = preferenceStore.getString(EXCLUDE_METHODS); + String avoidCallsTo = preferenceStore.getString(AVOID_CALLS); String timeout = preferenceStore.getString(TIMEOUT); String timeoutFactor = preferenceStore.getString(TIMEOUT_FACTOR); PitConfiguration.Builder builder = PitConfiguration.builder().withParallelExecution(parallelRun) @@ -294,14 +294,14 @@ public PitConfiguration getConfiguration() { } public void setExecutionMode(PitExecutionMode pitExecutionMode) { - getPreferenceStore().setValue(PIT_EXECUTION_MODE, pitExecutionMode.getId()); + getPreferenceStore().setValue(EXECUTION_SCOPE, pitExecutionMode.getId()); } public void setMutators(MutatorGroups mutators) { - getPreferenceStore().setValue(PIT_MUTATORS, mutators.getId()); + getPreferenceStore().setValue(MUTATORS, mutators.getId()); } public String getDefaultMutators() { - return getPreferenceStore().getString(PIT_MUTATORS); + return getPreferenceStore().getString(MUTATORS); } } diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java index 355856a8..8b6bc4e6 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java @@ -20,25 +20,37 @@ * Constants used to deal with Pitclipse's preferences. */ public final class PitPreferences { + public static final String MUTATORS_LABEL = "Mutators"; + public static final String MUTATORS = "pitMutators"; - public static final String PIT_MUTATORS = "pitMutators"; - - public static final String USE_INCREMENTAL_ANALYSIS = "Use &incremental analysis"; - public static final String EXCLUDE_CLASSES_FROM_PIT = "E&xcluded classes (e.g.*IntTest)"; - public static final String MUTATION_TESTS_RUN_IN_PARALLEL = "Mutation tests run in para&llel"; - public static final String EXCLUDE_METHODS_FROM_PIT = "Excluded &methods (e.g.*toString*)"; - public static final String AVOID_CALLS_FROM_PIT = "&Avoid calls to"; - public static final String PIT_TIMEOUT = "Pit Ti&meout"; - public static final String PIT_TIMEOUT_FACTOR = "Timeout &Factor"; - public static final String EXCLUDED_METHODS = "excludedMethods"; - public static final String AVOID_CALLS_TO = "avoidCallsTo"; - public static final String EXCLUDED_CLASSES = "excludedClasses"; + public static final String INCREMENTAL_ANALYSIS_LABEL = "Use &incremental analysis"; public static final String INCREMENTAL_ANALYSIS = "incrementalAnalysis"; - public static final String PIT_EXECUTION_MODE = "pitExecutionMode"; + + public static final String EXCLUDE_CLASSES_LABEL = "E&xcluded classes (e.g.*IntTest)"; + public static final String EXCLUDED_CLASSES = "excludedClasses"; + + public static final String RUN_IN_PARALLEL_LABEL = "Mutation tests run in para&llel"; public static final String RUN_IN_PARALLEL = "runInParallel"; + + public static final String EXCLUDE_METHODS_LABEL = "Excluded &methods (e.g.*toString*)"; + public static final String EXCLUDE_METHODS = "excludedMethods"; + + public static final String AVOID_CALLS_LABEL = "&Avoid calls to"; + public static final String AVOID_CALLS = "avoidCallsTo"; + + public static final String TIMEOUT_LABEL = "Pit Ti&meout"; public static final String TIMEOUT = "pitTimeout"; + + public static final String TIMEOUT_FACTOR_LABEL = "Timeout &Factor"; public static final String TIMEOUT_FACTOR = "pitTimeoutFactor"; + + public static final String EXECUTION_SCOPE_LABEL = "Pit execution scope"; + public static final String EXECUTION_SCOPE = "pitExecutionMode"; + + public static final String PREFERENCE_DESCRIPTION_LABEL = "Pitclipse Preferences"; + public static final String MUTATORS_DESCRIPTION_LABEL = "Mutator Preferences"; + private PitPreferences() { // utility class should not be instantiated } diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java index 8681404d..2fed62e9 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java @@ -21,10 +21,10 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES; import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_EXECUTION_MODE; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_SCOPE; import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_FACTOR; @@ -47,10 +47,10 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer { @Override public void initializeDefaultPreferences() { IPreferenceStore store = PitCoreActivator.getDefault().getPreferenceStore(); - store.setDefault(PIT_EXECUTION_MODE, "containingProject"); + store.setDefault(EXECUTION_SCOPE, "containingProject"); store.setDefault(RUN_IN_PARALLEL, true); store.setDefault(INCREMENTAL_ANALYSIS, false); - store.setDefault(AVOID_CALLS_TO, DEFAULT_AVOID_CALLS_TO_LIST); + store.setDefault(AVOID_CALLS, DEFAULT_AVOID_CALLS_TO_LIST); store.setDefault(DEFAULT_MUTATORS, "defaultMutators"); store.setDefault(TIMEOUT, DEFAULT_TIMEOUT); store.setDefault(TIMEOUT_FACTOR, DEFAULT_TIMEOUT_FACTOR.toString()); diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index 98d9a7fc..37e39511 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -50,11 +50,11 @@ import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATION_TESTS_RUN_IN_PARALLEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.USE_INCREMENTAL_ANALYSIS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS_LABEL; import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; @@ -257,9 +257,9 @@ private void createFilters(Font font, Composite comp) { group.setLayout(groupLayout); runInParallel = createNewCheckBox(font, group, groupLayout.numColumns, - MUTATION_TESTS_RUN_IN_PARALLEL); + RUN_IN_PARALLEL_LABEL); incrementalAnalysis = createNewCheckBox(font, group, groupLayout.numColumns, - USE_INCREMENTAL_ANALYSIS); + INCREMENTAL_ANALYSIS_LABEL); } private void createPreferences(Font font, Composite comp) { @@ -273,11 +273,11 @@ private void createPreferences(Font font, Composite comp) { misc.setLayout(miscLayout); excludedClassesText = createTextPreference(font, misc, miscLayout.numColumns, - EXCLUDE_CLASSES_FROM_PIT); + EXCLUDE_CLASSES_LABEL); excludedMethodsText = createTextPreference(font, misc, miscLayout.numColumns, - EXCLUDE_METHODS_FROM_PIT); + EXCLUDE_METHODS_LABEL); avoidCallsTo = createTextPreference(font, misc, miscLayout.numColumns, - AVOID_CALLS_FROM_PIT); + AVOID_CALLS_LABEL); } private Text createTextPreference(Font font, Composite comp, int columnsInParent, String label) { diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 20b957dc..44f513e6 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -51,7 +51,7 @@ import java.util.Arrays; import java.util.Iterator; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; /** @@ -97,7 +97,7 @@ public void dispose() { public void initializeFrom(ILaunchConfiguration config) { PitConfiguration preferences = PitCoreActivator.getDefault().getConfiguration(); - mutators = PitArgumentsTab.getAttributeFromConfig(config, PIT_MUTATORS, preferences.getMutators()); + mutators = PitArgumentsTab.getAttributeFromConfig(config, MUTATORS, preferences.getMutators()); System.out.println(mutators); if (!updateSelectionOfGroup(mutators)) { // no selection was made, because no match of data @@ -239,7 +239,7 @@ protected static void addSeparator(Composite parent) { } public void performApply(ILaunchConfigurationWorkingCopy config) { - config.setAttribute(PIT_MUTATORS, getMutators()); + config.setAttribute(MUTATORS, getMutators()); try { PitMigrationDelegate.mapResources(config); } catch (CoreException ce) { diff --git a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java index 0f39ea83..520eed10 100644 --- a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java +++ b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java @@ -41,7 +41,7 @@ import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; import static org.pitest.pitclipse.core.PitCoreActivator.getDefault; public class LaunchConfigurationWrapper { @@ -265,8 +265,8 @@ public List getMutatedProjects() throws CoreException { private List getMutators() throws CoreException { final String mutators; - if (launchConfig.hasAttribute(PIT_MUTATORS)) { - mutators = launchConfig.getAttribute(PIT_MUTATORS, ""); + if (launchConfig.hasAttribute(MUTATORS)) { + mutators = launchConfig.getAttribute(MUTATORS, ""); } else { mutators = pitConfiguration.getMutators(); } diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java index 1341c0b2..3bce0554 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java @@ -23,14 +23,16 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.core.MutatorGroups; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_DESCRIPTION_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; public class PitMutatorsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { public PitMutatorsPreferencePage() { super(GRID); setPreferenceStore(PitCoreActivator.getDefault().getPreferenceStore()); - setDescription("Mutator Preferences"); + setDescription(MUTATORS_DESCRIPTION_LABEL); } @Override @@ -44,7 +46,7 @@ private void createExecutionModeRadioButtons() { for (int i = 0; i < values.length; i++) { mutatorValues[i] = new String[] { values[i].getLabel(), values[i].getId() }; } - addField(new RadioGroupFieldEditor(PIT_MUTATORS, "Mutators", 1, mutatorValues, getFieldEditorParent())); + addField(new RadioGroupFieldEditor(MUTATORS, MUTATORS_LABEL, 1, mutatorValues, getFieldEditorParent())); } @Override diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java index 28ea1f09..82bbfc70 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java @@ -25,21 +25,7 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitExecutionMode; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_FROM_PIT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATION_TESTS_RUN_IN_PARALLEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_EXECUTION_MODE; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_TIMEOUT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.PIT_TIMEOUT_FACTOR; -import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT; -import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_FACTOR; -import static org.pitest.pitclipse.core.preferences.PitPreferences.USE_INCREMENTAL_ANALYSIS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.*; import static org.pitest.pitclipse.runner.config.PitExecutionMode.values; /** @@ -58,7 +44,7 @@ public class PitPreferencePage extends FieldEditorPreferencePage implements IWor public PitPreferencePage() { super(GRID); setPreferenceStore(PitCoreActivator.getDefault().getPreferenceStore()); - setDescription("Pitclipse Preferences"); + setDescription(PREFERENCE_DESCRIPTION_LABEL); } /** @@ -79,31 +65,31 @@ public void createFieldEditors() { } private void createAvoidCallsToField() { - addField(new StringFieldEditor(AVOID_CALLS_TO, AVOID_CALLS_FROM_PIT, getFieldEditorParent())); + addField(new StringFieldEditor(AVOID_CALLS, AVOID_CALLS_LABEL, getFieldEditorParent())); } private void createExcludeClassesField() { - addField(new StringFieldEditor(EXCLUDED_CLASSES, EXCLUDE_CLASSES_FROM_PIT, getFieldEditorParent())); + addField(new StringFieldEditor(EXCLUDED_CLASSES, EXCLUDE_CLASSES_LABEL, getFieldEditorParent())); } private void createExcludeMethodsField() { - addField(new StringFieldEditor(EXCLUDED_METHODS, EXCLUDE_METHODS_FROM_PIT, getFieldEditorParent())); + addField(new StringFieldEditor(EXCLUDE_METHODS, EXCLUDE_METHODS_LABEL, getFieldEditorParent())); } private void createUseIncrementalAnalysisOption() { - addField(new BooleanFieldEditor(INCREMENTAL_ANALYSIS, USE_INCREMENTAL_ANALYSIS, getFieldEditorParent())); + addField(new BooleanFieldEditor(INCREMENTAL_ANALYSIS, INCREMENTAL_ANALYSIS_LABEL, getFieldEditorParent())); } private void createRunInParallelOption() { - addField(new BooleanFieldEditor(RUN_IN_PARALLEL, MUTATION_TESTS_RUN_IN_PARALLEL, getFieldEditorParent())); + addField(new BooleanFieldEditor(RUN_IN_PARALLEL, RUN_IN_PARALLEL_LABEL, getFieldEditorParent())); } private void createPitTimeoutField() { - addField(new StringFieldEditor(TIMEOUT, PIT_TIMEOUT, getFieldEditorParent())); + addField(new StringFieldEditor(TIMEOUT, TIMEOUT_LABEL, getFieldEditorParent())); } private void createPitTimeoutFactorField() { - addField(new StringFieldEditor(TIMEOUT_FACTOR, PIT_TIMEOUT_FACTOR, getFieldEditorParent())); + addField(new StringFieldEditor(TIMEOUT_FACTOR, TIMEOUT_FACTOR_LABEL, getFieldEditorParent())); } private void createExecutionModeRadioButtons() { @@ -112,7 +98,7 @@ private void createExecutionModeRadioButtons() { for (int i = 0; i < values.length; i++) { executionModeValues[i] = new String[] { values[i].getLabel(), values[i].getId() }; } - addField(new RadioGroupFieldEditor(PIT_EXECUTION_MODE, "Pit execution scope", 1, executionModeValues, getFieldEditorParent())); + addField(new RadioGroupFieldEditor(EXECUTION_SCOPE, EXECUTION_SCOPE_LABEL, 1, executionModeValues, getFieldEditorParent())); } /* diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java index 3585c4eb..794bbd2d 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java @@ -57,6 +57,7 @@ private void openProject(SWTBotTreeItem project) { } private SWTBotTreeItem getProject(String projectName) { + bot.viewByTitle(PACKAGE_EXPLORER).show(); SWTBotTreeItem[] treeItems = bot.viewByTitle(PACKAGE_EXPLORER).bot().tree().getAllItems(); for (SWTBotTreeItem treeItem : treeItems) { if (projectName.equals(treeItem.getText())) { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java index 1fe00ebe..bd9644a7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java @@ -28,19 +28,19 @@ import java.math.BigDecimal; import static java.math.BigDecimal.ZERO; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_SCOPE_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_FACTOR_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS_LABEL; import static org.pitest.pitclipse.ui.behaviours.pageobjects.SwtBotTreeHelper.selectAndExpand; public class PitPreferenceSelector implements Closeable { - private static final String USE_INCREMENTAL_ANALYSIS_LABEL = "Use incremental analysis"; - private static final String MUTATION_TESTS_RUN_IN_PARALLEL_LABEL = "Mutation tests run in parallel"; - private static final String EXCLUDED_CLASSES_LABEL = "Excluded classes (e.g.*IntTest)"; - private static final String EXCLUDED_METHODS_LABEL = "Excluded methods (e.g.*toString*)"; - private static final String AVOID_CALLS_TO_LABEL = "Avoid calls to"; private static final String MUTATORS_LABEL = "Mutators"; - private static final String EXECUTION_MODE_LABEL = "Pit Execution Scope"; - private static final String PIT_TIMEOUT_LABEL = "Pit Timeout"; - private static final String PIT_TIMEOUT_FACTOR_LABEL = "Timeout Factor"; private final SWTWorkbenchBot bot; public PitPreferenceSelector(SWTWorkbenchBot bot) { @@ -72,7 +72,7 @@ private void activatePreferenceShell() { } public PitExecutionMode getPitExecutionMode() { - return getSelectedExecutionMode().from(EXECUTION_MODE_LABEL); + return getSelectedExecutionMode().from(EXECUTION_SCOPE_LABEL); } private PitExecutionMode getActiveExecutionMode() { @@ -85,43 +85,43 @@ private PitExecutionMode getActiveExecutionMode() { } public boolean isPitRunInParallel() { - return getBoolean().from(MUTATION_TESTS_RUN_IN_PARALLEL_LABEL); + return getBoolean().from(RUN_IN_PARALLEL_LABEL); } public boolean isIncrementalAnalysisEnabled() { - return getBoolean().from(USE_INCREMENTAL_ANALYSIS_LABEL); + return getBoolean().from(INCREMENTAL_ANALYSIS_LABEL); } public void setPitRunInParallel(boolean inParallel) { - setSelectionFor(MUTATION_TESTS_RUN_IN_PARALLEL_LABEL).to(inParallel); + setSelectionFor(RUN_IN_PARALLEL_LABEL).to(inParallel); } public void setPitIncrementalAnalysisEnabled(boolean incremental) { - setSelectionFor(USE_INCREMENTAL_ANALYSIS_LABEL).to(incremental); + setSelectionFor(INCREMENTAL_ANALYSIS_LABEL).to(incremental); } public String getExcludedClasses() { - return getText().from(EXCLUDED_CLASSES_LABEL); + return getText().from(EXCLUDE_CLASSES_LABEL); } public void setExcludedClasses(String excludedClasses) { - setTextFor(EXCLUDED_CLASSES_LABEL).to(excludedClasses); + setTextFor(EXCLUDE_CLASSES_LABEL).to(excludedClasses); } public String getExcludedMethods() { - return getText().from(EXCLUDED_METHODS_LABEL); + return getText().from(EXCLUDE_METHODS_LABEL); } public void setExcludedMethods(String excludedMethods) { - setTextFor(EXCLUDED_METHODS_LABEL).to(excludedMethods); + setTextFor(EXCLUDE_METHODS_LABEL).to(excludedMethods); } public String getAvoidCallsTo() { - return getText().from(AVOID_CALLS_TO_LABEL); + return getText().from(AVOID_CALLS_LABEL); } public void setAvoidCallsTo(String avoidCallsTo) { - setTextFor(AVOID_CALLS_TO_LABEL).to(avoidCallsTo); + setTextFor(AVOID_CALLS_LABEL).to(avoidCallsTo); } public MutatorGroups getMutators() { @@ -139,11 +139,11 @@ private Optional expandPitMutatorPreferences() { } public void setPitTimeoutConst(int timeout) { - setTextFor(PIT_TIMEOUT_LABEL).to(timeout); + setTextFor(TIMEOUT_LABEL).to(timeout); } public void setPitTimeoutFactor(int factor) { - setTextFor(PIT_TIMEOUT_FACTOR_LABEL).to(factor); + setTextFor(TIMEOUT_FACTOR_LABEL).to(factor); } private static interface PreferenceGetter { @@ -288,10 +288,10 @@ public PitExecutionMode getPreference(String label) { } public int getTimeout() { - return getInteger().from(PIT_TIMEOUT_LABEL); + return getInteger().from(TIMEOUT_LABEL); } public BigDecimal getPitTimeoutFactor() { - return getBigDecimal().from(PIT_TIMEOUT_FACTOR_LABEL); + return getBigDecimal().from(TIMEOUT_FACTOR_LABEL); } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index b543ee32..f672420c 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -62,11 +62,11 @@ public List getConfigurations() { private PitRunConfiguration getPitConfiguration(SWTBotTreeItem treeItem) { String name = treeItem.getText(); String project = bot.textWithLabel(PitArgumentsTab.PROJECT_TEXT).getText(); - boolean runInParallel = bot.checkBox(PitPreferences.MUTATION_TESTS_RUN_IN_PARALLEL).isChecked(); - boolean incrementalAnalysis = bot.checkBox(PitPreferences.USE_INCREMENTAL_ANALYSIS).isChecked(); - String excludedClasses = bot.textWithLabel(PitPreferences.EXCLUDE_CLASSES_FROM_PIT).getText(); - String excludedMethods = bot.textWithLabel(PitPreferences.EXCLUDE_METHODS_FROM_PIT).getText(); - String avoidCallsTo = bot.textWithLabel(PitPreferences.AVOID_CALLS_FROM_PIT).getText(); + boolean runInParallel = bot.checkBox(PitPreferences.RUN_IN_PARALLEL_LABEL).isChecked(); + boolean incrementalAnalysis = bot.checkBox(PitPreferences.INCREMENTAL_ANALYSIS_LABEL).isChecked(); + String excludedClasses = bot.textWithLabel(PitPreferences.EXCLUDE_CLASSES_LABEL).getText(); + String excludedMethods = bot.textWithLabel(PitPreferences.EXCLUDE_METHODS_LABEL).getText(); + String avoidCallsTo = bot.textWithLabel(PitPreferences.AVOID_CALLS_LABEL).getText(); return new Builder().withName(name).withProjects(project).withRunInParallel(runInParallel) .withIncrementalAnalysis(incrementalAnalysis).withExcludedClasses(excludedClasses) .withExcludedMethods(excludedMethods).withAvoidCallsTo(avoidCallsTo).build(); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseMultipleProjectsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseMultipleProjectsTest.java index 4d7f2f28..13d97060 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseMultipleProjectsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseMultipleProjectsTest.java @@ -83,7 +83,7 @@ public void testExecutionMode() throws CoreException { } finally { // reset default values IPreferenceStore preferenceStore = PitCoreActivator.getDefault().getPreferenceStore(); - preferenceStore.setValue(PitPreferences.PIT_EXECUTION_MODE, PROJECT_ISOLATION.toString()); + preferenceStore.setValue(PitPreferences.EXECUTION_SCOPE, PROJECT_ISOLATION.toString()); PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen(); assertEquals(PROJECT_ISOLATION, selector.getPitExecutionMode()); selector.close(); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index c5229ec5..4188382d 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -153,8 +153,8 @@ public void launchConfigurationsWithChangedValues() throws CoreException { preferenceStore.setValue(PitPreferences.RUN_IN_PARALLEL, true); preferenceStore.setValue(PitPreferences.INCREMENTAL_ANALYSIS, false); preferenceStore.setValue(PitPreferences.EXCLUDED_CLASSES, PitConfiguration.DEFAULT_EXCLUDED_CLASSES); - preferenceStore.setValue(PitPreferences.AVOID_CALLS_TO, PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST); - preferenceStore.setValue(PitPreferences.EXCLUDED_METHODS, ""); + preferenceStore.setValue(PitPreferences.AVOID_CALLS, PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST); + preferenceStore.setValue(PitPreferences.EXCLUDE_METHODS, ""); } } From 87a67a3b1def812fdc9415109171a00afb8470c6 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Thu, 22 Jul 2021 14:43:54 +0200 Subject: [PATCH 12/50] First working prototype for a mutator tab * combined MutatorGroups and Mutators, because they are basically the same and pit handles it similar * using reflection to get all ids of the mutators from pit --- .../pitest/pitclipse/core/MutatorGroups.java | 46 ------- .../org/pitest/pitclipse/core/Mutators.java | 120 +++++++++++------ .../pitclipse/core/PitCoreActivator.java | 8 +- .../core/preferences/PitPreferences.java | 2 + .../pitclipse/launch/ui/PitMutatorsTab.java | 124 +++++++++++++----- .../ui/PitMutatorsPreferencePage.java | 6 +- .../pageobjects/PitPreferenceSelector.java | 16 +-- .../behaviours/pageobjects/WindowsMenu.java | 6 +- .../ui/behaviours/steps/PreferencesSteps.java | 10 +- .../ui/tests/PitclipseOptionsTest.java | 6 +- 10 files changed, 192 insertions(+), 152 deletions(-) delete mode 100644 bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java deleted file mode 100644 index 794d452c..00000000 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/MutatorGroups.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright 2012-2019 Phil Glover and contributors - * - * 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.pitest.pitclipse.core; - -public enum MutatorGroups { - OLDDEFAULTS("OLD_DEFAULTS", "&Old default Mutators", ""), - DEFAULTS("DEFAULTS", "&Default Mutators", ""), - STRONGER("STRONGER", "&Stronger Mutators", ""), - ALL("ALL", "&All Mutators", ""); - - private final String label; - private final String id; - private final String description; - - private MutatorGroups(String id, String label, String description) { - this.id = id; - this.label = label; - this.description = description; - } - - public String getLabel() { - return label; - } - - public String getId() { - return id; - } - - public String getDescription() { - return description; - } -} diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java index d5e98618..e64f7c24 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java @@ -1,60 +1,91 @@ +/******************************************************************************* + * Copyright 2012-2021 Phil Glover and contributors + * + * 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.pitest.pitclipse.core; +import org.pitest.mutationtest.engine.gregor.config.Mutator; + +/** + * Enum which holds information about the mutators of pit.
+ * The name of new values must be the exact String, + * which is used by PIT in the class {@link Mutator}. + */ @SuppressWarnings("checkstyle:LineLength") public enum Mutators { - - CONDITIONALS_BOUNDARY("CONDITIONALS_BOUNDARY", "Conditionals Boundary", "Replaces the relational operators <, <=, >, >=", true), - INCREMENTS("INCREMENTS", "Increments", "Mutates increments, decrements and assignment increments and decrements of local variables (stack variables). Replaces increments with decrements and vice versa", true), - INVERT_NEGS("INVERT_NEGS", "Invert Negatives", "Inverts negation of integer and floating point numbers", true), - MATH("MATH", "Math", "Replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation", true), - NEGATE_CONDITIONALS("NEGATE_CONDITIONALS", "Negate Conditionals", "Mutates all conditionals found", true), - RETURN_VALS("RETURN_VALS", "Return Values", "Mutates the return values of method calls. Depending on the return type of the method another mutation is used", true), - VOID_METHOD_CALLS("VOID_METHOD_CALLS", "Void Method Call", "Removes method calls to void methods", true), - CONSTRUCTOR_CALLS("CONSTRUCTOR_CALLS", "Constructor Call", "Replaces constructor calls with null values", false), - EMPTY_RETURNS("EMPTY_RETURNS", "Empty Returns", "Replaces return values with an 'empty' value", false), - FALSE_RETURNS("FALSE_RETURNS", "False Returns", "Replaces primitive and boxed boolean return values with false", false), - INLINE_CONSTS("INLINE_CONSTS", "Inline Constant", "Mutates inline constants. An inline constant is a literal value assigned to a non-final variable", false), - NULL_RETURNS("NULL_RETURNS", "Null Returns", "Replaces return values with null. Method that can be mutated by the EMPTY_RETURNS mutator or that are directly annotated with NotNull are not mutated", false), - NON_VOID_METHOD_CALLS("NON_VOID_METHOD_CALLS", "Non Void Method Call", "Removes method calls to non void methods. Their return value is replaced by the Java Default Value for that specific type", false), - PRIMITIVE_RETURNS("PRIMITIVE_RETURNS", "Primite Returns", "Replaces int, short, long, char, float and double return values with 0", false), - REMOVE_CONDITIONALS("REMOVE_CONDITIONALS", "Remove Conditionals", "Removes all conditionals statements such that the guarded statements always execute", false), - REMOVE_INCREMENTS("REMOVE_INCREMENTS", "Remove Increments", "Removes local variable increments", false), - TRUE_RETURNS("TRUE_RETURNS", "True Returns", "Replaces primitive and boxed boolean return values with true", false), - EXPERIMENTAL_ARGUMENT_PROPAGATION("EXPERIMENTAL_ARGUMENT_PROPAGATION", "Experimentation Argument Propagation", "Replaces method call with one of its parameters of matching type", false), - EXPERIMENTAL_BIG_INTEGER("EXPERIMENTAL_BIG_INTEGER", "Experimental Big Integer", "Swaps big integer methods", false), - EXPERIMENTAL_NAKED_RECEIVER("EXPERIMENTAL_NAKED_RECEIVER", "Experimental Naked Receiver", "Replaces method call with a naked receiver", false), - EXPERIMENTAL_MEMBER_VARIABLE("EXPERIMENTAL_MEMBER_VARIABLE", "Experimental Member Variable", "Removes assignments to member variables. Can even remove assignments to final members. The members will be initialized with their Java Default Value", false), - EXPERIMENTAL_SWITCH_MUTATOR("EXPERIMENTAL_SWITCH", "Experimental Switch", "Finds the first label within a switch statement that differs from the default label. Mutates the switch statement by replacing the default label (wherever it is used) with this label. ALl the other labels are replaced by the default one", false), - ABS("ABS", "Negation", "Replaces any use of a numeric variable (local variable, field, array cell) with its negation", false), - AOR("AOR", "Arithmetic Operator Replacement", "Like the Math mutator, replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation", false), - AOD("AOD", "Arithmetic Operator Deletion", "Replaces an arithmetic operation with one of its members", false), - CRCR("CRCR", "Constant Replacement", "Like the Inline Constant mutator, mutates inline constant", false), - OBBN("OBBN", "Bitwise Operator", "Mutates bitwise and (&) and or (|)", false), - ROR("ROR", "Relational Operator Replacement", "Replaces a relational operator with another one", false), - UOI("UOI", "Unary Operator Insertion", "Inserts a unary operator (increment or decrement) to a variable call. Affects local variables, array variables, fields and parameters", false); - - private final String id; - - private final String name; + OLD_DEFAULTS("Old defaults", "&Old default Mutators"), + DEFAULTS("Defaults", "&Default Mutators"), + STRONGER("Stronger defaults", "&Stronger Mutators"), + ALL("All", "&All Mutators"), + CONDITIONALS_BOUNDARY("Conditionals Boundary", "Replaces the relational operators <, <=, >, >=", true), + INCREMENTS("Increments", "Mutates increments, decrements and assignment increments and decrements of local variables (stack variables). Replaces increments with decrements and vice versa", true), + INVERT_NEGS("Invert Negatives", "Inverts negation of integer and floating point numbers", true), + MATH("Math", "Replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation", true), + NEGATE_CONDITIONALS("Negate Conditionals", "Mutates all conditionals found", true), + RETURN_VALS("Return Values", "Mutates the return values of method calls. Depending on the return type of the method another mutation is used", true), + VOID_METHOD_CALLS("Void Method Call", "Removes method calls to void methods", true), + CONSTRUCTOR_CALLS("Constructor Call", "Replaces constructor calls with null values"), + EMPTY_RETURNS("Empty Returns", "Replaces return values with an 'empty' value"), + FALSE_RETURNS("False Returns", "Replaces primitive and boxed boolean return values with false"), + TRUE_RETURNS("True Returns", "Replaces primitive and boxed boolean return values with true"), + INLINE_CONSTS("Inline Constant", "Mutates inline constants. An inline constant is a literal value assigned to a non-final variable"), + NULL_RETURNS("Null Returns", "Replaces return values with null. Method that can be mutated by the EMPTY_RETURNS mutator or that are directly annotated with NotNull are not mutated"), + NON_VOID_METHOD_CALLS("Non Void Method Call", "Removes method calls to non void methods. Their return value is replaced by the Java Default Value for that specific type"), + PRIMITIVE_RETURNS("Primite Returns", "Replaces int, short, long, char, float and double return values with 0"), + REMOVE_CONDITIONALS("Remove Conditionals", "Removes all conditionals statements such that the guarded statements always execute"), + REMOVE_INCREMENTS("Remove Increments", "Removes local variable increments"), + EXPERIMENTAL_ARGUMENT_PROPAGATION("Experimentation Argument Propagation", "Replaces method call with one of its parameters of matching type"), + EXPERIMENTAL_BIG_INTEGER("Experimental Big Integer", "Swaps big integer methods"), + EXPERIMENTAL_NAKED_RECEIVER("Experimental Naked Receiver", "Replaces method call with a naked receiver"), + EXPERIMENTAL_MEMBER_VARIABLE("Experimental Member Variable", "Removes assignments to member variables. Can even remove assignments to final members. The members will be initialized with their Java Default Value"), + EXPERIMENTAL_SWITCH("Experimental Switch", "Finds the first label within a switch statement that differs from the default label. Mutates the switch statement by replacing the default label (wherever it is used) with this label. ALl the other labels are replaced by the default one"), + ABS("Negation", "Replaces any use of a numeric variable (local variable, field, array cell) with its negation"), + AOR("Arithmetic Operator Replacement", "Like the Math mutator, replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation"), + AOD("Arithmetic Operator Deletion", "Replaces an arithmetic operation with one of its members"), + CRCR("Constant Replacement", "Like the Inline Constant mutator, mutates inline constant"), + OBBN("Bitwise Operator", "Mutates bitwise and (&) and or (|)"), + ROR("Relational Operator Replacement", "Replaces a relational operator with another one"), + UOI("Unary Operator Insertion", "Inserts a unary operator (increment or decrement) to a variable call. Affects local variables, array variables, fields and parameters"); + /** + * Descriptor which is used to display the name of this mutator in a table + */ + private final String descriptor; + /** + * Description of this mutator + */ private final String description; - + /** + * true, if this mutator is contained in the DEFAULTS group of PIT + */ private final boolean activeByDefault; - private Mutators(String id, String name, String description, boolean activeByDefault) { - this.id = id; - this.name = name; + private Mutators(String descriptor, String description) { + this(descriptor, description, false); + } + + private Mutators(String descriptor, String description, boolean activeByDefault) { + this.descriptor = descriptor; this.description = description; this.activeByDefault = activeByDefault; } - public String getId() { - return id; + public String getDescriptor() { + return descriptor; } - public String getName() { - return name; - } public String getDescription() { return description; @@ -64,4 +95,7 @@ public boolean isActiveByDefault() { return activeByDefault; } + public static Mutators[] getMainGroup() { + return new Mutators[] {DEFAULTS,STRONGER,ALL}; + } } diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index 8c65e21f..3c090e4f 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -284,8 +284,8 @@ public PitConfiguration getConfiguration() { break; } } - for (MutatorGroups mutatorMode : MutatorGroups.values()) { - if (mutatorMode.getId().equals(mutators)) { + for (Mutators mutatorMode : Mutators.values()) { + if (mutatorMode.name().equals(mutators)) { builder.withMutators(mutatorMode.toString()); break; } @@ -297,8 +297,8 @@ public void setExecutionMode(PitExecutionMode pitExecutionMode) { getPreferenceStore().setValue(EXECUTION_SCOPE, pitExecutionMode.getId()); } - public void setMutators(MutatorGroups mutators) { - getPreferenceStore().setValue(MUTATORS, mutators.getId()); + public void setMutators(Mutators mutators) { + getPreferenceStore().setValue(MUTATORS, mutators.name()); } public String getDefaultMutators() { diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java index 8b6bc4e6..f8937adb 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java @@ -22,6 +22,8 @@ public final class PitPreferences { public static final String MUTATORS_LABEL = "Mutators"; public static final String MUTATORS = "pitMutators"; + + public static final String INDIVIDUAL_MUTATORS = "pitIndividualMutators"; public static final String INCREMENTAL_ANALYSIS_LABEL = "Use &incremental analysis"; public static final String INCREMENTAL_ANALYSIS = "incrementalAnalysis"; diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 44f513e6..766d94ec 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -27,30 +27,36 @@ import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CellLabelProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; import org.osgi.framework.Bundle; -import org.pitest.pitclipse.core.MutatorGroups; +import org.pitest.mutationtest.engine.gregor.MethodMutatorFactory; +import org.pitest.mutationtest.engine.gregor.config.Mutator; import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; +import java.lang.reflect.Field; import java.net.URL; import java.util.Arrays; +import java.util.Collection; import java.util.Iterator; +import java.util.Map; +import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; @@ -58,12 +64,15 @@ * Tab allowing to configure a PIT analyze. */ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { - private static final int NUMBER_OF_COLUMNS = MutatorGroups.values().length + 2; - private static final String CUSTOM_MUTATOR_RADIO_TEXT = "Mutators selected below"; - private static final String CUSTOM_MUTATOR_RADIO_DATA = "CUSTOM"; - private static final String MUTATOR_LINK_TEXT = "See the documentation on Pitest.org"; + private static final int NUMBER_OF_COLUMNS = Mutators.getMainGroup().length + 2; private static final String DESCRIPTION_TEXT = "Select the mutators used to alter the code."; + private static final String MUTATOR_LINK_TEXT = "See the documentation on Pitest.org"; private static final String MUTATOR_LINK = "https://pitest.org/quickstart/mutators/"; + private static final String CUSTOM_MUTATOR_RADIO_TEXT = "Mutators selected below"; + private static final String CUSTOM_MUTATOR_RADIO_DATA = "CUSTOM"; + private static final String COLUMN_DESCRIPTION = "Description"; + private static final String COLUMN_NAME = "Name"; + private static final String MUTATORS_FIELD_NAME = "MUTATORS"; private Image icon; private String mutators; private CheckboxTableViewer mutatorsTable; @@ -103,18 +112,20 @@ public void initializeFrom(ILaunchConfiguration config) { // no selection was made, because no match of data // select custom mutators button customMutatorsButton.setSelection(true); - // TODO: select mutators which are set } + // restore checked mutators + final String individualMutatos = PitArgumentsTab.getAttributeFromConfig(config, INDIVIDUAL_MUTATORS, ""); + for (String mutatorId : individualMutatos.split(",")) { + mutatorsTable.setChecked(mutatorId, true); + } + disableTableIfUnused(); } public void createControl(Composite parent) { mainComp = new Composite(parent, SWT.NONE); setControl(mainComp); - GridLayout topLayout = new GridLayout(); - topLayout.verticalSpacing = 0; - topLayout.numColumns = NUMBER_OF_COLUMNS; - mainComp.setLayout(topLayout); + GridLayoutFactory.fillDefaults().numColumns(NUMBER_OF_COLUMNS).applyTo(mainComp); Font font = parent.getFont(); mainComp.setFont(font); @@ -124,7 +135,7 @@ public void createControl(Composite parent) { createSpacer(mainComp); createMutatorGroupsWidgets(font, mainComp); createSpacer(mainComp); - createMutatorsWidgets(mainComp); + createMutatorsTable(mainComp); disableTableIfUnused(); setDirty(false); @@ -166,12 +177,12 @@ private void createMutatorGroupsWidgets(Font font, Composite parent) { mutateWithLabel.setText("Mutate with: "); GridDataFactory.swtDefaults().applyTo(mutateWithLabel); - groupButtons = new Button[MutatorGroups.values().length]; + groupButtons = new Button[Mutators.getMainGroup().length]; int i = 0; - for (MutatorGroups mutatorGroup : MutatorGroups.values()) { + for (Mutators mutatorGroup : Mutators.getMainGroup()) { Button button = new Button(grouopComposite, SWT.RADIO); - button.setText(mutatorGroup.getLabel()); - button.setData(mutatorGroup.getId()); + button.setText(mutatorGroup.getDescriptor()); + button.setData(mutatorGroup.name()); button.setFont(font); button.addSelectionListener(widgetSelectedAdapter(event -> { final String old = mutators; @@ -204,21 +215,50 @@ private void createMutatorGroupsWidgets(Font font, Composite parent) { * Execution Hooks are found from extension points. Each execution hook provide * a checkbox that can be used to activate / deactivate the hook. */ - private void createMutatorsWidgets(Composite parent) { - mutatorsTable = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + private void createMutatorsTable(Composite parent) { + mutatorsTable = CheckboxTableViewer.newCheckList(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); mutatorsTable.getTable().setHeaderVisible(true); mutatorsTable.setContentProvider(new ArrayContentProvider()); - GridDataFactory.swtDefaults().grab(false, false).span(NUMBER_OF_COLUMNS, 1).applyTo(mutatorsTable.getTable()); + GridDataFactory.swtDefaults().grab(true, true).span(NUMBER_OF_COLUMNS, 1).applyTo(mutatorsTable.getTable()); TableViewerColumn colName = new TableViewerColumn(mutatorsTable, SWT.FILL | SWT.H_SCROLL | SWT.V_SCROLL); - colName.getColumn().setText("Name"); - colName.setLabelProvider(new LambdaLabelProvider(Mutators::getName)); + colName.getColumn().setText(COLUMN_NAME); + colName.setLabelProvider(new CellLabelProvider() { + @Override + public void update(ViewerCell cell) { + final String name = (String) cell.getElement(); + try { + final Mutators info = Mutators.valueOf(name); + cell.setText(info.getDescriptor()); + } catch (IllegalArgumentException e) { + // if no info in our enum is present use default + cell.setText(name); + } + } + }); TableViewerColumn colDescription = new TableViewerColumn(mutatorsTable, SWT.FILL | SWT.H_SCROLL | SWT.V_SCROLL); - colDescription.getColumn().setText("Description"); - colDescription.setLabelProvider(new LambdaLabelProvider(Mutators::getDescription)); + colDescription.getColumn().setText(COLUMN_DESCRIPTION); + colDescription.setLabelProvider(new CellLabelProvider() { + @Override + public void update(ViewerCell cell) { + final String name = (String) cell.getElement(); + try { + final Mutators info = Mutators.valueOf(name); + cell.setText(info.getDescription()); + } catch (IllegalArgumentException e) { + // if no info in our enum is present use default + cell.setText("Nothing found. Could be NON-FUNCTIONING."); + } + } + }); - mutatorsTable.setInput(Mutators.values()); + try { + mutatorsTable.setInput(getPitMutators()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } colName.getColumn().pack(); colDescription.getColumn().pack(); @@ -229,6 +269,21 @@ private void createMutatorsWidgets(Composite parent) { mutatorsTable.addCheckStateListener(event -> updateLaunchConfigurationDialog()); } + /** + * Hack because the Mutator.java from pit does not allow to get the keys of the + * mutators yet.
+ * Should be replaced, if + * Pit PR gets merged. + * @return keys of all mutators as Strings + * @throws Exception if the reflection failed in any way + */ + @SuppressWarnings("unchecked") + private Collection getPitMutators() throws Exception { + Field field = Mutator.class.getDeclaredField(MUTATORS_FIELD_NAME); + field.setAccessible(true); + return ((Map>) field.get(null)).keySet(); + } + private void disableTableIfUnused() { mutatorsTable.getTable().setEnabled(customMutatorsButton.getSelection()); } @@ -239,7 +294,12 @@ protected static void addSeparator(Composite parent) { } public void performApply(ILaunchConfigurationWorkingCopy config) { - config.setAttribute(MUTATORS, getMutators()); + config.setAttribute(INDIVIDUAL_MUTATORS, getIndividualMutators()); + if (isBasicMutatorGroup()) { + config.setAttribute(MUTATORS, mutators); + } else { + config.setAttribute(MUTATORS, getIndividualMutators()); + } try { PitMigrationDelegate.mapResources(config); } catch (CoreException ce) { @@ -247,19 +307,11 @@ public void performApply(ILaunchConfigurationWorkingCopy config) { } } - /** - * Returns the mutators as a String and if individual mutators are used, - * mutators are separated with commas - * @return mutators as string - */ - private String getMutators() { - if (isBasicMutatorGroup()) { - return mutators; - } - StringBuilder sb = new StringBuilder(); + private String getIndividualMutators() { + StringBuilder sb = new StringBuilder(""); Iterator iterator = Arrays.asList(mutatorsTable.getCheckedElements()).iterator(); while (iterator.hasNext()) { - sb.append(((Mutators) iterator.next()).getId()); + sb.append((String) iterator.next()); if (iterator.hasNext()) { sb.append(','); } diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java index 3bce0554..98a53b67 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java @@ -21,7 +21,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.pitest.pitclipse.core.PitCoreActivator; -import org.pitest.pitclipse.core.MutatorGroups; +import org.pitest.pitclipse.core.Mutators; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_DESCRIPTION_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_LABEL; @@ -41,10 +41,10 @@ public void createFieldEditors() { } private void createExecutionModeRadioButtons() { - MutatorGroups[] values = MutatorGroups.values(); + Mutators[] values = Mutators.getMainGroup(); String[][] mutatorValues = new String[values.length][2]; for (int i = 0; i < values.length; i++) { - mutatorValues[i] = new String[] { values[i].getLabel(), values[i].getId() }; + mutatorValues[i] = new String[] { values[i].getDescriptor(), values[i].name() }; } addField(new RadioGroupFieldEditor(MUTATORS, MUTATORS_LABEL, 1, mutatorValues, getFieldEditorParent())); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java index bd9644a7..ecbf37f4 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java @@ -21,7 +21,7 @@ import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.pitest.pitclipse.core.MutatorGroups; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.runner.config.PitExecutionMode; import java.io.Closeable; @@ -124,7 +124,7 @@ public void setAvoidCallsTo(String avoidCallsTo) { setTextFor(AVOID_CALLS_LABEL).to(avoidCallsTo); } - public MutatorGroups getMutators() { + public Mutators getMutators() { return getSelectedMutators().from(MUTATORS_LABEL); } @@ -263,17 +263,17 @@ public Boolean getPreference(String label) { }); } - private PreferenceGetterBuilder getSelectedMutators() { - return new PreferenceGetterBuilder(new PreferenceGetter() { + private PreferenceGetterBuilder getSelectedMutators() { + return new PreferenceGetterBuilder(new PreferenceGetter() { @Override - public MutatorGroups getPreference(String label) { + public Mutators getPreference(String label) { expandPitMutatorPreferences(); - for (MutatorGroups mutator : MutatorGroups.values()) { - if (bot.radio(mutator.getLabel()).isSelected()) { + for (Mutators mutator : Mutators.getMainGroup()) { + if (bot.radio(mutator.getDescriptor()).isSelected()) { return mutator; } } - return MutatorGroups.DEFAULTS; + return Mutators.DEFAULTS; } }); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java index af4ed4cd..5f7870a2 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java @@ -25,7 +25,7 @@ import org.eclipse.swtbot.swt.finder.waits.Conditions; import org.eclipse.ui.dialogs.PreferencesUtil; import org.pitest.pitclipse.core.PitCoreActivator; -import org.pitest.pitclipse.core.MutatorGroups; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.runner.config.PitExecutionMode; public class WindowsMenu { @@ -155,11 +155,11 @@ public void openPitMutationsView() { viewSelector.selectView("PIT", "PIT Mutations"); } - public MutatorGroups getMutators() { + public Mutators getMutators() { return openPreferences().andThen().getMutators(); } - public void setMutators(MutatorGroups mutators) { + public void setMutators(Mutators mutators) { PitCoreActivator.getDefault().setMutators(mutators); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java index 033b27a0..69e2baba 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java @@ -21,7 +21,7 @@ import cucumber.api.java.en.When; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; -import org.pitest.pitclipse.core.MutatorGroups; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.runner.config.PitExecutionMode; import java.math.BigDecimal; @@ -33,8 +33,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.pitest.pitclipse.core.MutatorGroups.ALL; -import static org.pitest.pitclipse.core.MutatorGroups.STRONGER; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_MUTATORS; import static org.pitest.pitclipse.runner.config.PitExecutionMode.PROJECT_ISOLATION; @@ -149,18 +147,18 @@ public void setAvoidCalls(String avoidCallsTo) { @Then("the default mutators preference is selected") public void defaultMutators() { - MutatorGroups selectedMutators = PAGES.getWindowsMenu().getMutators(); + Mutators selectedMutators = PAGES.getWindowsMenu().getMutators(); assertThat(selectedMutators.toString(), is(equalTo(DEFAULT_MUTATORS))); } @Given("the stronger mutator preference is selected") public void useStrongerMutators() { - PAGES.getWindowsMenu().setMutators(STRONGER); + PAGES.getWindowsMenu().setMutators(Mutators.STRONGER); } @Given("the all mutators preference is selected") public void useAllMutators() { - PAGES.getWindowsMenu().setMutators(ALL); + PAGES.getWindowsMenu().setMutators(Mutators.ALL); } @Given("the timeout constant is {int}") diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 4188382d..f23178d4 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -17,7 +17,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.pitest.pitclipse.core.MutatorGroups; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.core.preferences.PitPreferences; import org.pitest.pitclipse.runner.config.PitConfiguration; @@ -83,7 +83,7 @@ public void useDefaultMutators() throws CoreException { @Test public void useStrongerMutators() throws CoreException { // now set STRONGER mutators - PAGES.getWindowsMenu().setMutators(MutatorGroups.STRONGER); + PAGES.getWindowsMenu().setMutators(Mutators.STRONGER); try { runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); coverageReportGenerated(2, 80, 0); @@ -98,7 +98,7 @@ public void useStrongerMutators() throws CoreException { "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f"); } finally { // it's crucial to reset it to the default or we break other tests - PAGES.getWindowsMenu().setMutators(MutatorGroups.DEFAULTS); + PAGES.getWindowsMenu().setMutators(Mutators.DEFAULTS); } } From b1dfae394a6a6f237d2999109dc441e3685a0302 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Thu, 22 Jul 2021 15:01:05 +0200 Subject: [PATCH 13/50] Updated the defaults to match with pitest.org * if the custom mutators option is selected for the first time, the default mutators are selected --- .../org/pitest/pitclipse/core/Mutators.java | 24 ++++++++++++++----- .../pitclipse/launch/ui/PitMutatorsTab.java | 20 ++++++++++++---- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java index e64f7c24..f5843792 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java @@ -16,6 +16,8 @@ package org.pitest.pitclipse.core; +import java.util.ArrayList; + import org.pitest.mutationtest.engine.gregor.config.Mutator; /** @@ -34,16 +36,16 @@ public enum Mutators { INVERT_NEGS("Invert Negatives", "Inverts negation of integer and floating point numbers", true), MATH("Math", "Replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation", true), NEGATE_CONDITIONALS("Negate Conditionals", "Mutates all conditionals found", true), - RETURN_VALS("Return Values", "Mutates the return values of method calls. Depending on the return type of the method another mutation is used", true), + RETURN_VALS("Return Values", "Mutates the return values of method calls. Depending on the return type of the method another mutation is used"), VOID_METHOD_CALLS("Void Method Call", "Removes method calls to void methods", true), CONSTRUCTOR_CALLS("Constructor Call", "Replaces constructor calls with null values"), - EMPTY_RETURNS("Empty Returns", "Replaces return values with an 'empty' value"), - FALSE_RETURNS("False Returns", "Replaces primitive and boxed boolean return values with false"), - TRUE_RETURNS("True Returns", "Replaces primitive and boxed boolean return values with true"), + EMPTY_RETURNS("Empty Returns", "Replaces return values with an 'empty' value",true), + FALSE_RETURNS("False Returns", "Replaces primitive and boxed boolean return values with false",true), + TRUE_RETURNS("True Returns", "Replaces primitive and boxed boolean return values with true",true), INLINE_CONSTS("Inline Constant", "Mutates inline constants. An inline constant is a literal value assigned to a non-final variable"), - NULL_RETURNS("Null Returns", "Replaces return values with null. Method that can be mutated by the EMPTY_RETURNS mutator or that are directly annotated with NotNull are not mutated"), + NULL_RETURNS("Null Returns", "Replaces return values with null. Method that can be mutated by the EMPTY_RETURNS mutator or that are directly annotated with NotNull are not mutated", true), NON_VOID_METHOD_CALLS("Non Void Method Call", "Removes method calls to non void methods. Their return value is replaced by the Java Default Value for that specific type"), - PRIMITIVE_RETURNS("Primite Returns", "Replaces int, short, long, char, float and double return values with 0"), + PRIMITIVE_RETURNS("Primite Returns", "Replaces int, short, long, char, float and double return values with 0", true), REMOVE_CONDITIONALS("Remove Conditionals", "Removes all conditionals statements such that the guarded statements always execute"), REMOVE_INCREMENTS("Remove Increments", "Removes local variable increments"), EXPERIMENTAL_ARGUMENT_PROPAGATION("Experimentation Argument Propagation", "Replaces method call with one of its parameters of matching type"), @@ -98,4 +100,14 @@ public boolean isActiveByDefault() { public static Mutators[] getMainGroup() { return new Mutators[] {DEFAULTS,STRONGER,ALL}; } + + public static ArrayList getDefaultMutators() { + ArrayList defaultMutators = new ArrayList(); + for (Mutators m : values()) { + if (m.isActiveByDefault()) { + defaultMutators.add(m.name()); + } + } + return defaultMutators; + } } diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 766d94ec..de828c1a 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -107,21 +107,31 @@ public void dispose() { public void initializeFrom(ILaunchConfiguration config) { PitConfiguration preferences = PitCoreActivator.getDefault().getConfiguration(); mutators = PitArgumentsTab.getAttributeFromConfig(config, MUTATORS, preferences.getMutators()); - System.out.println(mutators); if (!updateSelectionOfGroup(mutators)) { // no selection was made, because no match of data // select custom mutators button customMutatorsButton.setSelection(true); } // restore checked mutators - final String individualMutatos = PitArgumentsTab.getAttributeFromConfig(config, INDIVIDUAL_MUTATORS, ""); - for (String mutatorId : individualMutatos.split(",")) { - mutatorsTable.setChecked(mutatorId, true); - } + intializeMutatorsTable(config); disableTableIfUnused(); } + private void intializeMutatorsTable(ILaunchConfiguration config) { + final String individualMutatos = PitArgumentsTab.getAttributeFromConfig(config, INDIVIDUAL_MUTATORS, ""); + if (individualMutatos.equals("")) { + // no mutators where set, use defaults + for (String mutator : Mutators.getDefaultMutators()) { + mutatorsTable.setChecked(mutator, true); + } + } else { + for (String mutator : individualMutatos.split(",")) { + mutatorsTable.setChecked(mutator, true); + } + } + } + public void createControl(Composite parent) { mainComp = new Composite(parent, SWT.NONE); setControl(mainComp); From 4d98c718482a6fa36c6be63c1801b124229e24fa Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Thu, 22 Jul 2021 16:35:12 +0200 Subject: [PATCH 14/50] Cosmetic changes * exclude main group from mutators now --- .../org/pitest/pitclipse/core/Mutators.java | 30 +++++---- .../pitclipse/launch/ui/PitMutatorsTab.java | 61 ++++++++++++------- .../ui/PitMutatorsPreferencePage.java | 25 +++++--- 3 files changed, 70 insertions(+), 46 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java index f5843792..27d4cc47 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java @@ -22,8 +22,8 @@ /** * Enum which holds information about the mutators of pit.
- * The name of new values must be the exact String, - * which is used by PIT in the class {@link Mutator}. + * The name of new values must be the exact String, which is used by PIT + * in the class {@link Mutator}. */ @SuppressWarnings("checkstyle:LineLength") public enum Mutators { @@ -39,9 +39,9 @@ public enum Mutators { RETURN_VALS("Return Values", "Mutates the return values of method calls. Depending on the return type of the method another mutation is used"), VOID_METHOD_CALLS("Void Method Call", "Removes method calls to void methods", true), CONSTRUCTOR_CALLS("Constructor Call", "Replaces constructor calls with null values"), - EMPTY_RETURNS("Empty Returns", "Replaces return values with an 'empty' value",true), - FALSE_RETURNS("False Returns", "Replaces primitive and boxed boolean return values with false",true), - TRUE_RETURNS("True Returns", "Replaces primitive and boxed boolean return values with true",true), + EMPTY_RETURNS("Empty Returns", "Replaces return values with an 'empty' value", true), + FALSE_RETURNS("False Returns", "Replaces primitive and boxed boolean return values with false", true), + TRUE_RETURNS("True Returns", "Replaces primitive and boxed boolean return values with true", true), INLINE_CONSTS("Inline Constant", "Mutates inline constants. An inline constant is a literal value assigned to a non-final variable"), NULL_RETURNS("Null Returns", "Replaces return values with null. Method that can be mutated by the EMPTY_RETURNS mutator or that are directly annotated with NotNull are not mutated", true), NON_VOID_METHOD_CALLS("Non Void Method Call", "Removes method calls to non void methods. Their return value is replaced by the Java Default Value for that specific type"), @@ -52,7 +52,7 @@ public enum Mutators { EXPERIMENTAL_BIG_INTEGER("Experimental Big Integer", "Swaps big integer methods"), EXPERIMENTAL_NAKED_RECEIVER("Experimental Naked Receiver", "Replaces method call with a naked receiver"), EXPERIMENTAL_MEMBER_VARIABLE("Experimental Member Variable", "Removes assignments to member variables. Can even remove assignments to final members. The members will be initialized with their Java Default Value"), - EXPERIMENTAL_SWITCH("Experimental Switch", "Finds the first label within a switch statement that differs from the default label. Mutates the switch statement by replacing the default label (wherever it is used) with this label. ALl the other labels are replaced by the default one"), + EXPERIMENTAL_SWITCH("Experimental Switch", "Finds the first label within a switch statement that differs from the default label. Mutates the switch statement by replacing the default label (wherever it is used) with this label. All the other labels are replaced by the default one"), ABS("Negation", "Replaces any use of a numeric variable (local variable, field, array cell) with its negation"), AOR("Arithmetic Operator Replacement", "Like the Math mutator, replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation"), AOD("Arithmetic Operator Deletion", "Replaces an arithmetic operation with one of its members"), @@ -60,7 +60,7 @@ public enum Mutators { OBBN("Bitwise Operator", "Mutates bitwise and (&) and or (|)"), ROR("Relational Operator Replacement", "Replaces a relational operator with another one"), UOI("Unary Operator Insertion", "Inserts a unary operator (increment or decrement) to a variable call. Affects local variables, array variables, fields and parameters"); - + /** * Descriptor which is used to display the name of this mutator in a table */ @@ -73,11 +73,11 @@ public enum Mutators { * true, if this mutator is contained in the DEFAULTS group of PIT */ private final boolean activeByDefault; - + private Mutators(String descriptor, String description) { this(descriptor, description, false); } - + private Mutators(String descriptor, String description, boolean activeByDefault) { this.descriptor = descriptor; this.description = description; @@ -88,7 +88,6 @@ public String getDescriptor() { return descriptor; } - public String getDescription() { return description; } @@ -96,9 +95,14 @@ public String getDescription() { public boolean isActiveByDefault() { return activeByDefault; } - - public static Mutators[] getMainGroup() { - return new Mutators[] {DEFAULTS,STRONGER,ALL}; + + public static ArrayList getMainGroup() { + final ArrayList mainGroup = new ArrayList(); + mainGroup.add(DEFAULTS); + mainGroup.add(STRONGER); + mainGroup.add(ALL); + mainGroup.add(OLD_DEFAULTS); + return mainGroup; } public static ArrayList getDefaultMutators() { diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index de828c1a..d0360c73 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -16,6 +16,17 @@ package org.pitest.pitclipse.launch.ui; +import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; +import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; + +import java.lang.reflect.Field; +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; @@ -30,7 +41,9 @@ import org.eclipse.jface.viewers.CellLabelProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -49,22 +62,11 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; -import java.lang.reflect.Field; -import java.net.URL; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; -import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; - /** * Tab allowing to configure a PIT analyze. */ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { - private static final int NUMBER_OF_COLUMNS = Mutators.getMainGroup().length + 2; + private static final int NUMBER_OF_COLUMNS = Mutators.getMainGroup().size() + 2; private static final String DESCRIPTION_TEXT = "Select the mutators used to alter the code."; private static final String MUTATOR_LINK_TEXT = "See the documentation on Pitest.org"; private static final String MUTATOR_LINK = "https://pitest.org/quickstart/mutators/"; @@ -73,6 +75,7 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private static final String COLUMN_DESCRIPTION = "Description"; private static final String COLUMN_NAME = "Name"; private static final String MUTATORS_FIELD_NAME = "MUTATORS"; + private static final String NO_DESCRIPTION_TEXT = "No description found yet."; private Image icon; private String mutators; private CheckboxTableViewer mutatorsTable; @@ -135,8 +138,7 @@ private void intializeMutatorsTable(ILaunchConfiguration config) { public void createControl(Composite parent) { mainComp = new Composite(parent, SWT.NONE); setControl(mainComp); - GridLayoutFactory.fillDefaults().numColumns(NUMBER_OF_COLUMNS).applyTo(mainComp); - + GridLayoutFactory.swtDefaults().numColumns(2).applyTo(mainComp); Font font = parent.getFont(); mainComp.setFont(font); @@ -149,6 +151,7 @@ public void createControl(Composite parent) { disableTableIfUnused(); setDirty(false); + mainComp.pack(); } /** @@ -169,6 +172,7 @@ public void widgetSelected(SelectionEvent e) { } }); + GridDataFactory.swtDefaults().applyTo(link); } /** @@ -187,7 +191,7 @@ private void createMutatorGroupsWidgets(Font font, Composite parent) { mutateWithLabel.setText("Mutate with: "); GridDataFactory.swtDefaults().applyTo(mutateWithLabel); - groupButtons = new Button[Mutators.getMainGroup().length]; + groupButtons = new Button[Mutators.getMainGroup().size()]; int i = 0; for (Mutators mutatorGroup : Mutators.getMainGroup()) { Button button = new Button(grouopComposite, SWT.RADIO); @@ -223,15 +227,27 @@ private void createMutatorGroupsWidgets(Font font, Composite parent) { /** * Creates a group containing a table showing available Execution Hooks. * Execution Hooks are found from extension points. Each execution hook provide - * a checkbox that can be used to activate / deactivate the hook. + * a check box that can be used to activate / deactivate the hook. */ private void createMutatorsTable(Composite parent) { - mutatorsTable = CheckboxTableViewer.newCheckList(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + mutatorsTable = CheckboxTableViewer.newCheckList(parent, SWT.MULTI | SWT.BORDER); mutatorsTable.getTable().setHeaderVisible(true); mutatorsTable.setContentProvider(new ArrayContentProvider()); - GridDataFactory.swtDefaults().grab(true, true).span(NUMBER_OF_COLUMNS, 1).applyTo(mutatorsTable.getTable()); + // filter out groups which are present in the main group + mutatorsTable.setFilters(new ViewerFilter() { + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + try { + return !Mutators.getMainGroup().contains(Mutators.valueOf((String) element)); + } catch (IllegalArgumentException e) { + // not in predefined mutators, is okay + return true; + } + } + }); + GridDataFactory.swtDefaults().grab(false, false).span(NUMBER_OF_COLUMNS, 1).applyTo(mutatorsTable.getTable()); - TableViewerColumn colName = new TableViewerColumn(mutatorsTable, SWT.FILL | SWT.H_SCROLL | SWT.V_SCROLL); + TableViewerColumn colName = new TableViewerColumn(mutatorsTable, SWT.FILL); colName.getColumn().setText(COLUMN_NAME); colName.setLabelProvider(new CellLabelProvider() { @Override @@ -247,7 +263,7 @@ public void update(ViewerCell cell) { } }); - TableViewerColumn colDescription = new TableViewerColumn(mutatorsTable, SWT.FILL | SWT.H_SCROLL | SWT.V_SCROLL); + TableViewerColumn colDescription = new TableViewerColumn(mutatorsTable, SWT.FILL); colDescription.getColumn().setText(COLUMN_DESCRIPTION); colDescription.setLabelProvider(new CellLabelProvider() { @Override @@ -258,7 +274,7 @@ public void update(ViewerCell cell) { cell.setText(info.getDescription()); } catch (IllegalArgumentException e) { // if no info in our enum is present use default - cell.setText("Nothing found. Could be NON-FUNCTIONING."); + cell.setText(NO_DESCRIPTION_TEXT); } } }); @@ -266,8 +282,7 @@ public void update(ViewerCell cell) { try { mutatorsTable.setInput(getPitMutators()); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new RuntimeException("Input for mutatorTable was not set correctly.", e); } colName.getColumn().pack(); diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java index 98a53b67..081a376b 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java @@ -16,16 +16,18 @@ package org.pitest.pitclipse.preferences.ui; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_DESCRIPTION_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_LABEL; + +import java.util.ArrayList; + import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.RadioGroupFieldEditor; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; -import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.core.Mutators; - -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_DESCRIPTION_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; +import org.pitest.pitclipse.core.PitCoreActivator; public class PitMutatorsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { @@ -41,14 +43,17 @@ public void createFieldEditors() { } private void createExecutionModeRadioButtons() { - Mutators[] values = Mutators.getMainGroup(); - String[][] mutatorValues = new String[values.length][2]; - for (int i = 0; i < values.length; i++) { - mutatorValues[i] = new String[] { values[i].getDescriptor(), values[i].name() }; + ArrayList values = Mutators.getMainGroup(); + String[][] mutatorValues = new String[values.size()][2]; + int i = 0; + for (Mutators mutator : values) { + mutatorValues[i++] = new String[] { mutator.getDescriptor(), mutator.name() }; } addField(new RadioGroupFieldEditor(MUTATORS, MUTATORS_LABEL, 1, mutatorValues, getFieldEditorParent())); } @Override - public void init(IWorkbench workbench) { /* Intentionally Empty */ } + public void init(IWorkbench workbench) { + // Intentionally Empty + } } From 08a74743a08c63a38e51d1f56f86312f0cbaf7e6 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Thu, 22 Jul 2021 16:54:12 +0200 Subject: [PATCH 15/50] Show error message, if no mutator is selected Also disable run and apply, if the selection is not valid --- .../pitclipse/launch/ui/PitMutatorsTab.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index d0360c73..ab0b71b6 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -76,6 +76,7 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private static final String COLUMN_NAME = "Name"; private static final String MUTATORS_FIELD_NAME = "MUTATORS"; private static final String NO_DESCRIPTION_TEXT = "No description found yet."; + private static final String ERROR_MESSAGE = "At least one mutator or mutator group needs to be selected!"; private Image icon; private String mutators; private CheckboxTableViewer mutatorsTable; @@ -345,12 +346,7 @@ private String getIndividualMutators() { } public void setDefaults(ILaunchConfigurationWorkingCopy workingCopy) { - /* - * IJavaElement javaElement = getContext(); if (javaElement != null) { - * initializeJavaProject(javaElement, workingCopy); } else { - * workingCopy.setAttribute( - * IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); } - */ + // Intentionally left empty } private void createSpacer(Composite comp) { @@ -390,4 +386,28 @@ private boolean updateSelectionOfGroup(String value) { private boolean isBasicMutatorGroup() { return !customMutatorsButton.getSelection(); } + + /** + * Only allow save, if one of the main mutator groups is selected or at least + * one mutator is selected inside the mutatorTable + */ + @Override + public boolean canSave() { + return isBasicMutatorGroup() || mutatorsTable.getCheckedElements().length > 0; + } + + @Override + public boolean isValid(ILaunchConfiguration launchConfig) { + return canSave(); + } + + @Override + protected void updateLaunchConfigurationDialog() { + if (canSave()) { + setErrorMessage(null); + } else { + setErrorMessage(ERROR_MESSAGE); + } + super.updateLaunchConfigurationDialog(); + } } From 0e1fc3aba66ada3f4e05e0ee394b48dab270f8df Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Fri, 23 Jul 2021 09:22:51 +0200 Subject: [PATCH 16/50] Added options test for old defaults They were added within the last commits and are also a group listet on pitest.org --- .../ui/tests/PitclipseOptionsTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index f23178d4..ecb1fd8f 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -67,6 +67,27 @@ public void defaultOptions() { selector.close(); } + @Test + public void useOldDefaultsMutators() throws CoreException { + // set OLD_DEFAULTS mutators + PAGES.getWindowsMenu().setMutators(Mutators.OLD_DEFAULTS); + try { + runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); + coverageReportGenerated(2, 80, 0); + mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | replaced return of integer sized value with (x == 0 ? 1 : 0)"); + } finally { + // it's crucial to reset it to the default or we break other tests + PAGES.getWindowsMenu().setMutators(Mutators.DEFAULTS); + } + } + @Test public void useDefaultMutators() throws CoreException { runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); From ca0e8b4c2e3962c923cb9ac7e12b81f0617a3187 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Mon, 26 Jul 2021 08:42:41 +0200 Subject: [PATCH 17/50] First tests for mutations tab in launch config --- .../pitclipse/launch/ui/PitArgumentsTab.java | 37 +-- .../launch/ui/PitLaunchShortcut.java | 64 ++--- .../pitclipse/launch/ui/PitMutatorsTab.java | 8 +- .../pageobjects/PitRunConfiguration.java | 67 ++++- .../pageobjects/RunConfigurationSelector.java | 233 +++++++++++++++++- .../ui/behaviours/pageobjects/RunMenu.java | 58 ++++- .../ui/tests/AbstractPitclipseSWTBotTest.java | 44 +++- ...clipseRunConfigurationMutationTabTest.java | 202 +++++++++++++++ 8 files changed, 632 insertions(+), 81 deletions(-) create mode 100644 tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index d0b1af3b..dfc9ea8e 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -16,6 +16,23 @@ package org.pitest.pitclipse.launch.ui; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; +import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL_LABEL; +import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; + +import java.net.URL; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; @@ -45,27 +62,11 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; -import java.net.URL; - -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; -import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS_LABEL; -import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; - /** * Tab allowing to configure a PIT analyze. */ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab { + public static final String NAME = "PIT"; private static final int NUMBER_OF_COLUMNS = 3; public static final String TEST_CLASS_RADIO_TEXT = "Run mutations from a unit test"; public static final String TEST_CLASS_TEXT = "Test Class:"; @@ -310,7 +311,7 @@ private Button createNewCheckBox(Font font, Composite comp, int columnsInParent, @Override public String getName() { - return "PIT"; + return NAME; } @Override diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchShortcut.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchShortcut.java index 8a4f7936..4ee8efc3 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchShortcut.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchShortcut.java @@ -16,8 +16,36 @@ package org.pitest.pitclipse.launch.ui; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; +import static org.eclipse.jdt.core.IJavaElement.CLASS_FILE; +import static org.eclipse.jdt.core.IJavaElement.COMPILATION_UNIT; +import static org.eclipse.jdt.core.IJavaElement.JAVA_PROJECT; +import static org.eclipse.jdt.core.IJavaElement.METHOD; +import static org.eclipse.jdt.core.IJavaElement.PACKAGE_FRAGMENT; +import static org.eclipse.jdt.core.IJavaElement.PACKAGE_FRAGMENT_ROOT; +import static org.eclipse.jdt.core.IJavaElement.TYPE; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; +import static org.eclipse.jdt.ui.JavaElementLabels.ALL_FULLY_QUALIFIED; +import static org.eclipse.jdt.ui.JavaElementLabels.getTextLabel; +import static org.eclipse.jdt.ui.JavaUI.getEditorInputTypeRoot; +import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.asJavaElement; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.emptyLaunchConfiguration; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.emptyList; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.forEditorInputDo; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.getCorrespondingResource; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.toArrayOfILaunchConfiguration; +import static org.pitest.pitclipse.launch.ui.PitLaunchUiActivator.getActiveWorkbenchShell; +import static org.pitest.pitclipse.launch.ui.PitMigrationDelegate.mapResources; + +import java.util.List; +import java.util.Optional; +import java.util.function.Function; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -47,36 +75,8 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; - -import static org.eclipse.jdt.core.IJavaElement.CLASS_FILE; -import static org.eclipse.jdt.core.IJavaElement.COMPILATION_UNIT; -import static org.eclipse.jdt.core.IJavaElement.JAVA_PROJECT; -import static org.eclipse.jdt.core.IJavaElement.METHOD; -import static org.eclipse.jdt.core.IJavaElement.PACKAGE_FRAGMENT; -import static org.eclipse.jdt.core.IJavaElement.PACKAGE_FRAGMENT_ROOT; -import static org.eclipse.jdt.core.IJavaElement.TYPE; -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; -import static org.eclipse.jdt.ui.JavaElementLabels.ALL_FULLY_QUALIFIED; -import static org.eclipse.jdt.ui.JavaElementLabels.getTextLabel; -import static org.eclipse.jdt.ui.JavaUI.getEditorInputTypeRoot; -import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.asJavaElement; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.emptyLaunchConfiguration; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.emptyList; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.forEditorInputDo; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.getCorrespondingResource; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.toArrayOfILaunchConfiguration; -import static org.pitest.pitclipse.launch.ui.PitLaunchUiActivator.getActiveWorkbenchShell; -import static org.pitest.pitclipse.launch.ui.PitMigrationDelegate.mapResources; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; /** * Allows to launch a PIT analyze from a contextual menu. diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index ab0b71b6..f3121087 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -66,11 +66,13 @@ * Tab allowing to configure a PIT analyze. */ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { + public static final String NAME = "Mutators"; + private static final int NUMBER_OF_COLUMNS = Mutators.getMainGroup().size() + 2; private static final String DESCRIPTION_TEXT = "Select the mutators used to alter the code."; private static final String MUTATOR_LINK_TEXT = "See the documentation on Pitest.org"; private static final String MUTATOR_LINK = "https://pitest.org/quickstart/mutators/"; - private static final String CUSTOM_MUTATOR_RADIO_TEXT = "Mutators selected below"; + public static final String CUSTOM_MUTATOR_RADIO_TEXT = "Mutators selected below"; private static final String CUSTOM_MUTATOR_RADIO_DATA = "CUSTOM"; private static final String COLUMN_DESCRIPTION = "Description"; private static final String COLUMN_NAME = "Name"; @@ -89,7 +91,7 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { @Override public String getName() { - return "Mutators"; + return NAME; } @Override @@ -393,7 +395,7 @@ private boolean isBasicMutatorGroup() { */ @Override public boolean canSave() { - return isBasicMutatorGroup() || mutatorsTable.getCheckedElements().length > 0; + return isBasicMutatorGroup() || (!isBasicMutatorGroup() && mutatorsTable.getCheckedElements().length > 0); } @Override diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitRunConfiguration.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitRunConfiguration.java index 23f8747d..26bf93f7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitRunConfiguration.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitRunConfiguration.java @@ -16,32 +16,37 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; -import com.google.common.collect.ImmutableList; +import static com.google.common.collect.ImmutableList.copyOf; +import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST; import java.util.List; -import static com.google.common.collect.ImmutableList.copyOf; -import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST; +import com.google.common.collect.ImmutableList; public class PitRunConfiguration { private final String name; private final List projects; + private final String testObject; private final boolean runInParallel; private final boolean incrementalAnalysis; private final String excludedClasses; private final String excludedMethods; private final String avoidCallsTo; + private final boolean testClass; - private PitRunConfiguration(String name, List projects, boolean runInParallel, boolean incrementalAnalysis, - String excludedClasses, String excludedMethods, String avoidCallsTo) { + private PitRunConfiguration(String name, List projects, String testObject, boolean testClass, + boolean runInParallel, boolean incrementalAnalysis, String excludedClasses, String excludedMethods, + String avoidCallsTo) { this.name = name; this.projects = projects; + this.testObject = testObject; this.runInParallel = runInParallel; this.incrementalAnalysis = incrementalAnalysis; this.excludedClasses = excludedClasses; this.excludedMethods = excludedMethods; this.avoidCallsTo = avoidCallsTo; + this.testClass = testClass; } public String getName() { @@ -52,18 +57,40 @@ public List getProjects() { return projects; } + public String getTestObject() { + return testObject; + } + public static class Builder { private String name; + private String testObject = null; private List projects = ImmutableList.of(); private boolean runInParallel = false; private boolean incrementalAnalysis = false; - private String excludedClasses = ""; + private boolean testClass = true; + private String excludedClasses = "*Test"; private String excludedMethods = ""; private String avoidCallsTo = DEFAULT_AVOID_CALLS_TO_LIST; + public Builder(PitRunConfiguration configuration) { + this.name = configuration.getName(); + this.testObject = configuration.getTestObject(); + this.projects = copyOf(configuration.getProjects()); + this.runInParallel = configuration.isRunInParallel(); + this.incrementalAnalysis = configuration.isIncrementalAnalysis(); + this.testClass = configuration.isTestClass(); + this.excludedClasses = configuration.getExcludedClasses(); + this.excludedMethods = configuration.getExcludedMethods(); + this.avoidCallsTo = configuration.getAvoidCallsTo(); + } + + public Builder() { + // intentionally empty + } + public PitRunConfiguration build() { - return new PitRunConfiguration(name, projects, runInParallel, incrementalAnalysis, excludedClasses, - excludedMethods, avoidCallsTo); + return new PitRunConfiguration(name, projects, testObject, testClass, runInParallel, incrementalAnalysis, + excludedClasses, excludedMethods, avoidCallsTo); } public Builder withName(String name) { @@ -76,6 +103,26 @@ public Builder withProjects(String... projects) { return this; } + public Builder withTestObject(String testObject) { + this.testObject = testObject; + return this; + } + + public Builder withTestDir(String testDir) { + this.testClass = false; + return withTestObject(testDir); + } + + public Builder withTestClassOrDir(boolean isTestClass) { + this.testClass = isTestClass; + return this; + } + + public Builder withTestClass(String testClass) { + this.testClass = true; + return withTestObject(testClass); + } + public Builder withRunInParallel(boolean runInParallel) { this.runInParallel = runInParallel; return this; @@ -121,4 +168,8 @@ public String getExcludedMethods() { public String getAvoidCallsTo() { return avoidCallsTo; } + + public boolean isTestClass() { + return testClass; + } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index f672420c..f2b23c0f 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -16,22 +16,32 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; -import com.google.common.collect.ImmutableList; +import static com.google.common.collect.ImmutableList.builder; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.TableItem; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.preferences.PitPreferences; import org.pitest.pitclipse.launch.ui.PitArgumentsTab; +import org.pitest.pitclipse.launch.ui.PitMutatorsTab; import org.pitest.pitclipse.ui.behaviours.pageobjects.PitRunConfiguration.Builder; +import org.pitest.pitclipse.ui.swtbot.SWTBotMenuHelper; -import java.util.List; - -import static com.google.common.collect.ImmutableList.builder; -import static org.pitest.pitclipse.ui.behaviours.pageobjects.SwtBotTreeHelper.selectAndExpand; +import com.google.common.collect.ImmutableList; public class RunConfigurationSelector { + private static final String RUN = "Run"; + private static final String RUN_CONFIGURATIONS = "Run Configurations"; private final SWTWorkbenchBot bot; public RunConfigurationSelector(SWTWorkbenchBot bot) { @@ -39,16 +49,15 @@ public RunConfigurationSelector(SWTWorkbenchBot bot) { } public PitRunConfiguration getConfiguration(String configName) { - activateShell(); + activateConfiguration(configName); Builder builder = new PitRunConfiguration.Builder(); return builder.build(); } public List getConfigurations() { - activateShell(); try { ImmutableList.Builder builder = builder(); - SWTBotTreeItem[] configurations = activateShell().getItems(); + SWTBotTreeItem[] configurations = getPitConfigurationItem().getItems(); for (SWTBotTreeItem treeItem : configurations) { treeItem.select(); builder.add(getPitConfiguration(treeItem)); @@ -62,6 +71,13 @@ public List getConfigurations() { private PitRunConfiguration getPitConfiguration(SWTBotTreeItem treeItem) { String name = treeItem.getText(); String project = bot.textWithLabel(PitArgumentsTab.PROJECT_TEXT).getText(); + boolean isTestClass = bot.radio(PitArgumentsTab.TEST_CLASS_RADIO_TEXT).isSelected(); + String testObject; + if (isTestClass) { + testObject = bot.textWithLabel(PitArgumentsTab.TEST_CLASS_TEXT).getText(); + } else { + testObject = bot.textWithLabel(PitArgumentsTab.TEST_DIR_TEXT).getText(); + } boolean runInParallel = bot.checkBox(PitPreferences.RUN_IN_PARALLEL_LABEL).isChecked(); boolean incrementalAnalysis = bot.checkBox(PitPreferences.INCREMENTAL_ANALYSIS_LABEL).isChecked(); String excludedClasses = bot.textWithLabel(PitPreferences.EXCLUDE_CLASSES_LABEL).getText(); @@ -69,17 +85,210 @@ private PitRunConfiguration getPitConfiguration(SWTBotTreeItem treeItem) { String avoidCallsTo = bot.textWithLabel(PitPreferences.AVOID_CALLS_LABEL).getText(); return new Builder().withName(name).withProjects(project).withRunInParallel(runInParallel) .withIncrementalAnalysis(incrementalAnalysis).withExcludedClasses(excludedClasses) - .withExcludedMethods(excludedMethods).withAvoidCallsTo(avoidCallsTo).build(); + .withExcludedMethods(excludedMethods).withAvoidCallsTo(avoidCallsTo).withTestObject(testObject) + .withTestClassOrDir(isTestClass).build(); } - private SWTBotTreeItem activateShell() { - SWTBotShell shell = bot.shell("Run Configurations"); + private SWTBotShell activateShell() { + // look if shell is already open + for (SWTBotShell shell : bot.shells()) { + if (shell.getText().equals(RUN_CONFIGURATIONS)) { + shell.activate(); + return shell; + } + } + // shell was not open, open and activate it + SWTBotMenuHelper menuHelper = new SWTBotMenuHelper(); + menuHelper.findMenu(bot.menu(RUN), RUN_CONFIGURATIONS + "...").click(); + SWTBotShell shell = bot.shell(RUN_CONFIGURATIONS); shell.activate(); + return shell; + } + + private SWTBotTreeItem getPitConfigurationItem() { + activateShell(); for (SWTBotTreeItem treeItem : bot.tree().getAllItems()) { if ("PIT Mutation Test".equals(treeItem.getText())) { - return selectAndExpand(treeItem); + return treeItem.select().expand(); } } return null; } + + private void activateConfiguration(String configurationName) { + for (SWTBotTreeItem i : getPitConfigurationItem().getItems()) { + if (i.getText().equals(configurationName)) { + i.click(); + } + } + } + + public void activateMutatorsTab(String configurationName) { + activateConfigurationTab(configurationName, PitMutatorsTab.NAME); + } + + public void activatePitTab(String configurationName) { + activateConfigurationTab(configurationName, PitArgumentsTab.NAME); + } + + private void activateConfigurationTab(String configurationName, String name) { + activateShell(); + activateConfiguration(configurationName); + bot.cTabItem(PitMutatorsTab.NAME).activate(); + } + + public void createRunConfiguration(String configurationName, String projectName, String className) { + getPitConfigurationItem().contextMenu("New Configuration").click(); + bot.textWithLabel("Name:").setText(configurationName); + activateShell().bot().button("Apply").click(); + PitRunConfiguration config = new Builder().withName(configurationName).withProjects(projectName) + .withTestClass(className).build(); + setConfiguration(config); + } + + public void setProjectForConfiguration(String configurationName, String project) { + setConfiguration(new Builder(getConfiguration(configurationName)).withProjects(project).build()); + } + + public void setTestClassForConfiguration(String configurationName, String testClass) { + setConfiguration(new Builder(getConfiguration(configurationName)).withTestClass(testClass).build()); + } + + public void setTestDirForConfiguration(String configurationName, String testDir) { + setConfiguration(new Builder(getConfiguration(configurationName)).withTestDir(testDir).build()); + } + + private void setConfiguration(PitRunConfiguration config) { + activateConfiguration(config.getName()); + bot.textWithLabel(PitArgumentsTab.PROJECT_TEXT).setText(getProjectsAsString(config)); + if (config.isTestClass()) { + bot.radio(PitArgumentsTab.TEST_CLASS_RADIO_TEXT).click(); + bot.textWithLabel(PitArgumentsTab.TEST_CLASS_TEXT).setText(config.getTestObject()); + } else { + bot.radio(PitArgumentsTab.TEST_DIR_RADIO_TEXT).click(); + bot.textWithLabel(PitArgumentsTab.TEST_DIR_TEXT).setText(config.getTestObject()); + + } + if (config.isRunInParallel()) { + bot.checkBox(PitPreferences.RUN_IN_PARALLEL_LABEL).select(); + } else { + bot.checkBox(PitPreferences.RUN_IN_PARALLEL_LABEL).deselect(); + } + if (config.isIncrementalAnalysis()) { + bot.checkBox(PitPreferences.INCREMENTAL_ANALYSIS_LABEL).select(); + } else { + bot.checkBox(PitPreferences.INCREMENTAL_ANALYSIS_LABEL).deselect(); + } + bot.textWithLabel(PitPreferences.EXCLUDE_CLASSES_LABEL).setText(config.getExcludedClasses()); + bot.textWithLabel(PitPreferences.EXCLUDE_METHODS_LABEL).setText(config.getExcludedMethods()); + bot.textWithLabel(PitPreferences.AVOID_CALLS_LABEL).setText(config.getAvoidCallsTo()); + // close shell and save + closeConfigurationShell(); + } + + /** + * @param config where the projects are listed + * @return String which lists all projects of the configuration separated with + * commas + */ + private String getProjectsAsString(PitRunConfiguration config) { + Iterator it = config.getProjects().iterator(); + StringBuilder sb = new StringBuilder(); + while (it.hasNext()) { + sb.append(it.next()); + if (it.hasNext()) { + sb.append(','); + } + } + return sb.toString(); + } + + public void setMutatorGroup(String configurationName, Mutators mutatorGroup) { + activateMutatorsTab(configurationName); + bot.radio(mutatorGroup.getDescriptor()).click(); + closeConfigurationShell(); + } + + public void setAdditionalCustomMutator(String configurationName, Mutators mutator) { + activateMutatorsTab(configurationName); + SWTBotRadio radioButton = bot.radio(PitMutatorsTab.CUSTOM_MUTATOR_RADIO_TEXT); + if (!radioButton.isSelected()) { + radioButton.click(); + } + SWTBotTable table = bot.table(); + setMutator(table, mutator); + closeConfigurationShell(); + } + + public void setOneCustomMutator(String configurationName, Mutators mutator) { + activateMutatorsTab(configurationName); + bot.radio(PitMutatorsTab.CUSTOM_MUTATOR_RADIO_TEXT).click(); + uncheckAllMutators(); + SWTBotTable table = bot.table(); + setMutator(table, mutator); + closeConfigurationShell(); + } + + public void checkAllMutators(String configurationName) { + activateMutatorsTab(configurationName); + bot.radio(PitMutatorsTab.CUSTOM_MUTATOR_RADIO_TEXT).click(); + SWTBotTable table = bot.table(); + Display.getDefault().syncExec(() -> { + for (TableItem item : table.widget.getItems()) { + item.setChecked(true); + } + }); + closeConfigurationShell(); + } + + /** + * Assumes the Mutator tab is active and custom mutator mode is selected. + */ + private void uncheckAllMutators() { + SWTBotTable table = bot.table(); + Display.getDefault().syncExec(() -> { + for (TableItem item : table.widget.getItems()) { + item.setChecked(false); + } + }); + // don't close, because you cannot apply empty mutators + } + + /** + * Assumes the Mutator tab is active and custom mutator mode is selected. + * @param table where to check the mutator + * @param mutator which is set to active + */ + private void setMutator(SWTBotTable table, Mutators mutator) { + Display.getDefault().syncExec(() -> { + for (TableItem item : table.widget.getItems()) { + if (item.getData().equals(mutator.name())) { + item.setChecked(true); + break; + } + } + }); + } + + /** + * Closes the configuration shell and applies, if possible. + */ + private void closeConfigurationShell() { + SWTBotShell shell = bot.shell(RUN_CONFIGURATIONS); + SWTBotButton apply = shell.bot().button("Apply"); + if (apply.isEnabled()) { + apply.click(); + } + shell.close(); + } + + public void runWithConfiguration(String configurationName) { + activateConfiguration(configurationName); + SWTBotShell shell = bot.shell(RUN_CONFIGURATIONS); + shell.bot() + .button(RUN) + .click(); + shell.close(); + } + } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java index a08a07d8..63b21096 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java @@ -22,6 +22,7 @@ import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.runner.PitOptions; import org.pitest.pitclipse.ui.swtbot.PitOptionsNotifier; import org.pitest.pitclipse.ui.swtbot.SWTBotMenuHelper; @@ -32,7 +33,6 @@ public class RunMenu { private static final String RUN_AS = "Run As"; private static final String PIT_MUTATION_TEST = "PIT Mutation Test"; private static final String JUNIT_TEST = "JUnit Test"; - private static final String RUN_CONFIGURATIONS = "Run Configurations"; private final SWTWorkbenchBot bot; private final RunConfigurationSelector runConfigurationSelector; @@ -56,6 +56,10 @@ public void runPit() { ensureSelectTestConfigurationDialogIsClosed(); } + public void runPitWithConfiguration(String configurationName) { + runConfigurationSelector.runWithConfiguration(configurationName); + } + /** * The 'Select a Test Configuration' dialog only appears when Pit has been * launched at least once. If it is not found then PIT has been launched @@ -78,13 +82,61 @@ private void ensureSelectTestConfigurationDialogIsClosed() { } public List runConfigurations() { - SWTBotMenuHelper menuHelper = new SWTBotMenuHelper(); - menuHelper.findMenu(bot.menu(RUN), RUN_CONFIGURATIONS).click(); return runConfigurationSelector.getConfigurations(); } + public void createRunConfiguration(String configurationName, String projectName, String className) { + runConfigurationSelector.createRunConfiguration(configurationName, projectName, className); + } + + public void setProjectForConfiguration(String configurationName, String project) { + runConfigurationSelector.setProjectForConfiguration(configurationName, project); + } + + public void setTestClassForConfiguration(String configurationName, String testClass) { + runConfigurationSelector.setTestClassForConfiguration(configurationName, testClass); + } + public PitOptions getLastUsedPitOptions() { return PitOptionsNotifier.INSTANCE.getLastUsedOptions(); } + /** + * Selects the given group in the mutator launch configuration tab. + * @param configurationName where to select the group + * @param mutatorGroup which group to select + */ + public void setMutatorGroup(String configurationName, Mutators mutatorGroup) { + runConfigurationSelector.setMutatorGroup(configurationName, mutatorGroup); + + } + + /** + * Checks all custom mutators for the given configuration + * @param configurationName of the configuration, where to select all mutators + */ + public void checkAllMutators(String configurationName) { + runConfigurationSelector.checkAllMutators(configurationName); + } + + /** + * Adds the given mutator to the list of checked mutators for the given + * configuration + * @param configurationName which the mutator should be added + * @param mutator which should be added + */ + public void setAdditionalCustomMutator(String configurationName, Mutators mutator) { + runConfigurationSelector.setAdditionalCustomMutator(configurationName, mutator); + } + + /** + * Unchecks all custom mutators and selects the given mutator for the + * configuration specified by the given name + * @param configurationName where to select the one mutator + * @param mutator which to select in the configuration + */ + public void setOneCustomMutator(String configurationName, Mutators mutator) { + runConfigurationSelector.setOneCustomMutator(configurationName, mutator); + } + } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 52048f34..c46b9738 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -26,7 +26,9 @@ import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -51,6 +53,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.launch.ui.PitLaunchShortcut; import org.pitest.pitclipse.runner.results.DetectionStatus; @@ -301,11 +304,7 @@ protected static void consoleContains(int generatedMutants, int killedMutants, int testsRun, int testsPerMutations) { PAGES.views().waitForTestsAreRunOnConsole(); - SWTBotView consoleView = bot.viewByPartName("Console"); - consoleView.show(); - String consoleText = consoleView.bot() - .styledText().getText() - .replace("\r", ""); + final String consoleText = getConsoleText(); // System.out.println(consoleText); if (generatedMutants == 0) { @@ -343,6 +342,41 @@ protected static void consoleContains(int generatedMutants, int killedMutants, } } + private static String getConsoleText() { + SWTBotView consoleView = bot.viewByPartName("Console"); + consoleView.show(); + return consoleView.bot() + .styledText().getText() + .replace("\r", ""); + } + + /** + * Asserts that the only active mutator was the given mutator. + * @param mutators which should be the only active mutator + */ + protected static void mutatorIs(Mutators mutators) { + final String consoleText = getConsoleText(); + assertThat(consoleText, containsString(String.format("mutators=[%s]", mutators.name()))); + } + + /** + * Asserts that the only active mutators are the given mutators. + * @param mutators which should be the only active mutators + */ + protected static void mutatorsAre(Collection mutators) { + final String consoleText = getConsoleText(); + // build String to match against console text + Iterator iterator = mutators.iterator(); + StringBuilder sb = new StringBuilder(); + while (iterator.hasNext()) { + sb.append(iterator.next().name()); + if (iterator.hasNext()) { + sb.append(','); + } + } + assertThat(consoleText, containsString(String.format("mutators=[%s]", sb.toString()))); + } + /** * The expectedMutationsTable String argument represents the expected * mutations table, this is an example of String: diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java new file mode 100644 index 00000000..c30d791b --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -0,0 +1,202 @@ +package org.pitest.pitclipse.ui.tests; + +import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.pitest.pitclipse.core.Mutators; + +/** + * @author Jonas Kutscha + * + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class PitclipseRunConfigurationMutationTabTest extends AbstractPitclipseSWTBotTest { + private static final String TEST_PROJECT = "org.pitest.pitclipse.testprojects.twoclasses"; + private static final String TEST_CONFIG_NAME = "Testing Config"; + private static final String FOO_BAR_PACKAGE = "foo.bar"; + private static final String FOO_TEST_CLASS = "FooTest"; + + private static final int COVERAGE = 40; + private static final int TESTED_CLASSES = 2; + + @BeforeClass + public static void initialSetup() throws CoreException { + importTestProject(TEST_PROJECT); + PAGES.getRunMenu().createRunConfiguration(TEST_CONFIG_NAME, + TEST_PROJECT, + FOO_BAR_PACKAGE + '.' + FOO_TEST_CLASS); + } + + + @Test + public void useOldDefaultsMutatorsGroup() { + // set OLD_DEFAULTS mutators + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.OLD_DEFAULTS); + // run test and confirm result is as expected + PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0); + mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | replaced return of integer sized value with (x == 0 ? 1 : 0)"); + } + + @Test + public void useDefaultMutatorsGroup() { + // set DEFAULTS mutators + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.DEFAULTS); + // run test and confirm result is as expected + PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0); + mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | replaced int return with 0 for foo/bar/Bar::f\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f"); + } + + @Test + public void useStrongerMutatorsGroup() { + // now set STRONGER mutators + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.STRONGER); + // run test and confirm result is as expected + PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0); + mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | removed conditional - replaced equality check with false\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | removed conditional - replaced equality check with false\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | replaced int return with 0 for foo/bar/Bar::f\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f"); + } + + @Test + public void checkOneMutant() { + PAGES.getRunMenu().setOneCustomMutator(TEST_CONFIG_NAME, Mutators.NEGATE_CONDITIONALS); + // run test and confirm result is as expected + PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0); + // check that mutator was selected as only mutator + mutatorIs(Mutators.NEGATE_CONDITIONALS); + mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional"); + } + + @Test + public void useAllMutatorsGroup() { + // now set ALL mutators group + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.ALL); + // run test and confirm result is as expected + PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1); + mutationsAre(getAllMutantsResult()); + } + + @Test + public void checkAllMutants() { + PAGES.getRunMenu().checkAllMutators(TEST_CONFIG_NAME); + // run test and confirm result is as expected + PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1); + mutationsAre(getAllMutantsResult()); + } + + private String getAllMutantsResult(){ + return "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | Substituted 1 with -1\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | Substituted 1 with -1\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | Substituted 1 with 0\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | Substituted 1 with 0\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | Substituted 1 with 0\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | Substituted 1 with 2\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | not equal to equal\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | not equal to greater or equal\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | not equal to greater than\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | not equal to less or equal\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | not equal to less than\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | removed call to java/util/ArrayList::size\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | removed conditional - replaced equality check with false\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 7 | removed conditional - replaced equality check with true\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 10 | Substituted 0 with -1\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 10 | Substituted 0 with -1\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 10 | Substituted 0 with 1\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 10 | Substituted 0 with 1\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 10 | Substituted 0 with 1\n" + + "SURVIVED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "KILLED | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 6 | removed call to java/util/ArrayList::\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 6 | removed call to java/util/ArrayList::\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | Substituted 1 with -1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | Substituted 1 with -1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | Substituted 1 with 2\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | negated conditional\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | not equal to equal\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | not equal to greater or equal\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | not equal to greater than\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | not equal to less or equal\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | not equal to less than\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | removed call to java/util/ArrayList::size\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | removed conditional - replaced equality check with false\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 7 | removed conditional - replaced equality check with true\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Decremented (--a) integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Decremented (a--) integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Incremented (++a) integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Incremented (a++) integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Negated integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Replaced integer addition with division\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Replaced integer addition with modulus\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Replaced integer addition with multiplication\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Replaced integer operation by second member\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Replaced integer operation with first member\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Substituted 1 with -1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Substituted 1 with -1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | Substituted 1 with 2\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | replaced int return with 0 for foo/bar/Bar::f\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 8 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 10 | Substituted 0 with -1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 10 | Substituted 0 with -1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 10 | Substituted 0 with 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 10 | Substituted 0 with 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 10 | Substituted 0 with 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Bar | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Decremented (--a) integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Decremented (a--) integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Incremented (++a) integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Incremented (a++) integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Negated integer local variable number 1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Replaced integer addition with division\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Replaced integer addition with modulus\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Replaced integer addition with multiplication\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Replaced integer addition with subtraction\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Replaced integer operation by second member\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Replaced integer operation with first member\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Substituted 1 with -1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Substituted 1 with -1\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Substituted 1 with 0\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Substituted 1 with 2\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f\n" + + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | replaced return of integer sized value with (x == 0 ? 1 : 0)"; + + } +} From 651cda44a42a605a91911e3df9e638bd7439697a Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Mon, 26 Jul 2021 10:13:41 +0200 Subject: [PATCH 18/50] Removed unused LambdaLabelProvider --- .../launch/ui/LambdaLabelProvider.java | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/LambdaLabelProvider.java diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/LambdaLabelProvider.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/LambdaLabelProvider.java deleted file mode 100644 index 45d734e5..00000000 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/LambdaLabelProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.pitest.pitclipse.launch.ui; - -import org.eclipse.jface.viewers.ColumnLabelProvider; - -import java.util.function.Function; - -class LambdaLabelProvider extends ColumnLabelProvider { - - private final Function labelProvider; - - public LambdaLabelProvider(Function labelProvider) { - super(); - this.labelProvider = labelProvider; - } - - @Override - @SuppressWarnings("unchecked") - public String getText(Object element) { - try { - return labelProvider.apply((T) element); - } - catch (ClassCastException e) { - return ""; - } - } - -} \ No newline at end of file From bac44f523c92e5f587e959d0de0faae639ae8c1e Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Mon, 26 Jul 2021 17:30:21 +0200 Subject: [PATCH 19/50] Sevaral fixes after code review for mutator tab --- .../pitclipse/core/PitCoreActivator.java | 4 +- .../core/preferences/PitPreferences.java | 18 ++++---- .../pitclipse/launch/ui/PitArgumentsTab.java | 28 ++++++------- .../pitclipse/launch/ui/PitMutatorsTab.java | 13 ++++-- .../config/LaunchConfigurationWrapper.java | 22 +++++----- .../preferences/ui/PitPreferencePage.java | 4 +- .../pageobjects/PackageExplorer.java | 28 +++++++------ .../pageobjects/PitPreferenceSelector.java | 12 +++--- .../pageobjects/PitRunConfiguration.java | 42 ++++++++++++++++--- .../pageobjects/RunConfigurationSelector.java | 21 +++++----- .../ui/tests/AbstractPitclipseSWTBotTest.java | 2 + .../ui/tests/PitclipseOptionsTest.java | 2 +- ...clipseRunConfigurationMutationTabTest.java | 17 +++++++- 13 files changed, 133 insertions(+), 80 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index 38252af7..f88f63ea 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -19,7 +19,7 @@ import static org.eclipse.core.runtime.FileLocator.getBundleFile; import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS; import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_SCOPE; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; @@ -272,7 +272,7 @@ public PitConfiguration getConfiguration() { boolean parallelRun = preferenceStore.getBoolean(RUN_IN_PARALLEL); boolean incrementalAnalysis = preferenceStore.getBoolean(INCREMENTAL_ANALYSIS); String excludedClasses = preferenceStore.getString(EXCLUDED_CLASSES); - String excludedMethods = preferenceStore.getString(EXCLUDE_METHODS); + String excludedMethods = preferenceStore.getString(EXCLUDED_METHODS); String avoidCallsTo = preferenceStore.getString(AVOID_CALLS); String timeout = preferenceStore.getString(TIMEOUT); String timeoutFactor = preferenceStore.getString(TIMEOUT_FACTOR); diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java index f8937adb..2107ed0d 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright 2012-2019 Phil Glover and contributors - * + * Copyright 2012-2021 Phil Glover and contributors + * * 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 @@ -22,20 +22,20 @@ public final class PitPreferences { public static final String MUTATORS_LABEL = "Mutators"; public static final String MUTATORS = "pitMutators"; - + public static final String INDIVIDUAL_MUTATORS = "pitIndividualMutators"; public static final String INCREMENTAL_ANALYSIS_LABEL = "Use &incremental analysis"; public static final String INCREMENTAL_ANALYSIS = "incrementalAnalysis"; - public static final String EXCLUDE_CLASSES_LABEL = "E&xcluded classes (e.g.*IntTest)"; + public static final String EXCLUDED_CLASSES_LABEL = "E&xcluded classes (e.g.*IntTest)"; public static final String EXCLUDED_CLASSES = "excludedClasses"; public static final String RUN_IN_PARALLEL_LABEL = "Mutation tests run in para&llel"; public static final String RUN_IN_PARALLEL = "runInParallel"; - public static final String EXCLUDE_METHODS_LABEL = "Excluded &methods (e.g.*toString*)"; - public static final String EXCLUDE_METHODS = "excludedMethods"; + public static final String EXCLUDED_METHODS_LABEL = "Excluded &methods (e.g.*toString*)"; + public static final String EXCLUDED_METHODS = "excludedMethods"; public static final String AVOID_CALLS_LABEL = "&Avoid calls to"; public static final String AVOID_CALLS = "avoidCallsTo"; @@ -45,7 +45,7 @@ public final class PitPreferences { public static final String TIMEOUT_FACTOR_LABEL = "Timeout &Factor"; public static final String TIMEOUT_FACTOR = "pitTimeoutFactor"; - + public static final String EXECUTION_SCOPE_LABEL = "Pit execution scope"; public static final String EXECUTION_SCOPE = "pitExecutionMode"; diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index dfc9ea8e..ca1c4aa5 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright 2012-2019 Phil Glover and contributors - * + * Copyright 2012-2021 Phil Glover and contributors + * * 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 @@ -20,8 +20,8 @@ import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL_LABEL; import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; @@ -89,7 +89,7 @@ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab { private Text excludedClassesText; private Text excludedMethodsText; private Text avoidCallsTo; - + @Override public Image getImage() { Bundle bundle = Platform.getBundle(PitLaunchUiActivator.PLUGIN_ID); @@ -98,7 +98,7 @@ public Image getImage() { icon = ImageDescriptor.createFromURL(iconURL).createImage(); return icon; } - + @Override public void dispose() { if (icon != null) { @@ -258,14 +258,14 @@ private void createFilters(Font font, Composite comp) { group.setLayoutData(groupGrid); GridLayout groupLayout = new GridLayout(1, false); group.setLayout(groupLayout); - + runInParallel = createNewCheckBox(font, group, groupLayout.numColumns, RUN_IN_PARALLEL_LABEL); incrementalAnalysis = createNewCheckBox(font, group, groupLayout.numColumns, INCREMENTAL_ANALYSIS_LABEL); } - - private void createPreferences(Font font, Composite comp) { + + private void createPreferences(Font font, Composite comp) { Group misc = new Group(comp, SWT.NONE); misc.setText(" Preferences "); misc.setFont(font); @@ -274,11 +274,11 @@ private void createPreferences(Font font, Composite comp) { misc.setLayoutData(miscGrid); GridLayout miscLayout = new GridLayout(2, false); misc.setLayout(miscLayout); - + excludedClassesText = createTextPreference(font, misc, miscLayout.numColumns, - EXCLUDE_CLASSES_LABEL); + EXCLUDED_CLASSES_LABEL); excludedMethodsText = createTextPreference(font, misc, miscLayout.numColumns, - EXCLUDE_METHODS_LABEL); + EXCLUDED_METHODS_LABEL); avoidCallsTo = createTextPreference(font, misc, miscLayout.numColumns, AVOID_CALLS_LABEL); } diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index f3121087..1ac497ba 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright 2012-2019 Phil Glover and contributors - * + * Copyright 2012-2021 Jonas Kutscha and contributors + * * 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 @@ -64,6 +64,7 @@ /** * Tab allowing to configure a PIT analyze. + * @author Jonas Kutscha */ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { public static final String NAME = "Mutators"; @@ -110,6 +111,7 @@ public void dispose() { } } + @Override public void initializeFrom(ILaunchConfiguration config) { PitConfiguration preferences = PitCoreActivator.getDefault().getConfiguration(); mutators = PitArgumentsTab.getAttributeFromConfig(config, MUTATORS, preferences.getMutators()); @@ -138,6 +140,7 @@ private void intializeMutatorsTable(ILaunchConfiguration config) { } } + @Override public void createControl(Composite parent) { mainComp = new Composite(parent, SWT.NONE); setControl(mainComp); @@ -321,6 +324,7 @@ protected static void addSeparator(Composite parent) { GridDataFactory.fillDefaults().span(NUMBER_OF_COLUMNS, 1).applyTo(separator); } + @Override public void performApply(ILaunchConfigurationWorkingCopy config) { config.setAttribute(INDIVIDUAL_MUTATORS, getIndividualMutators()); if (isBasicMutatorGroup()) { @@ -347,6 +351,7 @@ private String getIndividualMutators() { return sb.toString(); } + @Override public void setDefaults(ILaunchConfigurationWorkingCopy workingCopy) { // Intentionally left empty } diff --git a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java index a60f14d8..38a19d2c 100644 --- a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java +++ b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java @@ -16,8 +16,14 @@ package org.pitest.pitclipse.launch.config; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; +import static org.pitest.pitclipse.core.PitCoreActivator.getDefault; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; + +import java.io.File; +import java.math.BigDecimal; +import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -35,14 +41,8 @@ import org.pitest.pitclipse.runner.PitOptions.PitOptionsBuilder; import org.pitest.pitclipse.runner.config.PitConfiguration; -import java.io.File; -import java.math.BigDecimal; -import java.util.List; - -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; -import static org.pitest.pitclipse.core.PitCoreActivator.getDefault; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; public class LaunchConfigurationWrapper { @@ -127,8 +127,6 @@ public PitOptions.PitOptionsBuilder getPitOptionsBuilder() throws CoreException int timeout = pitConfiguration.getTimeout(); BigDecimal timeoutFactor = pitConfiguration.getTimeoutFactor(); - - PitOptionsBuilder builder = PitOptions.builder().withClassesToMutate(classPath) .withSourceDirectories(sourceDirs).withReportDirectory(reportDir).withThreads(threadCount) .withExcludedClasses(excludedClasses).withExcludedMethods(excludedMethods) diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java index 82bbfc70..6ac15b9b 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java @@ -69,11 +69,11 @@ private void createAvoidCallsToField() { } private void createExcludeClassesField() { - addField(new StringFieldEditor(EXCLUDED_CLASSES, EXCLUDE_CLASSES_LABEL, getFieldEditorParent())); + addField(new StringFieldEditor(EXCLUDED_CLASSES, EXCLUDED_CLASSES_LABEL, getFieldEditorParent())); } private void createExcludeMethodsField() { - addField(new StringFieldEditor(EXCLUDE_METHODS, EXCLUDE_METHODS_LABEL, getFieldEditorParent())); + addField(new StringFieldEditor(EXCLUDED_METHODS, EXCLUDED_METHODS_LABEL, getFieldEditorParent())); } private void createUseIncrementalAnalysisOption() { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java index 794bbd2d..ab7bfd9b 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright 2012-2019 Phil Glover and contributors - * + * Copyright 2012-2021 Phil Glover and contributors + * * 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 @@ -16,20 +16,20 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; - -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; - -import java.util.List; -import java.util.NoSuchElementException; - import static com.google.common.base.Strings.isNullOrEmpty; import static org.junit.Assert.fail; import static org.pitest.pitclipse.ui.behaviours.pageobjects.SwtBotTreeHelper.selectAndExpand; import static org.pitest.pitclipse.ui.util.VerifyUtil.isNotNull; +import java.util.List; +import java.util.NoSuchElementException; + +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; + public class PackageExplorer { private static final String PACKAGE_EXPLORER = "Package Explorer"; @@ -57,6 +57,8 @@ private void openProject(SWTBotTreeItem project) { } private SWTBotTreeItem getProject(String projectName) { + // You need to have the focus on the explorer, otherwise the project doesn't get + // selected properly bot.viewByTitle(PACKAGE_EXPLORER).show(); SWTBotTreeItem[] treeItems = bot.viewByTitle(PACKAGE_EXPLORER).bot().tree().getAllItems(); for (SWTBotTreeItem treeItem : treeItems) { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java index ecbf37f4..87ce0d8f 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java @@ -29,8 +29,8 @@ import static java.math.BigDecimal.ZERO; import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_CLASSES_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDE_METHODS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_SCOPE_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_LABEL; @@ -101,19 +101,19 @@ public void setPitIncrementalAnalysisEnabled(boolean incremental) { } public String getExcludedClasses() { - return getText().from(EXCLUDE_CLASSES_LABEL); + return getText().from(EXCLUDED_CLASSES_LABEL); } public void setExcludedClasses(String excludedClasses) { - setTextFor(EXCLUDE_CLASSES_LABEL).to(excludedClasses); + setTextFor(EXCLUDED_CLASSES_LABEL).to(excludedClasses); } public String getExcludedMethods() { - return getText().from(EXCLUDE_METHODS_LABEL); + return getText().from(EXCLUDED_METHODS_LABEL); } public void setExcludedMethods(String excludedMethods) { - setTextFor(EXCLUDE_METHODS_LABEL).to(excludedMethods); + setTextFor(EXCLUDED_METHODS_LABEL).to(excludedMethods); } public String getAvoidCallsTo() { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitRunConfiguration.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitRunConfiguration.java index 26bf93f7..c7d3a7e4 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitRunConfiguration.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitRunConfiguration.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright 2012-2019 Phil Glover and contributors - * + * Copyright 2012-2021 Phil Glover and contributors + * * 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 @@ -24,16 +24,46 @@ import com.google.common.collect.ImmutableList; public class PitRunConfiguration { - + /** + * Name of the configuration + */ private final String name; + /** + * List of the projects which are in the scope of mutation + */ private final List projects; + /** + * Name of the test object. Can be the name of a class or directory. + */ private final String testObject; + /** + * True, if the test object is a class + */ + private final boolean testClass; + /** + * True, if the tests should be run in pararllel + */ private final boolean runInParallel; + /** + * True, if incremental analysis should be used + */ private final boolean incrementalAnalysis; + /** + * List of globs to match against class names. Matching classes will be excluded + * from mutation. + */ private final String excludedClasses; + /** + * List of globs to match against method names. Methods matching the globs will + * be excluded from mutation. + */ private final String excludedMethods; + /** + * List of packages and classes which are to be considered outside the scope of + * mutation. Any lines of code containing calls to these classes will not be + * mutated. + */ private final String avoidCallsTo; - private final boolean testClass; private PitRunConfiguration(String name, List projects, String testObject, boolean testClass, boolean runInParallel, boolean incrementalAnalysis, String excludedClasses, String excludedMethods, diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index f2b23c0f..2ff5ae18 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -80,8 +80,8 @@ private PitRunConfiguration getPitConfiguration(SWTBotTreeItem treeItem) { } boolean runInParallel = bot.checkBox(PitPreferences.RUN_IN_PARALLEL_LABEL).isChecked(); boolean incrementalAnalysis = bot.checkBox(PitPreferences.INCREMENTAL_ANALYSIS_LABEL).isChecked(); - String excludedClasses = bot.textWithLabel(PitPreferences.EXCLUDE_CLASSES_LABEL).getText(); - String excludedMethods = bot.textWithLabel(PitPreferences.EXCLUDE_METHODS_LABEL).getText(); + String excludedClasses = bot.textWithLabel(PitPreferences.EXCLUDED_CLASSES_LABEL).getText(); + String excludedMethods = bot.textWithLabel(PitPreferences.EXCLUDED_METHODS_LABEL).getText(); String avoidCallsTo = bot.textWithLabel(PitPreferences.AVOID_CALLS_LABEL).getText(); return new Builder().withName(name).withProjects(project).withRunInParallel(runInParallel) .withIncrementalAnalysis(incrementalAnalysis).withExcludedClasses(excludedClasses) @@ -107,20 +107,23 @@ private SWTBotShell activateShell() { private SWTBotTreeItem getPitConfigurationItem() { activateShell(); + final String itemName = "PIT Mutation Test"; for (SWTBotTreeItem treeItem : bot.tree().getAllItems()) { - if ("PIT Mutation Test".equals(treeItem.getText())) { + if (itemName.equals(treeItem.getText())) { return treeItem.select().expand(); } } - return null; + throw new RuntimeException("Could not find '" + itemName + "' in the configurations tab."); } private void activateConfiguration(String configurationName) { for (SWTBotTreeItem i : getPitConfigurationItem().getItems()) { if (i.getText().equals(configurationName)) { i.click(); + return; } } + throw new RuntimeException("Could not find '" + configurationName + "' in the configurations of PIT."); } public void activateMutatorsTab(String configurationName) { @@ -179,8 +182,8 @@ private void setConfiguration(PitRunConfiguration config) { } else { bot.checkBox(PitPreferences.INCREMENTAL_ANALYSIS_LABEL).deselect(); } - bot.textWithLabel(PitPreferences.EXCLUDE_CLASSES_LABEL).setText(config.getExcludedClasses()); - bot.textWithLabel(PitPreferences.EXCLUDE_METHODS_LABEL).setText(config.getExcludedMethods()); + bot.textWithLabel(PitPreferences.EXCLUDED_CLASSES_LABEL).setText(config.getExcludedClasses()); + bot.textWithLabel(PitPreferences.EXCLUDED_METHODS_LABEL).setText(config.getExcludedMethods()); bot.textWithLabel(PitPreferences.AVOID_CALLS_LABEL).setText(config.getAvoidCallsTo()); // close shell and save closeConfigurationShell(); @@ -286,9 +289,7 @@ public void runWithConfiguration(String configurationName) { activateConfiguration(configurationName); SWTBotShell shell = bot.shell(RUN_CONFIGURATIONS); shell.bot() - .button(RUN) - .click(); - shell.close(); + .button(RUN) + .click(); } - } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 90d69260..6f9ee5bb 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -368,6 +368,7 @@ private static String getConsoleText() { * @param mutators which should be the only active mutator */ protected static void mutatorIs(Mutators mutators) { + PAGES.views().waitForTestsAreRunOnConsole(); final String consoleText = getConsoleText(); assertThat(consoleText, containsString(String.format("mutators=[%s]", mutators.name()))); } @@ -377,6 +378,7 @@ protected static void mutatorIs(Mutators mutators) { * @param mutators which should be the only active mutators */ protected static void mutatorsAre(Collection mutators) { + PAGES.views().waitForTestsAreRunOnConsole(); final String consoleText = getConsoleText(); // build String to match against console text Iterator iterator = mutators.iterator(); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index ecb1fd8f..e3a831da 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -175,7 +175,7 @@ public void launchConfigurationsWithChangedValues() throws CoreException { preferenceStore.setValue(PitPreferences.INCREMENTAL_ANALYSIS, false); preferenceStore.setValue(PitPreferences.EXCLUDED_CLASSES, PitConfiguration.DEFAULT_EXCLUDED_CLASSES); preferenceStore.setValue(PitPreferences.AVOID_CALLS, PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST); - preferenceStore.setValue(PitPreferences.EXCLUDE_METHODS, ""); + preferenceStore.setValue(PitPreferences.EXCLUDED_METHODS, ""); } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index c30d791b..8ea0ed6f 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -1,3 +1,18 @@ +/******************************************************************************* + * Copyright 2012-2021 Jonas Kutscha and contributors + * + * 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.pitest.pitclipse.ui.tests; import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; @@ -102,7 +117,7 @@ public void useAllMutatorsGroup() { coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1); mutationsAre(getAllMutantsResult()); } - + @Test public void checkAllMutants() { PAGES.getRunMenu().checkAllMutators(TEST_CONFIG_NAME); From 0ed7deca859ca969637a0a3e88df39e63fa86856 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Mon, 26 Jul 2021 17:52:36 +0200 Subject: [PATCH 20/50] Delete test run config after class --- .../pageobjects/RunConfigurationSelector.java | 18 ++++++++++++++++++ .../ui/behaviours/pageobjects/RunMenu.java | 8 ++++++++ ...tclipseRunConfigurationMutationTabTest.java | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index 2ff5ae18..99d7b8ed 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -17,6 +17,7 @@ package org.pitest.pitclipse.ui.behaviours.pageobjects; import static com.google.common.collect.ImmutableList.builder; +import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive; import java.util.Iterator; import java.util.List; @@ -43,6 +44,7 @@ public class RunConfigurationSelector { private static final String RUN = "Run"; private static final String RUN_CONFIGURATIONS = "Run Configurations"; private final SWTWorkbenchBot bot; + private final static String DELETE_SHELL_TITLE = "Confirm Launch Configuration Deletion"; public RunConfigurationSelector(SWTWorkbenchBot bot) { this.bot = bot; @@ -292,4 +294,20 @@ public void runWithConfiguration(String configurationName) { .button(RUN) .click(); } + + /** + * Deletes the pit run configuration, which matches the given name + * @param configurationName which should be deleted + */ + public void removeConfig(String configurationName) { + for (SWTBotTreeItem i : getPitConfigurationItem().getItems()) { + if (i.getText().equals(configurationName)) { + i.contextMenu("Delete").click(); + bot.waitUntil(shellIsActive(DELETE_SHELL_TITLE)); + bot.shell(DELETE_SHELL_TITLE).bot().button("Delete").click(); + return; + } + } + throw new RuntimeException("Could not find '" + configurationName + "' in the configurations of PIT."); + } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java index 63b21096..c0365dcb 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java @@ -139,4 +139,12 @@ public void setOneCustomMutator(String configurationName, Mutators mutator) { runConfigurationSelector.setOneCustomMutator(configurationName, mutator); } + /** + * Removes the pit run configuration, which matches the given name. + * @param configurationName which should be removed + */ + public void removeConfig(String configurationName) { + runConfigurationSelector.removeConfig(configurationName); + } + } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index 8ea0ed6f..1da3f1b4 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,6 +47,11 @@ public static void initialSetup() throws CoreException { FOO_BAR_PACKAGE + '.' + FOO_TEST_CLASS); } + @AfterClass + public static void removeConfig() { + PAGES.getRunMenu().removeConfig(TEST_CONFIG_NAME); + } + @Test public void useOldDefaultsMutatorsGroup() { From 487259313c4df40853fde4dc09cfc8441b9dffc3 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Tue, 27 Jul 2021 09:08:36 +0200 Subject: [PATCH 21/50] Clean console after tests in MutationTabTest --- .../ui/tests/PitclipseRunConfigurationMutationTabTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index 1da3f1b4..3644d6c0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -52,6 +53,10 @@ public static void removeConfig() { PAGES.getRunMenu().removeConfig(TEST_CONFIG_NAME); } + @After + public void clearConsole() { + PAGES.views().clearConsole(); + } @Test public void useOldDefaultsMutatorsGroup() { From b05572da791192e8d14676358c8f7786ba9f29a7 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Tue, 27 Jul 2021 11:32:06 +0200 Subject: [PATCH 22/50] Use now implemented PIT API to get mutator ids --- .../org/pitest/pitclipse/core/Mutators.java | 10 +++---- .../pitclipse/launch/ui/PitMutatorsTab.java | 30 +------------------ .../ui/PitMutatorsPreferencePage.java | 4 +-- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java index 27d4cc47..0b0674eb 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java @@ -17,6 +17,7 @@ package org.pitest.pitclipse.core; import java.util.ArrayList; +import java.util.List; import org.pitest.mutationtest.engine.gregor.config.Mutator; @@ -25,7 +26,6 @@ * The name of new values must be the exact String, which is used by PIT * in the class {@link Mutator}. */ -@SuppressWarnings("checkstyle:LineLength") public enum Mutators { OLD_DEFAULTS("Old defaults", "&Old default Mutators"), DEFAULTS("Defaults", "&Default Mutators"), @@ -96,8 +96,8 @@ public boolean isActiveByDefault() { return activeByDefault; } - public static ArrayList getMainGroup() { - final ArrayList mainGroup = new ArrayList(); + public static List getMainGroup() { + final ArrayList mainGroup = new ArrayList<>(); mainGroup.add(DEFAULTS); mainGroup.add(STRONGER); mainGroup.add(ALL); @@ -105,8 +105,8 @@ public static ArrayList getMainGroup() { return mainGroup; } - public static ArrayList getDefaultMutators() { - ArrayList defaultMutators = new ArrayList(); + public static List getDefaultMutators() { + ArrayList defaultMutators = new ArrayList<>(); for (Mutators m : values()) { if (m.isActiveByDefault()) { defaultMutators.add(m.name()); diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 1ac497ba..f03813df 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -20,12 +20,9 @@ import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; -import java.lang.reflect.Field; import java.net.URL; import java.util.Arrays; -import java.util.Collection; import java.util.Iterator; -import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; @@ -56,7 +53,6 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; import org.osgi.framework.Bundle; -import org.pitest.mutationtest.engine.gregor.MethodMutatorFactory; import org.pitest.mutationtest.engine.gregor.config.Mutator; import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.PitCoreActivator; @@ -77,7 +73,6 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private static final String CUSTOM_MUTATOR_RADIO_DATA = "CUSTOM"; private static final String COLUMN_DESCRIPTION = "Description"; private static final String COLUMN_NAME = "Name"; - private static final String MUTATORS_FIELD_NAME = "MUTATORS"; private static final String NO_DESCRIPTION_TEXT = "No description found yet."; private static final String ERROR_MESSAGE = "At least one mutator or mutator group needs to be selected!"; private Image icon; @@ -284,37 +279,14 @@ public void update(ViewerCell cell) { } } }); - - try { - mutatorsTable.setInput(getPitMutators()); - } catch (Exception e) { - throw new RuntimeException("Input for mutatorTable was not set correctly.", e); - } - + mutatorsTable.setInput(Mutator.allMutatorIds()); colName.getColumn().pack(); colDescription.getColumn().pack(); - mutatorsTable.getTable().setEnabled(true); - // Update the tab when a hook is activated / deactivated mutatorsTable.addCheckStateListener(event -> updateLaunchConfigurationDialog()); } - /** - * Hack because the Mutator.java from pit does not allow to get the keys of the - * mutators yet.
- * Should be replaced, if - * Pit PR gets merged. - * @return keys of all mutators as Strings - * @throws Exception if the reflection failed in any way - */ - @SuppressWarnings("unchecked") - private Collection getPitMutators() throws Exception { - Field field = Mutator.class.getDeclaredField(MUTATORS_FIELD_NAME); - field.setAccessible(true); - return ((Map>) field.get(null)).keySet(); - } - private void disableTableIfUnused() { mutatorsTable.getTable().setEnabled(customMutatorsButton.getSelection()); } diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java index 081a376b..3bab49b3 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java @@ -20,7 +20,7 @@ import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_DESCRIPTION_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_LABEL; -import java.util.ArrayList; +import java.util.List; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.RadioGroupFieldEditor; @@ -43,7 +43,7 @@ public void createFieldEditors() { } private void createExecutionModeRadioButtons() { - ArrayList values = Mutators.getMainGroup(); + List values = Mutators.getMainGroup(); String[][] mutatorValues = new String[values.size()][2]; int i = 0; for (Mutators mutator : values) { From 436bcf9bfb84a1d8a8b0aa8c8c0ffaa73fb1096e Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 29 Jul 2021 09:09:31 +0200 Subject: [PATCH 23/50] Dispose SWT widgets properly for the mutants tab --- .../pitclipse/launch/ui/PitMutatorsTab.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index f03813df..392685d6 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -81,9 +81,6 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private Button customMutatorsButton; private Button[] groupButtons; private Composite mainComp; - private Label descriptionLabel; - private Composite grouopComposite; - private Label mutateWithLabel; @Override public String getName() { @@ -101,9 +98,14 @@ public Image getImage() { @Override public void dispose() { - if (icon != null) { + if (icon != null && !icon.isDisposed()) { icon.dispose(); } + if (mainComp != null && !mainComp.isDisposed()) { + mainComp.dispose(); + } + // always call super.dispose() last, if dispose() is overridden. + super.dispose(); } @Override @@ -161,7 +163,7 @@ public void createControl(Composite parent) { * @param parent where to add the description */ private void createDescription(Composite parent) { - descriptionLabel = new Label(parent, SWT.NONE); + final Label descriptionLabel = new Label(parent, SWT.NONE); descriptionLabel.setText(DESCRIPTION_TEXT); GridDataFactory.swtDefaults().indent(5, 0).applyTo(descriptionLabel); Link link = new Link(parent, SWT.NONE); @@ -184,10 +186,10 @@ public void widgetSelected(SelectionEvent e) { */ private void createMutatorGroupsWidgets(Font font, Composite parent) { // add own composite to group options closer together - grouopComposite = new Composite(parent, SWT.NONE); + final Composite grouopComposite = new Composite(parent, SWT.NONE); GridDataFactory.swtDefaults().span(NUMBER_OF_COLUMNS, 1).applyTo(grouopComposite); GridLayoutFactory.swtDefaults().numColumns(NUMBER_OF_COLUMNS).applyTo(grouopComposite); - mutateWithLabel = new Label(grouopComposite, SWT.NONE); + final Label mutateWithLabel = new Label(grouopComposite, SWT.NONE); mutateWithLabel.setFont(font); mutateWithLabel.setText("Mutate with: "); GridDataFactory.swtDefaults().applyTo(mutateWithLabel); From 599257628bc66832e652db3999a8a596fa0c0a93 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Tue, 3 Aug 2021 23:40:20 +0200 Subject: [PATCH 24/50] Update existing tests to use resturctured tests and fixes --- .../ui/behaviours/pageobjects/Console.java | 19 +++++++++++++++++++ .../ui/tests/AbstractPitclipseSWTBotTest.java | 7 ++++--- .../ui/tests/PitclipseOptionsTest.java | 2 +- ...clipseRunConfigurationMutationTabTest.java | 15 +++++++-------- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/Console.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/Console.java index b9b09e7e..dd0a6e79 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/Console.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/Console.java @@ -15,6 +15,8 @@ ******************************************************************************/ package org.pitest.pitclipse.ui.behaviours.pageobjects; +import java.util.List; + import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; @@ -39,4 +41,21 @@ public String getText() { console.show(); return console.bot().styledText().getText(); } + + /** + * If the Console view can be found, clear it + */ + public void clearConsole() { + List allViews = bot.views(); + for (SWTBotView view : allViews) { + if ("Console".equals(view.getTitle())) { + view.show(); + if (!view.bot().styledText().getText().isEmpty()) { + // use button to clear, because setting the text to "" works not synchronously + view.toolbarButton("Clear Console").click(); + } + return; + } + } + } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 47ae5ac4..78085589 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -18,6 +18,7 @@ import static java.lang.Integer.parseInt; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -25,6 +26,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -314,9 +316,8 @@ protected static void runProjectTest(final String projectName) throws CoreExcept * Asserts that the only active mutator was the given mutator. * @param mutators which should be the only active mutator */ - protected static void mutatorIs(Mutators mutators) { - final String consoleText = PAGES.getConsole().getText(); - assertThat(consoleText, containsString(String.format("mutators=[%s]", mutators.name()))); + protected static void mutatorIs(Mutators mutator) { + mutatorsAre(Arrays.asList(new Mutators[] { mutator })); } /** diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index 8e06c7fb..ca637975 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -73,7 +73,7 @@ public void useOldDefaultsMutators() throws CoreException { PAGES.getWindowsMenu().setMutators(Mutators.OLD_DEFAULTS); try { runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); - coverageReportGenerated(2, 80, 0); + coverageReportGenerated(2, 80, 0, 6, 0); mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index 3644d6c0..cb720c93 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -55,7 +55,7 @@ public static void removeConfig() { @After public void clearConsole() { - PAGES.views().clearConsole(); + PAGES.getConsole().clearConsole(); } @Test @@ -64,7 +64,7 @@ public void useOldDefaultsMutatorsGroup() { PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.OLD_DEFAULTS); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); - coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0, 8, 0); mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + @@ -81,7 +81,7 @@ public void useDefaultMutatorsGroup() { PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.DEFAULTS); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); - coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0, 6, 0); mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 8 | Replaced integer addition with subtraction\n" + @@ -96,7 +96,7 @@ public void useStrongerMutatorsGroup() { PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.STRONGER); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); - coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0, 8, 0); mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | removed conditional - replaced equality check with false\n" + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + @@ -112,7 +112,7 @@ public void checkOneMutant() { PAGES.getRunMenu().setOneCustomMutator(TEST_CONFIG_NAME, Mutators.NEGATE_CONDITIONALS); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); - coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0, 2, 0); // check that mutator was selected as only mutator mutatorIs(Mutators.NEGATE_CONDITIONALS); mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + @@ -125,7 +125,7 @@ public void useAllMutatorsGroup() { PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.ALL); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); - coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1, 83, 1); mutationsAre(getAllMutantsResult()); } @@ -134,7 +134,7 @@ public void checkAllMutants() { PAGES.getRunMenu().checkAllMutators(TEST_CONFIG_NAME); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); - coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1, 83, 1); mutationsAre(getAllMutantsResult()); } @@ -223,6 +223,5 @@ private String getAllMutantsResult(){ "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | Substituted 1 with 2\n" + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f\n" + "NO_COVERAGE | " + TEST_PROJECT + " |foo.bar | foo.bar.Foo | 8 | replaced return of integer sized value with (x == 0 ? 1 : 0)"; - } } From 74d46b973f1a2f03ac3958a07a03b0a5ff00876c Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Wed, 4 Aug 2021 08:14:56 +0200 Subject: [PATCH 25/50] Reworked selection mechanism for tests --- .../pitclipse/launch/ui/PitArgumentsTab.java | 1 - .../org.pitest.pitclipse.ui.tests.launch | 40 ------------------- .../pageobjects/RunConfigurationSelector.java | 26 +++++++----- .../ui/behaviours/pageobjects/RunMenu.java | 2 +- .../ui/swtbot/PitResultNotifier.java | 3 +- .../ui/tests/PitclipseOptionsTest.java | 2 +- ...clipseRunConfigurationMutationTabTest.java | 4 +- 7 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index ca1c4aa5..5c46c423 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -58,7 +58,6 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import org.osgi.framework.Bundle; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; diff --git a/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch b/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch deleted file mode 100644 index 7df304b7..00000000 --- a/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index 99d7b8ed..bd81edf5 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -35,6 +35,7 @@ import org.pitest.pitclipse.launch.ui.PitArgumentsTab; import org.pitest.pitclipse.launch.ui.PitMutatorsTab; import org.pitest.pitclipse.ui.behaviours.pageobjects.PitRunConfiguration.Builder; +import org.pitest.pitclipse.ui.swtbot.PitResultNotifier.PitSummary; import org.pitest.pitclipse.ui.swtbot.SWTBotMenuHelper; import com.google.common.collect.ImmutableList; @@ -239,8 +240,9 @@ public void checkAllMutators(String configurationName) { bot.radio(PitMutatorsTab.CUSTOM_MUTATOR_RADIO_TEXT).click(); SWTBotTable table = bot.table(); Display.getDefault().syncExec(() -> { - for (TableItem item : table.widget.getItems()) { - item.setChecked(true); + final int itemCount = table.widget.getItems().length; + for (int i = 0; i < itemCount; i++) { + table.getTableItem(i).check(); } }); closeConfigurationShell(); @@ -265,14 +267,7 @@ private void uncheckAllMutators() { * @param mutator which is set to active */ private void setMutator(SWTBotTable table, Mutators mutator) { - Display.getDefault().syncExec(() -> { - for (TableItem item : table.widget.getItems()) { - if (item.getData().equals(mutator.name())) { - item.setChecked(true); - break; - } - } - }); + table.getTableItem(mutator.getDescriptor()).check(); } /** @@ -287,12 +282,21 @@ private void closeConfigurationShell() { shell.close(); } - public void runWithConfiguration(String configurationName) { + /** + * Runs the configuration specified by the given name and waits for it to be + * finished. + * @param configurationName + */ + public void runWithConfigurationAndWaitForIt(String configurationName) { + // reset Summary result + PitSummary.INSTANCE.resetSummary(); activateConfiguration(configurationName); SWTBotShell shell = bot.shell(RUN_CONFIGURATIONS); shell.bot() .button(RUN) .click(); + // wait for pit + PitSummary.INSTANCE.waitForPitToFinish(); } /** diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java index 864711f8..69cf55a8 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java @@ -59,7 +59,7 @@ public void runPit() { } public void runPitWithConfiguration(String configurationName) { - runConfigurationSelector.runWithConfiguration(configurationName); + runConfigurationSelector.runWithConfigurationAndWaitForIt(configurationName); } /** diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitResultNotifier.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitResultNotifier.java index 368afe84..451d8805 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitResultNotifier.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/swtbot/PitResultNotifier.java @@ -124,7 +124,8 @@ public void waitForPitToFinish() { } /** - * Waits for PIT to finish. + * Waits for PIT to finish.
+ * Mandatory to call {@link #resetSummary()} before. * @param timeOut after the wait stops, if not set use SWTBotPreferences.TIMEOUT */ public void waitForPitToFinish(long timeOut) { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index ca637975..c1dfebf8 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -73,7 +73,7 @@ public void useOldDefaultsMutators() throws CoreException { PAGES.getWindowsMenu().setMutators(Mutators.OLD_DEFAULTS); try { runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); - coverageReportGenerated(2, 80, 0, 6, 0); + coverageReportGenerated(2, 80, 0, 8, 0); mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional\n" + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 10 | replaced return of integer sized value with (x == 0 ? 1 : 0)\n" + "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index cb720c93..c4cd5138 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -125,7 +125,7 @@ public void useAllMutatorsGroup() { PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.ALL); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); - coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1, 83, 1); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1, 84, 1); mutationsAre(getAllMutantsResult()); } @@ -134,7 +134,7 @@ public void checkAllMutants() { PAGES.getRunMenu().checkAllMutators(TEST_CONFIG_NAME); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); - coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1, 83, 1); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 1, 84, 1); mutationsAre(getAllMutantsResult()); } From 6095bd364f97de841a468a6e2b8e5c9d54581c94 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Wed, 4 Aug 2021 08:21:22 +0200 Subject: [PATCH 26/50] Added missing import --- .../src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index 5c46c423..ca1c4aa5 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -58,6 +58,7 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; +import org.osgi.framework.Bundle; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; From e6088843030a158efa058a374c0a6f0c464ffdc5 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Wed, 4 Aug 2021 13:05:32 +0200 Subject: [PATCH 27/50] Added image registry for icons --- .../build.properties | 1 + .../org.pitest.pitclipse.core/icons/pit.gif | Bin 0 -> 217 bytes .../pitclipse/core/PitCoreActivator.java | 38 ++++++++++++++++++ .../pitclipse/launch/ui/PitArgumentsTab.java | 22 +--------- .../pitclipse/launch/ui/PitMutatorsTab.java | 16 +------- 5 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 bundles/org.pitest.pitclipse.core/icons/pit.gif diff --git a/bundles/org.pitest.pitclipse.core/build.properties b/bundles/org.pitest.pitclipse.core/build.properties index d3f1f000..a028eff6 100644 --- a/bundles/org.pitest.pitclipse.core/build.properties +++ b/bundles/org.pitest.pitclipse.core/build.properties @@ -1,5 +1,6 @@ source.. = src/ bin.includes = plugin.xml,\ META-INF/,\ + icons/,\ . jars.compile.order = . diff --git a/bundles/org.pitest.pitclipse.core/icons/pit.gif b/bundles/org.pitest.pitclipse.core/icons/pit.gif new file mode 100644 index 0000000000000000000000000000000000000000..d40430cd0caaef3f2d7a249c0cecba329f906fdd GIT binary patch literal 217 zcmZ?wbhEHb6krfwaA9Cj{K>+>00cT90wmV5f+745L(_lu_W#_S|9QLq^LPIj?D;P_ z;lKRk|JDos+b;YczV3hQ#{cQt{&ye$Kk?N6i!c9Qe)a$MyZ`q;{D1iI|I<(ZpMU=U z`s@GizyJUL4>A@Nu!bct^rS>~Ij&mw`oz9f-1|StaIDO>5o5FDWK2|a>|kj0N;{bn zRCI!Ku|j}_lEmr747@x!_mdN@|7PXxSsrmSCv4aBwuMz^?Rf4s>$ctb{MXQ3t=U77 G!5RSeOks%t literal 0 HcmV?d00001 diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index f88f63ea..11431580 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -31,20 +31,29 @@ import java.io.File; import java.io.IOException; import java.math.BigDecimal; +import java.net.URL; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.preferences.ScopedPreferenceStore; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.pitest.pitclipse.runner.config.PitConfiguration; import org.pitest.pitclipse.runner.config.PitExecutionMode; @@ -78,6 +87,15 @@ public class PitCoreActivator extends Plugin { // The shared instance private static PitCoreActivator plugin; + /** + * Image registry for this plug in + */ + private ImageRegistry imageRegistry; + /** + * Key under which the pit icon is put in the registry + */ + private static final String PIT_ICON = "org.pitest.pitclipse.pitIcon"; + private IPreferenceStore preferences; private List pitClasspath = new ArrayList<>(); @@ -88,6 +106,24 @@ public class PitCoreActivator extends Plugin { private File historyFile; + + /** + * Must run in UI thread. + */ + private void initIcons() { + imageRegistry = new ImageRegistry(); + Bundle bundle = FrameworkUtil.getBundle(getClass()); + URL url = FileLocator.find(bundle, new Path("icons/pit.gif"), null); + imageRegistry.put(PIT_ICON, ImageDescriptor.createFromURL(url).createImage()); + } + + /** + * @return Returns the pit icon. + */ + public Image getPitIcon() { + return imageRegistry.get(PIT_ICON); + } + public List getPitClasspath() { return pitClasspath; } @@ -141,6 +177,8 @@ public void start(BundleContext context) throws Exception { // NOPMD - Base pitestJunit5PluginClasspath = new ArrayList<>(); addMavenJarToClasspath(pitestJunit5PluginClasspath, ORG_PITEST_JUNIT5_PLUGIN, "pitest-junit5-plugin.jar"); } + // needs to run in UI thread to create icons + Display.getDefault().syncExec(this::initIcons); } private void addMavenJarToClasspath(List classpath, String bundleName, String jarFile) throws IOException { diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index ca1c4aa5..256fc725 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -31,19 +31,13 @@ import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; -import java.net.URL; - import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ui.JavaElementLabelProvider; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -58,7 +52,6 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import org.osgi.framework.Bundle; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; @@ -76,8 +69,6 @@ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab { public static final String SCOPE_GROUP_TEXT = " Mutation Scope "; public static final String PROJECT_TEXT = "Project to mutate: "; - private Image icon; - private Text testClassText; private Text projectText; private Button testClassRadioButton; @@ -92,18 +83,7 @@ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab { @Override public Image getImage() { - Bundle bundle = Platform.getBundle(PitLaunchUiActivator.PLUGIN_ID); - Path path = new Path("icons/pit.gif"); - URL iconURL = FileLocator.find(bundle, path, null); - icon = ImageDescriptor.createFromURL(iconURL).createImage(); - return icon; - } - - @Override - public void dispose() { - if (icon != null) { - icon.dispose(); - } + return PitCoreActivator.getDefault().getPitIcon(); } @Override diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 392685d6..d8f9cce1 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -20,20 +20,15 @@ import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; -import java.net.URL; import java.util.Arrays; import java.util.Iterator; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CellLabelProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; @@ -52,7 +47,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; -import org.osgi.framework.Bundle; import org.pitest.mutationtest.engine.gregor.config.Mutator; import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.PitCoreActivator; @@ -75,7 +69,6 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private static final String COLUMN_NAME = "Name"; private static final String NO_DESCRIPTION_TEXT = "No description found yet."; private static final String ERROR_MESSAGE = "At least one mutator or mutator group needs to be selected!"; - private Image icon; private String mutators; private CheckboxTableViewer mutatorsTable; private Button customMutatorsButton; @@ -89,18 +82,11 @@ public String getName() { @Override public Image getImage() { - Bundle bundle = Platform.getBundle(PitLaunchUiActivator.PLUGIN_ID); - Path path = new Path("icons/pit.gif"); - URL iconURL = FileLocator.find(bundle, path, null); - icon = ImageDescriptor.createFromURL(iconURL).createImage(); - return icon; + return PitCoreActivator.getDefault().getPitIcon(); } @Override public void dispose() { - if (icon != null && !icon.isDisposed()) { - icon.dispose(); - } if (mainComp != null && !mainComp.isDisposed()) { mainComp.dispose(); } From 891acc795c7cbd650ac5adac77e8932e1325f1a8 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Wed, 4 Aug 2021 19:02:13 +0200 Subject: [PATCH 28/50] Added all missing mutatot descriptions --- .../org/pitest/pitclipse/core/Mutators.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java index 0b0674eb..b316d3f7 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java @@ -1,12 +1,12 @@ /******************************************************************************* * Copyright 2012-2021 Phil Glover and contributors - * + * * 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 @@ -39,6 +39,7 @@ public enum Mutators { RETURN_VALS("Return Values", "Mutates the return values of method calls. Depending on the return type of the method another mutation is used"), VOID_METHOD_CALLS("Void Method Call", "Removes method calls to void methods", true), CONSTRUCTOR_CALLS("Constructor Call", "Replaces constructor calls with null values"), + RETURNS("All Returns", "Group which includes all return mutators"), EMPTY_RETURNS("Empty Returns", "Replaces return values with an 'empty' value", true), FALSE_RETURNS("False Returns", "Replaces primitive and boxed boolean return values with false", true), TRUE_RETURNS("True Returns", "Replaces primitive and boxed boolean return values with true", true), @@ -47,6 +48,10 @@ public enum Mutators { NON_VOID_METHOD_CALLS("Non Void Method Call", "Removes method calls to non void methods. Their return value is replaced by the Java Default Value for that specific type"), PRIMITIVE_RETURNS("Primite Returns", "Replaces int, short, long, char, float and double return values with 0", true), REMOVE_CONDITIONALS("Remove Conditionals", "Removes all conditionals statements such that the guarded statements always execute"), + REMOVE_CONDITIONALS_EQ_IF("Remove Equal Conditionals If", "Remove equal conditions and replace with true, execute if part"), + REMOVE_CONDITIONALS_EQ_ELSE("Remove Equal Conditionals Else", "Remove equal conditions and replace with false, execute else part"), + REMOVE_CONDITIONALS_ORD_IF("Remove Order Checks If", "Remove order conditions and replace with true, execute if part"), + REMOVE_CONDITIONALS_ORD_ELSE("Remove Order Checks Else", "Remove order conditions and replace with false, execute else part"), REMOVE_INCREMENTS("Remove Increments", "Removes local variable increments"), EXPERIMENTAL_ARGUMENT_PROPAGATION("Experimentation Argument Propagation", "Replaces method call with one of its parameters of matching type"), EXPERIMENTAL_BIG_INTEGER("Experimental Big Integer", "Swaps big integer methods"), @@ -55,10 +60,35 @@ public enum Mutators { EXPERIMENTAL_SWITCH("Experimental Switch", "Finds the first label within a switch statement that differs from the default label. Mutates the switch statement by replacing the default label (wherever it is used) with this label. All the other labels are replaced by the default one"), ABS("Negation", "Replaces any use of a numeric variable (local variable, field, array cell) with its negation"), AOR("Arithmetic Operator Replacement", "Like the Math mutator, replaces binary arithmetic operations for either integer or floating-point arithmetic with another operation"), + AOR_1("Arithmetic Operator Replacement 1", "+ -> -, - -> +, * -> /, / -> *, % -> *"), + AOR_2("Arithmetic Operator Replacement 2", "+ -> *, - -> *, * -> %, / -> %, % -> /"), + AOR_3("Arithmetic Operator Replacement 3", "+ -> /, - -> /, * -> +, / -> +, % -> +"), + AOR_4("Arithmetic Operator Replacement 4", "+ -> %, - -> %, * -> -, / -> -, % -> -"), AOD("Arithmetic Operator Deletion", "Replaces an arithmetic operation with one of its members"), + AOD1("Arithmetic Operator Deletion 1", "int a = b + c; -> int a = b;"), + AOD2("Arithmetic Operator Deletion 2", "int a = b + c; -> int a = c;"), CRCR("Constant Replacement", "Like the Inline Constant mutator, mutates inline constant"), + CRCR1("Constant Replacement 1", "Replaces the inline constant c with 1"), + CRCR2("Constant Replacement 2", "Replaces the inline constant c with 0"), + CRCR3("Constant Replacement 3", "Replaces the inline constant c with -1"), + CRCR4("Constant Replacement 4", "Replaces the inline constant c with -c"), + CRCR5("Constant Replacement 5", "Replaces the inline constant c with c+1"), + CRCR6("Constant Replacement 6", "Replaces the inline constant c with c-1"), OBBN("Bitwise Operator", "Mutates bitwise and (&) and or (|)"), + OBBN1("Bitwise Operator 1", "a & b; -> a | b;"), + OBBN2("Bitwise Operator 2", "a & b; -> a;"), + OBBN3("Bitwise Operator 3", "a & b; -> b;"), ROR("Relational Operator Replacement", "Replaces a relational operator with another one"), + ROR1("Relational Operator Replacement 1", "< -> <=, <= -> <, > -> <, >= -> <, == -> <, != -> <"), + ROR2("Relational Operator Replacement 2", "< -> >, <= -> >, > -> <=, >= -> <=, == -> <=, != -> <="), + ROR3("Relational Operator Replacement 3", "< -> >=, <= -> >=, > -> >=, >= -> >, == -> >, != -> >"), + ROR4("Relational Operator Replacement 4", "< -> ==, <= -> ==, > -> ==, >= -> ==, == -> >=, != -> >="), + ROR5("Relational Operator Replacement 5", "< -> !=, <= -> !=, > -> !=, >= -> !=, == -> !=, != -> =="), + // XXX REMOVE_SWITCH("",""), no data on the page of pitest + UOI1("Unary Operator Insertion 1", "Inserts a unary operator to a variable call from the variable a to a++"), + UOI2("Unary Operator Insertion 2", "Inserts a unary operator to a variable call from the variable a to a--"), + UOI3("Unary Operator Insertion 3", "Inserts a unary operator to a variable call from the variable a to ++a"), + UOI4("Unary Operator Insertion 4", "Inserts a unary operator to a variable call from the variable a to --a"), UOI("Unary Operator Insertion", "Inserts a unary operator (increment or decrement) to a variable call. Affects local variables, array variables, fields and parameters"); /** From 1a9e20bd7cddfba3252ac5f2f34707fa47d0be96 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Thu, 5 Aug 2021 13:48:15 +0200 Subject: [PATCH 29/50] Added deletted launch config back --- .../org.pitest.pitclipse.ui.tests.launch | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch diff --git a/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch b/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch new file mode 100644 index 00000000..c975aa1f --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 1bde0fd9e55cab3d033c70634fe717b9d86eccb9 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Thu, 5 Aug 2021 14:56:41 +0200 Subject: [PATCH 30/50] Added // NOSONAR and added check for mutator changes --- .../META-INF/MANIFEST.MF | 3 +- .../pitclipse/runner/PitRunnerTest.java | 80 ++++++++++++++----- ...clipseRunConfigurationMutationTabTest.java | 12 +-- 3 files changed, 66 insertions(+), 29 deletions(-) diff --git a/tests/org.pitest.pitclipse.runner.tests/META-INF/MANIFEST.MF b/tests/org.pitest.pitclipse.runner.tests/META-INF/MANIFEST.MF index ac11b564..d7f8b8e7 100644 --- a/tests/org.pitest.pitclipse.runner.tests/META-INF/MANIFEST.MF +++ b/tests/org.pitest.pitclipse.runner.tests/META-INF/MANIFEST.MF @@ -13,4 +13,5 @@ Require-Bundle: org.apache.commons.lang3;bundle-version="3.1.0", org.objenesis;bundle-version="1.0.0", org.junit;bundle-version="4.12.0", org.eclipse.core.runtime;bundle-version="[3.11.1,4.0.0)", - com.google.guava + com.google.guava, + org.pitest.pitclipse.core diff --git a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitRunnerTest.java b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitRunnerTest.java index bdcbceab..20ae3a19 100644 --- a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitRunnerTest.java +++ b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitRunnerTest.java @@ -16,17 +16,17 @@ package org.pitest.pitclipse.runner; -import org.eclipse.core.runtime.Platform; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; -import org.junit.Before; -import org.junit.Test; -import org.pitest.mutationtest.MutationResultListenerFactory; -import org.pitest.pitclipse.example.empty.EmptyClass; -import org.pitest.pitclipse.runner.results.ObjectFactory; -import org.pitest.pitclipse.runner.results.mutations.RecordingMutationsDispatcher; -import org.pitest.util.ServiceLoader; +import static java.util.Arrays.asList; +import static java.util.stream.Collectors.toSet; +import static org.eclipse.core.runtime.FileLocator.getBundleFile; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.collection.IsEmptyCollection.empty; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -38,16 +38,19 @@ import java.util.List; import java.util.Set; -import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toSet; -import static org.eclipse.core.runtime.FileLocator.getBundleFile; -import static org.hamcrest.CoreMatchers.hasItems; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.collection.IsEmptyCollection.empty; +import org.eclipse.core.runtime.Platform; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; +import org.junit.Before; +import org.junit.Test; +import org.pitest.mutationtest.MutationResultListenerFactory; +import org.pitest.mutationtest.engine.gregor.config.Mutator; +import org.pitest.pitclipse.core.Mutators; +import org.pitest.pitclipse.example.empty.EmptyClass; +import org.pitest.pitclipse.runner.results.ObjectFactory; +import org.pitest.pitclipse.runner.results.mutations.RecordingMutationsDispatcher; +import org.pitest.util.ServiceLoader; /** * Tests the behavior of a {@link PitRunner}'s functions. @@ -177,5 +180,38 @@ private static List classPathWithPitestAndJUnit() throws IOException { new File("lib/junit.jar").getAbsolutePath() ); } - + + /** + * This test case is in place to detect whether the supplied mutators from pit + * changed and we need to change {@link Mutators}. + */ + @Test + public void testTheMutatorApiOfPit() { + assertThat(getPitMutatorsAsString(), equalTo(getExpectedMutatorsAsString())); + } + + private String getPitMutatorsAsString() { + StringBuilder sb = new StringBuilder(); + for (String mutator : Mutator.allMutatorIds()) { + sb.append(mutator).append(','); + } + return sb.toString(); + } + + private String getExpectedMutatorsAsString() { + return "INVERT_NEGS,RETURN_VALS,INLINE_CONSTS,MATH,VOID_METHOD_CALLS," + + "NEGATE_CONDITIONALS,CONDITIONALS_BOUNDARY,INCREMENTS," + + "REMOVE_INCREMENTS,NON_VOID_METHOD_CALLS,CONSTRUCTOR_CALLS," + + "REMOVE_CONDITIONALS_EQ_IF,REMOVE_CONDITIONALS_EQ_ELSE," + + "REMOVE_CONDITIONALS_ORD_IF,REMOVE_CONDITIONALS_ORD_ELSE," + + "REMOVE_CONDITIONALS,TRUE_RETURNS,FALSE_RETURNS," + + "PRIMITIVE_RETURNS,EMPTY_RETURNS,NULL_RETURNS," + + "RETURNS,EXPERIMENTAL_MEMBER_VARIABLE," + + "EXPERIMENTAL_SWITCH,EXPERIMENTAL_ARGUMENT_PROPAGATION," + + "EXPERIMENTAL_NAKED_RECEIVER,EXPERIMENTAL_BIG_INTEGER," + + "AOR_1,AOR_2,AOR_3,AOR_4,ABS,AOD1,AOD2,CRCR1,CRCR2,CRCR3,CRCR4," + + "CRCR5,CRCR6,OBBN1,OBBN2,OBBN3,ROR1,ROR2,ROR3,ROR4,ROR5,UOI1," + + "UOI2,UOI3,UOI4,REMOVE_SWITCH,OLD_DEFAULTS,STRONGER,ALL,DEFAULTS," + + "AOR,AOD,CRCR,OBBN,ROR,UOI,"; + } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index 5be8370f..f69133a0 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -59,7 +59,7 @@ public void clearConsole() { } @Test - public void useOldDefaultsMutatorsGroup() { + public void useOldDefaultsMutatorsGroup() { // NOSONAR // set OLD_DEFAULTS mutators PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.OLD_DEFAULTS); // run test and confirm result is as expected @@ -76,7 +76,7 @@ public void useOldDefaultsMutatorsGroup() { } @Test - public void useDefaultMutatorsGroup() { + public void useDefaultMutatorsGroup() { // NOSONAR // set DEFAULTS mutators PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.DEFAULTS); // run test and confirm result is as expected @@ -91,7 +91,7 @@ public void useDefaultMutatorsGroup() { } @Test - public void useStrongerMutatorsGroup() { + public void useStrongerMutatorsGroup() { // NOSONAR // now set STRONGER mutators PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.STRONGER); // run test and confirm result is as expected @@ -108,7 +108,7 @@ public void useStrongerMutatorsGroup() { } @Test - public void checkOneMutant() { + public void checkOneMutant() { // NOSONAR PAGES.getRunMenu().setOneCustomMutator(TEST_CONFIG_NAME, Mutators.NEGATE_CONDITIONALS); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); @@ -120,7 +120,7 @@ public void checkOneMutant() { } @Test - public void useAllMutatorsGroup() { + public void useAllMutatorsGroup() { // NOSONAR // now set ALL mutators group PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.ALL); // run test and confirm result is as expected @@ -130,7 +130,7 @@ public void useAllMutatorsGroup() { } @Test - public void checkAllMutants() { + public void checkAllMutants() { // NOSONAR PAGES.getRunMenu().checkAllMutators(TEST_CONFIG_NAME); // run test and confirm result is as expected PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); From 8978c28add259bf9bcf9f0fc65c83898a06401d0 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 5 Aug 2021 19:03:22 +0200 Subject: [PATCH 31/50] Added test class for pit api and not use other class --- .../pitclipse/runner/MutatorApiOfPitTest.java | 60 +++++++++++++++++++ .../pitclipse/runner/PitRunnerTest.java | 37 ------------ 2 files changed, 60 insertions(+), 37 deletions(-) create mode 100644 tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/MutatorApiOfPitTest.java diff --git a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/MutatorApiOfPitTest.java b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/MutatorApiOfPitTest.java new file mode 100644 index 00000000..57e558f0 --- /dev/null +++ b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/MutatorApiOfPitTest.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright 2021 Jonas Kutscha and contributors + * + * 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.pitest.pitclipse.runner; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import org.junit.Test; +import org.pitest.mutationtest.engine.gregor.config.Mutator; +import org.pitest.pitclipse.core.Mutators; + +/** + * This test case is in place to detect whether the supplied mutators from pit + * changed and we need to change {@link Mutators}. + */ +public class MutatorApiOfPitTest { + @Test + public void testTheMutatorApiOfPit() { + assertThat(getPitMutatorsAsString(), equalTo(getExpectedMutatorsAsString())); + } + + private String getPitMutatorsAsString() { + StringBuilder sb = new StringBuilder(); + for (String mutator : Mutator.allMutatorIds()) { + sb.append(mutator).append('\n'); + } + return sb.toString(); + } + + private String getExpectedMutatorsAsString() { + return "INVERT_NEGS\nRETURN_VALS\nINLINE_CONSTS\nMATH\nVOID_METHOD_CALLS\n" + + "NEGATE_CONDITIONALS\nCONDITIONALS_BOUNDARY\nINCREMENTS\n" + + "REMOVE_INCREMENTS\nNON_VOID_METHOD_CALLS\nCONSTRUCTOR_CALLS\n" + + "REMOVE_CONDITIONALS_EQ_IF\nREMOVE_CONDITIONALS_EQ_ELSE\n" + + "REMOVE_CONDITIONALS_ORD_IF\nREMOVE_CONDITIONALS_ORD_ELSE\n" + + "REMOVE_CONDITIONALS\nTRUE_RETURNS\nFALSE_RETURNS\n" + + "PRIMITIVE_RETURNS\nEMPTY_RETURNS\nNULL_RETURNS\n" + + "RETURNS\nEXPERIMENTAL_MEMBER_VARIABLE\n" + + "EXPERIMENTAL_SWITCH\nEXPERIMENTAL_ARGUMENT_PROPAGATION\n" + + "EXPERIMENTAL_NAKED_RECEIVER\nEXPERIMENTAL_BIG_INTEGER\n" + + "AOR_1\nAOR_2\nAOR_3\nAOR_4\nABS\nAOD1\nAOD2\nCRCR1\nCRCR2\nCRCR3\nCRCR4\n" + + "CRCR5\nCRCR6\nOBBN1\nOBBN2\nOBBN3\nROR1\nROR2\nROR3\nROR4\nROR5\nUOI1\n" + + "UOI2\nUOI3\nUOI4\nREMOVE_SWITCH\nOLD_DEFAULTS\nSTRONGER\nALL\nDEFAULTS\n" + + "AOR\nAOD\nCRCR\nOBBN\nROR\nUOI\n"; + } +} diff --git a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitRunnerTest.java b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitRunnerTest.java index 20ae3a19..dde6dd28 100644 --- a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitRunnerTest.java +++ b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitRunnerTest.java @@ -24,7 +24,6 @@ import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.collection.IsEmptyCollection.empty; @@ -45,8 +44,6 @@ import org.junit.Before; import org.junit.Test; import org.pitest.mutationtest.MutationResultListenerFactory; -import org.pitest.mutationtest.engine.gregor.config.Mutator; -import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.example.empty.EmptyClass; import org.pitest.pitclipse.runner.results.ObjectFactory; import org.pitest.pitclipse.runner.results.mutations.RecordingMutationsDispatcher; @@ -180,38 +177,4 @@ private static List classPathWithPitestAndJUnit() throws IOException { new File("lib/junit.jar").getAbsolutePath() ); } - - /** - * This test case is in place to detect whether the supplied mutators from pit - * changed and we need to change {@link Mutators}. - */ - @Test - public void testTheMutatorApiOfPit() { - assertThat(getPitMutatorsAsString(), equalTo(getExpectedMutatorsAsString())); - } - - private String getPitMutatorsAsString() { - StringBuilder sb = new StringBuilder(); - for (String mutator : Mutator.allMutatorIds()) { - sb.append(mutator).append(','); - } - return sb.toString(); - } - - private String getExpectedMutatorsAsString() { - return "INVERT_NEGS,RETURN_VALS,INLINE_CONSTS,MATH,VOID_METHOD_CALLS," + - "NEGATE_CONDITIONALS,CONDITIONALS_BOUNDARY,INCREMENTS," + - "REMOVE_INCREMENTS,NON_VOID_METHOD_CALLS,CONSTRUCTOR_CALLS," + - "REMOVE_CONDITIONALS_EQ_IF,REMOVE_CONDITIONALS_EQ_ELSE," + - "REMOVE_CONDITIONALS_ORD_IF,REMOVE_CONDITIONALS_ORD_ELSE," + - "REMOVE_CONDITIONALS,TRUE_RETURNS,FALSE_RETURNS," + - "PRIMITIVE_RETURNS,EMPTY_RETURNS,NULL_RETURNS," + - "RETURNS,EXPERIMENTAL_MEMBER_VARIABLE," + - "EXPERIMENTAL_SWITCH,EXPERIMENTAL_ARGUMENT_PROPAGATION," + - "EXPERIMENTAL_NAKED_RECEIVER,EXPERIMENTAL_BIG_INTEGER," + - "AOR_1,AOR_2,AOR_3,AOR_4,ABS,AOD1,AOD2,CRCR1,CRCR2,CRCR3,CRCR4," + - "CRCR5,CRCR6,OBBN1,OBBN2,OBBN3,ROR1,ROR2,ROR3,ROR4,ROR5,UOI1," + - "UOI2,UOI3,UOI4,REMOVE_SWITCH,OLD_DEFAULTS,STRONGER,ALL,DEFAULTS," + - "AOR,AOD,CRCR,OBBN,ROR,UOI,"; - } } From d3227e40c05f012c210efac9917d6d9f8c808fe9 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 5 Aug 2021 19:53:30 +0200 Subject: [PATCH 32/50] Fine tuned conditions and reached coverage goal --- .../pitclipse/launch/ui/PitMutatorsTab.java | 8 ++----- .../pageobjects/RunConfigurationSelector.java | 16 ++++++-------- .../ui/behaviours/pageobjects/RunMenu.java | 11 +++++----- ...clipseRunConfigurationMutationTabTest.java | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index d8f9cce1..dacd2c23 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -156,10 +156,9 @@ private void createDescription(Composite parent) { link.setText("" + MUTATOR_LINK_TEXT + ""); link.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) { // NOSONAR we don't want to open external links Program.launch(MUTATOR_LINK); } - }); GridDataFactory.swtDefaults().applyTo(link); } @@ -330,9 +329,6 @@ private void createSpacer(Composite comp) { * @return true, if a button was selected */ private boolean updateSelectionOfGroup(String value) { - if (groupButtons == null || value == null) { - return false; - } boolean found = false; for (Button button : groupButtons) { boolean selection = false; @@ -360,7 +356,7 @@ private boolean isBasicMutatorGroup() { */ @Override public boolean canSave() { - return isBasicMutatorGroup() || (!isBasicMutatorGroup() && mutatorsTable.getCheckedElements().length > 0); + return isBasicMutatorGroup() || mutatorsTable.getCheckedElements().length > 0; } @Override diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index bd81edf5..22843177 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -215,14 +215,12 @@ public void setMutatorGroup(String configurationName, Mutators mutatorGroup) { closeConfigurationShell(); } - public void setAdditionalCustomMutator(String configurationName, Mutators mutator) { + public void toggleCustomMutator(String configurationName, Mutators mutator) { activateMutatorsTab(configurationName); SWTBotRadio radioButton = bot.radio(PitMutatorsTab.CUSTOM_MUTATOR_RADIO_TEXT); - if (!radioButton.isSelected()) { - radioButton.click(); - } + radioButton.click(); SWTBotTable table = bot.table(); - setMutator(table, mutator); + toggleMutator(table, mutator); closeConfigurationShell(); } @@ -231,7 +229,7 @@ public void setOneCustomMutator(String configurationName, Mutators mutator) { bot.radio(PitMutatorsTab.CUSTOM_MUTATOR_RADIO_TEXT).click(); uncheckAllMutators(); SWTBotTable table = bot.table(); - setMutator(table, mutator); + toggleMutator(table, mutator); closeConfigurationShell(); } @@ -266,8 +264,8 @@ private void uncheckAllMutators() { * @param table where to check the mutator * @param mutator which is set to active */ - private void setMutator(SWTBotTable table, Mutators mutator) { - table.getTableItem(mutator.getDescriptor()).check(); + private void toggleMutator(SWTBotTable table, Mutators mutator) { + table.getTableItem(mutator.getDescriptor()).toggleCheck(); } /** @@ -279,7 +277,7 @@ private void closeConfigurationShell() { if (apply.isEnabled()) { apply.click(); } - shell.close(); + shell.bot().button("Close").click(); } /** diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java index 69cf55a8..4564ad4a 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java @@ -122,13 +122,12 @@ public void checkAllMutators(String configurationName) { } /** - * Adds the given mutator to the list of checked mutators for the given - * configuration - * @param configurationName which the mutator should be added - * @param mutator which should be added + * Toggle the given mutator in the table of mutators + * @param configurationName which the mutator should be toggled + * @param mutator which should be toggled */ - public void setAdditionalCustomMutator(String configurationName, Mutators mutator) { - runConfigurationSelector.setAdditionalCustomMutator(configurationName, mutator); + public void toggleCustomMutator(String configurationName, Mutators mutator) { + runConfigurationSelector.toggleCustomMutator(configurationName, mutator); } /** diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index f69133a0..ba101f73 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -58,6 +58,28 @@ public void clearConsole() { PAGES.getConsole().clear(); } + @Test + public void pressMutatorGroupButtons() { // NOSONAR + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.OLD_DEFAULTS); + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.DEFAULTS); + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.STRONGER); + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.ALL); + PAGES.getRunMenu().setMutatorGroup(TEST_CONFIG_NAME, Mutators.DEFAULTS); + } + + @Test + public void selectNoMutator() { // NOSONAR + PAGES.getRunMenu().setOneCustomMutator(TEST_CONFIG_NAME, Mutators.NEGATE_CONDITIONALS); + PAGES.getRunMenu().toggleCustomMutator(TEST_CONFIG_NAME, Mutators.NEGATE_CONDITIONALS); + // should switch back to previous selected mutator + PAGES.getRunMenu().runPitWithConfiguration(TEST_CONFIG_NAME); + coverageReportGenerated(TESTED_CLASSES, COVERAGE, 0, 2, 0); + // check that mutator was selected as only mutator + mutatorIs(Mutators.NEGATE_CONDITIONALS); + mutationsAre( "SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional\n" + + "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional"); + } + @Test public void useOldDefaultsMutatorsGroup() { // NOSONAR // set OLD_DEFAULTS mutators From 25c6715c2e4bb0c5a610f5a9a1980a4a4388e262 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 5 Aug 2021 21:49:53 +0200 Subject: [PATCH 33/50] Use correct dependency for Mutator class --- bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF b/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF index d97cd33a..f7f93849 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF +++ b/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF @@ -16,7 +16,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.1,4.0.0)", org.pitest.pitclipse.launch, org.eclipse.jface;bundle-version="[3.11.1,4.0.0)", org.eclipse.ui.workbench;bundle-version="[3.107.1,4.0.0)", - org.eclipse.jdt.debug.ui;bundle-version="[3.7.101,4.0.0)", - org.pitest;bundle-version="1.6.7" -Import-Package: com.google.common.collect;version="21.0.0" + org.eclipse.jdt.debug.ui;bundle-version="[3.7.101,4.0.0)" +Import-Package: com.google.common.collect;version="21.0.0", + org.pitest.mutationtest.engine.gregor.config Export-Package: org.pitest.pitclipse.launch.ui From e971a00d777f3336ae336df19e2e89a27d23c376 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 5 Aug 2021 22:12:42 +0200 Subject: [PATCH 34/50] Removed whitespaces and small fixes --- .../src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java | 1 + .../src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java | 2 +- .../pitclipse/launch/config/LaunchConfigurationWrapper.java | 2 +- .../src/org/pitest/pitclipse/runner/PitOptions.java | 6 +++--- .../ui/tests/PitclipseRunConfigurationMutationTabTest.java | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index 256fc725..86ded57d 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -173,6 +173,7 @@ private void createProjectWidgets(Font font, Composite comp) { projectLabel.setFont(font); gd = new GridData(FILL_HORIZONTAL); + // 1 column less to fit label in front of the text field gd.horizontalSpan = NUMBER_OF_COLUMNS - 1; projectText = new Text(comp, SWT.SINGLE | SWT.BORDER); projectText.setLayoutData(gd); diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index dacd2c23..75c169f6 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2012-2021 Jonas Kutscha and contributors + * Copyright 2021 Jonas Kutscha and contributors * * 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 diff --git a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java index 38a19d2c..fc306993 100644 --- a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java +++ b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java @@ -114,7 +114,7 @@ public boolean isTestLaunch() throws CoreException { public PitOptions getPitOptions() throws CoreException { return getPitOptionsBuilder().build(); } - + public PitOptions.PitOptionsBuilder getPitOptionsBuilder() throws CoreException { List classPath = getClassesFromProject(); List sourceDirs = getSourceDirsForProject(); diff --git a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitOptions.java b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitOptions.java index 75eea793..13d18713 100644 --- a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitOptions.java +++ b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitOptions.java @@ -208,7 +208,7 @@ public PitOptionsBuilder withPackagesToTest(List packages) { this.packages = copyOf(packages); return this; } - + public PitOptionsBuilder withClassPath(List classPath) { this.classPath = copyOf(classPath); return this; @@ -297,7 +297,7 @@ public List getClassesToMutate() { public List getPackages() { return packages; } - + public List getClassPath() { return classPath; } @@ -317,7 +317,7 @@ public int getTimeout() { public BigDecimal getTimeoutFactor() { return timeoutFactor; } - + public boolean getUseJUnit5() { return useJUnit5; } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index ba101f73..a5086c29 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2012-2021 Jonas Kutscha and contributors + * Copyright 2021 Jonas Kutscha and contributors * * 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 From 9cf7454e483709a14a001822d6929f13b75f85f3 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 5 Aug 2021 22:13:47 +0200 Subject: [PATCH 35/50] Change mutators from ImmutableList to String --- .../config/LaunchConfigurationWrapper.java | 8 ++-- .../pitclipse/runner/PitCliArguments.java | 12 +++--- .../pitest/pitclipse/runner/PitOptions.java | 13 +++--- .../pitclipse/runner/PitCliArgumentsTest.java | 41 ++++++++++--------- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java index fc306993..1f3c6aaf 100644 --- a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java +++ b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java @@ -123,10 +123,10 @@ public PitOptions.PitOptionsBuilder getPitOptionsBuilder() throws CoreException List excludedClasses = getExcludedClasses(); List excludedMethods = getExcludedMethods(); List avoidCallsTo = getAvoidCallsTo(); - List mutators = getMutators(); + String mutators = getMutators(); int timeout = pitConfiguration.getTimeout(); BigDecimal timeoutFactor = pitConfiguration.getTimeoutFactor(); - + PitOptionsBuilder builder = PitOptions.builder().withClassesToMutate(classPath) .withSourceDirectories(sourceDirs).withReportDirectory(reportDir).withThreads(threadCount) .withExcludedClasses(excludedClasses).withExcludedMethods(excludedMethods) @@ -261,13 +261,13 @@ public List getMutatedProjects() throws CoreException { return projectFinder.getProjects(this); } - private List getMutators() throws CoreException { + private String getMutators() throws CoreException { final String mutators; if (launchConfig.hasAttribute(MUTATORS)) { mutators = launchConfig.getAttribute(MUTATORS, ""); } else { mutators = pitConfiguration.getMutators(); } - return ImmutableList.of(mutators); + return mutators; } } diff --git a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitCliArguments.java b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitCliArguments.java index d501aa39..6148844e 100644 --- a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitCliArguments.java +++ b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitCliArguments.java @@ -16,16 +16,16 @@ package org.pitest.pitclipse.runner; +import java.io.File; +import java.util.List; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.Lists; -import java.io.File; -import java.util.List; - /** * Turns {@link PitOptions} instances into CLI arguments - * that can be understand by PIT. + * that can be understand by PIT. */ public class PitCliArguments { @@ -98,10 +98,10 @@ private List avoidedCallsFrom(PitOptions options) { private List mutatorsFrom(PitOptions options) { Builder builder = ImmutableList.builder(); - List mutators = options.getMutators(); + String mutators = options.getMutators(); if (!mutators.isEmpty()) { builder.add("--mutators"); - builder.add(concat(commaSeparate(mutators))); + builder.add(mutators); } return builder.build(); } diff --git a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitOptions.java b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitOptions.java index 13d18713..275d9fa0 100644 --- a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitOptions.java +++ b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitOptions.java @@ -51,7 +51,7 @@ public final class PitOptions implements Serializable { private final ImmutableList excludedClasses; private final ImmutableList excludedMethods; private final ImmutableList avoidCallsTo; - private final ImmutableList mutators; + private final String mutators; private final int timeout; private final BigDecimal timeoutFactor; private final boolean useJUnit5; @@ -59,7 +59,8 @@ public final class PitOptions implements Serializable { private PitOptions(String classUnderTest, ImmutableList classesToMutate, ImmutableList sourceDirs, // NOSONAR this is used by our builder File reportDir, ImmutableList packages, ImmutableList classPath, int threads, File historyLocation, ImmutableList excludedClasses, ImmutableList excludedMethods, - ImmutableList avoidCallsTo, ImmutableList mutators, int timeout, BigDecimal timeoutFactor, boolean useJUnit5) { + ImmutableList avoidCallsTo, String mutators, int timeout, BigDecimal timeoutFactor, + boolean useJUnit5) { this.classUnderTest = classUnderTest; this.threads = threads; this.historyLocation = historyLocation; @@ -102,7 +103,7 @@ public static final class PitOptionsBuilder { private ImmutableList excludedClasses = ImmutableList.of(); private ImmutableList excludedMethods = ImmutableList.of(); private ImmutableList avoidCallsTo = copyOf(split(DEFAULT_AVOID_CALLS_TO_LIST)); - private ImmutableList mutators = copyOf(split(DEFAULT_MUTATORS)); + private String mutators = DEFAULT_MUTATORS; private int timeout = 3000; private BigDecimal timeoutFactor = BigDecimal.valueOf(1.25); private boolean useJUnit5 = false; @@ -239,8 +240,8 @@ public PitOptionsBuilder withAvoidCallsTo(List avoidCallsTo) { return this; } - public PitOptionsBuilder withMutators(List mutators) { - this.mutators = copyOf(mutators); + public PitOptionsBuilder withMutators(String mutators) { + this.mutators = mutators; return this; } @@ -306,7 +307,7 @@ public List getAvoidCallsTo() { return avoidCallsTo; } - public List getMutators() { + public String getMutators() { return mutators; } diff --git a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitCliArgumentsTest.java b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitCliArgumentsTest.java index b7c93e43..d101f271 100644 --- a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitCliArgumentsTest.java +++ b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/PitCliArgumentsTest.java @@ -16,26 +16,26 @@ package org.pitest.pitclipse.runner; -import com.google.common.base.Function; -import com.google.common.base.Splitter; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; - -import org.junit.Before; -import org.junit.Test; -import org.pitest.pitclipse.example.ExampleTest; - -import java.io.File; -import java.math.BigDecimal; -import java.util.List; - import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import static org.pitest.pitclipse.runner.config.PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST; +import java.io.File; +import java.math.BigDecimal; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.pitest.pitclipse.example.ExampleTest; + +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; + public class PitCliArgumentsTest { private static final String TEST_CLASS1 = PitOptionsTest.class.getCanonicalName(); @@ -50,7 +50,7 @@ public class PitCliArgumentsTest { private static final List EXCLUDED_METHODS = ImmutableList.of("*toString*", "leaveMeAlone*"); private static final File NO_HISTORY_FILE = null; private static final int DEFAULT_NUMBER_OF_THREADS = 1; - private static final List MUTATORS = ImmutableList.of("FOO", "BAR"); + private static final String MUTATORS = "FOO,BAR"; private static final List DEFAULT_AVOID_LIST = ImmutableList.copyOf(Splitter.on(',').trimResults() .omitEmptyStrings().split(DEFAULT_AVOID_CALLS_TO_LIST)); @@ -172,12 +172,13 @@ private void whenArgumentsAreMadeFrom(PitOptions options) { private void thenTheArgumentsAreMadeUpOf(File reportDir, List testSrcDirs, int threadCount, String testClass, List classesToMutate, File historyFile, List excludedClasses, List excludedMethods, - List avoidCallsTo, List mutators, int timeout, BigDecimal timeoutFactor) { + List avoidCallsTo, String mutators, int timeout, BigDecimal timeoutFactor) { Object[] expectedCliArgs = new ExpectedArgsBuilder().withThreadCount(threadCount).withReportDir(reportDir) .withClassUnderTest(testClass).withTargetClasses(classesToMutate) .withSourceDirectories(filesAsStrings(testSrcDirs)).withHistoryLocation(historyFile) .withExcludedClasses(excludedClasses).withExcludedMethods(excludedMethods).withMutators(MUTATORS) - .withAvoidCallsTo(avoidCallsTo).withMutators(mutators).withTimeout(timeout).withTimeoutFactor(timeoutFactor) + .withAvoidCallsTo(avoidCallsTo).withMutators(mutators).withTimeout(timeout) + .withTimeoutFactor(timeoutFactor) .build(); assertThat(actualCliArgs, is(equalTo(expectedCliArgs))); } @@ -204,7 +205,7 @@ private static final class ExpectedArgsBuilder { private List excludedClasses = NO_EXCLUDED_CLASSES; private List excludedMethods = NO_EXCLUDED_METHODS; private List avoidCallsTo = DEFAULT_AVOID_LIST; - private List mutators = MUTATORS; + private String mutators = MUTATORS; private int timeout = DEFAULT_TIMEOUT; private BigDecimal timeoutFactor = DEFAULT_TIMEOUT_FACTOR; @@ -227,8 +228,8 @@ public String[] build() { return asStrings(resultBuilder.build()); } - public ExpectedArgsBuilder withMutators(List mutators) { - this.mutators = ImmutableList.copyOf(mutators); + public ExpectedArgsBuilder withMutators(String mutators) { + this.mutators = mutators; return this; } From 9430da3aecc1dca3891ac6d3fb042a7e8c98bb75 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 5 Aug 2021 22:33:30 +0200 Subject: [PATCH 36/50] Use safley dispose for composite in mutators tab --- bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF | 3 ++- .../src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF b/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF index f7f93849..45817b85 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF +++ b/bundles/org.pitest.pitclipse.launch.ui/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.1,4.0.0)", org.pitest.pitclipse.launch, org.eclipse.jface;bundle-version="[3.11.1,4.0.0)", org.eclipse.ui.workbench;bundle-version="[3.107.1,4.0.0)", - org.eclipse.jdt.debug.ui;bundle-version="[3.7.101,4.0.0)" + org.eclipse.jdt.debug.ui;bundle-version="[3.7.101,4.0.0)", + org.pitest.pitclipse.ui;bundle-version="2.1.2" Import-Package: com.google.common.collect;version="21.0.0", org.pitest.mutationtest.engine.gregor.config Export-Package: org.pitest.pitclipse.launch.ui diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 75c169f6..79d5f0f6 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -51,6 +51,7 @@ import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; +import org.pitest.pitclipse.ui.utils.PitclipseUiUtils; /** * Tab allowing to configure a PIT analyze. @@ -87,9 +88,7 @@ public Image getImage() { @Override public void dispose() { - if (mainComp != null && !mainComp.isDisposed()) { - mainComp.dispose(); - } + PitclipseUiUtils.disposeSafely(mainComp); // always call super.dispose() last, if dispose() is overridden. super.dispose(); } From 6af809326fbb7bd5998ae6539ec34b1bc54c592d Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 5 Aug 2021 22:50:32 +0200 Subject: [PATCH 37/50] code review fixes for comments by lorenzoBettini --- .../pitclipse/launch/ui/PitMutatorsTab.java | 45 ++++++++----------- .../runner/config/PitConfiguration.java | 5 ++- .../META-INF/MANIFEST.MF | 3 +- .../org.pitest.pitclipse.ui.tests.launch | 2 +- .../pageobjects/RunConfigurationSelector.java | 27 +++++------ .../ui/behaviours/pageobjects/RunMenu.java | 1 - .../ui/tests/AbstractPitclipseSWTBotTest.java | 13 +----- ...clipseRunConfigurationMutationTabTest.java | 6 +++ 8 files changed, 43 insertions(+), 59 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 79d5f0f6..fa6c4743 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -16,12 +16,11 @@ package org.pitest.pitclipse.launch.ui; -import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; -import java.util.Arrays; -import java.util.Iterator; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; @@ -109,14 +108,14 @@ public void initializeFrom(ILaunchConfiguration config) { } private void intializeMutatorsTable(ILaunchConfiguration config) { - final String individualMutatos = PitArgumentsTab.getAttributeFromConfig(config, INDIVIDUAL_MUTATORS, ""); - if (individualMutatos.equals("")) { + final String individualMutators = PitArgumentsTab.getAttributeFromConfig(config, INDIVIDUAL_MUTATORS, ""); + if (individualMutators.isEmpty()) { // no mutators where set, use defaults for (String mutator : Mutators.getDefaultMutators()) { mutatorsTable.setChecked(mutator, true); } } else { - for (String mutator : individualMutatos.split(",")) { + for (String mutator : individualMutators.split(",")) { mutatorsTable.setChecked(mutator, true); } } @@ -185,14 +184,7 @@ private void createMutatorGroupsWidgets(Font font, Composite parent) { button.setText(mutatorGroup.getDescriptor()); button.setData(mutatorGroup.name()); button.setFont(font); - button.addSelectionListener(widgetSelectedAdapter(event -> { - final String old = mutators; - mutators = (String) event.widget.getData(); - if (((Button) event.widget).getSelection() && !old.equals(mutators)) { - updateLaunchConfigurationDialog(); - disableTableIfUnused(); - } - })); + button.addSelectionListener(new ButtonSelectionListener()); groupButtons[i++] = button; GridDataFactory.swtDefaults().applyTo(button); } @@ -200,15 +192,20 @@ private void createMutatorGroupsWidgets(Font font, Composite parent) { customMutatorsButton.setText(CUSTOM_MUTATOR_RADIO_TEXT); customMutatorsButton.setData(CUSTOM_MUTATOR_RADIO_DATA); customMutatorsButton.setFont(font); - customMutatorsButton.addSelectionListener(widgetSelectedAdapter(event -> { + customMutatorsButton.addSelectionListener(new ButtonSelectionListener()); + GridDataFactory.swtDefaults().applyTo(customMutatorsButton); + } + + private class ButtonSelectionListener extends SelectionAdapter { + @Override + public void widgetSelected(SelectionEvent event) { final String old = mutators; mutators = (String) event.widget.getData(); - if (!old.equals(mutators)) { + if (((Button) event.widget).getSelection() && !old.equals(mutators)) { updateLaunchConfigurationDialog(); disableTableIfUnused(); } - })); - GridDataFactory.swtDefaults().applyTo(customMutatorsButton); + } } /** @@ -298,15 +295,9 @@ public void performApply(ILaunchConfigurationWorkingCopy config) { } private String getIndividualMutators() { - StringBuilder sb = new StringBuilder(""); - Iterator iterator = Arrays.asList(mutatorsTable.getCheckedElements()).iterator(); - while (iterator.hasNext()) { - sb.append((String) iterator.next()); - if (iterator.hasNext()) { - sb.append(','); - } - } - return sb.toString(); + return Stream.of(mutatorsTable.getCheckedElements()) + .map(Object::toString) + .collect(Collectors.joining(",")); } @Override diff --git a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java index bc4985ad..af6ed970 100644 --- a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java +++ b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/config/PitConfiguration.java @@ -16,10 +16,10 @@ package org.pitest.pitclipse.runner.config; -import java.math.BigDecimal; - import static org.pitest.pitclipse.runner.config.PitExecutionMode.PROJECT_ISOLATION; +import java.math.BigDecimal; + public class PitConfiguration { public static final String DEFAULT_AVOID_CALLS_TO_LIST = "java.util.logging, org.apache.log4j, org.slf4j, org.apache.commons.logging, org.apache.logging.log4j"; public static final String DEFAULT_MUTATORS = "DEFAULTS"; @@ -120,6 +120,7 @@ public Builder withTimeout(int timeout) { this.timeout = timeout; return this; } + public PitConfiguration build() { return new PitConfiguration(executionMode, parallelExecution, incrementalAnalysis, excludedClasses, excludedMethods, avoidCallsTo, mutators, timeout, timeoutFactor); diff --git a/bundles/org.pitest.pitclipse.ui/META-INF/MANIFEST.MF b/bundles/org.pitest.pitclipse.ui/META-INF/MANIFEST.MF index 151968f6..b44fbff3 100644 --- a/bundles/org.pitest.pitclipse.ui/META-INF/MANIFEST.MF +++ b/bundles/org.pitest.pitclipse.ui/META-INF/MANIFEST.MF @@ -18,5 +18,6 @@ Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: Pitest.org Bundle-ClassPath: . -Export-Package: org.pitest.pitclipse.ui.extension.point +Export-Package: org.pitest.pitclipse.ui.extension.point, + org.pitest.pitclipse.ui.utils Automatic-Module-Name: org.pitest.pitclipse.ui diff --git a/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch b/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch index c975aa1f..7df304b7 100644 --- a/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch +++ b/tests/org.pitest.pitclipse.ui.tests/org.pitest.pitclipse.ui.tests.launch @@ -37,4 +37,4 @@ - \ No newline at end of file + diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index 22843177..1d14ed1f 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -18,9 +18,11 @@ import static com.google.common.collect.ImmutableList.builder; import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive; +import static org.junit.Assert.fail; -import java.util.Iterator; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.TableItem; @@ -116,7 +118,8 @@ private SWTBotTreeItem getPitConfigurationItem() { return treeItem.select().expand(); } } - throw new RuntimeException("Could not find '" + itemName + "' in the configurations tab."); + fail("Could not find '" + itemName + "' in the configurations tab."); + return null; // never reached } private void activateConfiguration(String configurationName) { @@ -126,7 +129,7 @@ private void activateConfiguration(String configurationName) { return; } } - throw new RuntimeException("Could not find '" + configurationName + "' in the configurations of PIT."); + fail("Could not find '" + configurationName + "' in the configurations of PIT."); } public void activateMutatorsTab(String configurationName) { @@ -198,15 +201,9 @@ private void setConfiguration(PitRunConfiguration config) { * commas */ private String getProjectsAsString(PitRunConfiguration config) { - Iterator it = config.getProjects().iterator(); - StringBuilder sb = new StringBuilder(); - while (it.hasNext()) { - sb.append(it.next()); - if (it.hasNext()) { - sb.append(','); - } - } - return sb.toString(); + return Stream.of(config.getProjects()) + .map(Object::toString) + .collect(Collectors.joining(",")); } public void setMutatorGroup(String configurationName, Mutators mutatorGroup) { @@ -290,9 +287,7 @@ public void runWithConfigurationAndWaitForIt(String configurationName) { PitSummary.INSTANCE.resetSummary(); activateConfiguration(configurationName); SWTBotShell shell = bot.shell(RUN_CONFIGURATIONS); - shell.bot() - .button(RUN) - .click(); + shell.bot().button(RUN).click(); // wait for pit PitSummary.INSTANCE.waitForPitToFinish(); } @@ -310,6 +305,6 @@ public void removeConfig(String configurationName) { return; } } - throw new RuntimeException("Could not find '" + configurationName + "' in the configurations of PIT."); + fail("Could not find '" + configurationName + "' in the configurations of PIT."); } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java index 4564ad4a..0a4e12da 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunMenu.java @@ -110,7 +110,6 @@ public PitOptions getLastUsedPitOptions() { */ public void setMutatorGroup(String configurationName, Mutators mutatorGroup) { runConfigurationSelector.setMutatorGroup(configurationName, mutatorGroup); - } /** diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index 78085589..e098a2f3 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -29,7 +29,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -326,16 +325,8 @@ protected static void mutatorIs(Mutators mutator) { */ protected static void mutatorsAre(Collection mutators) { final String consoleText = PAGES.getConsole().getText(); - // build String to match against console text - Iterator iterator = mutators.iterator(); - StringBuilder sb = new StringBuilder(); - while (iterator.hasNext()) { - sb.append(iterator.next().name()); - if (iterator.hasNext()) { - sb.append(','); - } - } - assertThat(consoleText, containsString(String.format("mutators=[%s]", sb.toString()))); + assertThat(consoleText, containsString(String.format("mutators=[%s]", + Stream.of(mutators).map(Object::toString).collect(Collectors.joining(","))))); } /** diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java index a5086c29..06d373db 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseRunConfigurationMutationTabTest.java @@ -141,6 +141,9 @@ public void checkOneMutant() { // NOSONAR "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional"); } + /** + * This test will probably fail, if mutators of pit get changed + */ @Test public void useAllMutatorsGroup() { // NOSONAR // now set ALL mutators group @@ -151,6 +154,9 @@ public void useAllMutatorsGroup() { // NOSONAR mutationsAre(getAllMutantsResult()); } + /** + * This test will probably fail, if mutators of pit get changed + */ @Test public void checkAllMutants() { // NOSONAR PAGES.getRunMenu().checkAllMutators(TEST_CONFIG_NAME); From d3d99916aa6205d7dbd87c5f8255aa0634045488 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Thu, 5 Aug 2021 23:46:44 +0200 Subject: [PATCH 38/50] Fix problems regarding Stream.of() --- .../ui/behaviours/pageobjects/RunConfigurationSelector.java | 3 +-- .../pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index 1d14ed1f..655d45ee 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.TableItem; @@ -201,7 +200,7 @@ private void setConfiguration(PitRunConfiguration config) { * commas */ private String getProjectsAsString(PitRunConfiguration config) { - return Stream.of(config.getProjects()) + return config.getProjects().stream() .map(Object::toString) .collect(Collectors.joining(",")); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java index e098a2f3..fa9d526c 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/AbstractPitclipseSWTBotTest.java @@ -326,7 +326,7 @@ protected static void mutatorIs(Mutators mutator) { protected static void mutatorsAre(Collection mutators) { final String consoleText = PAGES.getConsole().getText(); assertThat(consoleText, containsString(String.format("mutators=[%s]", - Stream.of(mutators).map(Object::toString).collect(Collectors.joining(","))))); + mutators.stream().map(Object::toString).collect(Collectors.joining(","))))); } /** From 1745a167b57aa43d92181faf03cdf17e34aede39 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Fri, 6 Aug 2021 10:43:05 +0200 Subject: [PATCH 39/50] Revert input organisation --- .../launch/ui/PitLaunchShortcut.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchShortcut.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchShortcut.java index 4ee8efc3..8a4f7936 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchShortcut.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitLaunchShortcut.java @@ -16,36 +16,8 @@ package org.pitest.pitclipse.launch.ui; -import static org.eclipse.jdt.core.IJavaElement.CLASS_FILE; -import static org.eclipse.jdt.core.IJavaElement.COMPILATION_UNIT; -import static org.eclipse.jdt.core.IJavaElement.JAVA_PROJECT; -import static org.eclipse.jdt.core.IJavaElement.METHOD; -import static org.eclipse.jdt.core.IJavaElement.PACKAGE_FRAGMENT; -import static org.eclipse.jdt.core.IJavaElement.PACKAGE_FRAGMENT_ROOT; -import static org.eclipse.jdt.core.IJavaElement.TYPE; -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; -import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; -import static org.eclipse.jdt.ui.JavaElementLabels.ALL_FULLY_QUALIFIED; -import static org.eclipse.jdt.ui.JavaElementLabels.getTextLabel; -import static org.eclipse.jdt.ui.JavaUI.getEditorInputTypeRoot; -import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; -import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.asJavaElement; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.emptyLaunchConfiguration; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.emptyList; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.forEditorInputDo; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.getCorrespondingResource; -import static org.pitest.pitclipse.launch.ui.LaunchShortcut.toArrayOfILaunchConfiguration; -import static org.pitest.pitclipse.launch.ui.PitLaunchUiActivator.getActiveWorkbenchShell; -import static org.pitest.pitclipse.launch.ui.PitMigrationDelegate.mapResources; - -import java.util.List; -import java.util.Optional; -import java.util.function.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -75,8 +47,36 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + +import static org.eclipse.jdt.core.IJavaElement.CLASS_FILE; +import static org.eclipse.jdt.core.IJavaElement.COMPILATION_UNIT; +import static org.eclipse.jdt.core.IJavaElement.JAVA_PROJECT; +import static org.eclipse.jdt.core.IJavaElement.METHOD; +import static org.eclipse.jdt.core.IJavaElement.PACKAGE_FRAGMENT; +import static org.eclipse.jdt.core.IJavaElement.PACKAGE_FRAGMENT_ROOT; +import static org.eclipse.jdt.core.IJavaElement.TYPE; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; +import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; +import static org.eclipse.jdt.ui.JavaElementLabels.ALL_FULLY_QUALIFIED; +import static org.eclipse.jdt.ui.JavaElementLabels.getTextLabel; +import static org.eclipse.jdt.ui.JavaUI.getEditorInputTypeRoot; +import static org.pitest.pitclipse.launch.PitLaunchArgumentsConstants.ATTR_TEST_CONTAINER; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_AVOID_CALLS_TO; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_CLASSES; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_EXCLUDE_METHODS; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_INCREMENTALLY; +import static org.pitest.pitclipse.launch.config.LaunchConfigurationWrapper.ATTR_TEST_IN_PARALLEL; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.asJavaElement; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.emptyLaunchConfiguration; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.emptyList; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.forEditorInputDo; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.getCorrespondingResource; +import static org.pitest.pitclipse.launch.ui.LaunchShortcut.toArrayOfILaunchConfiguration; +import static org.pitest.pitclipse.launch.ui.PitLaunchUiActivator.getActiveWorkbenchShell; +import static org.pitest.pitclipse.launch.ui.PitMigrationDelegate.mapResources; /** * Allows to launch a PIT analyze from a contextual menu. From 13e8e9e0c4cc44ac44761809fef4674a06c098a1 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Fri, 6 Aug 2021 10:25:30 +0200 Subject: [PATCH 40/50] slightly changed API test --- .../pitclipse/runner/MutatorApiOfPitTest.java | 82 +++++++++++++++---- 1 file changed, 65 insertions(+), 17 deletions(-) diff --git a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/MutatorApiOfPitTest.java b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/MutatorApiOfPitTest.java index 57e558f0..10c1426f 100644 --- a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/MutatorApiOfPitTest.java +++ b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/MutatorApiOfPitTest.java @@ -16,8 +16,7 @@ package org.pitest.pitclipse.runner; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.pitest.mutationtest.engine.gregor.config.Mutator; @@ -30,7 +29,7 @@ public class MutatorApiOfPitTest { @Test public void testTheMutatorApiOfPit() { - assertThat(getPitMutatorsAsString(), equalTo(getExpectedMutatorsAsString())); + assertEquals(getExpectedMutatorsAsString(), getPitMutatorsAsString()); } private String getPitMutatorsAsString() { @@ -42,19 +41,68 @@ private String getPitMutatorsAsString() { } private String getExpectedMutatorsAsString() { - return "INVERT_NEGS\nRETURN_VALS\nINLINE_CONSTS\nMATH\nVOID_METHOD_CALLS\n" - + "NEGATE_CONDITIONALS\nCONDITIONALS_BOUNDARY\nINCREMENTS\n" - + "REMOVE_INCREMENTS\nNON_VOID_METHOD_CALLS\nCONSTRUCTOR_CALLS\n" - + "REMOVE_CONDITIONALS_EQ_IF\nREMOVE_CONDITIONALS_EQ_ELSE\n" - + "REMOVE_CONDITIONALS_ORD_IF\nREMOVE_CONDITIONALS_ORD_ELSE\n" - + "REMOVE_CONDITIONALS\nTRUE_RETURNS\nFALSE_RETURNS\n" - + "PRIMITIVE_RETURNS\nEMPTY_RETURNS\nNULL_RETURNS\n" - + "RETURNS\nEXPERIMENTAL_MEMBER_VARIABLE\n" - + "EXPERIMENTAL_SWITCH\nEXPERIMENTAL_ARGUMENT_PROPAGATION\n" - + "EXPERIMENTAL_NAKED_RECEIVER\nEXPERIMENTAL_BIG_INTEGER\n" - + "AOR_1\nAOR_2\nAOR_3\nAOR_4\nABS\nAOD1\nAOD2\nCRCR1\nCRCR2\nCRCR3\nCRCR4\n" - + "CRCR5\nCRCR6\nOBBN1\nOBBN2\nOBBN3\nROR1\nROR2\nROR3\nROR4\nROR5\nUOI1\n" - + "UOI2\nUOI3\nUOI4\nREMOVE_SWITCH\nOLD_DEFAULTS\nSTRONGER\nALL\nDEFAULTS\n" - + "AOR\nAOD\nCRCR\nOBBN\nROR\nUOI\n"; + return "INVERT_NEGS\n" + + "RETURN_VALS\n" + + "INLINE_CONSTS\n" + + "MATH\n" + + "VOID_METHOD_CALLS\n" + + "NEGATE_CONDITIONALS\n" + + "CONDITIONALS_BOUNDARY\n" + + "INCREMENTS\n" + + "REMOVE_INCREMENTS\n" + + "NON_VOID_METHOD_CALLS\n" + + "CONSTRUCTOR_CALLS\n" + + "REMOVE_CONDITIONALS_EQ_IF\n" + + "REMOVE_CONDITIONALS_EQ_ELSE\n" + + "REMOVE_CONDITIONALS_ORD_IF\n" + + "REMOVE_CONDITIONALS_ORD_ELSE\n" + + "REMOVE_CONDITIONALS\n" + + "TRUE_RETURNS\n" + + "FALSE_RETURNS\n" + + "PRIMITIVE_RETURNS\n" + + "EMPTY_RETURNS\n" + + "NULL_RETURNS\n" + + "RETURNS\n" + + "EXPERIMENTAL_MEMBER_VARIABLE\n" + + "EXPERIMENTAL_SWITCH\n" + + "EXPERIMENTAL_ARGUMENT_PROPAGATION\n" + + "EXPERIMENTAL_NAKED_RECEIVER\n" + + "EXPERIMENTAL_BIG_INTEGER\n" + + "AOR_1\n" + + "AOR_2\n" + + "AOR_3\n" + + "AOR_4\n" + + "ABS\n" + + "AOD1\n" + + "AOD2\n" + + "CRCR1\n" + + "CRCR2\n" + + "CRCR3\n" + + "CRCR4\n" + + "CRCR5\n" + + "CRCR6\n" + + "OBBN1\n" + + "OBBN2\n" + + "OBBN3\n" + + "ROR1\n" + + "ROR2\n" + + "ROR3\n" + + "ROR4\n" + + "ROR5\n" + + "UOI1\n" + + "UOI2\n" + + "UOI3\n" + + "UOI4\n" + + "REMOVE_SWITCH\n" + + "OLD_DEFAULTS\n" + + "STRONGER\n" + + "ALL\n" + + "DEFAULTS\n" + + "AOR\n" + + "AOD\n" + + "CRCR\n" + + "OBBN\n" + + "ROR\n" + + "UOI\n"; } } From 3f985d61264653054a0b6923dca42d7960c0484a Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Fri, 6 Aug 2021 13:24:55 +0200 Subject: [PATCH 41/50] Removed worng comment --- .../src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index fa6c4743..00bba78b 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -154,7 +154,7 @@ private void createDescription(Composite parent) { link.setText("" + MUTATOR_LINK_TEXT + ""); link.addSelectionListener(new SelectionAdapter() { @Override - public void widgetSelected(SelectionEvent e) { // NOSONAR we don't want to open external links + public void widgetSelected(SelectionEvent e) { Program.launch(MUTATOR_LINK); } }); From 1d0aa89f67e0441a84577974be62f3df79737f58 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Sat, 7 Aug 2021 13:07:21 +0200 Subject: [PATCH 42/50] Constants name change and trim mutators before equals --- .../org/pitest/pitclipse/core/PitCoreActivator.java | 10 +++++----- .../pitclipse/core/preferences/PitPreferences.java | 8 ++++---- .../core/preferences/PreferenceInitializer.java | 8 ++++---- .../pitest/pitclipse/launch/ui/PitArgumentsTab.java | 4 ++-- .../pitclipse/preferences/ui/PitPreferencePage.java | 4 ++-- .../org/pitest/pitclipse/runner/PitCliArguments.java | 2 +- .../behaviours/pageobjects/PitPreferenceSelector.java | 10 +++++----- .../pageobjects/RunConfigurationSelector.java | 4 ++-- .../ui/tests/PitclipseMultipleProjectsTest.java | 2 +- .../pitclipse/ui/tests/PitclipseOptionsTest.java | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index 11431580..f8107313 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -17,11 +17,11 @@ package org.pitest.pitclipse.core; import static org.eclipse.core.runtime.FileLocator.getBundleFile; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS; import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_SCOPE; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_MODE; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT; @@ -305,13 +305,13 @@ public File getHistoryFile() { public PitConfiguration getConfiguration() { IPreferenceStore preferenceStore = getPreferenceStore(); - String executionMode = preferenceStore.getString(EXECUTION_SCOPE); + String executionMode = preferenceStore.getString(EXECUTION_MODE); String mutators = preferenceStore.getString(MUTATORS); boolean parallelRun = preferenceStore.getBoolean(RUN_IN_PARALLEL); boolean incrementalAnalysis = preferenceStore.getBoolean(INCREMENTAL_ANALYSIS); String excludedClasses = preferenceStore.getString(EXCLUDED_CLASSES); String excludedMethods = preferenceStore.getString(EXCLUDED_METHODS); - String avoidCallsTo = preferenceStore.getString(AVOID_CALLS); + String avoidCallsTo = preferenceStore.getString(AVOID_CALLS_TO); String timeout = preferenceStore.getString(TIMEOUT); String timeoutFactor = preferenceStore.getString(TIMEOUT_FACTOR); PitConfiguration.Builder builder = PitConfiguration.builder().withParallelExecution(parallelRun) @@ -340,7 +340,7 @@ public PitConfiguration getConfiguration() { } public void setExecutionMode(PitExecutionMode pitExecutionMode) { - getPreferenceStore().setValue(EXECUTION_SCOPE, pitExecutionMode.getId()); + getPreferenceStore().setValue(EXECUTION_MODE, pitExecutionMode.getId()); } public void setMutators(Mutators mutators) { diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java index 2107ed0d..934af53c 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java @@ -37,8 +37,8 @@ public final class PitPreferences { public static final String EXCLUDED_METHODS_LABEL = "Excluded &methods (e.g.*toString*)"; public static final String EXCLUDED_METHODS = "excludedMethods"; - public static final String AVOID_CALLS_LABEL = "&Avoid calls to"; - public static final String AVOID_CALLS = "avoidCallsTo"; + public static final String AVOID_CALLS_TO_LABEL = "&Avoid calls to"; + public static final String AVOID_CALLS_TO = "avoidCallsTo"; public static final String TIMEOUT_LABEL = "Pit Ti&meout"; public static final String TIMEOUT = "pitTimeout"; @@ -47,8 +47,8 @@ public final class PitPreferences { public static final String TIMEOUT_FACTOR = "pitTimeoutFactor"; - public static final String EXECUTION_SCOPE_LABEL = "Pit execution scope"; - public static final String EXECUTION_SCOPE = "pitExecutionMode"; + public static final String EXECUTION_MODE_LABEL = "Pit execution scope"; + public static final String EXECUTION_MODE = "pitExecutionMode"; public static final String PREFERENCE_DESCRIPTION_LABEL = "Pitclipse Preferences"; public static final String MUTATORS_DESCRIPTION_LABEL = "Mutator Preferences"; diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java index 2fed62e9..4d04f0e9 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PreferenceInitializer.java @@ -21,10 +21,10 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES; import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_SCOPE; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_MODE; import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_FACTOR; @@ -47,10 +47,10 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer { @Override public void initializeDefaultPreferences() { IPreferenceStore store = PitCoreActivator.getDefault().getPreferenceStore(); - store.setDefault(EXECUTION_SCOPE, "containingProject"); + store.setDefault(EXECUTION_MODE, "containingProject"); store.setDefault(RUN_IN_PARALLEL, true); store.setDefault(INCREMENTAL_ANALYSIS, false); - store.setDefault(AVOID_CALLS, DEFAULT_AVOID_CALLS_TO_LIST); + store.setDefault(AVOID_CALLS_TO, DEFAULT_AVOID_CALLS_TO_LIST); store.setDefault(DEFAULT_MUTATORS, "defaultMutators"); store.setDefault(TIMEOUT, DEFAULT_TIMEOUT); store.setDefault(TIMEOUT_FACTOR, DEFAULT_TIMEOUT_FACTOR.toString()); diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index 86ded57d..5ebef739 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -19,7 +19,7 @@ import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS_LABEL; @@ -261,7 +261,7 @@ private void createPreferences(Font font, Composite comp) { excludedMethodsText = createTextPreference(font, misc, miscLayout.numColumns, EXCLUDED_METHODS_LABEL); avoidCallsTo = createTextPreference(font, misc, miscLayout.numColumns, - AVOID_CALLS_LABEL); + AVOID_CALLS_TO_LABEL); } private Text createTextPreference(Font font, Composite comp, int columnsInParent, String label) { diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java index 6ac15b9b..35fb1d9a 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitPreferencePage.java @@ -65,7 +65,7 @@ public void createFieldEditors() { } private void createAvoidCallsToField() { - addField(new StringFieldEditor(AVOID_CALLS, AVOID_CALLS_LABEL, getFieldEditorParent())); + addField(new StringFieldEditor(AVOID_CALLS_TO, AVOID_CALLS_TO_LABEL, getFieldEditorParent())); } private void createExcludeClassesField() { @@ -98,7 +98,7 @@ private void createExecutionModeRadioButtons() { for (int i = 0; i < values.length; i++) { executionModeValues[i] = new String[] { values[i].getLabel(), values[i].getId() }; } - addField(new RadioGroupFieldEditor(EXECUTION_SCOPE, EXECUTION_SCOPE_LABEL, 1, executionModeValues, getFieldEditorParent())); + addField(new RadioGroupFieldEditor(EXECUTION_MODE, EXECUTION_MODE_LABEL, 1, executionModeValues, getFieldEditorParent())); } /* diff --git a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitCliArguments.java b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitCliArguments.java index 6148844e..ef3f9694 100644 --- a/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitCliArguments.java +++ b/bundles/org.pitest.pitclipse.runner/src/org/pitest/pitclipse/runner/PitCliArguments.java @@ -99,7 +99,7 @@ private List avoidedCallsFrom(PitOptions options) { private List mutatorsFrom(PitOptions options) { Builder builder = ImmutableList.builder(); String mutators = options.getMutators(); - if (!mutators.isEmpty()) { + if (!mutators.trim().isEmpty()) { builder.add("--mutators"); builder.add(mutators); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java index 87ce0d8f..6c1be584 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitPreferenceSelector.java @@ -28,10 +28,10 @@ import java.math.BigDecimal; import static java.math.BigDecimal.ZERO; -import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS_LABEL; -import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_SCOPE_LABEL; +import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_MODE_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_FACTOR_LABEL; @@ -72,7 +72,7 @@ private void activatePreferenceShell() { } public PitExecutionMode getPitExecutionMode() { - return getSelectedExecutionMode().from(EXECUTION_SCOPE_LABEL); + return getSelectedExecutionMode().from(EXECUTION_MODE_LABEL); } private PitExecutionMode getActiveExecutionMode() { @@ -117,11 +117,11 @@ public void setExcludedMethods(String excludedMethods) { } public String getAvoidCallsTo() { - return getText().from(AVOID_CALLS_LABEL); + return getText().from(AVOID_CALLS_TO_LABEL); } public void setAvoidCallsTo(String avoidCallsTo) { - setTextFor(AVOID_CALLS_LABEL).to(avoidCallsTo); + setTextFor(AVOID_CALLS_TO_LABEL).to(avoidCallsTo); } public Mutators getMutators() { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index 655d45ee..8e1a6d0e 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -86,7 +86,7 @@ private PitRunConfiguration getPitConfiguration(SWTBotTreeItem treeItem) { boolean incrementalAnalysis = bot.checkBox(PitPreferences.INCREMENTAL_ANALYSIS_LABEL).isChecked(); String excludedClasses = bot.textWithLabel(PitPreferences.EXCLUDED_CLASSES_LABEL).getText(); String excludedMethods = bot.textWithLabel(PitPreferences.EXCLUDED_METHODS_LABEL).getText(); - String avoidCallsTo = bot.textWithLabel(PitPreferences.AVOID_CALLS_LABEL).getText(); + String avoidCallsTo = bot.textWithLabel(PitPreferences.AVOID_CALLS_TO_LABEL).getText(); return new Builder().withName(name).withProjects(project).withRunInParallel(runInParallel) .withIncrementalAnalysis(incrementalAnalysis).withExcludedClasses(excludedClasses) .withExcludedMethods(excludedMethods).withAvoidCallsTo(avoidCallsTo).withTestObject(testObject) @@ -189,7 +189,7 @@ private void setConfiguration(PitRunConfiguration config) { } bot.textWithLabel(PitPreferences.EXCLUDED_CLASSES_LABEL).setText(config.getExcludedClasses()); bot.textWithLabel(PitPreferences.EXCLUDED_METHODS_LABEL).setText(config.getExcludedMethods()); - bot.textWithLabel(PitPreferences.AVOID_CALLS_LABEL).setText(config.getAvoidCallsTo()); + bot.textWithLabel(PitPreferences.AVOID_CALLS_TO_LABEL).setText(config.getAvoidCallsTo()); // close shell and save closeConfigurationShell(); } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseMultipleProjectsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseMultipleProjectsTest.java index af907e14..b09aa6df 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseMultipleProjectsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseMultipleProjectsTest.java @@ -81,7 +81,7 @@ public void testExecutionMode() throws CoreException { } finally { // reset default values IPreferenceStore preferenceStore = PitCoreActivator.getDefault().getPreferenceStore(); - preferenceStore.setValue(PitPreferences.EXECUTION_SCOPE, PROJECT_ISOLATION.toString()); + preferenceStore.setValue(PitPreferences.EXECUTION_MODE, PROJECT_ISOLATION.toString()); PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen(); assertEquals(PROJECT_ISOLATION, selector.getPitExecutionMode()); selector.close(); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index c1dfebf8..dd0b2f78 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -174,7 +174,7 @@ public void launchConfigurationsWithChangedValues() throws CoreException { preferenceStore.setValue(PitPreferences.RUN_IN_PARALLEL, true); preferenceStore.setValue(PitPreferences.INCREMENTAL_ANALYSIS, false); preferenceStore.setValue(PitPreferences.EXCLUDED_CLASSES, PitConfiguration.DEFAULT_EXCLUDED_CLASSES); - preferenceStore.setValue(PitPreferences.AVOID_CALLS, PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST); + preferenceStore.setValue(PitPreferences.AVOID_CALLS_TO, PitConfiguration.DEFAULT_AVOID_CALLS_TO_LIST); preferenceStore.setValue(PitPreferences.EXCLUDED_METHODS, ""); } } From ba059e861d3dca581e7899e0867198e8dae32755 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Sat, 7 Aug 2021 13:21:37 +0200 Subject: [PATCH 43/50] Added comment for custom radip button data --- .../src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 00bba78b..976dfbf0 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -64,6 +64,9 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private static final String MUTATOR_LINK_TEXT = "See the documentation on Pitest.org"; private static final String MUTATOR_LINK = "https://pitest.org/quickstart/mutators/"; public static final String CUSTOM_MUTATOR_RADIO_TEXT = "Mutators selected below"; + /** + * Needed for {@link ButtonSelectionListener#widgetSelected(SelectionEvent)} + */ private static final String CUSTOM_MUTATOR_RADIO_DATA = "CUSTOM"; private static final String COLUMN_DESCRIPTION = "Description"; private static final String COLUMN_NAME = "Name"; From 7f3ea066098155211d997d4115903102ce0644fc Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Sat, 7 Aug 2021 15:09:09 +0200 Subject: [PATCH 44/50] Use mutator group and individual mutators across the board --- .../org/pitest/pitclipse/core/Mutators.java | 1 + .../pitclipse/core/PitCoreActivator.java | 27 +++++++------ .../core/preferences/PitPreferences.java | 2 +- .../pitclipse/launch/ui/PitMutatorsTab.java | 38 +++++++++---------- .../config/LaunchConfigurationWrapper.java | 14 +++++-- .../ui/PitMutatorsPreferencePage.java | 4 +- .../behaviours/pageobjects/WindowsMenu.java | 4 +- .../ui/behaviours/steps/PreferencesSteps.java | 4 +- .../ui/tests/PitclipseOptionsTest.java | 8 ++-- 9 files changed, 56 insertions(+), 46 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java index b316d3f7..b87a6278 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/Mutators.java @@ -27,6 +27,7 @@ * in the class {@link Mutator}. */ public enum Mutators { + CUSTOM("Custom mutator data", "This is used for the custom settings of mutators and should not be seen by the user."), OLD_DEFAULTS("Old defaults", "&Old default Mutators"), DEFAULTS("Defaults", "&Default Mutators"), STRONGER("Stronger defaults", "&Stronger Mutators"), diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index f8107313..b84b1620 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -20,9 +20,10 @@ import static org.pitest.pitclipse.core.preferences.PitPreferences.AVOID_CALLS_TO; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_CLASSES; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXCLUDED_METHODS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS; import static org.pitest.pitclipse.core.preferences.PitPreferences.EXECUTION_MODE; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.INCREMENTAL_ANALYSIS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATOR_GROUP; import static org.pitest.pitclipse.core.preferences.PitPreferences.RUN_IN_PARALLEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT; import static org.pitest.pitclipse.core.preferences.PitPreferences.TIMEOUT_FACTOR; @@ -306,7 +307,8 @@ public File getHistoryFile() { public PitConfiguration getConfiguration() { IPreferenceStore preferenceStore = getPreferenceStore(); String executionMode = preferenceStore.getString(EXECUTION_MODE); - String mutators = preferenceStore.getString(MUTATORS); + String mutatorGroup = preferenceStore.getString(MUTATOR_GROUP); + String mutators = preferenceStore.getString(INDIVIDUAL_MUTATORS); boolean parallelRun = preferenceStore.getBoolean(RUN_IN_PARALLEL); boolean incrementalAnalysis = preferenceStore.getBoolean(INCREMENTAL_ANALYSIS); String excludedClasses = preferenceStore.getString(EXCLUDED_CLASSES); @@ -330,12 +332,13 @@ public PitConfiguration getConfiguration() { break; } } - for (Mutators mutatorMode : Mutators.values()) { - if (mutatorMode.name().equals(mutators)) { - builder.withMutators(mutatorMode.toString()); - break; - } + + if (mutatorGroup.equals(Mutators.CUSTOM.name())) { + builder.withMutators(mutators); + } else { + builder.withMutators(mutatorGroup); } + return builder.build(); } @@ -343,11 +346,11 @@ public void setExecutionMode(PitExecutionMode pitExecutionMode) { getPreferenceStore().setValue(EXECUTION_MODE, pitExecutionMode.getId()); } - public void setMutators(Mutators mutators) { - getPreferenceStore().setValue(MUTATORS, mutators.name()); + public void setMutatorGroup(Mutators mutators) { + getPreferenceStore().setValue(MUTATOR_GROUP, mutators.name()); } - + public String getDefaultMutators() { - return getPreferenceStore().getString(MUTATORS); + return getPreferenceStore().getString(MUTATOR_GROUP); } } diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java index 934af53c..6c2a2d9c 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/preferences/PitPreferences.java @@ -21,7 +21,7 @@ */ public final class PitPreferences { public static final String MUTATORS_LABEL = "Mutators"; - public static final String MUTATORS = "pitMutators"; + public static final String MUTATOR_GROUP = "pitMutators"; public static final String INDIVIDUAL_MUTATORS = "pitIndividualMutators"; diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 976dfbf0..91ef1951 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -17,7 +17,7 @@ package org.pitest.pitclipse.launch.ui; import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATOR_GROUP; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -64,15 +64,11 @@ public final class PitMutatorsTab extends AbstractLaunchConfigurationTab { private static final String MUTATOR_LINK_TEXT = "See the documentation on Pitest.org"; private static final String MUTATOR_LINK = "https://pitest.org/quickstart/mutators/"; public static final String CUSTOM_MUTATOR_RADIO_TEXT = "Mutators selected below"; - /** - * Needed for {@link ButtonSelectionListener#widgetSelected(SelectionEvent)} - */ - private static final String CUSTOM_MUTATOR_RADIO_DATA = "CUSTOM"; private static final String COLUMN_DESCRIPTION = "Description"; private static final String COLUMN_NAME = "Name"; private static final String NO_DESCRIPTION_TEXT = "No description found yet."; private static final String ERROR_MESSAGE = "At least one mutator or mutator group needs to be selected!"; - private String mutators; + private String currentMutatorGroup; private CheckboxTableViewer mutatorsTable; private Button customMutatorsButton; private Button[] groupButtons; @@ -98,8 +94,8 @@ public void dispose() { @Override public void initializeFrom(ILaunchConfiguration config) { PitConfiguration preferences = PitCoreActivator.getDefault().getConfiguration(); - mutators = PitArgumentsTab.getAttributeFromConfig(config, MUTATORS, preferences.getMutators()); - if (!updateSelectionOfGroup(mutators)) { + currentMutatorGroup = PitArgumentsTab.getAttributeFromConfig(config, MUTATOR_GROUP, preferences.getMutators()); + if (!updateSelectionOfGroup(currentMutatorGroup)) { // no selection was made, because no match of data // select custom mutators button customMutatorsButton.setSelection(true); @@ -187,24 +183,30 @@ private void createMutatorGroupsWidgets(Font font, Composite parent) { button.setText(mutatorGroup.getDescriptor()); button.setData(mutatorGroup.name()); button.setFont(font); - button.addSelectionListener(new ButtonSelectionListener()); + button.addSelectionListener(new UpdateDialogOnCurrentMutatorGroupChanged()); groupButtons[i++] = button; GridDataFactory.swtDefaults().applyTo(button); } customMutatorsButton = new Button(grouopComposite, SWT.RADIO); customMutatorsButton.setText(CUSTOM_MUTATOR_RADIO_TEXT); - customMutatorsButton.setData(CUSTOM_MUTATOR_RADIO_DATA); + // set data of button to name of the mutator custom + customMutatorsButton.setData(Mutators.CUSTOM.name()); customMutatorsButton.setFont(font); - customMutatorsButton.addSelectionListener(new ButtonSelectionListener()); + customMutatorsButton.addSelectionListener(new UpdateDialogOnCurrentMutatorGroupChanged()); GridDataFactory.swtDefaults().applyTo(customMutatorsButton); } - private class ButtonSelectionListener extends SelectionAdapter { + /** + * Called each time a mutator group is selected. If this mutator group was not + * previously selected, the launch configuration dialog is updated and the table + * may be disabled if unused. + */ + private class UpdateDialogOnCurrentMutatorGroupChanged extends SelectionAdapter { @Override public void widgetSelected(SelectionEvent event) { - final String old = mutators; - mutators = (String) event.widget.getData(); - if (((Button) event.widget).getSelection() && !old.equals(mutators)) { + final String old = currentMutatorGroup; + currentMutatorGroup = (String) event.widget.getData(); + if (((Button) event.widget).getSelection() && !old.equals(currentMutatorGroup)) { updateLaunchConfigurationDialog(); disableTableIfUnused(); } @@ -285,11 +287,7 @@ protected static void addSeparator(Composite parent) { @Override public void performApply(ILaunchConfigurationWorkingCopy config) { config.setAttribute(INDIVIDUAL_MUTATORS, getIndividualMutators()); - if (isBasicMutatorGroup()) { - config.setAttribute(MUTATORS, mutators); - } else { - config.setAttribute(MUTATORS, getIndividualMutators()); - } + config.setAttribute(MUTATOR_GROUP, currentMutatorGroup); try { PitMigrationDelegate.mapResources(config); } catch (CoreException ce) { diff --git a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java index 1f3c6aaf..a22335ae 100644 --- a/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java +++ b/bundles/org.pitest.pitclipse.launch/src/org/pitest/pitclipse/launch/config/LaunchConfigurationWrapper.java @@ -19,7 +19,8 @@ import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME; import static org.pitest.pitclipse.core.PitCoreActivator.getDefault; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.INDIVIDUAL_MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATOR_GROUP; import java.io.File; import java.math.BigDecimal; @@ -34,6 +35,7 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaCore; +import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.launch.ProjectClosedException; import org.pitest.pitclipse.core.launch.ProjectNotFoundException; import org.pitest.pitclipse.core.launch.TestClassNotFoundException; @@ -263,8 +265,14 @@ public List getMutatedProjects() throws CoreException { private String getMutators() throws CoreException { final String mutators; - if (launchConfig.hasAttribute(MUTATORS)) { - mutators = launchConfig.getAttribute(MUTATORS, ""); + if (launchConfig.hasAttribute(MUTATOR_GROUP)) { + if (launchConfig.getAttribute(MUTATOR_GROUP, "").equals(Mutators.CUSTOM.name())) { + // if we have custom mutators set, get them + mutators = launchConfig.getAttribute(INDIVIDUAL_MUTATORS, ""); + } else { + // use group + mutators = launchConfig.getAttribute(MUTATOR_GROUP, ""); + } } else { mutators = pitConfiguration.getMutators(); } diff --git a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java index 3bab49b3..25538ee2 100644 --- a/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java +++ b/bundles/org.pitest.pitclipse.preferences.ui/src/org/pitest/pitclipse/preferences/ui/PitMutatorsPreferencePage.java @@ -16,7 +16,7 @@ package org.pitest.pitclipse.preferences.ui; -import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS; +import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATOR_GROUP; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_DESCRIPTION_LABEL; import static org.pitest.pitclipse.core.preferences.PitPreferences.MUTATORS_LABEL; @@ -49,7 +49,7 @@ private void createExecutionModeRadioButtons() { for (Mutators mutator : values) { mutatorValues[i++] = new String[] { mutator.getDescriptor(), mutator.name() }; } - addField(new RadioGroupFieldEditor(MUTATORS, MUTATORS_LABEL, 1, mutatorValues, getFieldEditorParent())); + addField(new RadioGroupFieldEditor(MUTATOR_GROUP, MUTATORS_LABEL, 1, mutatorValues, getFieldEditorParent())); } @Override diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java index 5f7870a2..70c90eaa 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java @@ -159,8 +159,8 @@ public Mutators getMutators() { return openPreferences().andThen().getMutators(); } - public void setMutators(Mutators mutators) { - PitCoreActivator.getDefault().setMutators(mutators); + public void setMutatorGroup(Mutators mutators) { + PitCoreActivator.getDefault().setMutatorGroup(mutators); } public void setTimeoutConstant(int timeout) { diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java index 69e2baba..fccc4e67 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/steps/PreferencesSteps.java @@ -153,12 +153,12 @@ public void defaultMutators() { @Given("the stronger mutator preference is selected") public void useStrongerMutators() { - PAGES.getWindowsMenu().setMutators(Mutators.STRONGER); + PAGES.getWindowsMenu().setMutatorGroup(Mutators.STRONGER); } @Given("the all mutators preference is selected") public void useAllMutators() { - PAGES.getWindowsMenu().setMutators(Mutators.ALL); + PAGES.getWindowsMenu().setMutatorGroup(Mutators.ALL); } @Given("the timeout constant is {int}") diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java index dd0b2f78..3da792da 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseOptionsTest.java @@ -70,7 +70,7 @@ public void defaultOptions() { @Test public void useOldDefaultsMutators() throws CoreException { // set OLD_DEFAULTS mutators - PAGES.getWindowsMenu().setMutators(Mutators.OLD_DEFAULTS); + PAGES.getWindowsMenu().setMutatorGroup(Mutators.OLD_DEFAULTS); try { runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); coverageReportGenerated(2, 80, 0, 8, 0); @@ -84,7 +84,7 @@ public void useOldDefaultsMutators() throws CoreException { "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | replaced return of integer sized value with (x == 0 ? 1 : 0)"); } finally { // it's crucial to reset it to the default or we break other tests - PAGES.getWindowsMenu().setMutators(Mutators.DEFAULTS); + PAGES.getWindowsMenu().setMutatorGroup(Mutators.DEFAULTS); } } @@ -104,7 +104,7 @@ public void useDefaultMutators() throws CoreException { @Test public void useStrongerMutators() throws CoreException { // now set STRONGER mutators - PAGES.getWindowsMenu().setMutators(Mutators.STRONGER); + PAGES.getWindowsMenu().setMutatorGroup(Mutators.STRONGER); try { runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT); coverageReportGenerated(2, 80, 0, 8, 0); @@ -119,7 +119,7 @@ public void useStrongerMutators() throws CoreException { "NO_COVERAGE | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 8 | replaced int return with 0 for foo/bar/Foo::f"); } finally { // it's crucial to reset it to the default or we break other tests - PAGES.getWindowsMenu().setMutators(Mutators.DEFAULTS); + PAGES.getWindowsMenu().setMutatorGroup(Mutators.DEFAULTS); } } From 06aa5d809281b1eb1c4cab3293e5cc81801485d9 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Sat, 7 Aug 2021 15:59:04 +0200 Subject: [PATCH 45/50] getDefaultMutatorGroup and setDefaultMutatorGroup for consistency --- .../src/org/pitest/pitclipse/core/PitCoreActivator.java | 4 ++-- .../pitclipse/ui/behaviours/pageobjects/WindowsMenu.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index b84b1620..923a2cf6 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -346,11 +346,11 @@ public void setExecutionMode(PitExecutionMode pitExecutionMode) { getPreferenceStore().setValue(EXECUTION_MODE, pitExecutionMode.getId()); } - public void setMutatorGroup(Mutators mutators) { + public void setDefaultMutatorGroup(Mutators mutators) { getPreferenceStore().setValue(MUTATOR_GROUP, mutators.name()); } - public String getDefaultMutators() { + public String getDefaultMutatorGroup() { return getPreferenceStore().getString(MUTATOR_GROUP); } } diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java index 70c90eaa..546504d1 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/WindowsMenu.java @@ -160,7 +160,7 @@ public Mutators getMutators() { } public void setMutatorGroup(Mutators mutators) { - PitCoreActivator.getDefault().setMutatorGroup(mutators); + PitCoreActivator.getDefault().setDefaultMutatorGroup(mutators); } public void setTimeoutConstant(int timeout) { From bd60277f8ae085f3ef9de8dedc4ab9a437c4d6b7 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Sat, 7 Aug 2021 18:50:08 +0200 Subject: [PATCH 46/50] Moved the image registery to own activator class --- .../org.pitest.pitclipse.core/icons/pit.gif | Bin 217 -> 0 bytes .../pitclipse/core/PitCoreActivator.java | 38 -------- .../pitclipse/launch/ui/PitArgumentsTab.java | 3 +- .../pitclipse/launch/ui/PitMutatorsTab.java | 3 +- .../META-INF/MANIFEST.MF | 4 +- .../pitclipse/ui/core/PitUiActivator.java | 82 ++++++++++++++++++ 6 files changed, 89 insertions(+), 41 deletions(-) delete mode 100644 bundles/org.pitest.pitclipse.core/icons/pit.gif create mode 100644 bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/core/PitUiActivator.java diff --git a/bundles/org.pitest.pitclipse.core/icons/pit.gif b/bundles/org.pitest.pitclipse.core/icons/pit.gif deleted file mode 100644 index d40430cd0caaef3f2d7a249c0cecba329f906fdd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 217 zcmZ?wbhEHb6krfwaA9Cj{K>+>00cT90wmV5f+745L(_lu_W#_S|9QLq^LPIj?D;P_ z;lKRk|JDos+b;YczV3hQ#{cQt{&ye$Kk?N6i!c9Qe)a$MyZ`q;{D1iI|I<(ZpMU=U z`s@GizyJUL4>A@Nu!bct^rS>~Ij&mw`oz9f-1|StaIDO>5o5FDWK2|a>|kj0N;{bn zRCI!Ku|j}_lEmr747@x!_mdN@|7PXxSsrmSCv4aBwuMz^?Rf4s>$ctb{MXQ3t=U77 G!5RSeOks%t diff --git a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java index 923a2cf6..62a7b3a4 100644 --- a/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java +++ b/bundles/org.pitest.pitclipse.core/src/org/pitest/pitclipse/core/PitCoreActivator.java @@ -32,29 +32,20 @@ import java.io.File; import java.io.IOException; import java.math.BigDecimal; -import java.net.URL; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.preferences.ScopedPreferenceStore; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; import org.pitest.pitclipse.runner.config.PitConfiguration; import org.pitest.pitclipse.runner.config.PitExecutionMode; @@ -88,15 +79,6 @@ public class PitCoreActivator extends Plugin { // The shared instance private static PitCoreActivator plugin; - /** - * Image registry for this plug in - */ - private ImageRegistry imageRegistry; - /** - * Key under which the pit icon is put in the registry - */ - private static final String PIT_ICON = "org.pitest.pitclipse.pitIcon"; - private IPreferenceStore preferences; private List pitClasspath = new ArrayList<>(); @@ -107,24 +89,6 @@ public class PitCoreActivator extends Plugin { private File historyFile; - - /** - * Must run in UI thread. - */ - private void initIcons() { - imageRegistry = new ImageRegistry(); - Bundle bundle = FrameworkUtil.getBundle(getClass()); - URL url = FileLocator.find(bundle, new Path("icons/pit.gif"), null); - imageRegistry.put(PIT_ICON, ImageDescriptor.createFromURL(url).createImage()); - } - - /** - * @return Returns the pit icon. - */ - public Image getPitIcon() { - return imageRegistry.get(PIT_ICON); - } - public List getPitClasspath() { return pitClasspath; } @@ -178,8 +142,6 @@ public void start(BundleContext context) throws Exception { // NOPMD - Base pitestJunit5PluginClasspath = new ArrayList<>(); addMavenJarToClasspath(pitestJunit5PluginClasspath, ORG_PITEST_JUNIT5_PLUGIN, "pitest-junit5-plugin.jar"); } - // needs to run in UI thread to create icons - Display.getDefault().syncExec(this::initIcons); } private void addMavenJarToClasspath(List classpath, String bundleName, String jarFile) throws IOException { diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java index 5ebef739..7114b0d3 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitArgumentsTab.java @@ -54,6 +54,7 @@ import org.eclipse.swt.widgets.Text; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; +import org.pitest.pitclipse.ui.core.PitUiActivator; /** * Tab allowing to configure a PIT analyze. @@ -83,7 +84,7 @@ public final class PitArgumentsTab extends AbstractLaunchConfigurationTab { @Override public Image getImage() { - return PitCoreActivator.getDefault().getPitIcon(); + return PitUiActivator.getDefault().getPitIcon(); } @Override diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 91ef1951..f82c0e5b 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -50,6 +50,7 @@ import org.pitest.pitclipse.core.Mutators; import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; +import org.pitest.pitclipse.ui.core.PitUiActivator; import org.pitest.pitclipse.ui.utils.PitclipseUiUtils; /** @@ -81,7 +82,7 @@ public String getName() { @Override public Image getImage() { - return PitCoreActivator.getDefault().getPitIcon(); + return PitUiActivator.getDefault().getPitIcon(); } @Override diff --git a/bundles/org.pitest.pitclipse.ui/META-INF/MANIFEST.MF b/bundles/org.pitest.pitclipse.ui/META-INF/MANIFEST.MF index b44fbff3..25217aab 100644 --- a/bundles/org.pitest.pitclipse.ui/META-INF/MANIFEST.MF +++ b/bundles/org.pitest.pitclipse.ui/META-INF/MANIFEST.MF @@ -3,6 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: Pitclipse UI Bundle-SymbolicName: org.pitest.pitclipse.ui;singleton:=true Bundle-Version: 2.1.2.qualifier +Bundle-Activator: org.pitest.pitclipse.ui.core.PitUiActivator Require-Bundle: org.eclipse.ui;bundle-version="[3.107.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.11.1,4.0.0)", org.eclipse.core.resources;bundle-version="[3.10.1,4.0.0)", @@ -18,6 +19,7 @@ Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: Pitest.org Bundle-ClassPath: . -Export-Package: org.pitest.pitclipse.ui.extension.point, +Export-Package: org.pitest.pitclipse.ui.core, + org.pitest.pitclipse.ui.extension.point, org.pitest.pitclipse.ui.utils Automatic-Module-Name: org.pitest.pitclipse.ui diff --git a/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/core/PitUiActivator.java b/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/core/PitUiActivator.java new file mode 100644 index 00000000..ef7e44d6 --- /dev/null +++ b/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/core/PitUiActivator.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright 2021 Jonas Kutscha and contributors + * + * 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.pitest.pitclipse.ui.core; + +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; + +/** + * The ui activator class which initializes the icons of the plug in + */ +public class PitUiActivator extends AbstractUIPlugin { + /** + * Image registry for this plug in + */ + private ImageRegistry imageRegistry; + /** + * Key under which the pit icon is put in the registry + */ + private static final String PIT_ICON = "org.pitest.pitclipse.pitIcon"; + + /** + * The shared instance + */ + private static PitUiActivator plugin; + + @Override + public void start(BundleContext context) throws Exception { + plugin = this; // NOSONAR typical in Eclipse + initIcons(context); + super.start(context); + } + + /** + * Init of the icons of the plug in + */ + private void initIcons(BundleContext context) { + Display.getDefault().syncExec(() -> { + imageRegistry = new ImageRegistry(); + Bundle bundle = FrameworkUtil.getBundle(getClass()); + URL url = FileLocator.find(bundle, new Path("icons/pit.gif"), null); + imageRegistry.put(PIT_ICON, ImageDescriptor.createFromURL(url).createImage()); + }); + } + + /** + * @return Returns the pit icon. + */ + public Image getPitIcon() { + return imageRegistry.get(PIT_ICON); + } + + /** + * @return the shared instance + */ + public static PitUiActivator getDefault() { + return plugin; + } +} From 615e3f9661bfefce76f3a227533979ad016bef24 Mon Sep 17 00:00:00 2001 From: Jonas <50097340+JKutscha@users.noreply.github.com> Date: Sat, 7 Aug 2021 19:20:41 +0200 Subject: [PATCH 47/50] Remove icons folder from build of core --- bundles/org.pitest.pitclipse.core/build.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/org.pitest.pitclipse.core/build.properties b/bundles/org.pitest.pitclipse.core/build.properties index a028eff6..d3f1f000 100644 --- a/bundles/org.pitest.pitclipse.core/build.properties +++ b/bundles/org.pitest.pitclipse.core/build.properties @@ -1,6 +1,5 @@ source.. = src/ bin.includes = plugin.xml,\ META-INF/,\ - icons/,\ . jars.compile.order = . From 2002c64d59ad8cb9611b6dcf83471a8fcfd86387 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 9 Aug 2021 18:31:57 +0200 Subject: [PATCH 48/50] try to make UI tests less flaky in KDE --- .../ui/behaviours/pageobjects/RunConfigurationSelector.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java index 8e1a6d0e..47c5630d 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/RunConfigurationSelector.java @@ -101,11 +101,15 @@ private SWTBotShell activateShell() { return shell; } } + // make sure we don't have pending shells + bot.closeAllShells(); // shell was not open, open and activate it SWTBotMenuHelper menuHelper = new SWTBotMenuHelper(); menuHelper.findMenu(bot.menu(RUN), RUN_CONFIGURATIONS + "...").click(); SWTBotShell shell = bot.shell(RUN_CONFIGURATIONS); shell.activate(); + // make sure the dialog is active + bot.waitUntil(shellIsActive(RUN_CONFIGURATIONS)); return shell; } From 5e961cbcce9246843a4561f41e2379c47e365662 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Tue, 10 Aug 2021 14:08:58 +0200 Subject: [PATCH 49/50] Created link selection adapter to exclude from code coverage --- .../pitclipse/launch/ui/PitMutatorsTab.java | 9 +---- .../ui/utils/LinkSelectionAdapter.java | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/utils/LinkSelectionAdapter.java diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index f82c0e5b..6ed86cb2 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -41,7 +41,6 @@ import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; @@ -51,6 +50,7 @@ import org.pitest.pitclipse.core.PitCoreActivator; import org.pitest.pitclipse.runner.config.PitConfiguration; import org.pitest.pitclipse.ui.core.PitUiActivator; +import org.pitest.pitclipse.ui.utils.LinkSelectionAdapter; import org.pitest.pitclipse.ui.utils.PitclipseUiUtils; /** @@ -152,12 +152,7 @@ private void createDescription(Composite parent) { GridDataFactory.swtDefaults().indent(5, 0).applyTo(descriptionLabel); Link link = new Link(parent, SWT.NONE); link.setText("" + MUTATOR_LINK_TEXT + ""); - link.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - Program.launch(MUTATOR_LINK); - } - }); + link.addSelectionListener(new LinkSelectionAdapter(MUTATOR_LINK)); GridDataFactory.swtDefaults().applyTo(link); } diff --git a/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/utils/LinkSelectionAdapter.java b/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/utils/LinkSelectionAdapter.java new file mode 100644 index 00000000..dbf8cf12 --- /dev/null +++ b/bundles/org.pitest.pitclipse.ui/src/org/pitest/pitclipse/ui/utils/LinkSelectionAdapter.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2021 Jonas Kutscha and contributors + * + * 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.pitest.pitclipse.ui.utils; + +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.program.Program; + +/** + * Selection adapter which launches a browser with the link. + * @author jkutscha + */ +public class LinkSelectionAdapter extends SelectionAdapter { + private final String link; + + public LinkSelectionAdapter(final String link) { + this.link = link; + } + + @Override + public void widgetSelected(SelectionEvent e) { + Program.launch(link); + } +} From 3002ac3fadbb873dc9bfb592f2d03d8eeb7571e3 Mon Sep 17 00:00:00 2001 From: Jonas Kutscha Date: Tue, 10 Aug 2021 14:17:00 +0200 Subject: [PATCH 50/50] Removed cast to String, but was not needed --- .../src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java index 6ed86cb2..0ce58d01 100644 --- a/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java +++ b/bundles/org.pitest.pitclipse.launch.ui/src/org/pitest/pitclipse/launch/ui/PitMutatorsTab.java @@ -319,7 +319,7 @@ private boolean updateSelectionOfGroup(String value) { boolean found = false; for (Button button : groupButtons) { boolean selection = false; - if (((String) button.getData()).equals(value)) { + if (button.getData().equals(value)) { selection = true; found = true; }