package com.atlassian.webdriver.testing.rule;

import com.google.inject.Inject;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

/**
 * <p/>
 * A version of default, recommended rules that is injectable into the test. Use together with
 * {@link com.atlassian.webdriver.testing.runner.ProductContextRunner}.
 *
 * @since 2.1
 */
public final class DefaultProductContextRules
{
    private DefaultProductContextRules()
    {
        throw new AssertionError("Don't instantiate me");
    }

    public final static class ForClass implements TestRule
     {
         private final RuleChain chain;

         @Inject
         public ForClass(DriverCleanupRule driverCleanupRule)
         {
             this.chain = RuleChain.outerRule(driverCleanupRule);
         }

         @Override
         public Statement apply(Statement base, Description description)
         {
             return chain.apply(base, description);
         }
     }

    public final static class ForMethod implements TestRule
    {
        private final RuleChain chain;

        @Inject
        public ForMethod(IgnoreBrowserRule ignoreBrowserRule,
                         LogPageSourceRule logPageSourceRule,
                         SessionCleanupRule sessionCleanupRule,
                         WebDriverScreenshotRule webDriverScreenshotRule,
                         WindowSizeRule windowSizeRule)
        {
            this.chain = RuleChain.outerRule(ignoreBrowserRule)
                    .around(sessionCleanupRule)
                    .around(windowSizeRule)
                    .around(webDriverScreenshotRule)
                    .around(logPageSourceRule);
        }

        @Override
        public Statement apply(Statement base, Description description)
        {
            return chain.apply(base, description);
        }
    }

}

@@ -1209,24 +1209,92 @@
 rowserRule,%0A
+                         JavaScriptErrorsRule javaScriptErrorsRule,%0A
             
@@ -1695,32 +1695,82 @@
 windowSizeRule)%0A
+                    .around(javaScriptErrorsRule)%0A
                 

add JavaScriptErrorsRule to DefalutProductContextRules