### Question:
OkHttpValidatorRestApiClient implements ValidatorRestApiClient { @Override public void subscribeToBeaconCommitteeForAggregation( final int committeeIndex, final UInt64 aggregationSlot) { final SubscribeToBeaconCommitteeRequest request = new SubscribeToBeaconCommitteeRequest(committeeIndex, aggregationSlot); post(SUBSCRIBE_TO_COMMITTEE_FOR_AGGREGATION, request, null); } OkHttpValidatorRestApiClient(final String baseEndpoint); @VisibleForTesting  OkHttpValidatorRestApiClient(final HttpUrl baseEndpoint, final OkHttpClient okHttpClient); @Override Optional<GetForkResponse> getFork(); @Override Optional<GetGenesisResponse> getGenesis(); @Override @SuppressWarnings("unchecked") List<ValidatorDuties> getDuties(final ValidatorDutiesRequest request); @Override List<AttesterDuty> getAttestationDuties(
      final UInt64 epoch, final Collection<Integer> validatorIndexes); @Override List<ProposerDuty> getProposerDuties(final UInt64 epoch); @Override Optional<BeaconBlock> createUnsignedBlock(
      final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti); @Override void sendSignedBlock(final SignedBeaconBlock beaconBlock); @Override Optional<Attestation> createUnsignedAttestation(
      final UInt64 slot, final int committeeIndex); @Override void sendSignedAttestation(final Attestation attestation); @Override Optional<Attestation> createAggregate(final Bytes32 attestationHashTreeRoot); @Override void sendAggregateAndProof(final SignedAggregateAndProof signedAggregateAndProof); @Override void subscribeToBeaconCommitteeForAggregation(
      final int committeeIndex, final UInt64 aggregationSlot); @Override void subscribeToPersistentSubnets(final Set<SubnetSubscription> subnetSubscriptions); Optional<T> get(
      final ValidatorApiMethod apiMethod,
      final Map<String, String> queryParams,
      final Class<T> responseClass);  }### Answer:
@Test public void subscribeToBeaconCommitteeForAggregation_MakesExpectedRequest() throws Exception { final int committeeIndex = 1; final UInt64 aggregationSlot = UInt64.ONE; final SubscribeToBeaconCommitteeRequest expectedRequest = new SubscribeToBeaconCommitteeRequest(committeeIndex, aggregationSlot); mockWebServer.enqueue(new MockResponse().setResponseCode(200)); apiClient.subscribeToBeaconCommitteeForAggregation(committeeIndex, aggregationSlot); RecordedRequest request = mockWebServer.takeRequest(); assertThat(request.getMethod()).isEqualTo("POST"); assertThat(request.getPath()) .contains(ValidatorApiMethod.SUBSCRIBE_TO_COMMITTEE_FOR_AGGREGATION.getPath()); assertThat(request.getBody().readString(StandardCharsets.UTF_8)) .isEqualTo(asJson(expectedRequest)); }
@Test public void subscribeToBeaconCommitteeForAggregation_WhenBadRequest_DoesNotFailHandlingResponse() { final int committeeIndex = 1; final UInt64 aggregationSlot = UInt64.ONE; mockWebServer.enqueue(new MockResponse().setResponseCode(400)); apiClient.subscribeToBeaconCommitteeForAggregation(committeeIndex, aggregationSlot); }
@Test public void subscribeToBeaconCommitteeForAggregation_WhenServerError_ThrowsRuntimeException() { final int committeeIndex = 1; final UInt64 aggregationSlot = UInt64.ONE; mockWebServer.enqueue(new MockResponse().setResponseCode(500)); assertThatThrownBy( () -> apiClient.subscribeToBeaconCommitteeForAggregation(committeeIndex, aggregationSlot)) .isInstanceOf(RuntimeException.class) .hasMessageContaining("Unexpected response from Beacon Node API"); }