Skip to content

Commit 310ef07

Browse files
committed
feat: modified tests more in BoxerTest.java and modified code in Boxer.java. lesson_16 -JosephCaballero
1 parent fd647ea commit 310ef07

File tree

2 files changed

+96
-51
lines changed
  • lesson_16/objects/objects_app/src

2 files changed

+96
-51
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/boxer/Boxer.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ public int getPower() {
6161
return power;
6262
}
6363

64-
public HashMap<String, Character> getFightHistory() {
65-
return fights;
66-
}
67-
6864
public int getHealth() {
6965
return health;
7066
}
@@ -133,15 +129,6 @@ public void bout(Boxer boxer) throws BoxerIsRetiredException {
133129
public void setName(String name) {
134130
this.name = name;
135131
}
136-
137-
public void setFights(HashMap<String, Character> fights) {
138-
this.fights = fights;
139-
}
140-
141-
public void setPower(int power) {
142-
this.power = power;
143-
}
144-
145132
public void setHealth(int health) {
146133
this.health = health;
147134
}
@@ -150,27 +137,7 @@ public BoxerStyle getSkillSet() {
150137
return skillSet;
151138
}
152139

153-
public void setSkillSet(BoxerStyle skillSet) {
154-
this.skillSet = skillSet;
155-
}
156-
157140
public void setAbleToFight(boolean ableToFight) {
158141
this.ableToFight = ableToFight;
159142
}
160-
161-
public BoxerStyle[] getStyle() {
162-
return style;
163-
}
164-
165-
public void setStyle(BoxerStyle[] style) {
166-
this.style = style;
167-
}
168-
169-
public static Random getRand() {
170-
return rand;
171-
}
172-
173-
public static void setRand(Random rand) {
174-
Boxer.rand = rand;
175-
}
176143
}
Lines changed: 96 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
package com.codedifferently.lesson16.boxer;
22

3+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
34
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertFalse;
46
import static org.junit.jupiter.api.Assertions.assertNotEquals;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
59

610
import com.codedifferently.lesson16.boxer.Boxer.BoxerHasNoFightsException;
711
import com.codedifferently.lesson16.boxer.Boxer.BoxerIsRetiredException;
8-
import org.junit.jupiter.api.BeforeEach;
9-
import org.junit.jupiter.api.Test;
1012

1113
public 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

Comments
 (0)