File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
main/java/com/serenitydojo
test/java/com/serenitydojo Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .serenitydojo ;
2
2
3
+ /**
4
+ * A feline creature.
5
+ */
3
6
public class Cat {
7
+ /**
8
+ * The name of the cat
9
+ * This is important
10
+ */
4
11
private String name ;
5
12
private String favoriteFood ;
6
13
private int age ;
7
14
15
+ // A very useful field
16
+ public static final String CAT_NOISE = "Meow" ;
17
+
18
+ public static String usualFood () {
19
+ return "Tuna" ;
20
+ }
21
+
22
+ public Cat (String name , int age ) {
23
+ this .name = name ;
24
+ this .age = age ;
25
+ this .favoriteFood = usualFood ();
26
+ }
27
+
8
28
public Cat (String name , String favoriteFood , int age ) {
9
29
this .name = name ;
10
30
this .favoriteFood = favoriteFood ;
@@ -26,4 +46,25 @@ public String getFavoriteFood() {
26
46
public int getAge () {
27
47
return age ;
28
48
}
49
+
50
+ public void makeNoise () {
51
+ System .out .println (CAT_NOISE );
52
+ }
53
+
54
+ public void feed (String food ) {
55
+ System .out .println (name + " eats some " + food );
56
+ }
57
+
58
+ public void groom () {
59
+ lickPaws ();
60
+ cleanFur ();
61
+ }
62
+
63
+ private void cleanFur () {
64
+ System .out .println (name + " cleans his fur" );
65
+ }
66
+
67
+ private void lickPaws () {
68
+ System .out .println (name + " licks his paws" );
69
+ }
29
70
}
Original file line number Diff line number Diff line change 2
2
3
3
import org .junit .Assert ;
4
4
import org .junit .Test ;
5
+ import static com .serenitydojo .Cat .usualFood ;
5
6
6
7
public class WhenCreatingObjects {
7
8
@@ -24,4 +25,12 @@ public void creating_a_dog() {
24
25
// Assert.assertEquals(fido.getAge(), 5);
25
26
26
27
}
28
+
29
+ @ Test
30
+ public void cat_makes_noise () {
31
+ Cat felix = new Cat ("Felix" , 4 );
32
+ Cat spot = new Cat ("Spot" ,"Salmon" , 3 );
33
+
34
+ System .out .println ("Cats like " + usualFood ());
35
+ }
27
36
}
You can’t perform that action at this time.
0 commit comments