55import okhttp3 .mockwebserver .RecordedRequest ;
66import org .junit .Test ;
77
8+ import java .util .Calendar ;
9+ import java .util .Date ;
810import java .util .List ;
911
1012import static com .auth0 .client .MockServer .*;
11- import static com .auth0 .client .RecordedRequestMatcher .hasHeader ;
12- import static com .auth0 .client .RecordedRequestMatcher .hasMethodAndPath ;
13+ import static com .auth0 .client .RecordedRequestMatcher .*;
1314import static org .hamcrest .Matchers .*;
1415import static org .junit .Assert .assertThat ;
1516
@@ -35,19 +36,27 @@ public void shouldGetActiveUsersCount() throws Exception {
3536 public void shouldThrowOnGetDailyStatsWithNullDateFrom () throws Exception {
3637 exception .expect (IllegalArgumentException .class );
3738 exception .expectMessage ("'date from' cannot be null!" );
38- api .stats ().getDailyStats (null , "20161011" );
39+ api .stats ().getDailyStats (null , new Date () );
3940 }
4041
4142 @ Test
4243 public void shouldThrowOnGetDailyStatsWithNullDateTo () throws Exception {
4344 exception .expect (IllegalArgumentException .class );
4445 exception .expectMessage ("'date to' cannot be null!" );
45- api .stats ().getDailyStats ("20161011" , null );
46+ api .stats ().getDailyStats (new Date () , null );
4647 }
4748
49+ @ SuppressWarnings ("deprecation" )
4850 @ Test
4951 public void shouldGetDailyStats () throws Exception {
50- Request <List <DailyStats >> request = api .stats ().getDailyStats ("20161011" , "20161011" );
52+ Calendar calendar = Calendar .getInstance ();
53+ calendar .set (Calendar .YEAR , 2016 );
54+ calendar .set (Calendar .MONTH , Calendar .OCTOBER );
55+ calendar .set (Calendar .DATE , 11 );
56+ Date dateFrom = calendar .getTime ();
57+ calendar .set (Calendar .DATE , 12 );
58+ Date dateTo = calendar .getTime ();
59+ Request <List <DailyStats >> request = api .stats ().getDailyStats (dateFrom , dateTo );
5160 assertThat (request , is (notNullValue ()));
5261
5362 server .jsonResponse (MGMT_DAILY_STATS_LIST , 200 );
@@ -57,13 +66,15 @@ public void shouldGetDailyStats() throws Exception {
5766 assertThat (recordedRequest , hasMethodAndPath ("GET" , "/api/v2/stats/daily" ));
5867 assertThat (recordedRequest , hasHeader ("Content-Type" , "application/json" ));
5968 assertThat (recordedRequest , hasHeader ("Authorization" , "Bearer apiToken" ));
69+ assertThat (recordedRequest , hasQueryParameter ("from" , "20161011" ));
70+ assertThat (recordedRequest , hasQueryParameter ("to" , "20161012" ));
6071
6172 assertThat (response , is (notNullValue ()));
6273 }
6374
6475 @ Test
6576 public void shouldReturnEmptyDailyStats () throws Exception {
66- Request <List <DailyStats >> request = api .stats ().getDailyStats ("20161011" , "20161011" );
77+ Request <List <DailyStats >> request = api .stats ().getDailyStats (new Date (), new Date () );
6778 assertThat (request , is (notNullValue ()));
6879
6980 server .jsonResponse (MGMT_EMPTY_LIST , 200 );
@@ -72,4 +83,16 @@ public void shouldReturnEmptyDailyStats() throws Exception {
7283 assertThat (response , is (notNullValue ()));
7384 assertThat (response , is (emptyCollectionOf (DailyStats .class )));
7485 }
86+
87+ @ Test
88+ public void shouldFormatDateToYYYYMMDD () throws Exception {
89+ Calendar calendar = Calendar .getInstance ();
90+ calendar .set (Calendar .YEAR , 2010 );
91+ //Calendar.MONTH starts at 0 being January
92+ calendar .set (Calendar .MONTH , Calendar .JANUARY );
93+ calendar .set (Calendar .DATE , 22 );
94+
95+ assertThat (api .stats ().formatDate (calendar .getTime ()), is ("20100122" ));
96+
97+ }
7598}
0 commit comments