Esempio n. 1
0
  /** Tests the RacingAthlete.toString() method. */
  @Test
  public void testToString() {
    // Preparations

    defaultAthlete.setName(_defaultName);
    defaultAthlete.setAge(_defaultAge);

    defaultAthlete.setContestantID(_defaultID);

    String athleteString = defaultAthlete.toString();

    // Class

    assertTrue(
        "Does not contain class name",
        athleteString.contains(defaultAthlete.getClass().getSimpleName()));

    // Person Interface

    assertTrue("Does not contain name", athleteString.contains(_defaultName));

    assertTrue("Does not contain age", athleteString.contains(Integer.toString(_defaultAge)));

    // RaceParticipant Interface

    assertTrue("Does not contain ID", athleteString.contains(Integer.toString(_defaultID)));
  }
Esempio n. 2
0
  /** Test the injury status getter/setter */
  @Test
  public void testSetGetIsInjured() {
    boolean isInjured = true;

    defaultAthlete.setIsInjured(isInjured);

    assertEquals("Injury state was not set properly", isInjured, defaultAthlete.getIsInjured());
  }
Esempio n. 3
0
  /** Tests the constructors. */
  @Test
  public void testConstructors() {
    assertNotNull("Default RacingAthlete is null", defaultAthlete);

    assertEquals("Specific RacingAthlete: Name not matching", _name, specificAthlete.getName());

    assertEquals("Specific RacingAthlete: Age not matching", _age, specificAthlete.getAge());

    assertEquals(
        "Specific RacingAthlete: Contestant ID not matching",
        _id,
        specificAthlete.getContestantID());
  }
Esempio n. 4
0
  /** RaceParticipant: Wrapper to test the (abstract) peformRaceActivity() method. */
  public void testPerformRaceActivity(String expectedActivityName) {
    // Make sure the athlete is re-set (not injured)
    defaultAthlete = getDefaultRacingAthlete();

    assertEquals(
        "Race activity is not set properly",
        expectedActivityName,
        defaultAthlete.performRaceActivity());
  }
Esempio n. 5
0
  /** Tests the toDataString() method. */
  @Test
  public void testToDataString() {
    String athleteDataString = defaultAthlete.toDataString();

    assertTrue(
        "RacingAthlete.toDataString() does not contain name property",
        athleteDataString.contains("name="));

    assertTrue(
        "RacingAthlete.toDataString() does not contain age property",
        athleteDataString.contains("age="));

    assertTrue(
        "RacingAthlete.toDataString() does not contain contestantID property",
        athleteDataString.contains("contestantID="));

    assertTrue(
        "RacingAthlete.toDataString() does not contain isInjured property",
        athleteDataString.contains("isInjured="));
  }
Esempio n. 6
0
  /** Person: Test the age setter/getter. */
  @Test
  public void testSetGetAge() {
    defaultAthlete.setAge(_defaultAge);

    assertEquals("Age is not set properly", _defaultAge, defaultAthlete.getAge());
  }
Esempio n. 7
0
 /** Person: Test that name throws on empty string. */
 @Test(expected = IllegalArgumentException.class)
 public void testSetName_Throws_OnEmpty() {
   defaultAthlete.setName("");
 }
Esempio n. 8
0
  /** Ascertain that performRaceActivity() throws an AthleteInjuredException when injured. */
  @Test(expected = AthleteInjuredException.class)
  public void testPerformRaceActivity_Throws_OnInjury() {
    defaultAthlete.setIsInjured(true);

    defaultAthlete.performRaceActivity();
  }
Esempio n. 9
0
 /** RaceParticipant: Test that the contestantID remains in sensible bounds. */
 @Test(expected = IndexOutOfBoundsException.class)
 public void testSetContestantID_Throws_OnTooHigh() {
   // > 100.000
   defaultAthlete.setContestantID(100001);
 }
Esempio n. 10
0
 /** RaceParticipant: Test that the contestantID remains in sensible bounds. */
 @Test(expected = IndexOutOfBoundsException.class)
 public void testSetContestantID_Throws_OnTooLow() {
   // < 1
   defaultAthlete.setContestantID(0);
 }
Esempio n. 11
0
  /** RaceParticipant: Test the contestantID setter/getter. */
  @Test
  public void testSetGetContestantID() {
    defaultAthlete.setContestantID(_defaultID);

    assertEquals("ID is not set properly", _defaultID, defaultAthlete.getContestantID());
  }
Esempio n. 12
0
 /** Person: Test that age is in sensible bounds. */
 @Test(expected = IndexOutOfBoundsException.class)
 public void testSetAge_Throws_OnTooHigh() {
   defaultAthlete.setAge(301);
 }