package com.atlassian.bitbucket.rule;

import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import static org.junit.Assert.assertEquals;

public class RepeatRuleTest {
    
    private static final int NUMBER_OF_RETRIES = 100;

    @Test
    public void testRetries() {
       assertEquals(NUMBER_OF_RETRIES, evaluate(false));
    }

    private static int evaluate(boolean hasError) {
        final int[] evaluations = new int[1];
        boolean error = false;
        try {
            new RepeatRule(NUMBER_OF_RETRIES).apply(new Statement() {
                @Override
                public void evaluate() throws Throwable {
                    evaluations[0]++;
                }
            }, Description.createTestDescription(RepeatRuleTest.class, "foo")).evaluate();
        } catch (Throwable t) {
            error = true;
        }
        assertEquals(hasError, error);
        return evaluations[0];
    }
}
