-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove onUnhandled in CustomIOHandler (#27372)
* Remove onUnhandled in CustomIOHandler * Renaming CustomIOHandler to TransportHandler. No longer extending from IOHandler. * Adding TransportHandlerTest * Fix typo.
- Loading branch information
Showing
5 changed files
with
96 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...e-amqp/src/test/java/com/azure/core/amqp/implementation/handler/TransportHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.amqp.implementation.handler; | ||
|
||
import org.apache.qpid.proton.engine.Connection; | ||
import org.apache.qpid.proton.engine.Event; | ||
import org.apache.qpid.proton.engine.Transport; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Tests transport handler. | ||
*/ | ||
public class TransportHandlerTest { | ||
@Mock | ||
private Transport transport; | ||
@Mock | ||
private Connection connection; | ||
@Mock | ||
private Event event; | ||
|
||
private AutoCloseable autoCloseable; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
autoCloseable = MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@AfterEach | ||
public void afterEach() throws Exception { | ||
Mockito.framework().clearInlineMock(this); | ||
|
||
if (autoCloseable != null) { | ||
autoCloseable.close(); | ||
} | ||
} | ||
|
||
/** | ||
* Unbinds transport if there is one associated with the connection. | ||
*/ | ||
@Test | ||
public void unbindsTransport() { | ||
// Arrange | ||
when(event.getConnection()).thenReturn(connection); | ||
when(event.getTransport()).thenReturn(transport); | ||
|
||
when(connection.getTransport()).thenReturn(transport); | ||
|
||
final TransportHandler handler = new TransportHandler("name"); | ||
|
||
// Act | ||
handler.onTransportClosed(event); | ||
|
||
// Assert | ||
verify(transport).unbind(); | ||
} | ||
|
||
@Test | ||
public void noTransport() { | ||
// Arrange | ||
when(event.getTransport()).thenReturn(transport); | ||
when(event.getConnection()).thenReturn(connection); | ||
|
||
final TransportHandler handler = new TransportHandler("name"); | ||
|
||
// Act | ||
handler.onTransportClosed(event); | ||
|
||
// Assert | ||
verify(transport, never()).unbind(); | ||
} | ||
} |