### Question:
NetEnode implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { if (!p2pNetwork.isP2pEnabled()) { return p2pDisabledResponse(requestContext); } final Optional<EnodeURL> enodeURL = p2pNetwork.getLocalEnode(); if (!enodeURL.isPresent()) { return enodeUrlNotAvailable(requestContext); } return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), enodeURL.get().toString()); } NetEnode(final P2PNetwork p2pNetwork); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void shouldReturnEnode() { when(p2PNetwork.isP2pEnabled()).thenReturn(true); doReturn(enodeURL).when(p2PNetwork).getLocalEnode(); final JsonRpcRequestContext request = netEnodeRequest(); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), enodeURL.get().toString()); Assertions.assertThat(method.response(request)) .isEqualToComparingFieldByField(expectedResponse); }
@Test public void shouldReturnErrorWhenP2pDisabled() { when(p2PNetwork.isP2pEnabled()).thenReturn(false); final JsonRpcRequestContext request = netEnodeRequest(); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.P2P_DISABLED); Assertions.assertThat(method.response(request)) .isEqualToComparingFieldByField(expectedResponse); }
@Test public void shouldReturnErrorWhenP2PEnabledButNoEnodeFound() { when(p2PNetwork.isP2pEnabled()).thenReturn(true); doReturn(Optional.empty()).when(p2PNetwork).getLocalEnode(); final JsonRpcRequestContext request = netEnodeRequest(); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( request.getRequest().getId(), JsonRpcError.P2P_NETWORK_NOT_RUNNING); Assertions.assertThat(method.response(request)) .isEqualToComparingFieldByField(expectedResponse); }