Trick { public Player getMaster() { Suit desiredSuit = getDesiredSuit(); ValuedCardComparator comparator = new ValuedCardComparator(desiredSuit); PlayedCard masterCard = playedCards.stream() .max( (pc1, pc2) -> comparator.compare( ValuedCard.fromCard(pc1.card, trumpSuit), ValuedCard.fromCard(pc2.card, trumpSuit))) .orElse(null); if (masterCard == null) { throw new RuntimeException("Trick is empty; it has no master"); } return masterCard.player; } 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();  }
@Test public void getMaster() { class TestCase extends GameEngineTestHelper.TestCase { private Player currentPlayer; private Suit trumpSuit; private Map<Integer, List<String>> cards; private Player expected; TestCase( String name, Player currentPlayer, Suit trumpSuit, Map<Integer, List<String>> cards, Player expected) { super(name); this.currentPlayer = currentPlayer; this.trumpSuit = trumpSuit; this.cards = cards; this.expected = expected; } @Override protected void runAssertions() { assignCards(cards); Trick currentTrick = createTrick(currentPlayer, trumpSuit); assertThat(currentTrick.getMaster()) .as("Check trick's master is correct") .isEqualTo(expected); } } List<TestCase> testCases = new ArrayList<>( List.of( new TestCase( "First player is master - no trump", p1, Suit.SPADES, Map.of( 2, List.of(), 3, List.of(), 4, List.of("Ah"), 1, List.of()), p4), new TestCase( "First player is master - trump", p1, Suit.SPADES, Map.of( 2, List.of(), 3, List.of(), 4, List.of("As"), 1, List.of()), p4), new TestCase( "P3: As, P4: 9s - P3 is master", p1, Suit.HEARTS, Map.of( 2, List.of(), 3, List.of("As"), 4, List.of("9s"), 1, List.of()), p3), new TestCase( "P3: As (trump), P4: 9s - P4 is master", p1, Suit.SPADES, Map.of( 2, List.of(), 3, List.of("As"), 4, List.of("9s"), 1, List.of()), p4), new TestCase( "P3: Ts, P4: As - P4 is master", p1, Suit.HEARTS, Map.of( 2, List.of(), 3, List.of("Ts"), 4, List.of("As"), 1, List.of()), p4), new TestCase( "P3: Ts, P4: 7h (trump) - P4 is master", p1, Suit.HEARTS, Map.of( 2, List.of(), 3, List.of("Ts"), 4, List.of("7h"), 1, List.of()), p4), new TestCase( "P3: Ts, P4: 9h - P3 is master", p1, Suit.CLUBS, Map.of( 2, List.of(), 3, List.of("Ts"), 4, List.of("9h"), 1, List.of()), p3), new TestCase( "P2: Ts, P3: Ks, P4: Qs - P2 is master", p1, Suit.HEARTS, Map.of( 2, List.of("Ts"), 3, List.of("Ks"), 4, List.of("Qs"), 1, List.of()), p2), new TestCase( "P2: Ts, P3: Ks, P4: As - P4 is master", p1, Suit.HEARTS, Map.of( 2, List.of("Ts"), 3, List.of("Ks"), 4, List.of("As"), 1, List.of()), p4), new TestCase( "P2: Ts, P3: Ks, P4: Ac - P2 is master", p1, Suit.HEARTS, Map.of( 2, List.of("Ts"), 3, List.of("Ks"), 4, List.of("Ac"), 1, List.of()), p2), new TestCase( "P2: Ts, P3: 7h (trump), P4: Qs - P3 is master", p1, Suit.HEARTS, Map.of( 2, List.of("Ts"), 3, List.of("7h"), 4, List.of("Qs"), 1, List.of()), p3), new TestCase( "P2: Ts, P3: 7h (trump), P4: Jh - P4 is master", p1, Suit.HEARTS, Map.of( 2, List.of("Ts"), 3, List.of("7h"), 4, List.of("Jh"), 1, List.of()), p4))); testCases.forEach(TestCase::run); }