private void assertIce(
      JSONObject mediaDescription, String ufrag, String password, IceCandidate... candidates) {
    JSONObject ice = mediaDescription.optJSONObject("ice");
    assertNotNull(ice);
    assertEquals(ufrag, ice.optString("ufrag"));
    assertEquals(password, ice.optString("password"));

    JSONArray jsonCandidates = ice.optJSONArray("candidates");

    if (candidates.length == 0) {
      assertTrue(jsonCandidates == null || jsonCandidates.length() == 0);
      return;
    }
    assertNotNull(jsonCandidates);
    assertEquals(candidates.length, jsonCandidates.length());
    LinkedList<IceCandidate> remainingCandidates = new LinkedList<>(Arrays.asList(candidates));

    for (int i = 0; i < jsonCandidates.length(); i++) {
      JSONObject jsonCandidate = jsonCandidates.optJSONObject(i);
      assertNotNull(jsonCandidate);

      IceCandidate chosenCandidate = null;
      for (IceCandidate candidate : remainingCandidates) {
        if (candidate.isMatch(jsonCandidate)) {
          chosenCandidate = candidate;
          break;
        }
      }
      assertNotNull(chosenCandidate);
      remainingCandidates.remove(chosenCandidate);
    }
  }