コード例 #1
0
 private void extractCauses(Throwable failure, List<Throwable> causes) {
   if (failure instanceof MultipleBuildFailures) {
     MultipleBuildFailures exception = (MultipleBuildFailures) failure;
     for (Throwable componentFailure : exception.getCauses()) {
       extractCauses(componentFailure, causes);
     }
   } else if (failure instanceof LocationAwareException) {
     causes.addAll(((LocationAwareException) failure).getReportableCauses());
   } else {
     causes.add(failure.getCause());
   }
 }
  @Test
  @Ignore
  public void shippedOrdersAreNotShown() throws Exception {
    Order shipped = new Order("X");
    Order notShipped = new Order("Y");
    orders.addAll(asList(shipped, notShipped));
    shipped.ship();

    when(request.getMethod()).thenReturn("GET");
    when(request.getRequestURI()).thenReturn("/orders");

    ordersController.service();

    verify(ordersView).show(asList(notShipped));
  }
コード例 #3
0
  @Test // Uses of JMockit API: 3
  public void customArgumentMatcherUsingAnonymousClass() {
    mockedList.addAll(asList("one", "two"));

    new Verifications() {
      {
        mockedList.addAll(
            with(
                new Delegate<List<String>>() {
                  boolean matches(List<?> list) {
                    return list.size() == 2;
                  }
                }));
      }
    };
  }
コード例 #4
0
  @Test // Uses of JMockit API: 5
  public void customArgumentMatcherUsingNamedClass() {
    class IsListOfTwoElements implements Delegate<List<String>> {
      boolean matches(List<?> list) {
        return list.size() == 2;
      }
    }

    new Expectations() {
      {
        mockedList.addAll(with(new IsListOfTwoElements()));
        result = true;
        times = 1;
      }
    };

    mockedList.addAll(asList("one", "two"));

    // No need to re-verify the invocation of "addAll" here.
  }