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