Skip to content

Commit

Permalink
Removed references to AssumptionViolatedException to avoid dependency…
Browse files Browse the repository at this point in the history
… conflict issues
  • Loading branch information
wakaleo committed May 11, 2024
1 parent 4cc47a5 commit 796a865
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -43,7 +43,7 @@
<junit.version>4.13.2</junit.version>
<groovy.version>4.0.13</groovy.version>
<spock.version>2.4-M1-groovy-4.0</spock.version>
<byte-buddy.version>1.14.14</byte-buddy.version>
<byte-buddy.version>1.14.15</byte-buddy.version>
<guava.version>33.1.0-jre</guava.version>
<hamcrest.version>2.2</hamcrest.version>
<slf4j.version>2.0.9</slf4j.version>
Expand Down
Expand Up @@ -38,11 +38,9 @@
import net.thucydides.core.webdriver.ThucydidesWebDriverSupport;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.internal.AssumptionViolatedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -947,7 +945,12 @@ private Optional<TestOutcome> latestTestOutcome() {
}

private boolean isAssumptionFailure(Throwable rootCause) {
return (AssumptionViolatedException.class.isAssignableFrom(rootCause.getClass()));
try {
Class<?> assumptionViolationException = Class.forName("org.junit.AssumptionViolatedException");
return assumptionViolationException.isAssignableFrom(rootCause.getClass());
} catch (ClassNotFoundException e) {
return false;
}
}

private String stepTitleFrom(io.cucumber.messages.types.Step currentStep, TestStep testStep) {
Expand All @@ -962,9 +965,9 @@ private String embeddedTableDataIn(PickleStepTestStep currentStep) {
if (currentStep.getStep().getArgument() != null) {
StepArgument stepArgument = currentStep.getStep().getArgument();
if (stepArgument instanceof DataTableArgument) {
List<Map<String, Object>> rowList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> rowList = new ArrayList<>();
for (List<String> row : ((DataTableArgument) stepArgument).cells()) {
Map<String, Object> rowMap = new HashMap<String, Object>();
Map<String, Object> rowMap = new HashMap<>();
rowMap.put("cells", row);
rowList.add(rowMap);
}
Expand Down
Expand Up @@ -8,7 +8,6 @@
import net.thucydides.model.steps.ExecutedStepDescription;
import net.thucydides.model.steps.StepFailure;
import net.thucydides.core.steps.events.StepEventBusEventBase;
import org.junit.internal.AssumptionViolatedException;

import java.time.ZonedDateTime;
import java.util.*;
Expand Down Expand Up @@ -119,7 +118,12 @@ private Optional<TestOutcome> latestTestOutcome() {
}

private boolean isAssumptionFailure(Throwable rootCause) {
return (AssumptionViolatedException.class.isAssignableFrom(rootCause.getClass()));
try {
Class<?> assumptionViolationException = Class.forName("org.junit.AssumptionViolatedException");
return assumptionViolationException.isAssignableFrom(rootCause.getClass());
} catch (ClassNotFoundException e) {
return false;
}
}


Expand Down
Expand Up @@ -3,9 +3,10 @@
import net.thucydides.core.steps.BaseStepListener;
import net.thucydides.core.steps.StepEventBus;
import net.thucydides.core.steps.StepPublisher;
import org.junit.AssumptionViolatedException;
import org.junit.runners.model.Statement;

import java.lang.reflect.InvocationTargetException;

/**
* A JUnit statement that runs a Serenity-enabled test and then publishes the results via JUnit.
*/
Expand All @@ -31,12 +32,14 @@ public void evaluate() throws Throwable {
try {
updateCurrentEventBusFrom(publisher);
statement.evaluate();
} catch (AssumptionViolatedException assumptionViolated) {
stepEventBus().assumptionViolated(assumptionViolated.getMessage());
} catch (AssertionError assertionError) {
if (!stepEventBus().aStepInTheCurrentTestHasFailed()) {
throw assertionError;
}
} catch (Throwable throwable) {
if (throwable.getClass().getSimpleName().endsWith("AssumptionViolatedException")) {
stepEventBus().assumptionViolated(throwable.getMessage());
}
}
checkForStepFailures();
checkForAssumptionViolations();
Expand All @@ -62,7 +65,12 @@ private void checkForStepFailures() throws Throwable {

private void checkForAssumptionViolations() {
if (stepEventBus().assumptionViolated()) {
throw new AssumptionViolatedException(stepEventBus().getAssumptionViolatedMessage());
try {
Class<?> assumptionViolatedException = Class.forName("org.junit.AssumptionViolatedException");
throw ((RuntimeException) assumptionViolatedException.getConstructor(String.class).newInstance(stepEventBus().getAssumptionViolatedMessage()));
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
}
}
Expand Up @@ -3,7 +3,6 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
Expand Down Expand Up @@ -49,10 +48,12 @@ public void evaluate() throws Throwable {
base.evaluate();
result = "passed";
state.passes++;
} catch (AssumptionViolatedException e) {
result = "skipped";
} catch (Throwable t) {
result = "failed";
if (t.getClass().getSimpleName().endsWith("AssumptionViolatedException")) {
result = "skipped";
} else {
result = "failed";
}
state.failures++;
cause = t;
}
Expand Down

0 comments on commit 796a865

Please sign in to comment.