1
1
import static org .assertj .core .api .Assertions .assertThat ;
2
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
2
3
4
+ import com .codedifferently .lesson16 .Dog .Dog ;
3
5
import org .junit .jupiter .api .Test ;
4
6
5
7
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
+ }
7
15
8
16
public int getAge (int age ) {
9
17
return age ;
@@ -38,13 +46,13 @@ public String testGetGender() {
38
46
return getbreed (getGender );
39
47
}
40
48
41
- public Enum getColors (Enum Colors ) {
49
+ public Colors getColors (Colors Colors ) {
42
50
return Colors ;
43
51
}
44
52
45
53
@ Test
46
- private Enum testGetColors (Enum Colors ) {
47
- Enum getColors = Colors ;
54
+ public Colors testGetColors (Colors Colors ) {
55
+ Colors testColor = Colors . BROWN ;
48
56
assertThat (getColors (Colors ));
49
57
return getColors (Colors );
50
58
}
@@ -58,10 +66,40 @@ public void testgetColor() {
58
66
Boolean isFed (Boolean Fed ) {
59
67
var isNotFed = false ;
60
68
var isFed = true ;
61
- var getFedStatus = Fed | isNotFed ;
69
+ var getFedStatus = Fed || isNotFed ;
62
70
assertThat (getFedStatus ).isTrue ();
63
71
assertThat (Fed ).isFalse ();
64
72
assertThat (getFedStatus ).isEqualTo (isFed );
65
73
return getFedStatus == Fed ;
66
74
}
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
+ }
67
105
}
0 commit comments