Skip to content

Commit

Permalink
added test cases for EmptyBodyVoidRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
tanya732 committed Oct 9, 2024
1 parent a1fd41b commit f7277b0
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/test/java/com/auth0/net/EmptyBodyVoidRequestTest.java
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()));
}
}

0 comments on commit f7277b0

Please sign in to comment.