OptionalDependencyWrapper { public static <R> R wrapRunWithOptionalDependency(Supplier<R> supplier, String message) { try { return supplier.get(); } catch (NoClassDefFoundError ex) { throw new KubernetesClientException(String.format( "%s, an optional dependency. To use this functionality you must explicitly add this dependency to the classpath.", message), ex); } } private  OptionalDependencyWrapper(); static R wrapRunWithOptionalDependency(Supplier<R> supplier, String message);  }
@Test void testWrapRunWithOptionalDependencyHasAllDependenciesShouldNotThrowException() { final boolean result = wrapRunWithOptionalDependency(() -> true, "I have no optional dependencies"); assertThat(result, equalTo(true)); }
@Test void testWrapRunWithOptionalDependencyUsesDependencyShouldThrowException() { final KubernetesClientException exception = assertThrows(KubernetesClientException.class, () -> wrapRunWithOptionalDependency(() -> { throw new NoClassDefFoundError("com.1337.invalid.IDontExist"); }, "IDontExist class is provided by some optional package")); assertThat(exception.getMessage(), equalTo( "IDontExist class is provided by some optional package, an optional dependency. To use this functionality you must explicitly add this dependency to the classpath.")); }