package com.codeborne.selenide.junit5;

import com.codeborne.selenide.logevents.ErrorsCollector;

import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

import javax.annotation.ParametersAreNonnullByDefault;

import static com.codeborne.selenide.logevents.ErrorsCollector.LISTENER_SOFT_ASSERT;
import static com.codeborne.selenide.logevents.SelenideLogger.addListener;
import static com.codeborne.selenide.logevents.SelenideLogger.removeListener;

/**
 * By using this extension selenide will collect all failed asserts
 * from "should*" and "waitUntil" methods and throw after test finished.
 *
 * <br>
 * To use extension extend you test class with it:
 * <br>
 * {@code @ExtendWith({SoftAssertsExtension.class}}
 * <br>
 * Or register extension in test class:
 * <br>
 * {@code @RegisterExtension static SoftAssertsExtension softAsserts = new SoftAssertsExtension();}
 * <br>
 *
 * @author Aliaksandr Rasolka
 * @since 4.12.2
 */
@ParametersAreNonnullByDefault
public class SoftAssertsExtension implements BeforeEachCallback, AfterEachCallback {
  private final ErrorsCollector errorsCollector;

  public SoftAssertsExtension() {
    errorsCollector = new ErrorsCollector();
  }

  public ErrorsCollector getErrorsCollector() {
    return errorsCollector;
  }

  @Override
  public void beforeEach(final ExtensionContext context) {
    errorsCollector.clear();
    addListener(LISTENER_SOFT_ASSERT, errorsCollector);
  }

  @Override
  public void afterEach(final ExtensionContext context) {
    removeListener(LISTENER_SOFT_ASSERT);
    errorsCollector.failIfErrors(context.getDisplayName());
  }
}

@@ -559,16 +559,97 @@
 istener;
+%0Aimport static org.junit.jupiter.api.extension.ExtensionContext.Namespace.create;
 %0A%0A/**%0A *
@@ -1250,93 +1250,178 @@
 %0A  p
-rivate final ErrorsCollector errorsCollector;%0A%0A  public SoftAssertsExtension(
+ublic static final ExtensionContext.Namespace namespace = create(SoftAssertsExtension.class);%0A%0A  @Override%0A  public void beforeEach(final ExtensionContext context
 ) %7B%0A    
 erro
@@ -1408,33 +1408,33 @@
  context) %7B%0A    
-e
+E
 rrorsCollector =
@@ -1436,15 +1436,9 @@
 tor 
-= new E
+e
 rror
@@ -1451,46 +1451,73 @@
 ctor
-();%0A  %7D%0A%0A  public ErrorsCollector getE
+ = new ErrorsCollector();%0A    addListener(LISTENER_SOFT_ASSERT, e
 rror
@@ -1530,23 +1530,68 @@
 ctor
-() %7B
+);
 %0A    
-return
+context.getStore(namespace).put(LISTENER_SOFT_ASSERT,
  err
@@ -1602,16 +1602,17 @@
 ollector
+)
 ;%0A  %7D%0A%0A 
@@ -1628,38 +1628,37 @@
 e%0A  public void 
-before
+after
 Each(final Exten
@@ -1688,40 +1688,14 @@
     
-errorsCollector.clear();%0A    add
+remove
 List
@@ -1711,35 +1711,40 @@
 ENER_SOFT_ASSERT
-, e
+);%0A    E
 rrorsCollector);
@@ -1745,104 +1745,76 @@
 ctor
-);%0A  %7D%0A%0A  @Override%0A  public void afterEach(final ExtensionContext context) %7B%0A    removeListener
+ errorsCollector = (ErrorsCollector) context.getStore(namespace).get
 (LIS

make SoftAssertsExtension thread-safe