@@ -19,98 +19,99 @@ public class JWTCreatorTest {
1919 public ExpectedException exception = ExpectedException .none ();
2020
2121 @ Test
22- public void shouldThrowWhenInitializedWithoutAlgorithm () throws Exception {
22+ public void shouldThrowWhenRequestingSignWithoutAlgorithm () throws Exception {
2323 exception .expect (IllegalArgumentException .class );
2424 exception .expectMessage ("The Algorithm cannot be null" );
25- JWTCreator .init (null );
25+ JWTCreator .init ()
26+ .sign (null );
2627 }
2728
2829 @ SuppressWarnings ("Convert2Diamond" )
2930 @ Test
3031 public void shouldAddHeader () throws Exception {
3132 Map <String , Object > header = new HashMap <String , Object >();
3233 header .put ("asd" , 123 );
33- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
34+ String signed = JWTCreator .init ()
3435 .withHeader (header )
35- .sign ();
36+ .sign (Algorithm . HMAC256 ( "secret" ) );
3637
3738 assertThat (signed , is (notNullValue ()));
3839 assertThat (SignUtils .splitToken (signed )[0 ], is ("eyJhbGciOiJIUzI1NiIsImFzZCI6MTIzfQ" ));
3940 }
4041
4142 @ Test
4243 public void shouldAddIssuer () throws Exception {
43- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
44+ String signed = JWTCreator .init ()
4445 .withIssuer ("auth0" )
45- .sign ();
46+ .sign (Algorithm . HMAC256 ( "secret" ) );
4647
4748 assertThat (signed , is (notNullValue ()));
4849 assertThat (SignUtils .splitToken (signed )[1 ], is ("eyJpc3MiOiJhdXRoMCJ9" ));
4950 }
5051
5152 @ Test
5253 public void shouldAddSubject () throws Exception {
53- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
54+ String signed = JWTCreator .init ()
5455 .withSubject ("1234567890" )
55- .sign ();
56+ .sign (Algorithm . HMAC256 ( "secret" ) );
5657
5758 assertThat (signed , is (notNullValue ()));
5859 assertThat (SignUtils .splitToken (signed )[1 ], is ("eyJzdWIiOiIxMjM0NTY3ODkwIn0" ));
5960 }
6061
6162 @ Test
6263 public void shouldAddAudience () throws Exception {
63- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
64+ String signed = JWTCreator .init ()
6465 .withAudience (new String []{"Mark" })
65- .sign ();
66+ .sign (Algorithm . HMAC256 ( "secret" ) );
6667
6768 assertThat (signed , is (notNullValue ()));
6869 assertThat (SignUtils .splitToken (signed )[1 ], is ("eyJhdWQiOiJNYXJrIn0" ));
6970
7071
71- String signedArr = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
72+ String signedArr = JWTCreator .init ()
7273 .withAudience (new String []{"Mark" , "David" })
73- .sign ();
74+ .sign (Algorithm . HMAC256 ( "secret" ) );
7475
7576 assertThat (signedArr , is (notNullValue ()));
7677 assertThat (SignUtils .splitToken (signedArr )[1 ], is ("eyJhdWQiOlsiTWFyayIsIkRhdmlkIl19" ));
7778 }
7879
7980 @ Test
8081 public void shouldAddExpiresAt () throws Exception {
81- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
82+ String signed = JWTCreator .init ()
8283 .withExpiresAt (new Date (1477592000 ))
83- .sign ();
84+ .sign (Algorithm . HMAC256 ( "secret" ) );
8485
8586 assertThat (signed , is (notNullValue ()));
8687 assertThat (SignUtils .splitToken (signed )[1 ], is ("eyJleHAiOjE0Nzc1OTJ9" ));
8788 }
8889
8990 @ Test
9091 public void shouldAddNotBefore () throws Exception {
91- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
92+ String signed = JWTCreator .init ()
9293 .withNotBefore (new Date (1477592000 ))
93- .sign ();
94+ .sign (Algorithm . HMAC256 ( "secret" ) );
9495
9596 assertThat (signed , is (notNullValue ()));
9697 assertThat (SignUtils .splitToken (signed )[1 ], is ("eyJuYmYiOjE0Nzc1OTJ9" ));
9798 }
9899
99100 @ Test
100101 public void shouldAddIssuedAt () throws Exception {
101- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
102+ String signed = JWTCreator .init ()
102103 .withIssuedAt (new Date (1477592000 ))
103- .sign ();
104+ .sign (Algorithm . HMAC256 ( "secret" ) );
104105
105106 assertThat (signed , is (notNullValue ()));
106107 assertThat (SignUtils .splitToken (signed )[1 ], is ("eyJpYXQiOjE0Nzc1OTJ9" ));
107108 }
108109
109110 @ Test
110111 public void shouldAddJWTId () throws Exception {
111- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
112+ String signed = JWTCreator .init ()
112113 .withJWTId ("jwt_id_123" )
113- .sign ();
114+ .sign (Algorithm . HMAC256 ( "secret" ) );
114115
115116 assertThat (signed , is (notNullValue ()));
116117 assertThat (SignUtils .splitToken (signed )[1 ], is ("eyJqdGkiOiJqd3RfaWRfMTIzIn0" ));
@@ -119,28 +120,28 @@ public void shouldAddJWTId() throws Exception {
119120
120121 @ Test
121122 public void shouldRemoveClaimWhenPassingNull () throws Exception {
122- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
123+ String signed = JWTCreator .init ()
123124 .withIssuer ("iss" )
124125 .withIssuer (null )
125- .sign ();
126+ .sign (Algorithm . HMAC256 ( "secret" ) );
126127
127128 assertThat (signed , is (notNullValue ()));
128129 assertThat (SignUtils .splitToken (signed )[1 ], is ("e30" ));
129130 }
130131
131132 @ Test
132133 public void shouldSetCorrectAlgorithmInTheHeader () throws Exception {
133- String signed = JWTCreator .init (Algorithm . HMAC256 ( "secret" ) )
134- .sign ();
134+ String signed = JWTCreator .init ()
135+ .sign (Algorithm . HMAC256 ( "secret" ) );
135136
136137 assertThat (signed , is (notNullValue ()));
137138 assertThat (SignUtils .splitToken (signed )[0 ], is ("eyJhbGciOiJIUzI1NiJ9" ));
138139 }
139140
140141 @ Test
141142 public void shouldSetEmptySignatureIfAlgorithmIsNone () throws Exception {
142- String signed = JWTCreator .init (Algorithm . none () )
143- .sign ();
143+ String signed = JWTCreator .init ()
144+ .sign (Algorithm . none () );
144145 assertThat (signed , is (notNullValue ()));
145146 assertThat (SignUtils .splitToken (signed )[2 ], is ("" ));
146147 }
0 commit comments