Skip to content

Commit e757a00

Browse files
Jiankai ZhengJiankai Zheng
authored andcommitted
fix(api): fixed bug that returned wrong object
1 parent a2f2025 commit e757a00

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

src/main/java/spotify/api/impl/ArtistApiRetrofit.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import spotify.api.interfaces.ArtistApi;
1010
import spotify.exceptions.HttpRequestFailedException;
1111
import spotify.factories.RetrofitHttpServiceFactory;
12+
import spotify.models.albums.AlbumSimplified;
1213
import spotify.models.artists.ArtistFull;
1314
import spotify.models.artists.ArtistFullCollection;
14-
import spotify.models.artists.ArtistSimplified;
1515
import spotify.models.paging.Paging;
1616
import spotify.models.tracks.TrackFullCollection;
1717
import spotify.retrofit.services.ArtistService;
@@ -59,7 +59,7 @@ public ArtistFull getArtist(String artistId) {
5959
}
6060

6161
@Override
62-
public Paging<ArtistSimplified> getArtistAlbums(String artistId, List<AlbumType> listOfAlbumTypes, Map<String, String> options) {
62+
public Paging<AlbumSimplified> getArtistAlbums(String artistId, List<AlbumType> listOfAlbumTypes, Map<String, String> options) {
6363
options = ValidatorUtil.optionsValueCheck(options);
6464

6565
String albumTypesWithCommaDelimiter = listOfAlbumTypes.stream()
@@ -71,13 +71,13 @@ public Paging<ArtistSimplified> getArtistAlbums(String artistId, List<AlbumType>
7171
}
7272

7373
logger.trace("Constructing HTTP call to fetch albums of an artist.");
74-
Call<Paging<ArtistSimplified>> httpCall = artistService.getArtistAlbums("Bearer " + this.accessToken, artistId, options);
74+
Call<Paging<AlbumSimplified>> httpCall = artistService.getArtistAlbums("Bearer " + this.accessToken, artistId, options);
7575

7676
try {
7777
logger.info("Executing HTTP call to fetch albums of artist.");
7878
logger.debug("Fetching artist {} albums with following values: {}.", artistId, options);
7979
LoggingUtil.logHttpCall(logger, httpCall);
80-
Response<Paging<ArtistSimplified>> response = httpCall.execute();
80+
Response<Paging<AlbumSimplified>> response = httpCall.execute();
8181

8282
ResponseChecker.throwIfRequestHasNotBeenFulfilledCorrectly(response, HttpStatusCode.OK);
8383

src/main/java/spotify/api/interfaces/ArtistApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package spotify.api.interfaces;
22

33
import spotify.api.enums.AlbumType;
4+
import spotify.models.albums.AlbumSimplified;
45
import spotify.models.artists.ArtistFull;
56
import spotify.models.artists.ArtistFullCollection;
6-
import spotify.models.artists.ArtistSimplified;
77
import spotify.models.paging.Paging;
88
import spotify.models.tracks.TrackFullCollection;
99

@@ -13,7 +13,7 @@
1313
public interface ArtistApi {
1414
ArtistFull getArtist(String artistId);
1515

16-
Paging<ArtistSimplified> getArtistAlbums(String artistId, List<AlbumType> listOfAlbumTypes, Map<String, String> options);
16+
Paging<AlbumSimplified> getArtistAlbums(String artistId, List<AlbumType> listOfAlbumTypes, Map<String, String> options);
1717

1818
TrackFullCollection getArtistTopTracks(String artistId, Map<String, String> options);
1919

src/main/java/spotify/api/spotify/SpotifyApi.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
import spotify.api.enums.RepeatType;
99
import spotify.api.impl.*;
1010
import spotify.api.interfaces.*;
11-
import spotify.models.albums.AlbumFull;
12-
import spotify.models.albums.AlbumFullCollection;
13-
import spotify.models.albums.AlbumSimplifiedPaging;
14-
import spotify.models.albums.SavedAlbumFull;
11+
import spotify.models.albums.*;
1512
import spotify.models.artists.ArtistFull;
1613
import spotify.models.artists.ArtistFullCollection;
17-
import spotify.models.artists.ArtistSimplified;
1814
import spotify.models.audio.AudioAnalysis;
1915
import spotify.models.audio.AudioFeatures;
2016
import spotify.models.audio.AudioFeaturesCollection;
@@ -157,7 +153,7 @@ public ArtistFull getArtist(String artistId) {
157153
return artistApi.getArtist(artistId);
158154
}
159155

160-
public Paging<ArtistSimplified> getArtistAlbums(String artistId, List<AlbumType> listOfAlbumTypes, Map<String, String> options) {
156+
public Paging<AlbumSimplified> getArtistAlbums(String artistId, List<AlbumType> listOfAlbumTypes, Map<String, String> options) {
161157
logger.info("Requesting albums of an artist");
162158
return artistApi.getArtistAlbums(artistId, listOfAlbumTypes, options);
163159
}

src/main/java/spotify/retrofit/services/ArtistService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import retrofit2.Call;
44
import retrofit2.http.*;
5+
import spotify.models.albums.AlbumSimplified;
56
import spotify.models.artists.ArtistFull;
67
import spotify.models.artists.ArtistFullCollection;
7-
import spotify.models.artists.ArtistSimplified;
88
import spotify.models.paging.Paging;
99
import spotify.models.tracks.TrackFullCollection;
1010

@@ -15,9 +15,9 @@ public interface ArtistService {
1515
Call<ArtistFull> getArtist(@Header("Authorization") String accessToken, @Path("id") String artistId);
1616

1717
@GET("artists/{id}/albums")
18-
Call<Paging<ArtistSimplified>> getArtistAlbums(@Header("Authorization") String accessToken,
19-
@Path("id") String artistId,
20-
@QueryMap Map<String, String> options);
18+
Call<Paging<AlbumSimplified>> getArtistAlbums(@Header("Authorization") String accessToken,
19+
@Path("id") String artistId,
20+
@QueryMap Map<String, String> options);
2121

2222
@GET("artists/{id}/top-tracks")
2323
Call<TrackFullCollection> getArtistTopTracks(@Header("Authorization") String accessToken, @Path("id") String artistId, @QueryMap Map<String, String> options);

src/test/java/spotify/api/impl/ArtistApiRetrofitTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import spotify.api.enums.AlbumType;
1414
import spotify.exceptions.HttpRequestFailedException;
1515
import spotify.exceptions.SpotifyActionFailedException;
16+
import spotify.models.albums.AlbumSimplified;
1617
import spotify.models.artists.ArtistFull;
1718
import spotify.models.artists.ArtistFullCollection;
18-
import spotify.models.artists.ArtistSimplified;
1919
import spotify.models.paging.Paging;
2020
import spotify.models.tracks.TrackFullCollection;
2121
import spotify.retrofit.services.ArtistService;
@@ -50,7 +50,7 @@ public class ArtistApiRetrofitTest extends AbstractApiRetrofitTest {
5050
@Mock
5151
private Call<ArtistFullCollection> mockedArtistFullCollectionCall;
5252
@Mock
53-
private Call<Paging<ArtistSimplified>> mockedPagingArtistSimplifiedCall;
53+
private Call<Paging<AlbumSimplified>> mockedPagingAlbumSimplifiedCall;
5454
@Mock
5555
private Call<TrackFullCollection> mockedTrackFullCollectionCall;
5656

@@ -61,14 +61,14 @@ void setup() {
6161
sut = new ArtistApiRetrofit(fakeAccessToken, mockedArtistService);
6262

6363
when(mockedArtistService.getArtist(fakeAccessTokenWithBearer, fakeArtistId)).thenReturn(mockedArtistFullCall);
64-
when(mockedArtistService.getArtistAlbums(fakeAccessTokenWithBearer, fakeArtistId, fakeOptionalParameters)).thenReturn(mockedPagingArtistSimplifiedCall);
64+
when(mockedArtistService.getArtistAlbums(fakeAccessTokenWithBearer, fakeArtistId, fakeOptionalParameters)).thenReturn(mockedPagingAlbumSimplifiedCall);
6565
when(mockedArtistService.getArtistTopTracks(fakeAccessTokenWithBearer, fakeArtistId, fakeOptionalParameters)).thenReturn(mockedTrackFullCollectionCall);
6666
when(mockedArtistService.getRelatedArtists(fakeAccessTokenWithBearer, fakeArtistId)).thenReturn(mockedArtistFullCollectionCall);
6767
when(mockedArtistService.getArtists(fakeAccessTokenWithBearer, fakeArtistIds)).thenReturn(mockedArtistFullCollectionCall);
6868

6969
when(mockedArtistFullCall.request()).thenReturn(new Request.Builder().url(fakeUrl).build());
7070
when(mockedArtistFullCollectionCall.request()).thenReturn(new Request.Builder().url(fakeUrl).build());
71-
when(mockedPagingArtistSimplifiedCall.request()).thenReturn(new Request.Builder().url(fakeUrl).build());
71+
when(mockedPagingAlbumSimplifiedCall.request()).thenReturn(new Request.Builder().url(fakeUrl).build());
7272
when(mockedTrackFullCollectionCall.request()).thenReturn(new Request.Builder().url(fakeUrl).build());
7373
}
7474

@@ -118,8 +118,8 @@ void getArtistReturnsArtistFullWhenSuccessful() throws IOException {
118118

119119
@Test
120120
void getArtistAlbumsUsesCorrectValuesToCreateHttpCall() throws IOException {
121-
when(mockedArtistService.getArtistAlbums(fakeAccessTokenWithBearer, fakeArtistId, fakeOptionalParameterWithAlbumTypes)).thenReturn(mockedPagingArtistSimplifiedCall);
122-
when(mockedPagingArtistSimplifiedCall.execute()).thenReturn(Response.success(new Paging<>()));
121+
when(mockedArtistService.getArtistAlbums(fakeAccessTokenWithBearer, fakeArtistId, fakeOptionalParameterWithAlbumTypes)).thenReturn(mockedPagingAlbumSimplifiedCall);
122+
when(mockedPagingAlbumSimplifiedCall.execute()).thenReturn(Response.success(new Paging<>()));
123123

124124
sut.getArtistAlbums(fakeArtistId, listOfFakeAlbumType, null);
125125

@@ -128,15 +128,15 @@ void getArtistAlbumsUsesCorrectValuesToCreateHttpCall() throws IOException {
128128

129129
@Test
130130
void getArtistAlbumsExecutesHttpCall() throws IOException {
131-
when(mockedPagingArtistSimplifiedCall.execute()).thenReturn(Response.success(new Paging<>()));
131+
when(mockedPagingAlbumSimplifiedCall.execute()).thenReturn(Response.success(new Paging<>()));
132132

133133
sut.getArtistAlbums(fakeArtistId, listOfFakeAlbumType, fakeOptionalParameters);
134-
verify(mockedPagingArtistSimplifiedCall).execute();
134+
verify(mockedPagingAlbumSimplifiedCall).execute();
135135
}
136136

137137
@Test
138138
void getArtistAlbumsThrowsSpotifyActionFailedExceptionWhenError() throws IOException {
139-
when(mockedPagingArtistSimplifiedCall.execute())
139+
when(mockedPagingAlbumSimplifiedCall.execute())
140140
.thenReturn(
141141
Response.error(
142142
400,
@@ -149,14 +149,14 @@ void getArtistAlbumsThrowsSpotifyActionFailedExceptionWhenError() throws IOExcep
149149

150150
@Test
151151
void getArtistAlbumsThrowsHttpRequestFailedWhenHttpFails() throws IOException {
152-
when(mockedPagingArtistSimplifiedCall.execute()).thenThrow(IOException.class);
152+
when(mockedPagingAlbumSimplifiedCall.execute()).thenThrow(IOException.class);
153153

154154
Assertions.assertThrows(HttpRequestFailedException.class, () -> sut.getArtistAlbums(fakeArtistId, listOfFakeAlbumType, fakeOptionalParameters));
155155
}
156156

157157
@Test
158-
void getArtistAlbumsReturnsPagingArtistSimplifiedWhenSuccessful() throws IOException {
159-
when(mockedPagingArtistSimplifiedCall.execute()).thenReturn(Response.success(new Paging<>()));
158+
void getArtistAlbumsReturnsPagingAlbumSimplifiedWhenSuccessful() throws IOException {
159+
when(mockedPagingAlbumSimplifiedCall.execute()).thenReturn(Response.success(new Paging<>()));
160160

161161
Assertions.assertNotNull(sut.getArtistAlbums(fakeArtistId, listOfFakeAlbumType, fakeOptionalParameters));
162162
}

0 commit comments

Comments
 (0)