-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test cases for EmptyBodyVoidRequest
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.auth0.net; | ||
|
||
import com.auth0.client.MockServer; | ||
import com.auth0.client.mgmt.TokenProvider; | ||
import com.auth0.net.client.Auth0HttpClient; | ||
import com.auth0.net.client.DefaultHttpClient; | ||
import com.auth0.net.client.HttpMethod; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.auth0.client.MockServer.AUTH_TOKENS; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
public class EmptyBodyVoidRequestTest { | ||
|
||
private Auth0HttpClient client; | ||
private TokenProvider tokenProvider; | ||
private MockServer server; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
client = new DefaultHttpClient.Builder().build(); | ||
server = new MockServer(); | ||
tokenProvider = new TokenProvider() { | ||
@Override | ||
public String getToken() { | ||
return "Bearer abc"; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<String> getTokenAsync() { | ||
return CompletableFuture.completedFuture("Bearer abc"); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void shouldCreatePOSTRequest() throws Exception { | ||
EmptyBodyVoidRequest<Void> request = new EmptyBodyVoidRequest<>(client, tokenProvider, server.getBaseUrl(), HttpMethod.POST, new TypeReference<Void>() {}); | ||
assertThat(request, is(notNullValue())); | ||
|
||
server.jsonResponse(AUTH_TOKENS, 200); | ||
Void execute = request.execute().getBody(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
assertThat(recordedRequest.getMethod(), is(HttpMethod.POST.toString())); | ||
assertThat(execute, is(nullValue())); | ||
} | ||
} |