Example #1
0
  // TODO: Improve this test, perhaps with an Actor
  @Test
  public void foldForJavaApiMustWork() throws Exception {
    LinkedList<Future<String>> listFutures = new LinkedList<Future<String>>();
    StringBuilder expected = new StringBuilder();

    for (int i = 0; i < 10; i++) {
      expected.append("test");
      listFutures.add(
          Futures.future(
              new Callable<String>() {
                public String call() {
                  return "test";
                }
              },
              system.dispatcher()));
    }

    Future<String> result =
        Futures.fold(
            "",
            listFutures,
            new Function2<String, String, String>() {
              public String apply(String r, String t) {
                return r + t;
              }
            },
            system.dispatcher());

    assertEquals(Await.result(result, timeout), expected.toString());
  }