Ejemplo n.º 1
0
  public void getColumnTypes() {
    ArrayTable<Integer, Integer, Result<?>> table = ArrayTable.create(INDICES, INDICES);
    table.put(0, 0, Result.success(1));
    table.put(0, 1, Result.success("abc"));
    table.put(1, 0, Result.success(2));
    table.put(1, 1, Result.success("def"));

    List<Class<?>> columnTypes = TradeReportFormatter.INSTANCE.getColumnTypes(report(table));
    assertThat(columnTypes).isEqualTo(ImmutableList.of(Integer.class, String.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
  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));
  }
Ejemplo n.º 4
0
  /**
   * Tests that executing a function that returns a success result returns the underlying result
   * without wrapping it.
   */
  public void executeSuccessResultValue() {
    SupplierFunction<Result<String>> fn = SupplierFunction.of(() -> Result.success("foo"));
    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).hasValue("foo");
  }
Ejemplo n.º 5
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");
  }