-
Notifications
You must be signed in to change notification settings - Fork 24
fix: correctly implemented code into lesson 16 with coverage results over 80% #536
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
deceeb5
task: working on lesson 15by adding test to get at least 80% coverage
JEKLUND251 8818846
readded work to new file to get 80% coverage
JEKLUND251 5694715
fix: wrorking to fix code errors in lesson 16
JEKLUND251 ef2b7e2
fix: correctly implemented work into lesson 16
JEKLUND251 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
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
76 changes: 76 additions & 0 deletions
76
lesson_15/tdd/tdd_app/src/test/java/com/codedifferently/lesson15/EmployeeManagerTest.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,76 @@ | ||
package com.codedifferently.lesson15; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class EmployeeManagerTest { | ||
@Test | ||
public void employeeManagerTest() { | ||
// Arrange | ||
EmployeeManager employeeManager = new EmployeeManager(); | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineer", 0); | ||
// Act | ||
employeeManager.addEmployee(employee); | ||
// Assert | ||
assertThat(employeeManager.getEmployeeCount()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void testAddEmployee() { | ||
// Arrange | ||
EmployeeManager employeeManager = new EmployeeManager(); | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineer", 0); | ||
// Act | ||
employeeManager.addEmployee(employee); | ||
// Assert | ||
assertThat(employeeManager.getEmployeeCount()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void testGetEmployee() { | ||
// Arrange | ||
EmployeeManager employeeManager = new EmployeeManager(); | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineer", 0); | ||
employeeManager.addEmployee(employee); | ||
// Act | ||
Employee retrievedEmployee = employeeManager.getEmployee(1); | ||
// Assert | ||
assertThat(retrievedEmployee).isEqualTo(employee); | ||
} | ||
|
||
@Test | ||
public void testUpdateEmployee() { | ||
// Arrange | ||
EmployeeManager employeeManager = new EmployeeManager(); | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineer", 500000); | ||
employeeManager.addEmployee(employee); | ||
// Act | ||
employee.setName("Justin Eklund Updated"); | ||
employeeManager.updateEmployee(employee); | ||
// Assert | ||
assertThat(employeeManager.getEmployee(1).getName()).isEqualTo("Justin Eklund Updated"); | ||
} | ||
|
||
@Test | ||
public void testRemoveEmployee() { | ||
// Arrange | ||
EmployeeManager employeeManager = new EmployeeManager(); | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineer", 0); | ||
employeeManager.addEmployee(employee); | ||
// Act | ||
employeeManager.removeEmployee(1); | ||
// Assert | ||
assertThat(employeeManager.getEmployeeCount()).isEqualTo(0); | ||
} | ||
|
||
@Test | ||
public void testAssertEmployeeInCollection() { | ||
// Arrange | ||
EmployeeManager employeeManager = new EmployeeManager(); | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineer", 0); | ||
employeeManager.addEmployee(employee); | ||
// Act & Assert | ||
assertThat(employeeManager.getEmployee(1)).isEqualTo(employee); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
lesson_15/tdd/tdd_app/src/test/java/com/codedifferently/lesson15/EmployeeTest.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,116 @@ | ||
package com.codedifferently.lesson15; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class EmployeeTest { | ||
|
||
@Test | ||
public void testGetDetails() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
String details = employee.getDetails(); | ||
|
||
// Assert | ||
assertThat(details).isEqualTo("1 Justin Eklund Software Engineering 5000000.0"); | ||
} | ||
|
||
@Test | ||
public void testGetId() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
int id = employee.getId(); | ||
|
||
// Assert | ||
assertThat(id).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void testSetId() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
employee.setId(2); | ||
|
||
// Assert | ||
assertThat(employee.getId()).isEqualTo(2); | ||
} | ||
|
||
@Test | ||
public void testGetName() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
String name = employee.getName(); | ||
|
||
// Assert | ||
assertThat(name).isEqualTo("Justin Eklund"); | ||
} | ||
|
||
@Test | ||
public void testSetName() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
employee.setName("Justin Eklund"); | ||
|
||
// Assert | ||
assertThat(employee.getName()).isEqualTo("Justin Eklund"); | ||
} | ||
|
||
@Test | ||
public void testGetDepartment() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
String department = employee.getDepartment(); | ||
|
||
// Assert | ||
assertThat(department).isEqualTo("Software Engineering"); | ||
} | ||
|
||
@Test | ||
public void testSetDepartment() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
employee.setDepartment("Engineering"); | ||
|
||
// Assert | ||
assertThat(employee.getDepartment()).isEqualTo("Engineering"); | ||
} | ||
|
||
@Test | ||
public void testGetSalary() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
double salary = employee.getSalary(); | ||
|
||
// Assert | ||
assertThat(salary).isEqualTo(5000000); | ||
} | ||
|
||
@Test | ||
public void testSetSalary() { | ||
// Arrange | ||
Employee employee = new Employee(1, "Justin Eklund", "Software Engineering", 5000000); | ||
|
||
// Act | ||
employee.setSalary(5000000); | ||
|
||
// Assert | ||
assertThat(employee.getSalary()).isEqualTo(5000000); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
.../objects/objects_app/src/main/java/com/codedifferently/lesson16/justins_playlist/Playlist
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Files do not have the correct extensions, so this code won't run at all. |
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,43 @@ | ||
package com.codedifferently.lesson16.justins_playlist; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Playlist { | ||
private String name; | ||
private String genre; | ||
private int duration; | ||
private List<String> songs; | ||
|
||
public Playlist(String name, String genre, int duration) { | ||
this.name = name; | ||
this.genre = genre; | ||
this.duration = duration; | ||
this.songs = new ArrayList<>(); | ||
} | ||
|
||
// Getters and Setters | ||
public String getName() { return name; } | ||
public void setName(String name) { this.name = name; } | ||
|
||
public String getGenre() { return genre; } | ||
public void setGenre(String genre) { this.genre = genre; } | ||
|
||
public int getDuration() { return duration; } | ||
public void setDuration(int duration) { this.duration = duration; } | ||
|
||
public String getDetails() { | ||
return "Name: " + name + ", Genre: " + genre + ", Duration: " + duration; | ||
} | ||
|
||
public void addSong(String song) { | ||
if (song == null || song.isEmpty()) { | ||
throw new IllegalArgumentException("Song cannot be null or empty"); | ||
} | ||
songs.add(song); | ||
} | ||
|
||
public List<String> getSongs() { | ||
return songs; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...bjects_app/src/main/java/com/codedifferently/lesson16/justins_playlist/PlaylistExceptions
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,23 @@ | ||
package com.codedifferently.lesson16.justins_playlist; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Playlist { | ||
private final List<String> songs = new ArrayList<>(); | ||
|
||
public void addSong(String song) { | ||
songs.add(song); | ||
} | ||
|
||
public void playAll() { | ||
if (songs.isEmpty()) { | ||
throw new IllegalStateException("No songs in the playlist to play."); | ||
} | ||
|
||
System.out.println("Playing all songs in the playlist:"); | ||
for (String song : songs) { | ||
System.out.println("Playing: " + song); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...jects_app/src/test/java/com/codedifferently/lesson16/playlist.test/PlaylistExceptionsTest
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,41 @@ | ||
package com.codedifferently.lesson16.playlist.test; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class PlaylistTest { | ||
|
||
private Playlist playlist; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
playlist = new playlist(); | ||
} | ||
|
||
@Test | ||
public void testAddSongDoesNotThrow() { | ||
assertThatCode(() -> playlist.addSong("My Favorite Song")) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
public void testPlayAllThrowsWhenNoSongs() { | ||
assertThatThrownBy(() -> playlist.playAll()) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessage("No songs in the playlist to play."); | ||
} | ||
|
||
@Test | ||
public void testPlayAllPlaysSongsWhenNotEmpty() { | ||
playlist.addSong("Song 1"); | ||
playlist.addSong("Song 2"); | ||
|
||
// We're not capturing console output here — just making sure no exceptions are thrown | ||
assertThatCode(() -> playlist.playAll()) | ||
.doesNotThrowAnyException(); | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...objects/objects_app/src/test/java/com/codedifferently/lesson16/playlist.test/PlaylistTest
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,49 @@ | ||
package com.codedifferently.lesson16.justinsplaylist; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import static org.assertj.core.api.Assertions.*; | ||
import static org.assertj.core.api.assertThat; | ||
import com.codedifferently.lesson16.JustinsPlaylist.Playlist; | ||
|
||
public class playlistTest { | ||
|
||
private playlist playlist; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
playlist = new playlist("Chill Vibes", "Lo-Fi", 120); | ||
} | ||
|
||
@Test | ||
public void testGetDetailsReturnsCorrectInfo() { | ||
String details = playlist.getDetails(); | ||
assertThat(details).isEqualTo("Name: Chill Vibes, Genre: Lo-Fi, Duration: 120"); | ||
} | ||
|
||
@Test | ||
public void testAddSongSuccessfully() { | ||
playlist.addSong("Evening Walk"); | ||
assertThatCode(() -> playlist.playAll()).doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
public void testAddSongThrowsExceptionOnEmptyInput() { | ||
assertThatThrownBy(() -> Playlist.addSong(" ")) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Cannot add a null or empty song."); | ||
} | ||
|
||
@Test | ||
public void testPlayAllThrowsExceptionWhenNoSongs() { | ||
assertThatThrownBy(() -> playlist.playAll()) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessage("No songs in the playlist to play."); | ||
} | ||
|
||
@Test | ||
public void testSetAndGetName() { | ||
playlist.setName("Late Night Beats"); | ||
assertThat(playlist.getName()).isEqualTo("Late Night Beats"); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, must not have L15 work.