Skip to content

Commit

Permalink
81: test selection in PitMutationsView
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed May 12, 2021
1 parent 798593a commit b69bf3d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ private void createTreeViewer(Composite parent) {
viewer.setLabelProvider(new ViewLabelProvider());
viewer.addDoubleClickListener(ExpandingDoubleClick.LISTENER);
viewer.addDoubleClickListener(OpenMutationDoubleClick.LISTENER);
// viewer.addSelectionChangedListener(listener);
viewer.setInput(MutationsModel.EMPTY_MODEL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public PitMutationsView(SWTWorkbenchBot bot) {
}

public List<PitMutation> getMutations() {
PAGES.views().waitForTestsAreRunOnConsole();
SWTBotTree mutationTree = mutationTreeRoot();
return mutationsFrom(mutationTree);
}

private SWTBotTree mutationTreeRoot() {
PAGES.views().waitForTestsAreRunOnConsole();
SWTBotView mutationsView = bot.viewByTitle("PIT Mutations");
mutationsView.show();
// Make sure the 'PIT Mutations' view is opened
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public void mutationsAre(DataTable tableOfMutations) {
@When("the following mutation is selected")
public void mutationIsSelected(DataTable tableOfMutations) {
PitMutation mutation = mutationsFromExampleTable(tableOfMutations).get(0);
mutationIsSelected(mutation);
}

public void mutationIsSelected(PitMutation mutation) {
PAGES.getPitMutationsView()
.select(mutation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
@RunWith(SWTBotJunit4ClassRunner.class)
public abstract class AbstractPitclipseSWTBotTest {
protected static SWTWorkbenchBot bot;
private static int statusIndex = 0;
private static int projectIndex = 1;
private static int packageIndex = 2;
private static int classIndex = 3;
private static int lineIndex = 4;
private static int mutationIndex = 5;

@BeforeClass
public static void beforeClass() throws Exception {
Expand Down Expand Up @@ -292,27 +298,26 @@ protected static void consoleContains(int generatedMutants, int killedMutants,
protected static void mutationsAre(String expectedMutationsTable) {
List<PitMutation> expectedMutations = new ArrayList<>();
String[] lines = expectedMutationsTable.split("\n");
final int statusIndex = 0;
final int projectIndex = 1;
final int packageIndex = 2;
final int classIndex = 3;
final int lineIndex = 4;
final int mutationIndex = 5;
for (String string : lines) {
String[] mutationRow = string.split("\\|");
DetectionStatus status = DetectionStatus.valueOf(mutationRow[statusIndex].trim());
String project = mutationRow[projectIndex].trim();
String pkg = mutationRow[packageIndex].trim();
String className = mutationRow[classIndex].trim();
int line = parseInt(mutationRow[lineIndex].trim());
String mutation = mutationRow[mutationIndex].trim();
PitMutation pitMutation = PitMutation.builder().withStatus(status).withProject(project).withPackage(pkg)
.withClassName(className).withLineNumber(line).withMutation(mutation).build();
for (String line : lines) {
PitMutation pitMutation = fromMutationLine(line);
expectedMutations.add(pitMutation);
}
mutationsAre(expectedMutations);
}

protected static PitMutation fromMutationLine(String line) {
String[] mutationRow = line.split("\\|");
DetectionStatus status = DetectionStatus.valueOf(mutationRow[statusIndex].trim());
String project = mutationRow[projectIndex].trim();
String pkg = mutationRow[packageIndex].trim();
String className = mutationRow[classIndex].trim();
int lineNum = parseInt(mutationRow[lineIndex].trim());
String mutation = mutationRow[mutationIndex].trim();
PitMutation pitMutation = PitMutation.builder().withStatus(status).withProject(project).withPackage(pkg)
.withClassName(className).withLineNumber(lineNum).withMutation(mutation).build();
return pitMutation;
}

protected static void mutationsAre(List<PitMutation> expectedMutations) {
List<PitMutation> actualMutations = PAGES.getPitMutationsView().getMutations();
assertThat(actualMutations, equalTo(expectedMutations));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.pitest.pitclipse.ui.tests;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.pitest.pitclipse.ui.behaviours.steps.PitMutation;
import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps;

/**
* @author Lorenzo Bettini
*
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public class PitclipsePitMutationsViewTest extends AbstractPitclipseSWTBotTest {

private static final String TEST_PROJECT = "project1";
private static final String FOO_BAR_PACKAGE = "foo.bar";
private static final String FOO_CLASS = "Foo";
private static final String FOO_TEST_CLASS = "FooTest";
private static final String BAR_CLASS = "Bar";
private static final String BAR_TEST_CLASS = "BarTest";

@Test
public void selectMutationOpensTheClassAtTheRightLineNumber() throws CoreException {
createJavaProjectWithJUnit4(TEST_PROJECT);
verifyProjectExists(TEST_PROJECT);
createClassWithMethod(FOO_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT,
"public int f(int i) {\n"
+ " java.util.ArrayList<Object> pointless = new java.util.ArrayList<>();\n"
+ " if (pointless.size() == 1)\n"
+ " return i + 1;\n"
+ " else\n"
+ " return 0;\n"
+ "}");
createClassWithMethod(FOO_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT,
"@org.junit.Test public void badTest() {\n"
+ " " + FOO_CLASS + " x = new " + FOO_CLASS + "();\n"
+ " x.f(1);\n"
+ "}");
createClassWithMethod(BAR_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT,
"public int f(int i) {\n"
+ " java.util.ArrayList<Object> pointless = new java.util.ArrayList<>();\n"
+ " if (pointless.size() == 1)\n"
+ " return i + 1;\n"
+ " else\n"
+ " return 0;\n"
+ "}");
createClassWithMethod(BAR_TEST_CLASS, FOO_BAR_PACKAGE, TEST_PROJECT,
"@org.junit.Test public void badTest() {\n"
+ " " + BAR_CLASS + " x = new " + BAR_CLASS + "();\n"
+ " x.f(1);\n"
+ "}");
runPackageTest(FOO_BAR_PACKAGE, TEST_PROJECT);
coverageReportGenerated(2, 80, 0);
PitclipseSteps pitclipseSteps = new PitclipseSteps();
PitMutation mutation = fromMutationLine(
"SURVIVED | project1 | foo.bar | foo.bar.Foo | 7 | negated conditional");
pitclipseSteps.mutationIsSelected(mutation);
pitclipseSteps.mutationIsOpened(FOO_CLASS + ".java", 7);
mutation = fromMutationLine(
"SURVIVED | project1 | foo.bar | foo.bar.Bar | 7 | negated conditional");
pitclipseSteps.mutationIsSelected(mutation);
pitclipseSteps.mutationIsOpened(BAR_CLASS + ".java", 7);
}
}

0 comments on commit b69bf3d

Please sign in to comment.