|
| 1 | +package com.codedifferently.footballteamobject; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 8 | + |
| 9 | +import com.codedifferently.footballteamobject.FootballTeam.Conference; |
| 10 | +import java.util.HashMap; |
| 11 | +import java.util.Map; |
| 12 | +import org.junit.jupiter.api.BeforeEach; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | + |
| 15 | +public class FootballTeamTest { |
| 16 | + FootballTeam team; |
| 17 | + private Map<Integer, String> players; |
| 18 | + |
| 19 | + @BeforeEach |
| 20 | + void setUp() { |
| 21 | + team = new FootballTeam("Alabama", "Tuscaloosa", FootballTeam.Conference.SEC, new HashMap<>()); |
| 22 | + players = new HashMap<>(); |
| 23 | + players.put(2, "Derrick Henry"); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void testGetTeamName_ReturnsCorrectName() { |
| 28 | + assertEquals("Alabama", team.getTeamName()); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testGetTeamName_ReturnsNonNull() { |
| 33 | + assertNotNull(team.getTeamName()); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testAddPlayer() throws FootballTeam.DuplicatePlayerException { |
| 38 | + team.addPlayer(1, "John Doe"); |
| 39 | + assertEquals(1, team.getPlayerCount()); |
| 40 | + assertEquals("John Doe", team.getPlayers().get(1)); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testRemovePlayer() throws FootballTeam.DuplicatePlayerException { |
| 45 | + team.addPlayer(1, "John Doe"); |
| 46 | + team.removePlayer(1); |
| 47 | + assertEquals(0, team.getPlayerCount()); |
| 48 | + assertFalse(team.getPlayers().containsKey(1)); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testTallyJerseyNumbers_Under50() throws FootballTeam.DuplicatePlayerException { |
| 53 | + team.addPlayer(1, "Player 1"); |
| 54 | + team.tallyJerseyNumbers(); |
| 55 | + assertEquals(1, team.getJerseyNumberUnder50()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testPowerFiveConferences() { |
| 60 | + FootballTeam team = new FootballTeam("Team Name", "Location", Conference.ACC, new HashMap<>()); |
| 61 | + assertTrue(team.isPowerFive()); |
| 62 | + team = new FootballTeam("Team Name", "Location", Conference.BIG_12, new HashMap<>()); |
| 63 | + assertTrue(team.isPowerFive()); |
| 64 | + team = new FootballTeam("Team Name", "Location", Conference.BIG_10, new HashMap<>()); |
| 65 | + assertTrue(team.isPowerFive()); |
| 66 | + team = new FootballTeam("Team Name", "Location", Conference.PAC_12, new HashMap<>()); |
| 67 | + assertTrue(team.isPowerFive()); |
| 68 | + team = new FootballTeam("Team Name", "Location", Conference.SEC, new HashMap<>()); |
| 69 | + assertTrue(team.isPowerFive()); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void testGroupOfFiveConferences() { |
| 74 | + FootballTeam team = |
| 75 | + new FootballTeam("Team Name", "Location", Conference.AMERICAN, new HashMap<>()); |
| 76 | + assertFalse(team.isPowerFive()); |
| 77 | + team = new FootballTeam("Team Name", "Location", Conference.CONFERENCE_USA, new HashMap<>()); |
| 78 | + assertFalse(team.isPowerFive()); |
| 79 | + team = new FootballTeam("Team Name", "Location", Conference.MAC, new HashMap<>()); |
| 80 | + assertFalse(team.isPowerFive()); |
| 81 | + team = new FootballTeam("Team Name", "Location", Conference.MOUNTAIN_WEST, new HashMap<>()); |
| 82 | + assertFalse(team.isPowerFive()); |
| 83 | + team = new FootballTeam("Team Name", "Location", Conference.SUN_BELT, new HashMap<>()); |
| 84 | + assertFalse(team.isPowerFive()); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + void testDuplicatePlayerException() { |
| 89 | + String message = "A player with that number already exists."; |
| 90 | + DuplicatePlayerException exception = new DuplicatePlayerException(message); |
| 91 | + assertThatThrownBy( |
| 92 | + () -> { |
| 93 | + throw exception; |
| 94 | + }) |
| 95 | + .isInstanceOf(DuplicatePlayerException.class) |
| 96 | + .hasMessage(message); |
| 97 | + } |
| 98 | +} |
0 commit comments