Skip to content

Commit 959dcce

Browse files
committed
chore: edit test/ all passed except testwireless
connection tests
1 parent d1e4e5c commit 959dcce

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.codedifferently.lesson16.KimberleeObject;
22

33
public class ConnectionNotFoundException extends Exception {
4-
public ConnectionNotFoundException(String message) {
5-
super(message);
6-
}
7-
}
4+
public ConnectionNotFoundException(String message) {
5+
super(message);
6+
}
7+
}

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,28 @@ public void setColor(HeadPhoneColor color) {
8282
}
8383

8484
public class BrandUtils {
85-
private static final String[] PREFERRED_BRANDS = {"Beats", "Sony", "Bose", "SkullCandy", "Juicy"};
85+
private static final String[] PREFERRED_BRANDS = {
86+
"Beats", "Sony", "Bose", "SkullCandy", "Juicy"
87+
};
8688

87-
public static boolean isPreferredBrand(String brand) {
88-
return Arrays.asList(PREFERRED_BRANDS).contains(brand);
89+
public static boolean isPreferredBrand(String brand) {
90+
return Arrays.asList(PREFERRED_BRANDS).contains(brand);
91+
}
8992
}
90-
}
9193

9294
public void connectToBluetooth() {
9395
if (isPoweredOn && isWireless) {
94-
isConnectedToBluetooth = true;
96+
isConnectedToBluetooth = true;
9597
}
96-
}
98+
}
9799

98100
public boolean isConnectedToBluetooth() {
99-
return isConnectedToBluetooth;
100-
}
101+
return isConnectedToBluetooth;
102+
}
101103

102-
public void wirelessConnection() throws ConnectionNotFoundException {
104+
public void wirelessConnection() throws ConnectionNotFoundException {
103105
if (!isConnectedToBluetooth) {
104-
throw new ConnectionNotFoundException("Headphones Wireless Connection Not Found.");
106+
throw new ConnectionNotFoundException("Headphones Wireless Connection Not Found.");
105107
}
106-
107-
}
108+
}
108109
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
public class WirelessConnection {
44

5-
public WirelessConnection get(boolean isConnectedToBluetooth) {
6-
// TODO Auto-generated method stub
7-
throw new UnsupportedOperationException("Unimplemented method 'get'");
8-
}
9-
5+
public WirelessConnection get(boolean isConnectedToBluetooth) {
6+
// TODO Auto-generated method stub
7+
throw new UnsupportedOperationException("Unimplemented method 'get'");
8+
}
109
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.codedifferently.lesson16.KimberleeObjectTest;
22

3-
import java.util.function.BooleanSupplier;
3+
import java.util.Arrays;
4+
import java.util.List;
45

56
public class BrandsArray {
67

7-
public static BooleanSupplier isPreferredBrand(String string) {
8-
// TODO Auto-generated method stub
9-
throw new UnsupportedOperationException("Unimplemented method 'isPreferredBrand'");
8+
// Preferred brands stored in a List
9+
private static final List<String> PREFERRED_BRANDS =
10+
Arrays.asList("Beats", "Sony", "Bose", "SkullCandy", "Juicy");
11+
12+
// Method to check if a brand is preferred
13+
public static Boolean isPreferredBrand(String brand) {
14+
return PREFERRED_BRANDS.contains(brand);
1015
}
1116
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
package com.codedifferently.lesson16.KimberleeObjectTest;
22

3-
public class ConnectionNotFoundException {
4-
5-
}
3+
public class ConnectionNotFoundException {}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.codedifferently.lesson16.KimberleeObjectTest;
22

3+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
34
import static org.junit.jupiter.api.Assertions.*;
45

5-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
66
import com.codedifferently.lesson16.KimberleeObject.HeadPhones;
77
import com.codedifferently.lesson16.KimberleeObject.HeadPhones.HeadPhoneColor;
88
import org.junit.jupiter.api.BeforeEach;
@@ -96,20 +96,21 @@ public void testPreferredBrand() {
9696
@Test
9797
public void testwirelessConnection() throws Exception {
9898
// Arrange
99-
headphones.isPoweredOn();
99+
headphones.isPoweredOn();
100100
headphones.isWireless();
101101
// Act
102102
headphones.connectToBluetooth();
103103
// Assert
104-
assertTrue(headphones.isConnectedToBluetooth(), "Headphones should connect to bluetooh when wireless and turned on.");
104+
assertTrue(
105+
headphones.isConnectedToBluetooth(),
106+
"Headphones should connect to bluetooh when wireless and turned on.");
105107
}
106108

107109
@Test
108110
public void testwirelessConnection_connectionNotFound() throws Exception {
109111
// Act
110112
assertThatThrownBy(() -> headphones.wirelessConnection())
111-
.isInstanceOf(ConnectionNotFoundException.class)
112-
.hasMessage("Headphones Wireless Connection Not Found.");
113-
}
113+
.isInstanceOf(ConnectionNotFoundException.class)
114+
.hasMessage("Headphones Wireless Connection Not Found.");
115+
}
114116
}
115-

0 commit comments

Comments
 (0)