Ejemplo n.º 1
0
  public void getColumnTypesWithAllFailures() {
    ImmutableList<Integer> indices = ImmutableList.of(0, 1);
    ArrayTable<Integer, Integer, Result<?>> table = ArrayTable.create(indices, indices);
    table.put(0, 0, Result.failure(FailureReason.ERROR, "fail"));
    table.put(0, 1, Result.failure(FailureReason.ERROR, "fail"));
    table.put(1, 0, Result.failure(FailureReason.ERROR, "fail"));
    table.put(1, 1, Result.failure(FailureReason.ERROR, "fail"));

    List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
    assertThat(columnTypes).isEqualTo(ImmutableList.of(Object.class, Object.class));
  }
  // calculate one measure
  private Result<?> calculate(
      Measure measure, ResolvedBulletPaymentTrade trade, RatesScenarioMarketData marketData) {

    SingleMeasureCalculation calculator = CALCULATORS.get(measure);
    if (calculator == null) {
      return Result.failure(
          FailureReason.UNSUPPORTED, "Unsupported measure for BulletPaymentTrade: {}", measure);
    }
    return Result.of(() -> calculator.calculate(trade, marketData));
  }
Ejemplo n.º 3
0
  /**
   * Tests that executing a function that returns a failure result returns the underlying result
   * without wrapping it.
   */
  public void executeFailureResultValue() {
    SupplierFunction<Result<String>> fn =
        SupplierFunction.of(() -> Result.failure(FailureReason.NOT_APPLICABLE, "bar"));
    CalculationTask task = new CalculationTask(TARGET, 0, 0, fn, MAPPINGS, REPORTING_RULES);
    CalculationEnvironment marketData =
        CalculationEnvironment.builder().valuationDate(date(2011, 3, 8)).build();

    CalculationResult calculationResult = task.execute(marketData);
    Result<?> result = calculationResult.getResult();
    assertThat(result).isFailure(FailureReason.NOT_APPLICABLE).hasFailureMessageMatching("bar");
  }