Skip to content

Commit 1987b07

Browse files
committed
feat: added function from a collection member variable
1 parent 9ebe527 commit 1987b07

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package com.codedifferently.lesson16.KimberleeObject;
22

3+
import java.util.Arrays;
4+
35
public class HeadPhones {
6+
@SuppressWarnings("unused")
7+
private static final Object PREFERRED_BRANDS = null;
8+
49
private int volume = 0;
510
private boolean isPoweredOn = false;
611
private HeadPhoneColor headPhoneColor = HeadPhoneColor.BLACK;
@@ -16,6 +21,15 @@ public enum HeadPhoneColor {
1621
BLACK;
1722
}
1823

24+
public void BrandsArray() {
25+
String[] brands = new String[5];
26+
brands[0] = "Beats";
27+
brands[1] = "Sony";
28+
brands[2] = "Bose";
29+
brands[3] = "SkullCandy";
30+
brands[4] = "Juicy";
31+
}
32+
1933
public int getVolume(int i) {
2034
return volume;
2135
}
@@ -65,4 +79,14 @@ public void decreaseVolume() {
6579
public void setColor(HeadPhoneColor color) {
6680
this.headPhoneColor = color;
6781
}
82+
83+
public class BrandUtils {
84+
private static final String[] PREFERRED_BRANDS = {
85+
"Beats", "Sony", "Bose", "SkullCandy", "Juicy"
86+
};
87+
88+
public static boolean isPreferredBrand(String brand) {
89+
return Arrays.asList(PREFERRED_BRANDS).contains(brand);
90+
}
91+
}
6892
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.codedifferently.lesson16.KimberleeObjectTest;
2+
3+
import java.util.function.BooleanSupplier;
4+
5+
public class BrandsArray {
6+
7+
public static BooleanSupplier isPreferredBrand(String string) {
8+
// TODO Auto-generated method stub
9+
throw new UnsupportedOperationException("Unimplemented method 'isPreferredBrand'");
10+
}
11+
}

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

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

33
import static org.junit.jupiter.api.Assertions.*;
4-
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
54

65
import com.codedifferently.lesson16.KimberleeObject.HeadPhones;
76
import com.codedifferently.lesson16.KimberleeObject.HeadPhones.HeadPhoneColor;
@@ -17,15 +16,6 @@ public void setUp() {
1716
headphones = new HeadPhones();
1817
}
1918

20-
public void BrandsArray() {
21-
String[] brands = new String[5];
22-
brands[0] = "Beats";
23-
brands[1] = "Sony";
24-
brands[2] = "Bose";
25-
brands[3] = "SkullCandy";
26-
brands[4] = "Juicy";
27-
}
28-
2919
@Test
3020
public void testDefaultState() {
3121
assertEquals(0, headphones.getVolume(0), "Volume should be 0 by default.");
@@ -90,4 +80,15 @@ public void testSetColor() {
9080
headphones.getHeadPhoneColor(),
9181
"Headphone color should be set to Rose Gold.");
9282
}
83+
84+
@Test
85+
public void testPreferredBrand() {
86+
// Assert
87+
assertTrue(BrandsArray.isPreferredBrand("Beats"), "Beats should be a preferred brand.");
88+
assertTrue(BrandsArray.isPreferredBrand("Sony"), "Sony should be a preferred brand.");
89+
assertFalse(BrandsArray.isPreferredBrand("Apple"), "Apple should not be a preferred brand.");
90+
assertTrue(
91+
BrandsArray.isPreferredBrand("SkullCandy"), "SkullCandy should be a preferred brand.");
92+
assertTrue(BrandsArray.isPreferredBrand("Juicy"), "Juicy should be a preferred brand.");
93+
}
9394
}

0 commit comments

Comments
 (0)