mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Extended test cases to verify that any CardRequest passed in works with no side effect.
New tests (and fixed updated CardRequest implementation) verify that any method used for Card Retrieval when receiving directly CardRequest formatted strings as cardName won't have any side effect. In particular, the code is reliable to be robust enough to support passing in both card name (only) or a full cardRequest string. If the latter, any parameter in the request will be updated - accordingly - only when explicit params in function calls are provided. Also, new tests demonstrate that the current implementation has NO side effect when testing for multiple combinations. Therefore, whatever is requested in requestString won't be overruled, unless really requested too.
This commit is contained in:
@@ -93,6 +93,9 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
public static String compose(String cardName, String setCode) {
|
||||
setCode = setCode != null ? setCode : "";
|
||||
cardName = cardName != null ? cardName : "";
|
||||
if (cardName.indexOf(NameSetSeparator) != -1)
|
||||
// If cardName is another RequestString, just get card name and forget about the rest.
|
||||
cardName = CardRequest.fromString(cardName).cardName;
|
||||
return cardName + NameSetSeparator + setCode;
|
||||
}
|
||||
|
||||
@@ -514,9 +517,9 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
return setFilter && artIndexFilter && collectorNumberFilter;
|
||||
}
|
||||
}));
|
||||
if (candidates.isEmpty()) {
|
||||
if (candidates.isEmpty())
|
||||
return null;
|
||||
}
|
||||
|
||||
PaperCard candidate = candidates.get(0);
|
||||
// Before returning make sure that actual candidate has Image.
|
||||
// If not, try to replace current candidate with one having image,
|
||||
@@ -617,9 +620,10 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
final CardRequest cr = CardRequest.fromString(cardInfo);
|
||||
// Check whether input `frame` is null. In that case, fallback to default SetPreference !-)
|
||||
final CardArtPreference artPref = artPreference != null ? artPreference : this.defaultCardArtPreference;
|
||||
if (artIndex >= IPaperCard.DEFAULT_ART_INDEX && cr.artIndex < IPaperCard.DEFAULT_ART_INDEX) {
|
||||
cr.artIndex = artIndex;
|
||||
}
|
||||
cr.artIndex = Math.max(cr.artIndex, IPaperCard.DEFAULT_ART_INDEX);
|
||||
if (cr.artIndex != artIndex && artIndex > IPaperCard.DEFAULT_ART_INDEX )
|
||||
cr.artIndex = artIndex; // 2nd cond. is to verify that some actual value has been passed in.
|
||||
|
||||
List<PaperCard> cards = getAllCards(cr.cardName);
|
||||
if (releaseDate != null) {
|
||||
cards = Lists.newArrayList(Iterables.filter(cards, new Predicate<PaperCard>() {
|
||||
@@ -669,7 +673,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
Collections.reverse(acceptedEditions); // newest editions first
|
||||
PaperCard candidate = null;
|
||||
for (CardEdition ed : acceptedEditions) {
|
||||
PaperCard cardFromSet = getCardFromSet(cr.cardName, ed, artIndex, cr.isFoil);
|
||||
PaperCard cardFromSet = getCardFromSet(cr.cardName, ed, cr.artIndex, cr.isFoil);
|
||||
if (candidate == null && cardFromSet != null)
|
||||
// save the first card found, as the last backup in case no other candidate *with image* will be found
|
||||
candidate = cardFromSet;
|
||||
|
||||
Reference in New Issue
Block a user