Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import org.assertj.core.api.AbstractAssert;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
Expand All @@ -26,6 +25,7 @@
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.assertj.core.api.AbstractAssert;

import java.util.function.Supplier;

Expand All @@ -51,22 +51,26 @@ protected AllureLifecycle initialValue() {

private static final ThreadLocal<Boolean> RECORDING_MUTED = ThreadLocal.withInitial(() -> false);

@Pointcut("("
+ "call(public static * org.assertj.core.api.Assertions*.assertThat*(..))"
+ " || call(public static * org.assertj.core.api.BDDAssertions*.then*(..))"
+ " || call(public * org.assertj.core.api.*SoftAssertionsProvider+.assertThat*(..))"
+ " || call(public * org.assertj.core.api.*SoftAssertionsProvider+.then*(..))"
+ ")")
@Pointcut(
"("
+ "call(public static * org.assertj.core.api.Assertions*.assertThat*(..))"
+ " || call(public static * org.assertj.core.api.BDDAssertions*.then*(..))"
+ " || call(public * org.assertj.core.api.*SoftAssertionsProvider+.assertThat*(..))"
+ " || call(public * org.assertj.core.api.*SoftAssertionsProvider+.then*(..))"
+ ")"
)
public void assertFactoryCall() {
//pointcut body, should be empty
}

@Pointcut("("
+ "call(public * org.assertj.core.api.AbstractAssert+.*(..))"
+ " || call(public * org.assertj.core.api.Assert+.*(..))"
+ " || call(public * org.assertj.core.api.Descriptable+.*(..))"
+ ")"
+ " && target(assertion)")
@Pointcut(
"("
+ "call(public * org.assertj.core.api.AbstractAssert+.*(..))"
+ " || call(public * org.assertj.core.api.Assert+.*(..))"
+ " || call(public * org.assertj.core.api.Descriptable+.*(..))"
+ ")"
+ " && target(assertion)"
)
public void assertOperationCall(final AbstractAssert<?, ?> assertion) {
//pointcut body, should be empty
}
Expand All @@ -76,7 +80,10 @@ public void userCodeCall() {
//pointcut body, should be empty
}

@AfterReturning(pointcut = "assertFactoryCall() && userCodeCall()", returning = "result")
@AfterReturning(
pointcut = "assertFactoryCall() && userCodeCall()",
returning = "result"
)
public void logAssertCreation(final JoinPoint joinPoint, final Object result) {
if (isRecordingMuted() || !(result instanceof AbstractAssert)) {
return;
Expand All @@ -88,7 +95,8 @@ public void logAssertCreation(final JoinPoint joinPoint, final Object result) {

@Around("assertOperationCall(assertion) && userCodeCall()")
public Object logAssertOperation(final ProceedingJoinPoint joinPoint,
final AbstractAssert<?, ?> assertion) throws Throwable {
final AbstractAssert<?, ?> assertion)
throws Throwable {
final String methodName = getMethodName(joinPoint);
if (isRecordingMuted() || getRecorder().isIgnored(methodName)) {
return joinPoint.proceed();
Expand All @@ -110,8 +118,10 @@ public Object logAssertOperation(final ProceedingJoinPoint joinPoint,
}
}

@After("execution(public void org.assertj.core.api.DefaultAssertionErrorCollector.collectAssertionError("
+ "java.lang.AssertionError)) && args(error)")
@After(
"execution(public void org.assertj.core.api.DefaultAssertionErrorCollector.collectAssertionError("
+ "java.lang.AssertionError)) && args(error)"
)
public void softAssertionFailed(final AssertionError error) {
getRecorder().softAssertionFailed(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,37 @@ final class AssertJMethodSupport {
"toString"
);

private static final Set<String> NAVIGATION_METHODS = new HashSet<>(Arrays.asList(
"asBase64Decoded",
"asBoolean",
"asByte",
"asDouble",
"asFloat",
"asInstanceOf",
"asInt",
"asList",
"asLong",
"asShort",
"asString",
"bytes",
"decodedAsBase64",
"element",
"elements",
"extracting",
"extractingResultOf",
"first",
"flatExtracting",
"flatMap",
"last",
"map",
"rootCause",
"singleElement",
"size",
"usingRecursiveAssertion",
"usingRecursiveComparison"
));
private static final Set<String> NAVIGATION_METHODS = new HashSet<>(
Arrays.asList(
"asBase64Decoded",
"asBoolean",
"asByte",
"asDouble",
"asFloat",
"asInstanceOf",
"asInt",
"asList",
"asLong",
"asShort",
"asString",
"bytes",
"decodedAsBase64",
"element",
"elements",
"extracting",
"extractingResultOf",
"first",
"flatExtracting",
"flatMap",
"last",
"map",
"rootCause",
"singleElement",
"size",
"usingRecursiveAssertion",
"usingRecursiveComparison"
)
);

private AssertJMethodSupport() {
throw new IllegalStateException("do not instantiate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.qameta.allure.assertj;

import io.qameta.allure.model.Stage;
import io.qameta.allure.model.Parameter;
import io.qameta.allure.model.Stage;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.StepResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,10 @@ private boolean isNavigationResult(final AssertJOperation activeOperation) {
return activeOperation != null && activeOperation.isNavigation();
}

@SuppressWarnings("PMD.CompareObjectsWithEquals")
private boolean isInternalCallOnSameChain(final AssertJOperation activeOperation, final AssertJChain chain) {
return activeOperation != null && activeOperation.getChain() == chain;
}

@SuppressWarnings("PMD.CompareObjectsWithEquals")
private void pop(final AssertJOperation operation) {
if (operation.isNested()) {
operation.leaveNested();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ List<Parameter> renderParameters(final String methodName, final Object[] args) {
if (renderedOperation.contains(value)) {
continue;
}
parameters.add(new Parameter()
.setName(parameterName(methodName, index))
.setValue(value)
.setMode(Parameter.Mode.DEFAULT));
parameters.add(
new Parameter()
.setName(parameterName(methodName, index))
.setValue(value)
.setMode(Parameter.Mode.DEFAULT)
);
}
return parameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ void shouldRenderSmallArraysAsValues() {
@Test
void shouldRenderTuplesAsValues() {
final AllureResults results = runWithinTestContext(() -> {
assertThat(Arrays.asList(
tuple("first", Status.PASSED),
tuple("second", Status.FAILED)
))
assertThat(
Arrays.asList(
tuple("first", Status.PASSED),
tuple("second", Status.FAILED)
)
)
.containsExactly(
tuple("first", Status.PASSED),
tuple("second", Status.FAILED)
Expand Down Expand Up @@ -465,9 +467,11 @@ void shouldMarkTheFailedSoftAssertionOperationBeforeAssertAll() {
void shouldAttachNestedAssertionsUnderCallbackOperations() {
final AllureResults results = runWithinTestContext(() -> {
assertThat("alpha")
.satisfies(value -> assertThat(value)
.startsWith("al")
.endsWith("ha"));
.satisfies(
value -> assertThat(value)
.startsWith("al")
.endsWith("ha")
);
}, AllureAspectJ::setLifecycle);

final TestResult result = assertOnlyOneResult(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* @param <T> the type of attachment data
* @author charlie (Dmitry Baev).
*/
@SuppressWarnings("PMD.AvoidUncheckedExceptionsInSignatures")
@FunctionalInterface
public interface AttachmentRenderer<T extends AttachmentData> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class FreemarkerAttachmentRendererTest {
private static final String FILE_EXTENSION = "fileExtension";
private static final String HTML = ".html";


@AllureFeatures.Attachments
@Test
void shouldRenderRequestAttachment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public class AllureAwaitilityListener implements ConditionEvaluationListener<Obj

private String currentConditionStepUUID;

private static final InheritableThreadLocal<AllureLifecycle> LIFECYCLE
= new InheritableThreadLocal<AllureLifecycle>() {
private static final InheritableThreadLocal<AllureLifecycle> LIFECYCLE = new InheritableThreadLocal<AllureLifecycle>() {
@Override
protected AllureLifecycle initialValue() {
return Allure.getLifecycle();
Expand Down Expand Up @@ -225,7 +224,8 @@ public void exceptionIgnored(final IgnoredException ignoredException) {
getLifecycle().updateStep(awaitilityCondition -> {
final String currentExceptionIgnoredStepUUID = UUID.randomUUID().toString();
final String message = String.format(
onExceptionStepTextPattern, ignoredException.getThrowable().getMessage());
onExceptionStepTextPattern, ignoredException.getThrowable().getMessage()
);
final StringWriter stringWriter = new StringWriter();
ignoredException.getThrowable().printStackTrace(new PrintWriter(stringWriter));
final String stackTrace = stringWriter.toString();
Expand All @@ -239,7 +239,8 @@ public void exceptionIgnored(final IgnoredException ignoredException) {
);
getLifecycle().addAttachment(
ignoredException.getThrowable().getMessage(), "text/plain", ".txt",
stackTrace.getBytes(StandardCharsets.UTF_8));
stackTrace.getBytes(StandardCharsets.UTF_8)
);
getLifecycle().stopStep(currentExceptionIgnoredStepUUID);
});
}
Expand Down
Loading
Loading