Removed AvoidStarImport Rule
Added JavaDocType Rule
This commit is contained in:
@ -35,47 +35,50 @@ import org.junit.rules.ExpectedException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Test for the mute-idiom pattern
|
||||
*/
|
||||
public class MuteTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MuteTest.class);
|
||||
|
||||
private static final String MESSAGE = "should not occur";
|
||||
|
||||
|
||||
@Rule public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void muteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() {
|
||||
Mute.mute(() -> methodNotThrowingAnyException());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void muteShouldRethrowUnexpectedExceptionAsAssertionError() throws Exception {
|
||||
exception.expect(AssertionError.class);
|
||||
exception.expectMessage(MESSAGE);
|
||||
|
||||
|
||||
Mute.mute(() -> methodThrowingException());
|
||||
}
|
||||
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void methodNotThrowingAnyException() {
|
||||
LOGGER.info("Executed successfully");
|
||||
}
|
||||
|
||||
|
||||
private void methodThrowingException() throws Exception {
|
||||
throw new Exception(MESSAGE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user