Skip to content

Commit 1645ef5

Browse files
committed
Fixed issue and added TrackGetTest
1 parent 799f7d1 commit 1645ef5

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

pom.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77

88
<groupId>com.spotstat</groupId>
9-
<artifactId>spotstat</artifactId>
10-
<version>1.0-SNAPSHOT</version>
9+
<artifactId>S4J</artifactId>
10+
<version>1.1a</version>
1111

1212
<properties>
1313
<maven.compiler.source>17</maven.compiler.source>
@@ -18,12 +18,25 @@
1818

1919
<dependency>
2020
<groupId>org.junit.jupiter</groupId>
21-
<artifactId>junit-jupiter-api</artifactId>
21+
<artifactId>junit-jupiter</artifactId>
2222
<version>5.8.2</version>
2323
<scope>test</scope>
2424
</dependency>
2525

2626
</dependencies>
2727

28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-surefire-plugin</artifactId>
33+
<version>2.22.2</version>
34+
<configuration>
35+
<excludedGroups>SlowNetworkTest</excludedGroups>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
2841

2942
</project>

src/main/java/com/spotify/requests/AbstractRequest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public String buildRequestUrl() {
108108

109109
url = spotifyRequest.value();
110110
StringBuilder sb = new StringBuilder(url);
111-
//if (!url.endsWith("/")) sb.append("/");
111+
if (!url.endsWith("/")) sb.append("/");
112112

113113
List<Field> spotifySubRequestFields = new ArrayList<>();
114114
List<Field> spotifyFieldRequestFields = new ArrayList<>();
@@ -140,7 +140,10 @@ public String buildRequestUrl() {
140140
// Fields annotated with SpotifyRequestField
141141
for (Field field : spotifyFieldRequestFields) {
142142
field.setAccessible(true);
143-
if (!sb.toString().endsWith("&") && !sb.toString().endsWith("/")) sb.append("?");
143+
if (sb.toString().endsWith("/")) {
144+
sb = new StringBuilder(sb.substring(0, sb.length() - 1));
145+
sb.append("?");
146+
}
144147

145148
Object o = field.get(this);
146149
Class<?> type = field.getType();

src/test/java/com/spotify/requests/tracks/SeveralTracksGetTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.spotify.SpotifyClientBuilderTester;
55
import com.spotify.requests.RequestResponse;
66
import com.spotify.requests.util.Market;
7+
import org.junit.jupiter.api.Tag;
78
import org.junit.jupiter.api.Test;
89

910
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -27,6 +28,7 @@ public void severalTrackGetUrlBuildTest() {
2728

2829

2930
@Test
31+
@Tag("SlowNetworkTest")
3032
public void severalTrackGetExecuteTest() {
3133
String[] songs = new String[]{"1ljziaoMnRH95aPeOSGAtr", "2fOYcnUo9iPTOqIlSg26MY"};
3234
SeveralTracksGet tracksGet = new SeveralTracksGet(songs);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.spotify.requests.tracks;
2+
3+
import com.spotify.SpotifyClient;
4+
import com.spotify.SpotifyClientBuilderTester;
5+
import com.spotify.requests.RequestResponse;
6+
import org.junit.jupiter.api.Tag;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
class TrackGetTest {
12+
13+
14+
@Test
15+
public void trackGetUrlBuildTest() {
16+
TrackGet trackGet = new TrackGet("id1");
17+
18+
19+
String url = trackGet.buildRequestUrl();
20+
21+
22+
assertEquals("tracks/id1", url);
23+
}
24+
25+
@Test
26+
@Tag("SlowNetworkTest")
27+
public void trackGetExecuteTest() {
28+
String id = "2fOYcnUo9iPTOqIlSg26MY";
29+
TrackGet trackGet = new TrackGet(id);
30+
SpotifyClient scbt = new SpotifyClientBuilderTester().getBuiltClient();
31+
RequestResponse response = scbt.executeRequest(trackGet);
32+
33+
assertEquals(200, response.getCode());
34+
}
35+
36+
}

0 commit comments

Comments
 (0)