@VisibleForTesting
  void handleResponse(DiscoveryResponseData response)
  {
    ResourceType resourceType = response.getResourceType();
    switch (resourceType)
    {
      case NODE:
        handleD2NodeResponse(response);
        break;
      case D2_URI_MAP:
        handleD2URIMapResponse(response);
        break;
      case D2_URI:
        handleD2URICollectionResponse(response);
        break;
      default:
        throw new AssertionError("Missing case in enum switch: " + resourceType);
    }
  }
@Test(dataProvider = "badD2URIMapUpdateTestCases")
  public void testHandleD2URIMapUpdateWithBadData(DiscoveryResponseData badData, boolean invalidData)
  {
    XdsClientImplFixture fixture = new XdsClientImplFixture();
    fixture._clusterSubscriber.setData(null);
    fixture._xdsClientImpl.handleResponse(badData);
    fixture.verifyAckOrNack(invalidData, 1);
    // If the map is empty, we expect an empty map, but if it's invalid we expect a null
    D2URIMapUpdate expectedUpdate =
        invalidData
            ? (D2URIMapUpdate) D2_URI_MAP.emptyData()
            : new D2URIMapUpdate(Collections.emptyMap());
    verify(fixture._resourceWatcher).onChanged(eq(expectedUpdate));
    verify(fixture._clusterSubscriber).setData(eq(null));
    verifyZeroInteractions(fixture._serverMetricsProvider);
    D2URIMapUpdate actualData = (D2URIMapUpdate) fixture._clusterSubscriber.getData();
    Assert.assertEquals(actualData, expectedUpdate);

    fixture._clusterSubscriber.setData(D2_URI_MAP_UPDATE_WITH_DATA1);
    fixture._xdsClientImpl.handleResponse(badData);
    fixture.verifyAckOrNack(invalidData, 2);
    actualData = (D2URIMapUpdate) fixture._clusterSubscriber.getData();
    Objects.requireNonNull(actualData);
    if (invalidData) {
      verify(fixture._resourceWatcher).onChanged(eq(D2_URI_MAP_UPDATE_WITH_DATA1));
      // bad data will not overwrite the original valid data
      Assert.assertEquals(actualData.getURIMap(), D2_URI_MAP_UPDATE_WITH_DATA1.getURIMap());
    } else {
      verify(fixture._resourceWatcher, times(2)).onChanged(eq(expectedUpdate));
      // But an empty cluster should clear the data
      Assert.assertEquals(actualData.getURIMap(), Collections.emptyMap());
    }
    verifyZeroInteractions(fixture._serverMetricsProvider);
  }