Search in sources :

Example 1 with DraftCube

use of mage.game.draft.DraftCube in project mage by magefree.

the class VerifyCardDataTest method test_checkCardsInCubes.

@Test
public void test_checkCardsInCubes() {
    Reflections reflections = new Reflections("mage.tournament.cubes.");
    Set<Class<? extends DraftCube>> cubesList = reflections.getSubTypesOf(DraftCube.class);
    Assert.assertFalse("Can't find any cubes", cubesList.isEmpty());
    CardScanner.scan();
    Collection<String> errorsList = new ArrayList<>();
    for (Class<? extends DraftCube> cubeClass : cubesList) {
        // need drafts with fixed cards list (constructor with zero params)
        if (Arrays.stream(cubeClass.getConstructors()).noneMatch(c -> c.getParameterCount() == 0)) {
            continue;
        }
        DraftCube cube = (DraftCube) createNewObject(cubeClass);
        if (cube.getCubeCards().isEmpty()) {
            errorsList.add("Error: broken cube, empty cards list: " + cube.getClass().getCanonicalName());
        }
        for (DraftCube.CardIdentity cardId : cube.getCubeCards()) {
            // same find code as original cube
            CardInfo cardInfo;
            if (!cardId.getExtension().isEmpty()) {
                cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension(), false);
            } else {
                cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName(), false);
            }
            if (cardInfo == null) {
                errorsList.add("Error: broken cube, can't find card: " + cube.getClass().getCanonicalName() + " - " + cardId.getName());
            }
        }
    }
    if (!errorsList.isEmpty()) {
        printMessages(errorsList);
        Assert.fail("Found " + errorsList.size() + " errors in the cubes, look at logs above for more details");
    }
}
Also used : DraftCube(mage.game.draft.DraftCube) CardInfo(mage.cards.repository.CardInfo) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Aggregations

CardInfo (mage.cards.repository.CardInfo)1 DraftCube (mage.game.draft.DraftCube)1 Test (org.junit.Test)1 Reflections (org.reflections.Reflections)1