Skip to content

Commit 38c5323

Browse files
committed
chore: down to one failing test
1 parent c40303a commit 38c5323

File tree

2 files changed

+32
-27
lines changed
  • lesson_16/objects/objects_app/src

2 files changed

+32
-27
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,27 @@ public class HeadPhones {
99
private HeadPhoneColor headPhoneColor = HeadPhoneColor.BLACK;
1010
private boolean isWireless = true;
1111
private String brands = "Beats";
12+
boolean isPreferredBrand = BrandUtils.isPreferredBrand(brands);
1213
private boolean isConnectedToBluetooth = false;
1314
private BoostMode currentMode;
1415
private BoostMode[] modes = BoostMode.values();
1516
private int currentModeIndex = 0;
1617

18+
public void HeadPhones() {
19+
this.currentMode = BoostMode.BASS_BOOST;
20+
System.out.println("Constructor called: currentMode set to " + currentMode);
21+
}
22+
23+
public void nextBoostMode() {
24+
currentModeIndex = (currentModeIndex + 1) % modes.length;
25+
currentMode = modes[currentModeIndex];
26+
}
27+
28+
public BoostMode getCurrentMode() {
29+
System.out.println("getCurrentMode called: currentMode is " + currentMode);
30+
return currentMode;
31+
}
32+
1733
public enum HeadPhoneColor {
1834
RED,
1935
BLUE,
@@ -38,11 +54,7 @@ public enum BoostMode {
3854
TREBLE_BOOST;
3955
}
4056

41-
public void headPhones() {
42-
this.currentMode = BoostMode.BASS_BOOST;
43-
}
44-
45-
public int getVolume(int i) {
57+
public int getVolume() {
4658
return volume;
4759
}
4860

@@ -118,13 +130,4 @@ public void wirelessConnection() throws ConnectionNotFoundException {
118130
throw new ConnectionNotFoundException("Headphones Wireless Connection Not Found.");
119131
}
120132
}
121-
122-
public void nextBoostMode() {
123-
currentModeIndex = (currentModeIndex + 1) % modes.length;
124-
currentMode = modes[currentModeIndex];
125-
}
126-
127-
public BoostMode getCurrentMode() {
128-
return currentMode;
129-
}
130133
}

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.assertj.core.api.Assertions.assertThatThrownBy;
44
import static org.junit.jupiter.api.Assertions.*;
55

6-
import com.codedifferently.lesson16.KimberleeObject.BrandsArray;
76
import com.codedifferently.lesson16.KimberleeObject.ConnectionNotFoundException;
87
import com.codedifferently.lesson16.KimberleeObject.HeadPhones;
98
import com.codedifferently.lesson16.KimberleeObject.HeadPhones.BoostMode;
@@ -22,7 +21,7 @@ public void setUp() {
2221

2322
@Test
2423
public void testDefaultState() {
25-
assertEquals(0, headphones.getVolume(0), "Volume should be 0 by default.");
24+
assertEquals(0, headphones.getVolume(), "Volume should be 0 by default.");
2625
assertEquals(
2726
HeadPhoneColor.BLACK, headphones.getHeadPhoneColor(), "Color should be black by default.");
2827
assertFalse(headphones.isPoweredOn(), "HeadPhones should be off by default.");
@@ -57,12 +56,12 @@ public void testIncreaseVolume() {
5756
// Arrange
5857
headphones.turnOn();
5958
headphones.increaseVolume();
60-
assertEquals(1, headphones.getVolume(0), "Volume should increase by 1");
59+
assertEquals(1, headphones.getVolume(), "Volume should increase by 1");
6160
// Act
6261
headphones.setVolume(99);
6362
headphones.increaseVolume();
6463
// Assert
65-
assertEquals(100, headphones.getVolume(0), "Volume should not exceed 100.");
64+
assertEquals(100, headphones.getVolume(), "Volume should not exceed 100.");
6665
}
6766

6867
@Test
@@ -71,11 +70,11 @@ public void testDecreaseVolume() {
7170
headphones.turnOn();
7271
headphones.setVolume(1);
7372
headphones.decreaseVolume();
74-
assertEquals(0, headphones.getVolume(0), "Volume should decrease to 0.");
73+
assertEquals(0, headphones.getVolume(), "Volume should decrease to 0.");
7574
// Act
7675
headphones.decreaseVolume();
7776
// Assert
78-
assertEquals(0, headphones.getVolume(0), "Volume should not go lower than 0.");
77+
assertEquals(0, headphones.getVolume(), "Volume should not go lower than 0.");
7978
}
8079

8180
@Test
@@ -92,19 +91,22 @@ public void testSetColor() {
9291
@Test
9392
public void testPreferredBrand() {
9493
// Assert
95-
assertTrue(BrandsArray.isPreferredBrand("Beats"), "Beats should be a preferred brand.");
96-
assertTrue(BrandsArray.isPreferredBrand("Sony"), "Sony should be a preferred brand.");
97-
assertFalse(BrandsArray.isPreferredBrand("Apple"), "Apple should not be a preferred brand.");
9894
assertTrue(
99-
BrandsArray.isPreferredBrand("SkullCandy"), "SkullCandy should be a preferred brand.");
100-
assertTrue(BrandsArray.isPreferredBrand("Juicy"), "Juicy should be a preferred brand.");
95+
HeadPhones.BrandUtils.isPreferredBrand("Beats"), "Beats should be a preferred brand.");
96+
assertTrue(HeadPhones.BrandUtils.isPreferredBrand("Sony"), "Sony should be a preferred brand.");
97+
assertFalse(
98+
HeadPhones.BrandUtils.isPreferredBrand("Apple"), "Apple should not be a preferred brand.");
99+
assertTrue(
100+
HeadPhones.BrandUtils.isPreferredBrand("SkullCandy"),
101+
"SkullCandy should be a preferred brand.");
102+
assertTrue(
103+
HeadPhones.BrandUtils.isPreferredBrand("Juicy"), "Juicy should be a preferred brand.");
101104
}
102105

103106
@Test
104107
public void testwirelessConnection() throws Exception {
105108
// Arrange
106-
headphones.isPoweredOn();
107-
headphones.isWireless();
109+
headphones.turnOn();
108110
// Act
109111
headphones.connectToBluetooth();
110112
// Assert

0 commit comments

Comments
 (0)