Skip to content

Commit 347d1bd

Browse files
committed
Feat: fix
1 parent ff34f92 commit 347d1bd

File tree

1 file changed

+43
-5
lines changed
  • lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/Nile'sDogTest16

1 file changed

+43
-5
lines changed

lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/Nile'sDogTest16/DogTest.java

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import static org.assertj.core.api.Assertions.assertThat;
2+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
23

4+
import com.codedifferently.lesson16.Dog.Dog;
35
import org.junit.jupiter.api.Test;
46

57
public class DogTest {
6-
// public static void newDog(String[] args) {
8+
public abstract class EnumToArray {
9+
enum Colors {
10+
WHITE,
11+
BROWN,
12+
BLONDE;
13+
}
14+
}
715

816
public int getAge(int age) {
917
return age;
@@ -38,13 +46,13 @@ public String testGetGender() {
3846
return getbreed(getGender);
3947
}
4048

41-
public Enum getColors(Enum Colors) {
49+
public Colors getColors(Colors Colors) {
4250
return Colors;
4351
}
4452

4553
@Test
46-
private Enum testGetColors(Enum Colors) {
47-
Enum getColors = Colors;
54+
public Colors testGetColors(Colors Colors) {
55+
Colors testColor = Colors.BROWN;
4856
assertThat(getColors(Colors));
4957
return getColors(Colors);
5058
}
@@ -58,10 +66,40 @@ public void testgetColor() {
5866
Boolean isFed(Boolean Fed) {
5967
var isNotFed = false;
6068
var isFed = true;
61-
var getFedStatus = Fed | isNotFed;
69+
var getFedStatus = Fed || isNotFed;
6270
assertThat(getFedStatus).isTrue();
6371
assertThat(Fed).isFalse();
6472
assertThat(getFedStatus).isEqualTo(isFed);
6573
return getFedStatus == Fed;
6674
}
75+
76+
@Test
77+
public void testDogConstructorThrowsExceptionForNegativeAge() {
78+
// Arrange
79+
Colors colorList = Colors.getBROWN();
80+
int negativeAge = -1;
81+
String breed = "Mutt";
82+
String gender = "male";
83+
boolean isFed = true;
84+
Enum Color1 = null;
85+
86+
// Act & Assert
87+
assertThatThrownBy(() -> new Dog(negativeAge, breed, gender, Color1, isFed))
88+
.isInstanceOf(DogAgeException.class)
89+
.hasMessage("Age cannot be negative.");
90+
}
91+
92+
@Test
93+
public String testaddFavoriteToy(String toy) {
94+
95+
Enum Color1 = null;
96+
97+
Dog dog = new Dog(2, "Mutt", "male", Color1, true);
98+
99+
String favoriteToy = "Squeaky Fish";
100+
101+
assertThat(favoriteToy).isEqualTo("Squeaky Fish");
102+
103+
return toy;
104+
}
67105
}

0 commit comments

Comments
 (0)