@@ -17,25 +17,52 @@ public class AlgorithmTest {
1717 public ExpectedException exception = ExpectedException .none ();
1818
1919
20+ @ Test
21+ public void shouldThrowHMAC256VerificationWithNullSecretBytes () throws Exception {
22+ exception .expect (IllegalArgumentException .class );
23+ exception .expectMessage ("The Secret cannot be null" );
24+ byte [] secret = null ;
25+ Algorithm .HMAC256 (secret );
26+ }
27+
28+ @ Test
29+ public void shouldThrowHMAC384VerificationWithNullSecretBytes () throws Exception {
30+ exception .expect (IllegalArgumentException .class );
31+ exception .expectMessage ("The Secret cannot be null" );
32+ byte [] secret = null ;
33+ Algorithm .HMAC384 (secret );
34+ }
35+
36+ @ Test
37+ public void shouldThrowHMAC512VerificationWithNullSecretBytes () throws Exception {
38+ exception .expect (IllegalArgumentException .class );
39+ exception .expectMessage ("The Secret cannot be null" );
40+ byte [] secret = null ;
41+ Algorithm .HMAC512 (secret );
42+ }
43+
2044 @ Test
2145 public void shouldThrowHMAC256VerificationWithNullSecret () throws Exception {
2246 exception .expect (IllegalArgumentException .class );
2347 exception .expectMessage ("The Secret cannot be null" );
24- Algorithm .HMAC256 (null );
48+ String secret = null ;
49+ Algorithm .HMAC256 (secret );
2550 }
2651
2752 @ Test
2853 public void shouldThrowHMAC384VerificationWithNullSecret () throws Exception {
2954 exception .expect (IllegalArgumentException .class );
3055 exception .expectMessage ("The Secret cannot be null" );
31- Algorithm .HMAC384 (null );
56+ String secret = null ;
57+ Algorithm .HMAC384 (secret );
3258 }
3359
3460 @ Test
3561 public void shouldThrowHMAC512VerificationWithNullSecret () throws Exception {
3662 exception .expect (IllegalArgumentException .class );
3763 exception .expectMessage ("The Secret cannot be null" );
38- Algorithm .HMAC512 (null );
64+ String secret = null ;
65+ Algorithm .HMAC512 (secret );
3966 }
4067
4168 @ Test
@@ -81,36 +108,69 @@ public void shouldThrowECDSA512VerificationWithNullPublicKey() throws Exception
81108 }
82109
83110 @ Test
84- public void shouldCreateHMAC256Algorithm () throws Exception {
111+ public void shouldCreateHMAC256AlgorithmWithBytes () throws Exception {
112+ Algorithm algorithm = Algorithm .HMAC256 ("secret" .getBytes ());
113+
114+ assertThat (algorithm , is (notNullValue ()));
115+ assertThat (algorithm , is (instanceOf (HMACAlgorithm .class )));
116+ assertThat (algorithm .getDescription (), is ("HmacSHA256" ));
117+ assertThat (algorithm .getName (), is ("HS256" ));
118+ assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" .getBytes ()));
119+ }
120+
121+ @ Test
122+ public void shouldCreateHMAC384AlgorithmWithBytes () throws Exception {
123+ Algorithm algorithm = Algorithm .HMAC384 ("secret" .getBytes ());
124+
125+ assertThat (algorithm , is (notNullValue ()));
126+ assertThat (algorithm , is (instanceOf (HMACAlgorithm .class )));
127+ assertThat (algorithm .getDescription (), is ("HmacSHA384" ));
128+ assertThat (algorithm .getName (), is ("HS384" ));
129+ assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" .getBytes ()));
130+ }
131+
132+ @ Test
133+ public void shouldCreateHMAC512AlgorithmWithBytes () throws Exception {
134+ Algorithm algorithm = Algorithm .HMAC512 ("secret" .getBytes ());
135+
136+ assertThat (algorithm , is (notNullValue ()));
137+ assertThat (algorithm , is (instanceOf (HMACAlgorithm .class )));
138+ assertThat (algorithm .getDescription (), is ("HmacSHA512" ));
139+ assertThat (algorithm .getName (), is ("HS512" ));
140+ assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" .getBytes ()));
141+ }
142+
143+ @ Test
144+ public void shouldCreateHMAC256AlgorithmWithString () throws Exception {
85145 Algorithm algorithm = Algorithm .HMAC256 ("secret" );
86146
87147 assertThat (algorithm , is (notNullValue ()));
88148 assertThat (algorithm , is (instanceOf (HMACAlgorithm .class )));
89149 assertThat (algorithm .getDescription (), is ("HmacSHA256" ));
90150 assertThat (algorithm .getName (), is ("HS256" ));
91- assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" ));
151+ assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" . getBytes () ));
92152 }
93153
94154 @ Test
95- public void shouldCreateHMAC384Algorithm () throws Exception {
155+ public void shouldCreateHMAC384AlgorithmWithString () throws Exception {
96156 Algorithm algorithm = Algorithm .HMAC384 ("secret" );
97157
98158 assertThat (algorithm , is (notNullValue ()));
99159 assertThat (algorithm , is (instanceOf (HMACAlgorithm .class )));
100160 assertThat (algorithm .getDescription (), is ("HmacSHA384" ));
101161 assertThat (algorithm .getName (), is ("HS384" ));
102- assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" ));
162+ assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" . getBytes () ));
103163 }
104164
105165 @ Test
106- public void shouldCreateHMAC512Algorithm () throws Exception {
166+ public void shouldCreateHMAC512AlgorithmWithString () throws Exception {
107167 Algorithm algorithm = Algorithm .HMAC512 ("secret" );
108168
109169 assertThat (algorithm , is (notNullValue ()));
110170 assertThat (algorithm , is (instanceOf (HMACAlgorithm .class )));
111171 assertThat (algorithm .getDescription (), is ("HmacSHA512" ));
112172 assertThat (algorithm .getName (), is ("HS512" ));
113- assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" ));
173+ assertThat (((HMACAlgorithm ) algorithm ).getSecret (), is ("secret" . getBytes () ));
114174 }
115175
116176 @ Test
0 commit comments