GcpUtil { public static boolean isPermissionDenied(Throwable t) { return t instanceof GoogleJsonResponseException && isPermissionDenied((GoogleJsonResponseException) t); } private  GcpUtil(); static boolean isPermissionDenied(Throwable t); static boolean isPermissionDenied(GoogleJsonResponseException e); static boolean isPermissionDenied(GoogleJsonError error); static boolean isResourceExhausted(Throwable t); static boolean isResourceExhausted(GoogleJsonResponseException e); static boolean isResourceExhausted(GoogleJsonError error);  }
@Test public void responseIsPermissionDenied() { final Throwable permissionDenied = new GoogleJsonResponseException( new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()), PERMISSION_DENIED_ERROR); assertThat(GcpUtil.isPermissionDenied(permissionDenied), is(true)); }
@Test public void notFoundResponseIsNotPermissionDenied() { assertThat(GcpUtil.isPermissionDenied(new GoogleJsonResponseException( new HttpResponseException.Builder(404, "Not Found", new HttpHeaders()), new GoogleJsonError())), is(false)); assertThat(GcpUtil.isPermissionDenied(new GoogleJsonResponseException( new HttpResponseException.Builder(404, "Not Found", new HttpHeaders()), null)), is(false)); }
@Test public void errorIsPermissionDenied() { assertThat(GcpUtil.isPermissionDenied(PERMISSION_DENIED_ERROR), is(true)); }
@Test public void errorIsNotPermissionDenied() { assertThat(GcpUtil.isPermissionDenied(new GoogleJsonError()), is(false)); assertThat(GcpUtil.isPermissionDenied(new GoogleJsonError().set("status", "foo failed")), is(false)); }