### Question:
GetEthereumNameRecord implements Handler { @OpenApi( deprecated = true, path = ROUTE, method = HttpMethod.GET, summary = "Get the listening ENR address of the node.", tags = {TAG_NETWORK}, description = "Returns the beacon node's listening Ethereum Node Record (ENR) address." + " Replaced by standard api endpoint `/eth/v1/node/identity`.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = String.class), description = "Base64-encoded ENR or an empty string if Node Discovery Protocol v5 is not used.") }) @Override public void handle(Context ctx) throws Exception { ctx.header(Header.CACHE_CONTROL, CACHE_NONE); ctx.result(jsonProvider.objectToJSON(network.getEnr().orElse(""))); } GetEthereumNameRecord(NetworkDataProvider network, JsonProvider jsonProvider); @OpenApi( deprecated = true, path = ROUTE, method = HttpMethod.GET, summary = "Get the listening ENR address of the node.", tags = {TAG_NETWORK}, description = "Returns the beacon node's listening Ethereum Node Record (ENR) address." + " Replaced by standard api endpoint `/eth/v1/node/identity`.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = String.class), description = "Base64-encoded ENR or an empty string if Node Discovery Protocol v5 is not used.") }) @Override void handle(Context ctx); static final String ROUTE; }### Answer:
@Test public void shouldReturnEmptyStringWhenDiscoveryNotInUse() throws Exception { NetworkDataProvider network = new NetworkDataProvider(eth2Network); GetEthereumNameRecord handler = new GetEthereumNameRecord(network, jsonProvider); when(eth2Network.getEnr()).thenReturn(Optional.empty()); handler.handle(context); verify(context).header(Header.CACHE_CONTROL, CACHE_NONE); verify(context).result(jsonProvider.objectToJSON("")); }
@Test public void shouldReturnPopulatedStringWhenDiscoveryIsInUse() throws Exception { NetworkDataProvider network = new NetworkDataProvider(eth2Network); GetEthereumNameRecord handler = new GetEthereumNameRecord(network, jsonProvider); when(eth2Network.getEnr()).thenReturn(Optional.of(ENR)); handler.handle(context); verify(context).header(Header.CACHE_CONTROL, CACHE_NONE); verify(context).result(jsonProvider.objectToJSON(ENR)); }