1+ package com .codedifferently .lesson16 .cutecat ;
2+
3+ import org .junit .jupiter .api .Test ;
4+ import static org .junit .jupiter .api .Assertions .*;
5+ import java .util .ArrayList ;
6+
7+ public class CatTest {
8+
9+ @ Test
10+ public void testCreateNinjaCat () throws InvalidCatNameException {
11+ Cat cat = new Cat ("Ninja" , 13 , 9.3 , Breed .MAINCOON , true , false );
12+ assertEquals ("Ninja" , cat .getName ());
13+ assertEquals (13 , cat .getAge ());
14+ assertEquals (9.3 , cat .getWeight ());
15+ assertTrue (cat .getIsIndoor ());
16+ assertEquals (Breed .MAINCOON , cat .getBreed ());
17+ }
18+
19+ @ Test
20+ public void testfavoriteFoodsDefault () throws InvalidCatNameException {
21+ Cat cat = new Cat ("Ninja" , 13 , 9.3 , Breed .MAINCOON , true , false );
22+ ArrayList <String > foods = cat .getfavoriteFoods ();
23+ assertTrue (foods .contains ("Fancy Feast" ));
24+ assertTrue (foods .contains ("Purina Naturals" ));
25+ assertEquals (2 , foods .size ());
26+ }
27+
28+ @ Test
29+ public void testPrintFavoriteFoodsCoverage () throws InvalidCatNameException {
30+ Cat cat = new Cat ("Ninja" , 13 , 9.3 , Breed .MAINCOON , true , false );
31+ cat .printfavoriteFoods ();
32+ }
33+
34+ @ Test
35+ public void testAddFavoriteFood () throws InvalidCatNameException {
36+ Cat cat = new Cat ("Ninja" , 13 ,9.3 , Breed .MAINCOON , true , false );
37+ cat .addfavoriteFood ("Tuna" );
38+ ArrayList <String > foods = cat .getfavoriteFoods ();
39+ assertTrue (foods .contains ("Tuna" ));
40+ assertEquals (3 , foods .size ());
41+ }
42+
43+ @ Test
44+ public void testIsSenior () throws InvalidCatNameException {
45+ Cat cat = new Cat ("Ninja" , 13 , 9.3 , Breed .MAINCOON , true , false );
46+ assertTrue (cat .isSenior ());
47+ }
48+
49+ @ Test
50+ public void testCatName () throws InvalidCatNameException {
51+ Cat cat = new Cat ("Whiskers" ,5 , 5.4 , Breed .SPHYNX , false , true );
52+ assertEquals ("Whiskers" , cat .getName ());
53+ }
54+
55+ @ Test
56+ public void testCatMeow () throws InvalidCatNameException {
57+ Cat cat = new Cat ("Mittens" , 2 , 8.9 , Breed .SIAMESE , true , true );
58+ assertEquals ("Meow!" , cat .meow ());
59+ }
60+
61+ @ Test
62+ public void testGetName () throws InvalidCatNameException {
63+ Cat cat = new Cat ("Shadow" , 2 , 7.4 , Breed .BENGAL , true , true );
64+ assertEquals ("Shadow" , cat .getName ());
65+ }
66+
67+ @ Test
68+ public void testGetAge () throws InvalidCatNameException {
69+ Cat cat = new Cat ("Nine" , 2 , 13.2 , Breed .MAINCOON , true , false );
70+ assertEquals (2 , cat .getAge ());
71+ }
72+
73+ @ Test
74+ public void testMeow ()throws InvalidCatNameException {
75+ Cat cat = new Cat ("Frisky" , 2 , 5.4 , Breed .UNKNOWN , true , true );
76+ assertEquals ("Meow!" , cat .meow ());
77+ }
78+
79+ @ Test
80+ public void testWalk () throws InvalidCatNameException {
81+ Cat cat = new Cat ("Shadow" , 2 , 7.4 , Breed .BENGAL , true , false );
82+ assertEquals ("Shadow is walking." , cat .walk ());
83+ }
84+
85+ @ Test
86+ public void testSleep () throws InvalidCatNameException {
87+ Cat cat = new Cat ("Shadow" , 2 , 7.4 , Breed .BENGAL , true , false );
88+ assertEquals ("Shadow is sleeping." , cat .sleep ());
89+ }
90+
91+ @ Test
92+ public void testisKittenTrue () throws InvalidCatNameException {
93+ Cat cat = new Cat ("Tiny" , 0 , 2.5 , Breed .PERSIAN , true , true );
94+ assertTrue (cat .isKitten ());
95+ }
96+
97+ @ Test
98+ public void testIsKittenFalse () throws InvalidCatNameException {
99+ Cat cat = new Cat ("Trinity" , 3 , 5.6 , Breed .UNKNOWN , true , true );
100+ assertFalse (cat .isKitten ());
101+ }
102+
103+ }
0 commit comments