11package com .codedifferently .lesson16 .boxer ;
22
3+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
34import static org .junit .jupiter .api .Assertions .assertEquals ;
5+ import static org .junit .jupiter .api .Assertions .assertFalse ;
46import static org .junit .jupiter .api .Assertions .assertNotEquals ;
7+ import org .junit .jupiter .api .BeforeEach ;
8+ import org .junit .jupiter .api .Test ;
59
610import com .codedifferently .lesson16 .boxer .Boxer .BoxerHasNoFightsException ;
711import com .codedifferently .lesson16 .boxer .Boxer .BoxerIsRetiredException ;
8- import org .junit .jupiter .api .BeforeEach ;
9- import org .junit .jupiter .api .Test ;
1012
1113public class BoxerTest {
1214
1315 Boxer boxer ;
1416
1517 @ BeforeEach
1618 void setUp () {
17- boxer = new Boxer ("Joseph" , 100 , 100 );
19+ boxer = new Boxer ("Joseph" , 99 , 99 );
1820 }
1921
2022 @ Test
21- void testWorkout () {
23+ void testWorkout_addingTenPointsOfPower () {
2224 boxer .workout (10 );
23- assertEquals (110 , boxer .getPower ());
25+ assertEquals (109 , boxer .getPower ());
2426 }
2527
2628 @ Test
27- void testRest () {
29+ void testRest_restingToIncreaseHealth () {
2830 int previousHealth = boxer .getHealth ();
2931 boxer .rest ();
3032 assertNotEquals (boxer .getHealth (), previousHealth );
3133 }
32-
3334 @ Test
34- void testGetHealth () {
35- assertEquals (100 , boxer .getHealth ());
36- }
37-
38- @ Test
39- void testGetFightHistory () throws BoxerHasNoFightsException , BoxerIsRetiredException {
35+ void testGetFightHistory_makingAFighterToHaveABout () throws BoxerHasNoFightsException , BoxerIsRetiredException {
4036 Boxer mike = new Boxer ("mike" , 1000 , 1000 );
4137 boxer .bout (mike );
4238 assertEquals ("You fought " + mike .getName () + " L" , boxer .getFights ());
@@ -54,20 +50,102 @@ void testIsAbleToFight_boxerIsNotAbleToFight() throws BoxerIsRetiredException {
5450 }
5551
5652 @ Test
57- void testBout_makingNewBoxerToFightAnother () throws BoxerIsRetiredException {
53+ void testBout_makingNewBoxerToFightAnotherAndSeeTheResults () throws BoxerIsRetiredException {
5854 Boxer mike = new Boxer ("Mike" , 1000 , 1000 );
5955 boxer .bout (mike );
6056 assertEquals (false , boxer .getAbleToFight ());
6157 }
6258
6359 @ Test
64- void testGetFightHistory_noFights () {
65- assertEquals (boxer .getHealth (), 100 );
60+ void testBout_makingNewBoxerToFightAndDraw () throws BoxerIsRetiredException , BoxerHasNoFightsException {
61+ Boxer ryan = new Boxer ("Ryan Garcia" , 99 , 99 );
62+ boxer .bout (ryan );
63+ assertEquals (boxer .getFights (), "You fought Ryan Garcia D" );
64+ }
65+
66+ @ Test
67+ void testBout_makingNewBoxerToWinAgainstWithBoxer () throws BoxerIsRetiredException , BoxerHasNoFightsException {
68+ Boxer hitman = new Boxer ("Thomas Hearns" , 98 , 98 );
69+ boxer .bout (hitman );
70+ assertEquals (boxer .getFights (), "You fought " + hitman .getName () + " W" );
71+ }
72+
73+ @ Test
74+ void testGetHealth () {
75+ assertEquals (boxer .getHealth (), 99 );
6676 }
6777
6878 @ Test
69- void testRollSkillSet () {
79+ void testRollSkillSet_testingBasicIsNotWhatIsRolled () {
7080 boxer .rollSkillSet ();
71- assertNotEquals (boxer .getStyle (), "BASIC" );
81+ assertNotEquals (boxer .getSkillSet (), "BASIC" );
82+ }
83+
84+ @ Test
85+ void testAddFights () throws BoxerIsRetiredException , BoxerHasNoFightsException {
86+ boxer .addFights ("Marvin Hagler" , 'L' );
87+ assertEquals (boxer .getFights (), "You fought Marvin Hagler L" );
88+ }
89+
90+ @ Test
91+ void testAddFights_whenRetired () throws BoxerIsRetiredException {
92+ boxer .retire ();
93+ assertThatThrownBy (
94+ () -> {
95+ boxer .addFights ("lomachenko" , 'W' );
96+ })
97+ .isInstanceOf (BoxerIsRetiredException .class )
98+ .hasMessage ("Boxer is retired" );
99+ }
100+
101+ @ Test
102+ void testRetire_whenRetired () throws BoxerIsRetiredException {
103+ boxer .retire ();
104+ assertThatThrownBy (
105+ () -> {
106+ boxer .retire ();
107+ })
108+ .isInstanceOf (BoxerIsRetiredException .class )
109+ .hasMessage ("Boxer is already retired" );
110+ }
111+
112+ @ Test
113+ void testSetName () {
114+ boxer .setName ("Pablo" );
115+ assertEquals (boxer .getName (), "Pablo" );
116+ }
117+
118+ @ Test
119+ void testSetAbleToFight () {
120+ boxer .setAbleToFight (false );
121+ assertFalse (boxer .getAbleToFight ());
122+ }
123+
124+ @ Test
125+ void testSetHealth () {
126+ boxer .setHealth (2 );
127+ assertEquals (boxer .getHealth (), 2 );
128+ }
129+
130+ @ Test
131+ void testBoxerIsRetiredException_retiringBoxerThenThrowingException () throws BoxerIsRetiredException {
132+ Boxer leaonard = new Boxer ("Sugar ray" , 200 , 200 );
133+ boxer .retire ();
134+ assertThatThrownBy (
135+ () -> {
136+ boxer .bout (leaonard );
137+ })
138+ .isInstanceOf (BoxerIsRetiredException .class )
139+ .hasMessageContaining ("Boxer is retired" );
140+ }
141+
142+ @ Test
143+ void testBoxerHasNoFightsException_gettingFightsWhenNoFightsHaveBeenHad () {
144+ assertThatThrownBy (
145+ () -> {
146+ boxer .getFights ();
147+ })
148+ .isInstanceOf (BoxerHasNoFightsException .class )
149+ .hasMessageContaining ("Boxer hasnt fought anyone" );
72150 }
73151}
0 commit comments