### Question:
BKException extends org.apache.bookkeeper.client.api.BKException { public static int getExceptionCode(Throwable t, int defaultCode) { if (t == null) { return BKException.Code.OK; } else if (t instanceof BKException) { return ((BKException) t).getCode(); } else if (t.getCause() != null) { return getExceptionCode(t.getCause(), defaultCode); } else { return defaultCode; } } BKException(int code);   BKException(int code, Throwable cause); static BKException create(int code); static int getExceptionCode(Throwable t, int defaultCode); static int getExceptionCode(Throwable t); static final Function<Throwable, BKException> HANDLER; }### Answer:
@Test public void testBKExceptionCode() { Assert.assertEquals(BKException.Code.WriteException, BKException.getExceptionCode(new BKException.BKWriteException(), BKException.Code.ReadException)); }
@Test public void testNonBKExceptionCode() { Assert.assertEquals(BKException.Code.ReadException, BKException.getExceptionCode(new Exception(), BKException.Code.ReadException)); }
@Test public void testNestedBKExceptionCode() { Assert.assertEquals(BKException.Code.WriteException, BKException.getExceptionCode( new ExecutionException("test", new BKException.BKWriteException()), BKException.Code.ReadException)); }
@Test public void testDoubleNestedBKExceptionCode() { Assert.assertEquals(BKException.Code.WriteException, BKException.getExceptionCode( new ExecutionException("test", new CompletionException("blah", new BKException.BKWriteException())), BKException.Code.ReadException)); }