### Question:
EthUnsubscribe extends AbstractSubscriptionMethod { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { try { final UnsubscribeRequest unsubscribeRequest = getMapper().mapUnsubscribeRequest(requestContext); final boolean unsubscribed = subscriptionManager().unsubscribe(unsubscribeRequest); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), unsubscribed); } catch (final InvalidSubscriptionRequestException isEx) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST); } catch (final SubscriptionNotFoundException snfEx) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND); } catch (final Exception e) { return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR); } } EthUnsubscribe(
      final SubscriptionManager subscriptionManager, final SubscriptionRequestMapper mapper); @Override String getName(); @Override JsonRpcResponse response(final JsonRpcRequestContext requestContext);  }### Answer:
@Test public void responseContainsUnsubscribeStatus() { final JsonRpcRequestContext request = createJsonRpcRequest(); final UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest(1L, CONNECTION_ID); when(mapperMock.mapUnsubscribeRequest(eq(request))).thenReturn(unsubscribeRequest); when(subscriptionManagerMock.unsubscribe(eq(unsubscribeRequest))).thenReturn(true); final JsonRpcSuccessResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), true); assertThat(ethUnsubscribe.response(request)).isEqualTo(expectedResponse); }
@Test public void invalidUnsubscribeRequestReturnsInvalidRequestResponse() { final JsonRpcRequestContext request = createJsonRpcRequest(); when(mapperMock.mapUnsubscribeRequest(any())) .thenThrow(new InvalidSubscriptionRequestException()); final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.INVALID_REQUEST); assertThat(ethUnsubscribe.response(request)).isEqualTo(expectedResponse); }
@Test public void whenSubscriptionNotFoundReturnError() { final JsonRpcRequestContext request = createJsonRpcRequest(); when(mapperMock.mapUnsubscribeRequest(any())).thenReturn(mock(UnsubscribeRequest.class)); when(subscriptionManagerMock.unsubscribe(any())) .thenThrow(new SubscriptionNotFoundException(1L)); final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND); assertThat(ethUnsubscribe.response(request)).isEqualTo(expectedResponse); }
@Test public void uncaughtErrorOnSubscriptionManagerReturnsInternalErrorResponse() { final JsonRpcRequestContext request = createJsonRpcRequest(); when(mapperMock.mapUnsubscribeRequest(any())).thenReturn(mock(UnsubscribeRequest.class)); when(subscriptionManagerMock.unsubscribe(any())).thenThrow(new RuntimeException()); final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.INTERNAL_ERROR); assertThat(ethUnsubscribe.response(request)).isEqualTo(expectedResponse); }