mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-09-03 04:18:19 +00:00
docs: update mute idiom
This commit is contained in:
@@ -26,10 +26,12 @@ package com.iluwatar.mute;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* A utility class that allows you to utilize mute idiom.
|
||||
*/
|
||||
@Slf4j
|
||||
public final class Mute {
|
||||
|
||||
// The constructor is never meant to be called.
|
||||
@@ -40,7 +42,7 @@ public final class Mute {
|
||||
* Executes the <code>runnable</code> and throws the exception occurred within a {@link
|
||||
* AssertionError}. This method should be utilized to mute the operations that are guaranteed not
|
||||
* to throw an exception. For instance {@link ByteArrayOutputStream#write(byte[])} declares in
|
||||
* it's signature that it can throw an {@link IOException}, but in reality it cannot. This is
|
||||
* its signature that it can throw an {@link IOException}, but in reality it cannot. This is
|
||||
* because the bulk write method is not overridden in {@link ByteArrayOutputStream}.
|
||||
*
|
||||
* @param runnable a runnable that should never throw an exception on execution.
|
||||
|
||||
@@ -63,10 +63,9 @@ class MuteTest {
|
||||
|
||||
Mute.loggedMute(this::methodThrowingException);
|
||||
|
||||
assertTrue(new String(stream.toByteArray()).contains(MESSAGE));
|
||||
assertTrue(stream.toString().contains(MESSAGE));
|
||||
}
|
||||
|
||||
|
||||
private void methodNotThrowingAnyException() {
|
||||
LOGGER.info("Executed successfully");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user