Skip to content

Commit a4d4ee1

Browse files
committed
Feat: Syntax/incorrect class declaration fix
1 parent d589fa1 commit a4d4ee1

File tree

1 file changed

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

1 file changed

+5
-77
lines changed

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

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,36 @@
11
import static org.assertj.core.api.Assertions.assertThat;
22
import static org.assertj.core.api.Assertions.assertThatThrownBy;
33

4-
import java.util.ArrayList;
5-
import java.util.List;
64
import org.junit.jupiter.api.Test;
75

86
public class DogTest {
97

10-
// Test the Dog class
11-
public class Dog {
12-
// Custom exception
13-
public static class DogAgeException extends Exception {
14-
public DogAgeException(String message) {
15-
super(message);
16-
}
17-
}
18-
19-
// Enum for dog colors
20-
public enum Colors {
21-
WHITE,
22-
BROWN,
23-
BLONDE
24-
}
25-
26-
// Member variables
27-
private int age;
28-
private String breed;
29-
private String gender;
30-
private Colors color;
31-
private boolean isFed;
32-
private List<String> favoriteToys;
33-
34-
// Constructor
35-
public Dog(int age, String breed, String gender, Colors color, boolean isFed)
36-
throws DogAgeException {
37-
if (age < 0) {
38-
throw new DogAgeException("Age cannot be negative.");
39-
}
40-
this.age = age;
41-
this.breed = breed;
42-
this.gender = gender;
43-
this.color = color;
44-
this.isFed = isFed;
45-
this.favoriteToys = new ArrayList<>();
46-
}
47-
48-
// Getters
49-
public int getAge() {
50-
return age;
51-
}
52-
53-
public String getBreed() {
54-
return breed;
55-
}
56-
57-
public String getGender() {
58-
return gender;
59-
}
60-
61-
public Colors getColor() {
62-
return color;
63-
}
64-
65-
public boolean isFed() {
66-
return isFed;
67-
}
68-
69-
public String getFavoriteToys() {
70-
String favoriteToy = "Squeaky Fish";
71-
return favoriteToy;
72-
}
73-
74-
public String addFavoriteToy(String favoriteToy2) {
75-
String favoriteToy = "Squeaky Fish";
76-
return favoriteToy;
77-
}
78-
}
79-
808
@Test
81-
public void testGetAge() throws DogTest.Dog.DogAgeException {
9+
public void testGetAge() throws Dog.DogAgeException {
8210
Dog dog = new Dog(2, "Mutt", "male", Dog.Colors.BROWN, true);
8311
assertThat(dog.getAge()).isEqualTo(2);
8412
}
8513

8614
@Test
87-
public void testGetBreed() throws DogTest.Dog.DogAgeException {
15+
public void testGetBreed() throws Dog.DogAgeException {
8816
Dog dog = new Dog(2, "Mutt", "male", Dog.Colors.BROWN, true);
8917
assertThat(dog.getBreed()).isEqualTo("Mutt");
9018
}
9119

9220
@Test
93-
public void testGetGender() throws DogTest.Dog.DogAgeException {
21+
public void testGetGender() throws Dog.DogAgeException {
9422
Dog dog = new Dog(2, "Mutt", "male", Dog.Colors.BROWN, true);
9523
assertThat(dog.getGender()).isEqualTo("male");
9624
}
9725

9826
@Test
99-
void DogTesttestGetColor() throws DogTest.Dog.DogAgeException {
27+
public void testGetColor() throws Dog.DogAgeException {
10028
Dog dog = new Dog(2, "Mutt", "male", Dog.Colors.BROWN, true);
10129
assertThat(dog.getColor()).isEqualTo(Dog.Colors.BROWN);
10230
}
10331

10432
@Test
105-
public void testIsFed() throws DogTest.Dog.DogAgeException {
33+
public void testIsFed() throws Dog.DogAgeException {
10634
Dog dog = new Dog(2, "Mutt", "male", Dog.Colors.BROWN, true);
10735
assertThat(dog.isFed()).isTrue();
10836
}

0 commit comments

Comments
 (0)