-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: close connection if IllegalArgumentException or PduValidationEx…
…ception is caught Co-authored-by: Torsten Will <[email protected]>
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
src/test/java/com/sipgate/li/simulator/x2x3/X2X3NettyDecoderTest.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,50 @@ | ||
package com.sipgate.li.simulator.x2x3; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
import com.sipgate.li.lib.x2x3.PduValidationException; | ||
import com.sipgate.li.lib.x2x3.X2X3Decoder; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class X2X3NettyDecoderTest { | ||
|
||
@Mock | ||
X2X3Decoder x2X3Decoder; | ||
|
||
@InjectMocks | ||
X2X3NettyDecoder underTest; | ||
|
||
@Spy | ||
private ChannelHandlerContext channelHandlerContext; | ||
|
||
static Stream<Arguments> decoderExceptions() { | ||
return Stream.of( | ||
Arguments.arguments(new PduValidationException("something's broken", "it's your fault")), | ||
Arguments.arguments(new IllegalArgumentException("Header too large")) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("decoderExceptions") | ||
void it_closes_on_pdu_validation_exception(final Exception e) throws Exception { | ||
// GIVEN | ||
doThrow(e).when(x2X3Decoder).decode(any(), any()); | ||
|
||
// WHEN | ||
underTest.decode(channelHandlerContext, null, null); | ||
|
||
// THEN | ||
verify(channelHandlerContext).close(); | ||
} | ||
} |