content: package com.alicloud.openservices.tablestore.core.utils;
  
  import org.junit.rules.TestRule;
  import org.junit.runner.Description;
  import org.junit.runners.model.Statement;
  
  public class RepeatRule implements TestRule {
  
      private final int defaultTimes;
  
      public RepeatRule(int defaultTimes) {
          this.defaultTimes = defaultTimes;
      }
  
      private static class RepeatStatement extends Statement {
          private final Statement statement;
          private final int repeat;
  
          public RepeatStatement(Statement statement, int repeat) {
              this.statement = statement;
              this.repeat = repeat;
          }
  
          @Override
          public void evaluate() throws Throwable {
              for (int i = 0; i < repeat; i++) {
                  statement.evaluate();
              }
          }
  
      }
  
      @Override
      public Statement apply(Statement statement, Description description) {
          Statement result;
          Repeat repeat = description.getAnnotation(Repeat.class);
          if (repeat != null) {
              int times = repeat.value();
              result = new RepeatStatement(statement, times);
          } else {
              result = new RepeatStatement(statement, defaultTimes);
          }
          return result;
      }
  }