Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
echebbi committed Mar 23, 2024
1 parent fa97e5f commit 651eb74
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@

package org.pitest.pitclipse.runner.io;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.Socket;

import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals;
import static org.apache.commons.lang3.builder.HashCodeBuilder.reflectionHashCode;
import static org.hamcrest.CoreMatchers.equalTo;
Expand All @@ -43,10 +27,25 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.Socket;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class ObjectStreamSocketTest {

Expand Down Expand Up @@ -121,7 +120,7 @@ public void makeThrowsException() throws IOException {

@Test
public void readThrowsException() throws IOException, ClassNotFoundException {
InputStream inputStream = spy(new ByteArrayInputStream(asBytes(expectedObject)));
InputStream inputStream = new ByteArrayInputStream(asBytes(expectedObject));
OutputStream outputStream = new ByteArrayOutputStream();
when(underlyingSocket.getInputStream()).thenReturn(inputStream);
when(underlyingSocket.getOutputStream()).thenReturn(outputStream);
Expand All @@ -138,7 +137,7 @@ public void readThrowsException() throws IOException, ClassNotFoundException {

@Test
public void writeThrowsException() throws IOException, ClassNotFoundException {
InputStream inputStream = spy(new ByteArrayInputStream(asBytes(expectedObject)));
InputStream inputStream = new ByteArrayInputStream(asBytes(expectedObject));
OutputStream outputStream = new ByteArrayOutputStream();
when(underlyingSocket.getInputStream()).thenReturn(inputStream);
when(underlyingSocket.getOutputStream()).thenReturn(outputStream);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.pitest.pitclipse.ui.behaviours.pageobjects;

import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;

public class DurationElapsed extends DefaultCondition {

private Long time;

private long durationInSeconds;

public DurationElapsed(long duration) {
this.durationInSeconds = duration;
}

@Override
public boolean test() throws Exception {
if (time == null) {
time = System.currentTimeMillis();
}
return time + 2000 <= System.currentTimeMillis();
}

@Override
public String getFailureMessage() {
return "Failed to wait for " + durationInSeconds + " s";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public NoTestsFoundDialog(SWTWorkbenchBot bot) {
public void assertAppears() {
SWTBotShell shell = bot.shell("Pitclipse");
shell.activate();
bot.waitUntil(new DurationElapsed(500));
bot.label("No tests found");
bot.waitUntil(new DurationElapsed(500));
bot.button("OK").click();

bot.waitUntil(Conditions.shellCloses(shell));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public SWTBotView getView() {
SWTBotView mutationsView = bot.viewByTitle("PIT Mutations");
mutationsView.show();
mutationsView.setFocus();
//
// Make sure the 'PIT Mutations' view is opened
// this should not be required anymore
// bot.waitUntil(new ViewOpenedCondition(bot, "PIT Mutations"));
//
bot.waitUntil(new ViewOpenedCondition(bot, "PIT Mutations"));
return mutationsView;
}

Expand Down Expand Up @@ -157,12 +158,13 @@ private MutationsTree(ImmutableList<StatusTree> statuses) {
this.statuses = statuses;
}

public void select(PitMutation mutation) {
public boolean select(PitMutation mutation) {
String status = mutation.getStatus().toString();
for (StatusTree statusTree : statuses) {
if (status.equals(statusTree.statusName)) {
statusTree.select(mutation);
return;
if (statusTree.select(mutation)) {
return true;
}
}
}
throw new AssertionFailedError(
Expand All @@ -187,11 +189,12 @@ private StatusTree(String statusName, ImmutableList<ProjectTree> projects) {
this.projects = projects;
}

public void select(PitMutation mutation) {
public boolean select(PitMutation mutation) {
for (ProjectTree projectTree : projects) {
if (mutation.getProject().equals(projectTree.projectName)) {
projectTree.select(mutation);
return;
if (projectTree.select(mutation)) {
return true;
}
}
}
throw new AssertionFailedError(
Expand All @@ -218,11 +221,12 @@ private ProjectTree(String projectName, ImmutableList<PackageTree> packages) {
this.packages = packages;
}

public void select(PitMutation mutation) {
public boolean select(PitMutation mutation) {
for (PackageTree packageTree : packages) {
if (mutation.getPkg().equals(packageTree.packageName)) {
packageTree.select(mutation);
return;
if (packageTree.select(mutation)) {
return true;
}
}
}
throw new AssertionFailedError(
Expand All @@ -249,11 +253,12 @@ private PackageTree(String packageName, ImmutableList<ClassTree> classes) {
this.classes = classes;
}

public void select(PitMutation mutation) {
public boolean select(PitMutation mutation) {
for (ClassTree classTree : classes) {
if (mutation.getClassName().equals(classTree.className)) {
classTree.select(mutation);
return;
if (classTree.select(mutation)) {
return true;
}
}
}
throw new AssertionFailedError(
Expand All @@ -280,12 +285,12 @@ private ClassTree(String className, ImmutableList<MutationTree> projects) {
this.mutations = projects;
}

public void select(PitMutation mutation) {
public boolean select(PitMutation mutation) {
for (MutationTree mutationTree : mutations) {
if (mutation.getLineNumber() == mutationTree.lineNumber &&
mutation.getMutation().equals(mutationTree.mutation)) {
mutationTree.select();
return;
return true;
}
}
throw new AssertionFailedError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;

class ViewOpenedCondition extends DefaultCondition {
public class ViewOpenedCondition extends DefaultCondition {

private SWTWorkbenchBot bot;
private String viewTitle;

public ViewOpenedCondition(SWTWorkbenchBot bot, String viewTitle) {
this.bot = bot;
this.viewTitle = viewTitle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.runner.RunWith;
import org.pitest.pitclipse.core.PitCoreActivator;
import org.pitest.pitclipse.core.preferences.PitPreferences;
import org.pitest.pitclipse.ui.behaviours.pageobjects.DurationElapsed;
import org.pitest.pitclipse.ui.behaviours.pageobjects.PitPreferenceSelector;

/**
Expand Down Expand Up @@ -66,12 +67,14 @@ public void removeLaunchConfigurations() throws CoreException {
public void testExecutionMode() throws CoreException {
try {
PitPreferenceSelector selector = PAGES.getWindowsMenu().openPreferences().andThen();
bot.waitUntil(new DurationElapsed(200));
assertEquals(PROJECT_ISOLATION, selector.getPitExecutionMode());
selector.close();
runProjectTest(FOO_BAR_PROJECT);
// only the classes in the project is mutated
coverageReportGenerated(2, 100, 100, 3, 3);
selector = PAGES.getWindowsMenu().openPreferences().andThen();
bot.waitUntil(new DurationElapsed(200));
selector.setPitExecutionMode(WORKSPACE);
selector.close();
runProjectTest(FOO_BAR_PROJECT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.pitest.pitclipse.ui.tests;

import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withTitle;
import static org.eclipse.swtbot.eclipse.finder.waits.Conditions.waitForEditor;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand All @@ -10,6 +12,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.pitest.pitclipse.ui.behaviours.pageobjects.DurationElapsed;
import org.pitest.pitclipse.ui.behaviours.pageobjects.PitMutationsViewPageObject;
import org.pitest.pitclipse.ui.behaviours.steps.PitMutation;
import org.pitest.pitclipse.ui.behaviours.steps.PitclipseSteps;
Expand Down Expand Up @@ -47,12 +50,21 @@ public void selectMutationOpensTheClassAtTheRightLineNumber() throws CoreExcepti
coverageReportGenerated(2, 80, 0, 6, 0);
PitclipseSteps pitclipseSteps = new PitclipseSteps();
PitMutation mutation = fromMutationLine(
"SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | negated conditional");
"SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Foo | 7 | removed conditional - replaced equality check with false");
final PitMutationsViewPageObject pitMutationsView = new PitMutationsViewPageObject(bot);
pitMutationsView.getView();
bot.waitUntil(new DurationElapsed(200));
pitclipseSteps.doubleClickMutationInMutationsView(mutation);

bot.waitUntil(waitForEditor(withTitle(FOO_CLASS + ".java")));
bot.waitUntil(new DurationElapsed(200));
pitclipseSteps.mutationIsOpened(FOO_CLASS + ".java", 7);
mutation = fromMutationLine(
"SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | negated conditional");
"SURVIVED | " + TEST_PROJECT + " | foo.bar | foo.bar.Bar | 7 | removed conditional - replaced equality check with false");
pitclipseSteps.doubleClickMutationInMutationsView(mutation);

bot.waitUntil(waitForEditor(withTitle(BAR_CLASS + ".java")));
bot.waitUntil(new DurationElapsed(200));
pitclipseSteps.mutationIsOpened(BAR_CLASS + ".java", 7);
}

Expand Down

0 comments on commit 651eb74

Please sign in to comment.