-
Notifications
You must be signed in to change notification settings - Fork 25
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
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 2d3555a
fix: fixed created files
haldanek a3adbbe
feat: changed object/created new files
haldanek 7c413ca
feat: new object test file
haldanek 33c95fc
feats: adds object default testing/pass
haldanek cdf5726
Merge branch 'code-differently:main' into Lesson_16
haldanek db9a348
feat: added tests turn on and turn off/pass
haldanek 3f31a85
feat: added volume increase and decrease tests/pass
haldanek 9ebe527
feat: added setcolor test/pass
haldanek 5e4bdbe
Merge branch 'code-differently:main' into Lesson_16
haldanek 1987b07
feat: added function from a collection member variable
haldanek fa74a57
Merge remote-tracking branch 'refs/remotes/origin/Lesson_16' into Les…
haldanek d1e4e5c
feat: added custom exception
haldanek f0e41c6
Merge branch 'code-differently:main' into Lesson_16
haldanek 959dcce
chore: edit test/ all passed except testwireless
haldanek ae05f6a
Merge remote-tracking branch 'refs/remotes/origin/Lesson_16' into Les…
haldanek 8c2e099
chore: edit attempt
haldanek 3a908a1
chore: edit test files/ only 1 test failed
haldanek b1a0ee4
Merge branch 'code-differently:main' into Lesson_16
haldanek c3a6ac0
chore: added a new test making use of the loop function
haldanek c40303a
chore: debugging
haldanek 38c5323
chore: down to one failing test
haldanek 2431eb5
chore: fixed final test
haldanek f8cc50e
Merge branch 'code-differently:main' into Lesson_16
haldanek 43603e8
Merge branch 'code-differently:main' into Lesson_16
haldanek 0d024e9
Merge branch 'code-differently:main' into Lesson_16
haldanek 83021ed
chore: made requested changes, deleted redundant classes
haldanek 2195cbf
Merge remote-tracking branch 'refs/remotes/origin/Lesson_16' into Les…
haldanek 0e0eb2d
chore: undo rename
anthonydmays File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
...s/objects_app/src/main/java/com/codedifferently/lesson16/KimberleeObject/BrandsArray.java
haldanek marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...c/main/java/com/codedifferently/lesson16/KimberleeObject/ConnectionNotFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
...ts/objects_app/src/main/java/com/codedifferently/lesson16/KimberleeObject/HeadPhones.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ts_app/src/main/java/com/codedifferently/lesson16/KimberleeObject/WirelessConnection.java
haldanek marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
...ts_app/src/test/java/com/codedifferently/lesson16/KimberleeObjectTest/HeadPhonesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.