@Test
  public void testBatchBuy() throws EasyPostException, InterruptedException {
    List<Map<String, Object>> shipments = new ArrayList<Map<String, Object>>();
    Map<String, Object> shipmentMap = new HashMap<String, Object>();
    shipmentMap.put("to_address", defaultToAddress);
    shipmentMap.put("from_address", defaultFromAddress);
    shipmentMap.put("parcel", defaultParcel);
    shipmentMap.put("carrier", "USPS");
    shipmentMap.put("service", "Priority");
    shipments.add(shipmentMap);

    // create batch and wait until ready
    Map<String, Object> batchMap = new HashMap<String, Object>();
    batchMap.put("shipments", shipments);
    Batch batch = Batch.create(batchMap);
    while(true) {
      batch = batch.refresh();
      if ("created".equals(batch.getState())) {
        break;
      }
      Thread.sleep(3000);
    }

    batch.buy();
    while(true) {
      batch = batch.refresh();
      if ("purchased".equals(batch.getState())) {
        break;
      }
      Thread.sleep(3000);
    }

    assertEquals("Batch state is not purchased.", batch.getState(), "purchased");
  }