@Test public void aDeckOf0CardsDoesNotExist(){ Assertions.assertThatThrownBy(() -> factory.createDeck(0)) .isInstanceOf(IllegalArgumentException.class); }
public CardDeck createDeck(int numberOfCards) { if (numberOfCards % 4 != 0 || numberOfCards < 4 || numberOfCards > 52) { throw new IllegalArgumentException("Number of Cards must be multipler of 4 between 4 and 52"); } int numberOfRanks = numberOfCards / 4; Set<Card> cards = new TreeSet<>(); for (SUIT suit : SUIT.values()){ for (int i = 0; i < numberOfRanks; i++){ cards.add(aCard(suit, RANK.values()[i])); } } return new CardDeck(cards); }
CardDeckFactory { public CardDeck createDeck(int numberOfCards) { if (numberOfCards % 4 != 0 || numberOfCards < 4 || numberOfCards > 52) { throw new IllegalArgumentException("Number of Cards must be multipler of 4 between 4 and 52"); } int numberOfRanks = numberOfCards / 4; Set<Card> cards = new TreeSet<>(); for (SUIT suit : SUIT.values()){ for (int i = 0; i < numberOfRanks; i++){ cards.add(aCard(suit, RANK.values()[i])); } } return new CardDeck(cards); } }
CardDeckFactory { public CardDeck createDeck(int numberOfCards) { if (numberOfCards % 4 != 0 || numberOfCards < 4 || numberOfCards > 52) { throw new IllegalArgumentException("Number of Cards must be multipler of 4 between 4 and 52"); } int numberOfRanks = numberOfCards / 4; Set<Card> cards = new TreeSet<>(); for (SUIT suit : SUIT.values()){ for (int i = 0; i < numberOfRanks; i++){ cards.add(aCard(suit, RANK.values()[i])); } } return new CardDeck(cards); }  }
CardDeckFactory { public CardDeck createDeck(int numberOfCards) { if (numberOfCards % 4 != 0 || numberOfCards < 4 || numberOfCards > 52) { throw new IllegalArgumentException("Number of Cards must be multipler of 4 between 4 and 52"); } int numberOfRanks = numberOfCards / 4; Set<Card> cards = new TreeSet<>(); for (SUIT suit : SUIT.values()){ for (int i = 0; i < numberOfRanks; i++){ cards.add(aCard(suit, RANK.values()[i])); } } return new CardDeck(cards); }  CardDeck createDeck(int numberOfCards); }
CardDeckFactory { public CardDeck createDeck(int numberOfCards) { if (numberOfCards % 4 != 0 || numberOfCards < 4 || numberOfCards > 52) { throw new IllegalArgumentException("Number of Cards must be multipler of 4 between 4 and 52"); } int numberOfRanks = numberOfCards / 4; Set<Card> cards = new TreeSet<>(); for (SUIT suit : SUIT.values()){ for (int i = 0; i < numberOfRanks; i++){ cards.add(aCard(suit, RANK.values()[i])); } } return new CardDeck(cards); }  CardDeck createDeck(int numberOfCards);  }