From 651eb74798b5a53d68b9d4808dde3094caf044ce Mon Sep 17 00:00:00 2001 From: Emmanuel CHEBBI Date: Sat, 23 Mar 2024 23:27:03 +0100 Subject: [PATCH] WIP --- .../runner/io/ObjectStreamSocketTest.java | 37 +++++++++---------- .../pageobjects/DurationElapsed.java | 27 ++++++++++++++ .../pageobjects/NoTestsFoundDialog.java | 2 + .../PitMutationsViewPageObject.java | 37 +++++++++++-------- .../pageobjects/ViewOpenedCondition.java | 4 +- .../tests/PitclipseMultipleProjectsTest.java | 3 ++ .../tests/PitclipsePitMutationsViewTest.java | 16 +++++++- 7 files changed, 87 insertions(+), 39 deletions(-) create mode 100644 tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/DurationElapsed.java diff --git a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/io/ObjectStreamSocketTest.java b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/io/ObjectStreamSocketTest.java index 74c56d44..4e69538e 100644 --- a/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/io/ObjectStreamSocketTest.java +++ b/tests/org.pitest.pitclipse.runner.tests/src/org/pitest/pitclipse/runner/io/ObjectStreamSocketTest.java @@ -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; @@ -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 { @@ -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); @@ -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); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/DurationElapsed.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/DurationElapsed.java new file mode 100644 index 00000000..9a2254e6 --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/DurationElapsed.java @@ -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"; + } +} \ No newline at end of file diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NoTestsFoundDialog.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NoTestsFoundDialog.java index 58b53042..cb85606b 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NoTestsFoundDialog.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NoTestsFoundDialog.java @@ -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)); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsViewPageObject.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsViewPageObject.java index 9cbca2ff..18c4db07 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsViewPageObject.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PitMutationsViewPageObject.java @@ -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; } @@ -157,12 +158,13 @@ private MutationsTree(ImmutableList 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( @@ -187,11 +189,12 @@ private StatusTree(String statusName, ImmutableList 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( @@ -218,11 +221,12 @@ private ProjectTree(String projectName, ImmutableList 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( @@ -249,11 +253,12 @@ private PackageTree(String packageName, ImmutableList 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( @@ -280,12 +285,12 @@ private ClassTree(String className, ImmutableList 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( diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/ViewOpenedCondition.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/ViewOpenedCondition.java index 873d182b..0fb4b5c5 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/ViewOpenedCondition.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/ViewOpenedCondition.java @@ -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; 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 b09aa6df..6e8c9e4c 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 @@ -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; /** @@ -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); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipsePitMutationsViewTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipsePitMutationsViewTest.java index cda857e7..c20ac044 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipsePitMutationsViewTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipsePitMutationsViewTest.java @@ -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; @@ -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; @@ -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); }