### Question:
Mute { public static void loggedMute(CheckedRunnable runnable) { try { runnable.run(); } catch (Exception e) { e.printStackTrace(); } } private  Mute(); static void mute(CheckedRunnable runnable); static void loggedMute(CheckedRunnable runnable);  }### Answer:
@Test public void loggedMuteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() { Mute.loggedMute(this::methodNotThrowingAnyException); }
@Test public void loggedMuteShouldLogExceptionTraceBeforeSwallowingIt() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); System.setErr(new PrintStream(stream)); Mute.loggedMute(this::methodThrowingException); assertTrue(new String(stream.toByteArray()).contains(MESSAGE)); }
@Test void loggedMuteShouldLogExceptionTraceBeforeSwallowingIt() { var stream = new ByteArrayOutputStream(); System.setErr(new PrintStream(stream)); Mute.loggedMute(this::methodThrowingException); assertTrue(new String(stream.toByteArray()).contains(MESSAGE)); }
@Test public void loggedMuteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() { Mute.loggedMute(() -> methodNotThrowingAnyException()); }
@Test public void loggedMuteShouldLogExceptionTraceBeforeSwallowingIt() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); System.setErr(new PrintStream(stream)); Mute.loggedMute(() -> methodThrowingException()); assertTrue(new String(stream.toByteArray()).contains(MESSAGE)); }