Skip to content

Commit

Permalink
chore: adding missing method for retrieving patrons
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony D. Mays <anthony@morganlatimer.com>
  • Loading branch information
anthonydmays committed Apr 5, 2024
1 parent 41528e9 commit b3c82b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,27 @@ public void removeLibraryGuest(LibraryGuest guest) throws MediaItemCheckedOutExc
this.removeLibraryGuest(guest.getId());
}

/**
* Returns all librarians registered for this library.
*
* @return A unique set of librarians.
*/
public Set<Librarian> getLibrarians() {
return this.guestsById.values().stream()
.filter(g -> g instanceof Librarian)
.map(g -> (Librarian) g)
.collect(Collectors.toSet());
}

/**
* Returns all registered library patrons.
*
* @return A unique set of all Library patrons.
*/
public Set<LibraryGuest> getPatrons() {
return this.guestsById.values().stream().collect(Collectors.toSet());
}

/**
* Check out a item to a guest.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.codedifferently.lesson16.library.exceptions.MediaItemCheckedOutException;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -334,4 +335,19 @@ void testLibrary_preventsGuestFromCheckingOutNewspaper() {
assertThat(wasCheckedOut).isFalse();
assertThat(patron.getCheckedOutMediaItems().contains(newspaper)).isFalse();
}

@Test
void testLibrary_retrievesAllPatrons() {
// Arrange
Patron patron1 = new Patron("John Doe", "john@example.com");
Patron patron2 = new Patron("Jane Doe", "jane@example.com");
classUnderTest.addLibraryGuest(patron1);
classUnderTest.addLibraryGuest(patron2);

// Act
Set<LibraryGuest> guests = classUnderTest.getPatrons();

// Assert
assertThat(classUnderTest.getPatrons().size()).isEqualTo(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
<classpathentry kind="output" path="bin"/>
</classpath>

0 comments on commit b3c82b3

Please sign in to comment.