Skip to content

Commit 57e371b

Browse files
committed
fix: test that I was not using
1 parent ac08b37 commit 57e371b

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
public class BatteryPercentageCustomException extends Exception{
2-
public BatteryPercentageCustomException (String message){
3-
super (message);
4-
}
1+
public class BatteryPercentageCustomException extends Exception {
2+
public BatteryPercentageCustomException(String message) {
3+
super(message);
54
}
5+
}

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/SmartPhone/SmartPhone.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public class SmartPhone {
99
private int batteryPercentage;
1010
private boolean power;
1111
private ArrayList<String> apps;
12+
private int volume;
1213

1314
public SmartPhone(
1415
Name brandName, String model, int batteryPercentage, boolean power, ArrayList<String> apps) {
1516
this.brandName = brandName;
1617
this.batteryPercentage = batteryPercentage;
1718
this.power = power;
1819
this.apps = apps;
20+
this.volume = volume;
1921
}
2022

2123
public void setSmartPhonePowerbattery(int currentBatteryPercentage) {
@@ -29,13 +31,6 @@ public int getBatteryPercentage() {
2931
return batteryPercentage;
3032
}
3133

32-
public void setSmartPhoneBatteryPercentage(int currentBatteryPercentage) {
33-
if (currentBatteryPercentage < 0 || currentBatteryPercentage > 100) {
34-
throw new IllegalArgumentException("Battery percentage must be in between 0 and 100.");
35-
}
36-
this.batteryPercentage = currentBatteryPercentage;
37-
}
38-
3934
public String getSmartPhoneApps() {
4035
var smartPhoneApps = "";
4136
for (String s : apps) {
@@ -55,4 +50,12 @@ public int getSmartPhoneVolume() {
5550
public boolean isPowerOn() {
5651
return true;
5752
}
53+
54+
public void addSmartPhoneApps(String instagram) {
55+
apps.add("," + instagram);
56+
}
57+
58+
public void addSmartPhoneVolume() {
59+
volume++;
60+
}
5861
}

lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/SmartPhoneTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void BeforeTest() {
2020
"Iphone14",
2121
50,
2222
true,
23-
new ArrayList<>(Arrays.asList("Phone,Contacts,Photos,Settings,Calender")));
23+
new ArrayList<>(
24+
Arrays.asList("Phone,", "Contacts,", "Photos,", "Settings,", "Calender")));
2425
// Turn phone on
2526
}
2627

@@ -29,9 +30,10 @@ void testSmartPhoneCharge() {
2930
// Arrange
3031

3132
// Act
32-
smartPhone.chargeSmartPhone(); // Method with a loop to increase the battery percentage
33+
smartPhone.setSmartPhonePowerbattery(
34+
55); // Method with a loop to increase the battery percentage
3335
// Assert
34-
assertEquals(smartPhone.getBatteryPercentage(), 50);
36+
assertEquals(smartPhone.getBatteryPercentage(), 55);
3537
}
3638

3739
@Test
@@ -41,15 +43,16 @@ void testSmartPhoneApps() {
4143
// Act
4244
smartPhone.addSmartPhoneApps("Instagram"); // Method Add an app to my phone
4345
// Assert
44-
assertEquals(smartPhone.getSmartPhoneApps(), "Phone,Contacts,Photos,Settings,Calender");
46+
assertEquals(
47+
smartPhone.getSmartPhoneApps(), "Phone,Contacts,Photos,Settings,Calender,Instagram");
4548
}
4649

4750
@Test
4851
void testSmartPhoneRemoveApps() {
4952
// Arrange
5053
smartPhone.addSmartPhoneApps("Instagram");
5154
// Act
52-
smartPhone.removeSmartPhoneApps("Instagram"); // Method that removes the app from my phone
55+
smartPhone.removeSmartPhoneApps(",Instagram"); // Method that removes the app from my phone
5356
// Assert
5457
assertEquals(
5558
smartPhone.getSmartPhoneApps(),
@@ -69,10 +72,6 @@ void testSmartPhoneVolume() {
6972
assertNotEquals(smartPhone.getSmartPhoneVolume(), smartPhoneOldVolume);
7073
}
7174

72-
private void getSmartPhonePercentage() {
73-
throw new UnsupportedOperationException("Not supported yet.");
74-
}
75-
7675
@Test
7776
void testSmartPhonePowerStatus() {
7877
// Act

0 commit comments

Comments
 (0)