22
33import io .apimatic .core .security .DigestCodec ;
44import io .apimatic .core .security .DigestCodecFactory ;
5- import org .junit .Rule ;
65import org .junit .Test ;
7- import org .junit .rules .ExpectedException ;
86import org .junit .runner .RunWith ;
97import org .mockito .junit .MockitoJUnitRunner ;
108
119import static org .junit .Assert .assertArrayEquals ;
1210import static org .junit .Assert .assertEquals ;
11+ import static org .junit .Assert .assertThrows ;
1312
1413@ RunWith (MockitoJUnitRunner .class )
1514public class DigestCodecFactoryTest {
1615
17- /** Rule for expecting exceptions in tests. */
18- @ Rule
19- public ExpectedException thrown = ExpectedException .none ();
20-
2116 private static final byte HEX_BYTE_1 = 0x0A ;
2217 private static final byte HEX_BYTE_2 = 0x1B ;
2318 private static final byte HEX_BYTE_3 = (byte ) 0xFF ;
2419
25- private static final byte [] BASE64_INPUT = {1 , 2 , 3 , 4 , 5 };
2620 private static final byte BASE64_BYTE_1 = 1 ;
2721 private static final byte BASE64_BYTE_2 = 2 ;
2822 private static final byte BASE64_BYTE_3 = 3 ;
@@ -56,15 +50,17 @@ public void testHexEncodeEmpty() {
5650 @ Test
5751 public void testHexDecodeInvalidLength () {
5852 DigestCodec codec = DigestCodecFactory .hex ();
59- thrown .expect (IllegalArgumentException .class );
60- codec .decode ("abc" );
53+ assertThrows (IllegalArgumentException .class , () -> {
54+ codec .decode ("abc" );
55+ });
6156 }
6257
6358 @ Test
6459 public void testHexDecodeInvalidCharacter () {
6560 DigestCodec codec = DigestCodecFactory .hex ();
66- thrown .expect (IllegalArgumentException .class );
67- codec .decode ("zzzzz" );
61+ assertThrows (IllegalArgumentException .class , () -> {
62+ codec .decode ("zzzzz" );
63+ });
6864 }
6965
7066 @ Test
@@ -88,8 +84,9 @@ public void testBase64EncodeEmpty() {
8884 @ Test
8985 public void testBase64DecodeInvalid () {
9086 DigestCodec codec = DigestCodecFactory .base64 ();
91- thrown .expect (IllegalArgumentException .class );
92- codec .decode ("!@#$" );
87+ assertThrows (IllegalArgumentException .class , () -> {
88+ codec .decode ("!@#$" );
89+ });
9390 }
9491
9592 @ Test
@@ -114,7 +111,8 @@ public void testBase64UrlEncodeEmpty() {
114111 @ Test
115112 public void testBase64UrlDecodeInvalid () {
116113 DigestCodec codec = DigestCodecFactory .base64Url ();
117- thrown .expect (IllegalArgumentException .class );
118- codec .decode ("!@#$" );
114+ assertThrows (IllegalArgumentException .class , () -> {
115+ codec .decode ("!@#$" );
116+ });
119117 }
120118}
0 commit comments