Skip to content

Commit bdade0c

Browse files
committed
Fix-up : changing the HorseStable lowercase and fixing test
1 parent 582be86 commit bdade0c

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/HorseStable/HorseStable.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.codedifferently.lesson16.HorseStable;
1+
package com.codedifferently.lesson16.horseStable;
22

33
import java.util.ArrayList;
44
import java.util.List;
@@ -64,11 +64,17 @@ public void addHorse(String horseName) throws StableFullException {
6464
horses.add(horseName);
6565
}
6666

67-
public void displayHorses() {
67+
public void removeHorse(String horseName) {
68+
if (!horses.contains(horseName)) {
69+
throw new IllegalArgumentException("Horse not found in the stable.");
70+
}
71+
horses.remove(horseName);
72+
}
73+
74+
public String displayHorses() {
6875
if (horses.isEmpty()) {
69-
System.out.println("No horses in the stable.");
70-
return;
76+
return "No horses in the stable.";
7177
}
72-
System.out.println("There are " + horses.size() + " horses in " + name + ".");
78+
return "There are " + horses.size() + " horses in " + name + ".";
7379
}
7480
}

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/HorseStable/StableFullException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.codedifferently.lesson16.HorseStable;
1+
package com.codedifferently.lesson16.horseStable;
22

33
public class StableFullException extends Exception {
44
public StableFullException(String message) {

lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/HorseStableTest/HorseStableTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5-
import com.codedifferently.lesson16.HorseStable.HorseStable;
6-
import com.codedifferently.lesson16.HorseStable.StableFullException;
5+
import com.codedifferently.lesson16.horseStable.HorseStable;
6+
import com.codedifferently.lesson16.horseStable.StableFullException;
77
import org.junit.jupiter.api.BeforeEach;
88
import org.junit.jupiter.api.Test;
99

@@ -32,15 +32,20 @@ public void testAddHorse_Success() throws StableFullException {
3232
}
3333

3434
@Test
35-
public void testDisplayHorses_NoHorses() {
36-
stable.displayHorses();
35+
public void testDisplayHorses_NoHorses() throws StableFullException {
36+
stable.addHorse("Spirit");
37+
stable.addHorse("Shadow");
38+
stable.removeHorse("Spirit");
39+
stable.removeHorse("Shadow");
40+
41+
assertEquals(0, stable.getHorses().size());
3742
}
3843

3944
@Test
4045
public void testDisplayHorses_WithHorses() throws StableFullException {
4146
stable.addHorse("Spirit");
4247
stable.addHorse("Shadow");
43-
stable.displayHorses();
48+
assertEquals("There are 2 horses in Sunny Acres.", stable.displayHorses());
4449
}
4550

4651
@Test

0 commit comments

Comments
 (0)