diff --git a/mute-idiom/pom.xml b/mute-idiom/pom.xml index e4597446b..528b60967 100644 --- a/mute-idiom/pom.xml +++ b/mute-idiom/pom.xml @@ -1,47 +1,39 @@ - - - 4.0.0 - - com.iluwatar - java-design-patterns - 1.11.0-SNAPSHOT - - mute-idiom - - - junit - junit - test - - - org.mockito - mockito-core - test - - + + + 4.0.0 + + com.iluwatar + java-design-patterns + 1.11.0-SNAPSHOT + + mute-idiom + + + junit + junit + test + + + org.mockito + mockito-core + compile + + diff --git a/mute-idiom/src/main/java/com/iluwatar/mute/App.java b/mute-idiom/src/main/java/com/iluwatar/mute/App.java index edb5ebcc9..36da1c4f9 100644 --- a/mute-idiom/src/main/java/com/iluwatar/mute/App.java +++ b/mute-idiom/src/main/java/com/iluwatar/mute/App.java @@ -22,6 +22,9 @@ */ package com.iluwatar.mute; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + import java.io.ByteArrayOutputStream; import java.sql.Connection; import java.sql.SQLException; @@ -46,8 +49,9 @@ public class App { } private static void useOfLoggedMute() { - Connection connection = openConnection(); + Connection connection = null; try { + connection = openConnection(); readStuff(connection); } catch (SQLException ex) { ex.printStackTrace(); @@ -71,7 +75,9 @@ public class App { } } - private static Connection openConnection() { - return null; + private static Connection openConnection() throws SQLException { + Connection mockedConnection = mock(Connection.class); + doThrow(SQLException.class).when(mockedConnection).close(); + return mockedConnection; } } diff --git a/mute-idiom/src/main/java/com/iluwatar/mute/Mute.java b/mute-idiom/src/main/java/com/iluwatar/mute/Mute.java index ba055422b..3e1ad2e2e 100644 --- a/mute-idiom/src/main/java/com/iluwatar/mute/Mute.java +++ b/mute-idiom/src/main/java/com/iluwatar/mute/Mute.java @@ -50,8 +50,8 @@ public final class Mute { /** * Executes the runnable and logs the exception occurred on {@link System#err}. * This method should be utilized to mute the operations about which most you can do is log. - * For instance while closing a connection to database, all you can do is log the exception - * occurred. + * For instance while closing a connection to database, or cleaning up a resource, + * all you can do is log the exception occurred. * * @param runnable a runnable that may throw an exception on execution. */