### Question:
OkHttpValidatorRestApiClient implements ValidatorRestApiClient { @Override public Optional<Attestation> createAggregate(final Bytes32 attestationHashTreeRoot) { final Map<String, String> queryParams = new HashMap<>(); queryParams.put("slot", encodeQueryParam(UInt64.ZERO)); queryParams.put("attestation_data_root", encodeQueryParam(attestationHashTreeRoot)); return get(GET_AGGREGATE, queryParams, Attestation.class); } 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 createAggregate_MakesExpectedRequest() throws Exception { final UInt64 slot = UInt64.ZERO; final Bytes32 attestationHashTreeRoot = Bytes32.random(); mockWebServer.enqueue(new MockResponse().setResponseCode(204)); apiClient.createAggregate(attestationHashTreeRoot); RecordedRequest request = mockWebServer.takeRequest(); assertThat(request.getMethod()).isEqualTo("GET"); assertThat(request.getPath()).contains(ValidatorApiMethod.GET_AGGREGATE.getPath()); assertThat(request.getRequestUrl().queryParameter("slot")).isEqualTo(slot.toString()); assertThat(request.getRequestUrl().queryParameter("attestation_data_root")) .isEqualTo(attestationHashTreeRoot.toHexString()); }
@Test public void createAggregate_WhenBadParameters_ReturnsEmpty() { final Bytes32 attestationHashTreeRoot = Bytes32.random(); mockWebServer.enqueue(new MockResponse().setResponseCode(400)); assertThat(apiClient.createAggregate(attestationHashTreeRoot)).isEmpty(); }
@Test public void createAggregate_WhenServerError_ThrowsRuntimeException() { final Bytes32 attestationHashTreeRoot = Bytes32.random(); mockWebServer.enqueue(new MockResponse().setResponseCode(500)); assertThatThrownBy(() -> apiClient.createAggregate(attestationHashTreeRoot)) .isInstanceOf(RuntimeException.class) .hasMessageContaining("Unexpected response from Beacon Node API"); }