@Test public void getHighestTrump() { class TestCase extends GameEngineTestHelper.TestCase { private Player currentPlayer; private Suit trumpSuit; private Map<Integer, List<String>> cards; private ValuedCard expected; private boolean nullExpected = false; TestCase( String name, Player currentPlayer, Suit trumpSuit, Map<Integer, List<String>> cards, ValuedCard expected) { super(name); this.currentPlayer = currentPlayer; this.trumpSuit = trumpSuit; this.cards = cards; this.expected = expected; } TestCase nullExpected() { this.nullExpected = true; return this; } @Override protected void runAssertions() { assignCards(cards); Trick currentTrick = createTrick(currentPlayer, trumpSuit); if (nullExpected) { assertThat(currentTrick.getHighestTrump()) .as("Check trick's highest trump is null") .isNull(); } else { assertThat(currentTrick.getHighestTrump()) .as("Check trick's highest trump is correct") .isEqualTo(expected); } } } List<TestCase> testCases = new ArrayList<>( List.of( new TestCase( "No trump - return null", p1, Suit.CLUBS, Map.of( 2, List.of("As"), 3, List.of("7s"), 4, List.of("Ts"), 1, List.of()), null) .nullExpected(), new TestCase( "Trump C - 7h,Qh,Tc - return Tc", p1, Suit.CLUBS, Map.of( 2, List.of("7h"), 3, List.of("Qh"), 4, List.of("Tc"), 1, List.of()), ValuedCard.fromCard(stringToCard("Tc"), true)), new TestCase( "Trump C - 7c,9h,Tc return Tc", p1, Suit.CLUBS, Map.of( 2, List.of("7c"), 3, List.of("9h"), 4, List.of("Tc"), 1, List.of()), ValuedCard.fromCard(stringToCard("Tc"), true)), new TestCase( "Trump C - 7c,9c,Tc return 9c", p1, Suit.CLUBS, Map.of( 2, List.of("7c"), 3, List.of("9c"), 4, List.of("Tc"), 1, List.of()), ValuedCard.fromCard(stringToCard("9c"), true)))); testCases.forEach(TestCase::run); }
public ValuedCard getHighestTrump() { ValuedCardComparator comparator = new ValuedCardComparator(trumpSuit); return playedCards.stream() .filter(pc -> pc.card.getSuit().equals(trumpSuit)) .map(pc -> ValuedCard.fromCard(pc.card, true)) .max(comparator) .orElse(null); }
Trick { public ValuedCard getHighestTrump() { ValuedCardComparator comparator = new ValuedCardComparator(trumpSuit); return playedCards.stream() .filter(pc -> pc.card.getSuit().equals(trumpSuit)) .map(pc -> ValuedCard.fromCard(pc.card, true)) .max(comparator) .orElse(null); } }
Trick { public ValuedCard getHighestTrump() { ValuedCardComparator comparator = new ValuedCardComparator(trumpSuit); return playedCards.stream() .filter(pc -> pc.card.getSuit().equals(trumpSuit)) .map(pc -> ValuedCard.fromCard(pc.card, true)) .max(comparator) .orElse(null); } private  Trick(Suit trumpSuit, List<PlayedCard> playedCards); }
Trick { public ValuedCard getHighestTrump() { ValuedCardComparator comparator = new ValuedCardComparator(trumpSuit); return playedCards.stream() .filter(pc -> pc.card.getSuit().equals(trumpSuit)) .map(pc -> ValuedCard.fromCard(pc.card, true)) .max(comparator) .orElse(null); } private  Trick(Suit trumpSuit, List<PlayedCard> playedCards); static Trick emptyTrick(Suit trumpSuit); Card getPlayerCard(Player player); List<Player> getPlayers(); void add(Player player, Card card); boolean isComplete(); Player getMaster(); int getValue(); Suit getDesiredSuit(); ValuedCard getHighestTrump(); boolean isEmpty(); @Override String toString(); }
Trick { public ValuedCard getHighestTrump() { ValuedCardComparator comparator = new ValuedCardComparator(trumpSuit); return playedCards.stream() .filter(pc -> pc.card.getSuit().equals(trumpSuit)) .map(pc -> ValuedCard.fromCard(pc.card, true)) .max(comparator) .orElse(null); } private  Trick(Suit trumpSuit, List<PlayedCard> playedCards); static Trick emptyTrick(Suit trumpSuit); Card getPlayerCard(Player player); List<Player> getPlayers(); void add(Player player, Card card); boolean isComplete(); Player getMaster(); int getValue(); Suit getDesiredSuit(); ValuedCard getHighestTrump(); boolean isEmpty(); @Override String toString();  }