Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(models): cover country code arrays on model objects
  • Loading branch information
dargmuesli committed Sep 2, 2026
commit 3ad49bcd095f8ff47a1084530d1b4e78a4144885
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import org.junit.jupiter.api.Test;
import se.michaelthelin.spotify.TestUtil;
import se.michaelthelin.spotify.enums.AlbumType;
import se.michaelthelin.spotify.enums.CountryCode;
import se.michaelthelin.spotify.enums.Modality;
import se.michaelthelin.spotify.enums.ModelObjectType;
import se.michaelthelin.spotify.model_objects.miscellaneous.AudioAnalysis;
import se.michaelthelin.spotify.model_objects.specification.Album;
import se.michaelthelin.spotify.model_objects.specification.Playlist;
import se.michaelthelin.spotify.model_objects.special.AlbumSimplifiedSpecial;
import se.michaelthelin.spotify.model_objects.specification.Recommendations;

import java.io.IOException;
Expand Down Expand Up @@ -102,4 +104,25 @@ public void mapShapedObjectsAreReadByTheirOwnParser() throws IOException {

assertEquals("5099749994324", album.getExternalIds().getExternalIds().get("upc"));
}

/**
* The adapter registered for {@link CountryCode} has to reach the elements of a
* {@code CountryCode[]} field too, which is the only shape the enum appears in on a model object.
* A missing adapter does not fail: Gson would fall back to matching the constant name and hand
* back an array of nulls for anything it could not match.
*/
@Test
public void countryCodeArraysAreReadElementWise() {
AlbumSimplifiedSpecial album = new AlbumSimplifiedSpecial.JsonUtil().createModelObject(
"{\"name\":\"Wish\",\"available_markets\":[\"SE\",\"xk\",\"ZZ\"]}");

CountryCode[] markets = album.getAvailableMarkets();

assertEquals(3, markets.length);
assertEquals(CountryCode.SE, markets[0]);
// XK is user-assigned rather than ISO-assigned, and Spotify serves it as a market
assertEquals(CountryCode.XK, markets[1]);
// an unknown code nulls its own element instead of failing the whole object
assertNull(markets[2]);
}
}