package water.runner;

import org.junit.Ignore;
import org.junit.internal.runners.statements.RunAfters;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.MultipleFailureException;
import org.junit.runners.model.Statement;

import java.util.ArrayList;
import java.util.List;

@Ignore
public class H2ORunnerAfters extends RunAfters {

    private final Statement next;

    private final Object target;

    private final List<FrameworkMethod> afters;

    public H2ORunnerAfters(Statement next, List<FrameworkMethod> afters, Object target) {
        super(next, afters, target);
        this.next = next;
        this.target = target;
        this.afters = afters;
    }

    @Override
    public void evaluate() throws Throwable {
        List<Throwable> errors = new ArrayList<Throwable>();
        try {
            next.evaluate();
        } catch (Throwable e) {
            errors.add(e);
        } finally {
            // Clean all keys shared for the whole test class, created during @BeforeClass,
            // but not cleaned in @AfterClass.
            new CleanAllKeysTask().doAllNodes();
            for (FrameworkMethod each : afters) {
                try {
                    each.invokeExplosively(target);
                } catch (Throwable e) {
                    errors.add(e);
                }
            }
        }
        MultipleFailureException.assertEmpty(errors);
    }
}

@@ -1075,16 +1075,38 @@
 rClass.%0A
+            try %7B%0A    
         
@@ -1142,24 +1142,105 @@
 AllNodes();%0A
+            %7D catch (Throwable e) %7B%0A                errors.add(e);%0A            %7D%0A
             

fix case when failed could initialization error is eaten (#4729)