### Question:
EthSubscribe extends AbstractSubscriptionMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { try { final SubscribeRequest subscribeRequest = getMapper().mapSubscribeRequest(requestContext); final Long subscriptionId = subscriptionManager().subscribe(subscribeRequest); return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), Quantity.create(subscriptionId)); } catch (final InvalidSubscriptionRequestException isEx) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST); } catch (final Exception e) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR); } } EthSubscribe(
      final SubscriptionManager subscriptionManager, final SubscriptionRequestMapper mapper); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void responseContainsSubscriptionId() { final WebSocketRpcRequest webSocketRequest = createWebSocketRpcRequest(); final JsonRpcRequestContext jsonRpcrequestContext = new JsonRpcRequestContext(webSocketRequest); final SubscribeRequest subscribeRequest = new SubscribeRequest( SubscriptionType.SYNCING, null, null, webSocketRequest.getConnectionId()); when(mapperMock.mapSubscribeRequest(eq(jsonRpcrequestContext))).thenReturn(subscribeRequest); when(subscriptionManagerMock.subscribe(eq(subscribeRequest))).thenReturn(1L); final JsonRpcSuccessResponse expectedResponse = new JsonRpcSuccessResponse( jsonRpcrequestContext.getRequest().getId(), Quantity.create((1L))); assertThat(ethSubscribe.response(jsonRpcrequestContext)).isEqualTo(expectedResponse); }
@Test public void invalidSubscribeRequestRespondsInvalidRequestResponse() { final WebSocketRpcRequest webSocketRequest = createWebSocketRpcRequest(); final JsonRpcRequestContext jsonRpcrequestContext = new JsonRpcRequestContext(webSocketRequest); when(mapperMock.mapSubscribeRequest(any())) .thenThrow(new InvalidSubscriptionRequestException()); final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse( jsonRpcrequestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST); assertThat(ethSubscribe.response(jsonRpcrequestContext)).isEqualTo(expectedResponse); }
@Test public void uncaughtErrorOnSubscriptionManagerShouldRespondInternalErrorResponse() { final WebSocketRpcRequest webSocketRequest = createWebSocketRpcRequest(); final JsonRpcRequestContext jsonRpcrequestContext = new JsonRpcRequestContext(webSocketRequest); when(mapperMock.mapSubscribeRequest(any())).thenReturn(mock(SubscribeRequest.class)); when(subscriptionManagerMock.subscribe(any())).thenThrow(new RuntimeException()); final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse( jsonRpcrequestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR); assertThat(ethSubscribe.response(jsonRpcrequestContext)).isEqualTo(expectedResponse); }