Skip to content

feat: adds Lesson 16- Kimberlee's object-"headphones" with unit tests #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e387c14
feat: created lesson 16 object files
haldanek Oct 31, 2024
2d3555a
fix: fixed created files
haldanek Oct 31, 2024
a3adbbe
feat: changed object/created new files
haldanek Oct 31, 2024
7c413ca
feat: new object test file
haldanek Oct 31, 2024
33c95fc
feats: adds object default testing/pass
haldanek Nov 1, 2024
cdf5726
Merge branch 'code-differently:main' into Lesson_16
haldanek Nov 1, 2024
db9a348
feat: added tests turn on and turn off/pass
haldanek Nov 1, 2024
3f31a85
feat: added volume increase and decrease tests/pass
haldanek Nov 1, 2024
9ebe527
feat: added setcolor test/pass
haldanek Nov 1, 2024
5e4bdbe
Merge branch 'code-differently:main' into Lesson_16
haldanek Nov 1, 2024
1987b07
feat: added function from a collection member variable
haldanek Nov 1, 2024
fa74a57
Merge remote-tracking branch 'refs/remotes/origin/Lesson_16' into Les…
haldanek Nov 1, 2024
d1e4e5c
feat: added custom exception
haldanek Nov 1, 2024
f0e41c6
Merge branch 'code-differently:main' into Lesson_16
haldanek Nov 1, 2024
959dcce
chore: edit test/ all passed except testwireless
haldanek Nov 1, 2024
ae05f6a
Merge remote-tracking branch 'refs/remotes/origin/Lesson_16' into Les…
haldanek Nov 1, 2024
8c2e099
chore: edit attempt
haldanek Nov 1, 2024
3a908a1
chore: edit test files/ only 1 test failed
haldanek Nov 1, 2024
b1a0ee4
Merge branch 'code-differently:main' into Lesson_16
haldanek Nov 4, 2024
c3a6ac0
chore: added a new test making use of the loop function
haldanek Nov 5, 2024
c40303a
chore: debugging
haldanek Nov 5, 2024
38c5323
chore: down to one failing test
haldanek Nov 5, 2024
2431eb5
chore: fixed final test
haldanek Nov 5, 2024
f8cc50e
Merge branch 'code-differently:main' into Lesson_16
haldanek Nov 5, 2024
43603e8
Merge branch 'code-differently:main' into Lesson_16
haldanek Nov 14, 2024
0d024e9
Merge branch 'code-differently:main' into Lesson_16
haldanek Nov 17, 2024
83021ed
chore: made requested changes, deleted redundant classes
haldanek Nov 17, 2024
2195cbf
Merge remote-tracking branch 'refs/remotes/origin/Lesson_16' into Les…
haldanek Nov 17, 2024
0e0eb2d
chore: undo rename
anthonydmays Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.codedifferently.lesson16.KimberleeObject;

import java.util.Arrays;
import java.util.List;

public class BrandsArray {

// Preferred brands stored in a List
private static final List<String> PREFERRED_BRANDS =
Arrays.asList("Beats", "Sony", "Bose", "SkullCandy", "Juicy");

// Method to check if a brand is preferred
public static Boolean isPreferredBrand(String brand) {
return PREFERRED_BRANDS.contains(brand);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.codedifferently.lesson16.KimberleeObject;

public class ConnectionNotFoundException extends Exception {
public ConnectionNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package com.codedifferently.lesson16.KimberleeObject;

import java.util.Arrays;

public class HeadPhones {

private int volume = 0;
private boolean isPoweredOn = false;
private HeadPhoneColor headPhoneColor = HeadPhoneColor.BLACK;
private boolean isWireless = true;
private String brands = "Beats";
boolean isPreferredBrand = BrandUtils.isPreferredBrand(brands);
private boolean isConnectedToBluetooth = false;

public enum BoostMode {
BASS_BOOST,
VOCAL_BOOST,
TREBLE_BOOST;
}

private BoostMode currentMode;
private BoostMode[] modes = BoostMode.values();
private int currentModeIndex = 0;

public HeadPhones() {
this.currentMode = BoostMode.BASS_BOOST;
System.out.println("Constructor called: currentMode set to " + currentMode);
}

public void nextBoostMode() {
currentModeIndex = (currentModeIndex + 1) % modes.length;
currentMode = modes[currentModeIndex];
}

public BoostMode getCurrentMode() {
System.out.println("getCurrentMode called: currentMode is " + currentMode);
return currentMode;
}

public enum HeadPhoneColor {
RED,
BLUE,
ROSEGOLD,
PINK,
WHITE,
BLACK;
}

public void BrandsArray() {
String[] brands = new String[5];
brands[0] = "Beats";
brands[1] = "Sony";
brands[2] = "Bose";
brands[3] = "SkullCandy";
brands[4] = "Juicy";
}



public int getVolume() {
return volume;
}

public HeadPhoneColor getHeadPhoneColor() {
return headPhoneColor;
}

public boolean isPoweredOn() {
return isPoweredOn;
}

public boolean isWireless() {
return isWireless;
}

public String[] getBrandsArray() {
return BrandUtils.PREFERRED_BRANDS;
}

public void turnOn() {
isPoweredOn = true;
}

public void turnOff() {
isPoweredOn = false;
}

public void increaseVolume() {
if (volume < 100) {
volume++;
}
}

public void setVolume(int volume) {
if (volume >= 0 && volume <= 100) {
this.volume = volume;
}
}

public void decreaseVolume() {
if (volume > 0) {
volume--;
}
}

public void setColor(HeadPhoneColor color) {
this.headPhoneColor = color;
}

public class BrandUtils {
private static final String[] PREFERRED_BRANDS = {
"Beats", "Sony", "Bose", "SkullCandy", "Juicy"
};

public static boolean isPreferredBrand(String brand) {
return Arrays.asList(PREFERRED_BRANDS).contains(brand);
}
}

public boolean connectToBluetooth() {
if (isPoweredOn && isWireless) {
isConnectedToBluetooth = true;
}
return isConnectedToBluetooth;
}

public boolean isConnectedToBluetooth() {
return connectToBluetooth();
}

public void wirelessConnection() throws ConnectionNotFoundException {
if (!isConnectedToBluetooth) {
throw new ConnectionNotFoundException("Headphones Wireless Connection Not Found.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.codedifferently.lesson16.KimberleeObject;

public class WirelessConnection {
WirelessConnection wirelessConnection;

public void get(boolean isConnectedToBluetooth) {
if (!isConnectedToBluetooth) {
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package com.codedifferently.lesson16.KimberleeObjectTest;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.*;

import com.codedifferently.lesson16.KimberleeObject.ConnectionNotFoundException;
import com.codedifferently.lesson16.KimberleeObject.HeadPhones;
import com.codedifferently.lesson16.KimberleeObject.HeadPhones.BoostMode;
import com.codedifferently.lesson16.KimberleeObject.HeadPhones.HeadPhoneColor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class HeadPhonesTest {

private HeadPhones headphones;

@BeforeEach
public void setUp() {
headphones = new HeadPhones();
}

@Test
public void testDefaultState() {
assertEquals(0, headphones.getVolume(), "Volume should be 0 by default.");
assertEquals(
HeadPhoneColor.BLACK, headphones.getHeadPhoneColor(), "Color should be black by default.");
assertFalse(headphones.isPoweredOn(), "HeadPhones should be off by default.");
assertTrue(headphones.isWireless(), "HeadPhones should be wireless by default.");
assertArrayEquals(new String[] {"Beats"}, new String[] {"Beats"});
assertEquals(
BoostMode.BASS_BOOST,
headphones.getCurrentMode(),
"BASS_BOOST should be the default setting.");
}

@Test
public void testTurnOn() {
// Act
headphones.turnOn();
// Assert
assertTrue(headphones.isPoweredOn(), "Headphones should turn on after calling turnOn");
}

@Test
public void testTurnOff() {
// Arrange
headphones.turnOn();
// Act
headphones.turnOff();
// Assert
assertFalse(headphones.isPoweredOn(), "Headphones should turn off after calling");
}

@Test
public void testIncreaseVolume() {
// Arrange
headphones.turnOn();
headphones.increaseVolume();
assertEquals(1, headphones.getVolume(), "Volume should increase by 1");
// Act
headphones.setVolume(99);
headphones.increaseVolume();
// Assert
assertEquals(100, headphones.getVolume(), "Volume should not exceed 100.");
}

@Test
public void testDecreaseVolume() {
// Arrange
headphones.turnOn();
headphones.setVolume(1);
headphones.decreaseVolume();
assertEquals(0, headphones.getVolume(), "Volume should decrease to 0.");
// Act
headphones.decreaseVolume();
// Assert
assertEquals(0, headphones.getVolume(), "Volume should not go lower than 0.");
}

@Test
public void testSetColor() {
// Act
headphones.setColor(HeadPhoneColor.ROSEGOLD);
// Assert
assertEquals(
HeadPhoneColor.ROSEGOLD,
headphones.getHeadPhoneColor(),
"Headphone color should be set to Rose Gold.");
}

@Test
public void testPreferredBrand() {
// Assert
assertTrue(
HeadPhones.BrandUtils.isPreferredBrand("Beats"), "Beats should be a preferred brand.");
assertTrue(HeadPhones.BrandUtils.isPreferredBrand("Sony"), "Sony should be a preferred brand.");
assertFalse(
HeadPhones.BrandUtils.isPreferredBrand("Apple"), "Apple should not be a preferred brand.");
assertTrue(
HeadPhones.BrandUtils.isPreferredBrand("SkullCandy"),
"SkullCandy should be a preferred brand.");
assertTrue(
HeadPhones.BrandUtils.isPreferredBrand("Juicy"), "Juicy should be a preferred brand.");
}

@Test
public void testwirelessConnection() throws Exception {
// Arrange
headphones.turnOn();
// Act
headphones.connectToBluetooth();
// Assert
assertTrue(
headphones.isConnectedToBluetooth(),
"Headphones should connect to bluetooh when wireless and turned on.");
}

@Test
public void testwirelessConnection_connectionNotFound() throws Exception {
// Act
assertThatThrownBy(() -> headphones.wirelessConnection())
.isInstanceOf(ConnectionNotFoundException.class)
.hasMessage("Headphones Wireless Connection Not Found.");
}

@Test
public void testBoostMode() {
assertEquals(
BoostMode.BASS_BOOST,
headphones.getCurrentMode(),
"BASS_BOOST should be the default setting.");

headphones.nextBoostMode();
assertEquals(
BoostMode.VOCAL_BOOST,
headphones.getCurrentMode(),
"The next Boost setting should be VOCAL.");

headphones.nextBoostMode();
assertEquals(
BoostMode.TREBLE_BOOST,
headphones.getCurrentMode(),
"The next Boost setting should be TREBLE.");

headphones.nextBoostMode();
assertEquals(
BoostMode.BASS_BOOST,
headphones.getCurrentMode(),
"BoostMode cycle should return to BASS_BOOST.");
}
}
Loading