Use HubException for error in HandShakeResponse (#2914)

This commit is contained in:
Mikael Mengistu 2018-09-06 11:00:05 -07:00 committed by GitHub
parent b67137bc00
commit b0155446ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -50,7 +50,7 @@ public class HubConnection {
if (handshakeResponse.error != null) {
String errorMessage = "Error in handshake " + handshakeResponse.error;
logger.log(LogLevel.Error, errorMessage);
throw new Exception(errorMessage);
throw new HubException(errorMessage);
}
handshakeReceived = true;

View File

@ -14,6 +14,9 @@ import static org.junit.Assert.*;
public class HubConnectionTest {
private static final String RECORD_SEPARATOR = "\u001e";
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test
public void checkHubConnectionState() throws Exception {
Transport mockTransport = new MockTransport();
@ -40,6 +43,18 @@ public class HubConnectionTest {
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
}
@Test
public void HubConnectionReceiveHandshakeResponseWithError() throws Exception {
exceptionRule.expect(HubException.class);
exceptionRule.expectMessage("Requested protocol 'messagepack' is not available.");
MockTransport mockTransport = new MockTransport();
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport);
hubConnection.start();
mockTransport.receiveMessage("{\"error\": \"Requested protocol 'messagepack' is not available.\"}" + RECORD_SEPARATOR);
}
@Test
public void RegisteringMultipleHandlersAndBothGetTriggered() throws Exception {
AtomicReference<Double> value = new AtomicReference<>(0.0);
@ -673,9 +688,6 @@ public class HubConnectionTest {
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
}
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test
public void CannotSendBeforeStart() throws Exception {
exceptionRule.expect(HubException.class);