/** 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))); }
/** 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()); }
/** 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()); }
/** 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()); }
/** 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=")); }
/** Person: Test the age setter/getter. */ @Test public void testSetGetAge() { defaultAthlete.setAge(_defaultAge); assertEquals("Age is not set properly", _defaultAge, defaultAthlete.getAge()); }
/** Person: Test that name throws on empty string. */ @Test(expected = IllegalArgumentException.class) public void testSetName_Throws_OnEmpty() { defaultAthlete.setName(""); }
/** Ascertain that performRaceActivity() throws an AthleteInjuredException when injured. */ @Test(expected = AthleteInjuredException.class) public void testPerformRaceActivity_Throws_OnInjury() { defaultAthlete.setIsInjured(true); defaultAthlete.performRaceActivity(); }
/** RaceParticipant: Test that the contestantID remains in sensible bounds. */ @Test(expected = IndexOutOfBoundsException.class) public void testSetContestantID_Throws_OnTooHigh() { // > 100.000 defaultAthlete.setContestantID(100001); }
/** RaceParticipant: Test that the contestantID remains in sensible bounds. */ @Test(expected = IndexOutOfBoundsException.class) public void testSetContestantID_Throws_OnTooLow() { // < 1 defaultAthlete.setContestantID(0); }
/** RaceParticipant: Test the contestantID setter/getter. */ @Test public void testSetGetContestantID() { defaultAthlete.setContestantID(_defaultID); assertEquals("ID is not set properly", _defaultID, defaultAthlete.getContestantID()); }
/** Person: Test that age is in sensible bounds. */ @Test(expected = IndexOutOfBoundsException.class) public void testSetAge_Throws_OnTooHigh() { defaultAthlete.setAge(301); }