Skip to content

Commit a32efc8

Browse files
committed
add missing empty list tests
1 parent a165420 commit a32efc8

7 files changed

Lines changed: 47 additions & 19 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jacocoTestReport {
2222

2323
test {
2424
testLogging {
25-
events "passed", "skipped", "failed", "standardError"
25+
events "skipped", "failed"
2626
exceptionFormat "short"
2727
}
2828
}

src/main/java/com/auth0/AuthAPI.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public AuthAPI(String domain, String clientId, String clientSecret) {
4141
this.clientSecret = clientSecret;
4242

4343
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
44-
logging.setLevel(Level.BODY);
44+
logging.setLevel(Level.NONE);
4545
client = new OkHttpClient.Builder()
4646
.addInterceptor(logging)
4747
.build();
@@ -100,7 +100,8 @@ public Request<UserInfo> userInfo(String accessToken) {
100100
.addPathSegment("userinfo")
101101
.build()
102102
.toString();
103-
CustomRequest<UserInfo> request = new CustomRequest<>(client, url, "GET", new TypeReference<UserInfo>() {});
103+
CustomRequest<UserInfo> request = new CustomRequest<>(client, url, "GET", new TypeReference<UserInfo>() {
104+
});
104105
request.addHeader("Authorization", "Bearer " + accessToken);
105106
return request;
106107
}

src/main/java/com/auth0/MgmtAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public MgmtAPI(String domain, String apiToken) {
3030
this.apiToken = apiToken;
3131

3232
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
33-
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
33+
logging.setLevel(HttpLoggingInterceptor.Level.NONE);
3434
client = new OkHttpClient.Builder()
3535
.addInterceptor(logging)
3636
.build();

src/main/java/com/auth0/json/auth/UserInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import com.fasterxml.jackson.annotation.JsonAnyGetter;
44
import com.fasterxml.jackson.annotation.JsonAnySetter;
5+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
56
import com.fasterxml.jackson.annotation.JsonInclude;
67

78
import java.util.HashMap;
89
import java.util.Map;
910

11+
@JsonIgnoreProperties(ignoreUnknown = true)
1012
@JsonInclude(JsonInclude.Include.NON_NULL)
1113
public class UserInfo {
1214

src/test/java/com/auth0/MgmtAPITest.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,18 @@ public void shouldGetUserGuardianEnrollments() throws Exception {
16591659
assertThat(response, is(notNullValue()));
16601660
}
16611661

1662+
@Test
1663+
public void shouldReturnEmptyUserGuardianEnrollments() throws Exception {
1664+
Request<List<GuardianEnrollment>> request = api.getUserGuardianEnrollments("1");
1665+
assertThat(request, is(notNullValue()));
1666+
1667+
server.jsonResponse(MGMT_EMPTY_LIST, 200);
1668+
List<GuardianEnrollment> response = request.execute();
1669+
1670+
assertThat(response, is(notNullValue()));
1671+
assertThat(response, is(emptyCollectionOf(GuardianEnrollment.class)));
1672+
}
1673+
16621674
@Test
16631675
public void shouldThrowOnGetUserLogEventsWithNullId() throws Exception {
16641676
exception.expect(IllegalArgumentException.class);
@@ -1776,8 +1788,6 @@ public void shouldReturnEmptyUserLogEvents() throws Exception {
17761788
assertThat(response.getItems(), is(emptyCollectionOf(LogEvent.class)));
17771789
}
17781790

1779-
//TODO: Add empty arrays validation
1780-
17811791
@Test
17821792
public void shouldThrowOnDeleteUserMultifactorProviderWithNullId() throws Exception {
17831793
exception.expect(IllegalArgumentException.class);
@@ -1958,6 +1968,18 @@ public void shouldGetBlacklistedTokens() throws Exception {
19581968
assertThat(response, hasSize(2));
19591969
}
19601970

1971+
@Test
1972+
public void shouldReturnEmptyBlacklistedTokens() throws Exception {
1973+
Request<List<Token>> request = api.getBlacklistedTokens("myapi");
1974+
assertThat(request, is(notNullValue()));
1975+
1976+
server.jsonResponse(MGMT_EMPTY_LIST, 200);
1977+
List<Token> response = request.execute();
1978+
1979+
assertThat(response, is(notNullValue()));
1980+
assertThat(response, is(emptyCollectionOf(Token.class)));
1981+
}
1982+
19611983
@Test
19621984
public void shouldThrowOnBlacklistTokensWithNullToken() throws Exception {
19631985
exception.expect(IllegalArgumentException.class);
@@ -2196,6 +2218,18 @@ public void shouldListGuardianFactors() throws Exception {
21962218
assertThat(response, hasSize(2));
21972219
}
21982220

2221+
@Test
2222+
public void shouldReturnEmptyGuardianFactors() throws Exception {
2223+
Request<List<GuardianFactor>> request = api.listGuardianFactors();
2224+
assertThat(request, is(notNullValue()));
2225+
2226+
server.jsonResponse(MGMT_EMPTY_LIST, 200);
2227+
List<GuardianFactor> response = request.execute();
2228+
2229+
assertThat(response, is(notNullValue()));
2230+
assertThat(response, is(emptyCollectionOf(GuardianFactor.class)));
2231+
}
2232+
21992233
@Test
22002234
public void shouldThrowOnUpdateGuardianFactorWithNullName() throws Exception {
22012235
exception.expect(IllegalArgumentException.class);

src/test/java/com/auth0/json/auth/UserInfoTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99

1010
public class UserInfoTest extends JsonTest<UserInfo> {
1111

12-
private static final String json = "{\"email_verified\":false,\"clientID\":\"q2hnj2iu...\",\"updated_at\":\"2016-12-05T15:15:40.545Z\",\"name\":\"test.account@userinfo.com\",\"email\":\"test.account@userinfo.com\"}";
12+
private static final String json = "{\"email\":\"test.account@userinfo.com\",\"client_id\":\"q2hnj2iu...\"}";
1313

1414
@Test
1515
public void shouldSerialize() throws Exception {
1616
UserInfo info = new UserInfo();
17-
info.setValue("email_verified", false);
1817
info.setValue("email", "test.account@userinfo.com");
19-
info.setValue("clientID", "q2hnj2iu...");
20-
info.setValue("updated_at", "2016-12-05T15:15:40.545Z");
21-
info.setValue("name", "test.account@userinfo.com");
18+
info.setValue("client_id", "q2hnj2iu...");
2219

2320
String serialized = toJSON(info);
2421
assertThat(serialized, is(notNullValue()));
@@ -31,10 +28,7 @@ public void shouldDeserialize() throws Exception {
3128

3229
assertThat(info, is(notNullValue()));
3330

34-
assertThat(info.getValues(), IsMapContaining.hasEntry("email_verified", (Object) false));
3531
assertThat(info.getValues(), IsMapContaining.hasEntry("email", (Object) "test.account@userinfo.com"));
36-
assertThat(info.getValues(), IsMapContaining.hasEntry("clientID", (Object) "q2hnj2iu..."));
37-
assertThat(info.getValues(), IsMapContaining.hasEntry("updated_at", (Object) "2016-12-05T15:15:40.545Z"));
38-
assertThat(info.getValues(), IsMapContaining.hasEntry("name", (Object) "test.account@userinfo.com"));
32+
assertThat(info.getValues(), IsMapContaining.hasEntry("client_id", (Object) "q2hnj2iu..."));
3933
}
4034
}

src/test/java/com/auth0/json/mgmt/client/AddonTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99

1010
public class AddonTest extends JsonTest<Addon> {
1111

12-
private static final String json = "{\"a-boolean\":true,\"a-string\":\"text\"}";
12+
private static final String json = "{\"a-boolean\":true}";
1313

1414
@Test
1515
public void shouldSerialize() throws Exception {
1616
Addon addon = new Addon();
1717
addon.setProperty("a-boolean", true);
18-
addon.setProperty("a-string", "text");
1918

2019
String serialized = toJSON(addon);
2120
assertThat(serialized, is(notNullValue()));
@@ -29,8 +28,6 @@ public void shouldDeserialize() throws Exception {
2928
assertThat(addon, is(notNullValue()));
3029

3130
assertThat(addon.getProperties(), IsMapContaining.hasEntry("a-boolean", (Object) true));
32-
assertThat(addon.getProperties(), IsMapContaining.hasEntry("a-string", (Object) "text"));
3331
assertThat(addon.getProperty("a-boolean"), is((Object) true));
34-
assertThat(addon.getProperty("a-string"), is((Object) "text"));
3532
}
3633
}

0 commit comments

Comments
 (0)