Esempio n. 1
0
 /** {@inheritDoc} */
 public List<$T> readAllNow() {
   lockWrite();
   try {
     int $p = $gate.drainPermits();
     if ($p == 0) {
       return Collections.emptyList();
     } else {
       List<$T> $v = new ArrayList<$T>($p);
       for (int $i = 0; $i < $p; $i++) $v.add($queue.poll());
       return $v;
     }
   } finally {
     unlockWrite();
     checkForFinale();
   }
 }
Esempio n. 2
0
  /**
   * By default, this will always attempt to call {@link System#exit(int)} at the end of running
   * tests, exiting with 0 if all tests pass, 4 if any units have failed, and 5 if any unit failed
   * catastrophically (i.e. the entire case was not completed). This behavior and/or those values
   * can be overridden by overriding the {@link #succeeded()}, {@link #failed()}, and {@link
   * #aborted()} methods, respectively.
   */
  public synchronized void run() {
    List<Unit> $units = getUnits(); // list is assumed immutable on pain of death or idiocy

    $numUnits = $units.size();
    $numUnitsRun = 0;
    $numUnitsPassed = 0;
    $numUnitsFailed = 0;

    for (int $i = 0; $i < $units.size(); $i++) {
      Unit $unit = $units.get($i);
      if ($unit == null) continue;

      try {
        resetFailures();

        $log.info("TEST UNIT " + $unit.getName() + " STARTING...");
        $numUnitsRun++;
        $unit.call();
        if ($unit.expectExceptionType() != null) {
          $numUnitsFailed++;
          $log.error("EXPECTED EXCEPTION; TEST CASE ABORTED.");
          aborted();
        }
        if ($unitFailures == 0) {
          $numUnitsPassed++;
          $log.info("TEST UNIT " + $unit.getName() + " PASSED SUCCESSFULLY!\n");
        } else {
          $numUnitsFailed++;
          $log.info(
              "TEST UNIT " + $unit.getName() + " FAILED (WITH " + $unitFailures + " FAILURES)!\n");
        }
      } catch (AssertionFatal $e) {
        $numUnitsFailed++;
        $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e);
        aborted();
        break;
      } catch (AssertionFailed $e) {
        $numUnitsFailed++;
        $log.error("TEST UNIT " + $unit.getName() + " ABORTED.", $e);
      } catch (Throwable $e) {
        if ($unit.expectExceptionType() != null) {
          // some kind of exception was expected.
          if ($unit.expectExceptionType().isAssignableFrom($e.getClass())) {
            // and it was this kind that was expected, so this is good.
            $numUnitsPassed++;
            $unit.assertInstanceOf(
                $unit.expectExceptionType(), $e); // generates a normal confirmation message
            $log.info("TEST UNIT " + $unit.getName() + " PASSED SUCCESSFULLY!\n");
          } else {
            // and it wasn't this kind.  this represents fatal failure.
            $numUnitsFailed++;
            $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e);
            aborted();
            break;
          }
        } else {
          // no exception was expected.  any exception represents fatal failure.
          $numUnitsFailed++;
          $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e);
          aborted();
          break;
        }
      }
    }

    if ($numUnitsFailed > 0) failed();
    else succeeded();
  }