Skip to content

Commit 0a2c45b

Browse files
committed
Organised tests
1 parent 4c11219 commit 0a2c45b

File tree

5 files changed

+31
-41
lines changed

5 files changed

+31
-41
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.spotify.httpserver;
2+
3+
import com.http.HttpMethod;
4+
import com.http.HttpRequest;
5+
import com.http.HttpResponse;
6+
7+
public class ClientTest {
8+
9+
10+
public static void main(String[] args) {
11+
//Tests http request on a given server
12+
13+
HttpRequest httpRequest = new HttpRequest("http://127.0.0.1:8889/test/", HttpMethod.POST);
14+
httpRequest.addRequestHeader("Content-Type", "application/json");
15+
httpRequest.addContent("{\"t\" : true}");
16+
17+
HttpResponse httpResponse = httpRequest.execute();
18+
19+
System.out.printf("Code: %d Message %s Content: %s%n", httpResponse.getCode(),
20+
httpResponse.getMessage(), httpResponse.getContent());
21+
22+
23+
}
24+
25+
}

src/test/java/com/spotify/httpserver/ServerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
public class ServerTest {
1313

1414
public static void main(String[] args) throws IOException {
15+
// Initialised the server to test http request functionality alongside server functionality
16+
1517
HttpServer server = HttpServer.create(new InetSocketAddress(8889), 0);
1618
server.createContext("/test/", exchange -> {
1719
System.out.println("In handler");

src/test/java/com/spotify/httpserver/RequestTester.java renamed to src/test/java/com/spotify/httpserver/SpotifyRequestTester.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.net.URI;
1717
import java.util.Map;
1818

19-
public class RequestTester {
19+
public class SpotifyRequestTester {
2020

2121
private static final String CLIENT_ID = "49d248093d8c41dd8b65aba37c5ef665";
2222
private static final String CLIENT_SECRET = "381ccdf476ac4584b0d936663d5c2232";
@@ -27,6 +27,8 @@ public class RequestTester {
2727

2828

2929
public static void main(String[] args) throws Exception {
30+
// Tests the spotify authentication requests on custom http classes
31+
3032

3133
Desktop desktop = Desktop.getDesktop();
3234
server = HttpServer.create(new InetSocketAddress(8888), 0);

src/test/java/com/spotify/objects/track/TrackArtistTest.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/test/java/com/spotify/requests/users/CurrentUserProfileGetTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import org.junit.jupiter.api.Test;
66

77
import static org.junit.jupiter.api.Assertions.assertNotNull;
8-
import static org.junit.jupiter.api.Assertions.assertTrue;
98

109
class CurrentUserProfileGetTest {
1110

1211
@Test
1312
void serialize() {
14-
// the json to get back as an example response from execute.
13+
// Tests serialization
1514
JSONObject response = new JSONObject("{\"country\":\"GB\",\"display_name\":\"Duncan Jones\",\"email\":\"dj223@outlook.com\",\"explicit_content\":{\"filter_enabled\":false,\"filter_locked\":false},\"external_urls\":{\"spotify\":\"https://open.spotify.com/user/dj223-gb\"},\"followers\":{\"total\":6},\"href\":\"https://api.spotify.com/v1/users/dj223-gb\",\"id\":\"dj223-gb\",\"images\":[{\"url\":\"https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=215687718825007&height=300&width=300&ext=1658400961&hash=AeQuTLK8_J3FC0iEYeo\"}],\"product\":\"premium\",\"type\":\"user\",\"uri\":\"spotify:user:dj223-gb\"}");
1615
assertNotNull(response);
1716
CurrentUserProfileGet request = new CurrentUserProfileGet();

0 commit comments

Comments
 (0)