Issue #2567 - Unreachable Code in MisbehavingClassTest
Reworked MisbehavingClassTest to fix sections of unreachable code causing exception stack traces to be logged. Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
04c1447f88
commit
fe9bfda2c3
|
@ -18,14 +18,9 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.jsr356.misbehaving;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
|
@ -37,15 +32,15 @@ import org.eclipse.jetty.websocket.common.WebSocketSession;
|
|||
import org.eclipse.jetty.websocket.jsr356.EchoHandler;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class MisbehavingClassTest
|
||||
{
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private static Server server;
|
||||
private static EchoHandler handler;
|
||||
private static URI serverUri;
|
||||
|
@ -100,20 +95,21 @@ public class MisbehavingClassTest
|
|||
|
||||
try (StacklessLogging logging = new StacklessLogging(EndpointRuntimeOnOpen.class, WebSocketSession.class))
|
||||
{
|
||||
// expecting IOException during onOpen
|
||||
expectedException.expect(IOException.class);
|
||||
expectedException.expectCause(instanceOf(RuntimeException.class));
|
||||
container.connectToServer(socket, serverUri);
|
||||
expectedException.reportMissingExceptionWithMessage("Should have failed .connectToServer()");
|
||||
|
||||
assertThat("Close should have occurred",socket.closeLatch.await(1,TimeUnit.SECONDS),is(true));
|
||||
try
|
||||
{
|
||||
container.connectToServer(socket, serverUri);
|
||||
fail("Should have failed .connectToServer()");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
assertThat(e.getCause(), instanceOf(RuntimeException.class));
|
||||
}
|
||||
|
||||
Throwable cause = socket.errors.pop();
|
||||
assertThat("Error",cause,instanceOf(RuntimeException.class));
|
||||
assertThat("Close should have occurred", socket.closeLatch.await(1,TimeUnit.SECONDS), is(true));
|
||||
assertThat("Error", socket.errors.pop(), instanceOf(RuntimeException.class));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@Test
|
||||
public void testAnnotatedRuntimeOnOpen() throws Exception
|
||||
{
|
||||
|
@ -123,16 +119,18 @@ public class MisbehavingClassTest
|
|||
|
||||
try (StacklessLogging logging = new StacklessLogging(AnnotatedRuntimeOnOpen.class, WebSocketSession.class))
|
||||
{
|
||||
// expecting IOException during onOpen
|
||||
expectedException.expect(IOException.class);
|
||||
expectedException.expectCause(instanceOf(RuntimeException.class));
|
||||
container.connectToServer(socket, serverUri);
|
||||
expectedException.reportMissingExceptionWithMessage("Should have failed .connectToServer()");
|
||||
|
||||
assertThat("Close should have occurred",socket.closeLatch.await(1,TimeUnit.SECONDS),is(true));
|
||||
try
|
||||
{
|
||||
container.connectToServer(socket, serverUri);
|
||||
fail("Should have failed .connectToServer()");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
assertThat(e.getCause(), instanceOf(RuntimeException.class));
|
||||
}
|
||||
|
||||
Throwable cause = socket.errors.pop();
|
||||
assertThat("Error",cause,instanceOf(ArrayIndexOutOfBoundsException.class));
|
||||
assertThat("Close should have occurred", socket.closeLatch.await(1,TimeUnit.SECONDS), is(true));
|
||||
assertThat("Error",socket.errors.pop(), instanceOf(RuntimeException.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue