new method with tests to get all cards with a filter predicate.

New method in Interface API to get all cards in a given setCode.
This has changed the implementation of getArtCount avoiding to iterate over all the possible card prints.
This commit is contained in:
leriomaggio
2021-08-25 19:39:54 +01:00
parent 02a241de12
commit bccf6e0a27
3 changed files with 58 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
package forge.card;
import com.google.common.base.Predicate;
import forge.StaticData;
import forge.item.IPaperCard;
import forge.item.PaperCard;
@@ -10,7 +11,10 @@ import org.testng.annotations.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import static org.testng.Assert.*;
@@ -101,6 +105,44 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
this.legacyCardDb = new LegacyCardDb(data.getCommonCards().getAllCards(), data.getEditions());
}
/*
* TEST FOR GET ALL CARDS
*/
@Test
public void testGetAllCardsWithName(){
List<PaperCard> allCounterSpellPrints = this.cardDb.getAllCards(this.cardNameCounterspell);
assertNotNull(allCounterSpellPrints);
for (PaperCard card : allCounterSpellPrints)
assertEquals(card.getName(), this.cardNameCounterspell);
}
@Test
public void testGetAllCardsThatWerePrintedInSets(){
List<String> allowedSets = new ArrayList<>();
allowedSets.add(this.latestArtShivanDragonEdition);
Predicate<PaperCard> wasPrinted = (Predicate<PaperCard>) this.cardDb.wasPrintedInSets(allowedSets);
List<PaperCard> allCardsInSet = this.cardDb.getAllCards(wasPrinted);
assertNotNull(allCardsInSet);
}
@Test void testGetAllCardsOfaGivenNameAndLegalInSets(){
List<String> allowedSets = new ArrayList<>(Arrays.asList(this.editionsCounterspell));
Predicate<PaperCard> printedInSets = (Predicate<PaperCard>) this.cardDb.wasPrintedInSets(allowedSets);
List<PaperCard> allCounterSpellsInSets = this.cardDb.getAllCards(this.cardNameCounterspell, printedInSets);
assertNotNull(allCounterSpellsInSets);
assertTrue(allCounterSpellsInSets.size() > 0);
assertTrue(allCounterSpellsInSets.size() > 1);
for (PaperCard card : allCounterSpellsInSets) {
assertEquals(card.getName(), this.cardNameCounterspell);
}
}
/*
* TEST FOR CARD RETRIEVAL METHODS
*/
@Test
public void testGetCardByName() {
PaperCard legacyCard = this.legacyCardDb.getCard(cardNameShivanDragon);