Skip to content

Commit 9ebe527

Browse files
committed
feat: added setcolor test/pass
1 parent 3f31a85 commit 9ebe527

File tree

2 files changed

+30
-13
lines changed
  • lesson_16/objects/objects_app/src

2 files changed

+30
-13
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/KimberleeObject/HeadPhones.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
public class HeadPhones {
44
private int volume = 0;
55
private boolean isPoweredOn = false;
6-
private String HeadPhoneColor = "BLACK";
6+
private HeadPhoneColor headPhoneColor = HeadPhoneColor.BLACK;
77
private boolean isWireless = true;
88
private String brands = "Beats";
99

10+
public enum HeadPhoneColor {
11+
RED,
12+
BLUE,
13+
ROSEGOLD,
14+
PINK,
15+
WHITE,
16+
BLACK;
17+
}
18+
1019
public int getVolume(int i) {
1120
return volume;
1221
}
1322

14-
public String getHeadPhoneColor() {
15-
return HeadPhoneColor;
23+
public HeadPhoneColor getHeadPhoneColor() {
24+
return headPhoneColor;
1625
}
1726

1827
public boolean isPoweredOn() {
@@ -52,4 +61,8 @@ public void decreaseVolume() {
5261
volume--;
5362
}
5463
}
64+
65+
public void setColor(HeadPhoneColor color) {
66+
this.headPhoneColor = color;
67+
}
5568
}

lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/KimberleeObjectTest/HeadPhonesTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
55

66
import com.codedifferently.lesson16.KimberleeObject.HeadPhones;
7+
import com.codedifferently.lesson16.KimberleeObject.HeadPhones.HeadPhoneColor;
78
import org.junit.jupiter.api.BeforeEach;
89
import org.junit.jupiter.api.Test;
910

@@ -16,15 +17,6 @@ public void setUp() {
1617
headphones = new HeadPhones();
1718
}
1819

19-
public enum HeadPhoneColor {
20-
RED,
21-
BLUE,
22-
ROSEGOLD,
23-
PINK,
24-
WHITE,
25-
BLACK;
26-
}
27-
2820
public void BrandsArray() {
2921
String[] brands = new String[5];
3022
brands[0] = "Beats";
@@ -37,7 +29,8 @@ public void BrandsArray() {
3729
@Test
3830
public void testDefaultState() {
3931
assertEquals(0, headphones.getVolume(0), "Volume should be 0 by default.");
40-
assertEquals("BLACK", headphones.getHeadPhoneColor(), "Color should be black by default.");
32+
assertEquals(
33+
HeadPhoneColor.BLACK, headphones.getHeadPhoneColor(), "Color should be black by default.");
4134
assertFalse(headphones.isPoweredOn(), "HeadPhones should be off by default.");
4235
assertTrue(headphones.isWireless(), "HeadPhones should be wireless by default.");
4336
assertArrayEquals(new String[] {"Beats"}, new String[] {"Beats"});
@@ -86,4 +79,15 @@ public void testDecreaseVolume() {
8679
// Assert
8780
assertEquals(0, headphones.getVolume(0), "Volume should not go lower than 0.");
8881
}
82+
83+
@Test
84+
public void testSetColor() {
85+
// Act
86+
headphones.setColor(HeadPhoneColor.ROSEGOLD);
87+
// Assert
88+
assertEquals(
89+
HeadPhoneColor.ROSEGOLD,
90+
headphones.getHeadPhoneColor(),
91+
"Headphone color should be set to Rose Gold.");
92+
}
8993
}

0 commit comments

Comments
 (0)