### Question:
TableStoreUtils { static StatusCode handleCause(Throwable cause) { if (cause instanceof ExecutionException) { return handleCause(cause.getCause()); } else if (cause instanceof MVCCStoreException) { MVCCStoreException mse = (MVCCStoreException) cause; return mvccCodeToStatusCode(mse.getCode()); } else { return StatusCode.INTERNAL_SERVER_ERROR; } }    }### Answer:
@Test public void testHandleCause() { StatusCode[] protoCodes = new StatusCode[]{ StatusCode.SUCCESS, StatusCode.INTERNAL_SERVER_ERROR, StatusCode.BAD_REQUEST, StatusCode.BAD_REQUEST, StatusCode.UNEXPECTED, StatusCode.BAD_REVISION, StatusCode.BAD_REVISION, StatusCode.KEY_NOT_FOUND, StatusCode.KEY_EXISTS, }; Code[] codes = new Code[]{ Code.OK, Code.INTERNAL_ERROR, Code.INVALID_ARGUMENT, Code.ILLEGAL_OP, Code.UNEXPECTED, Code.BAD_REVISION, Code.SMALLER_REVISION, Code.KEY_NOT_FOUND, Code.KEY_EXISTS, }; for (int i = 0; i < codes.length; i++) { Code code = codes[i]; MVCCStoreException exception = new MVCCStoreException(code, "test-" + code); assertEquals(protoCodes[i], handleCause(exception)); } }
@Test public void testHandleUnknownCause() { Exception exception = new Exception("test-unknown-cause"); assertEquals(StatusCode.INTERNAL_SERVER_ERROR, handleCause(exception)); }
@Test public void testHandleExecutionException() { MVCCStoreException exception = new MVCCStoreException( Code.BAD_REVISION, "bad-revision"); ExecutionException ee = new ExecutionException(exception); assertEquals(StatusCode.BAD_REVISION, handleCause(ee)); }