File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
lesson_16/api/api_app/src
main/java/com/codedifferently/lesson16/library
test/java/com/codedifferently/lesson16/library
lib/java/codedifferently-instructional/instructional-lib Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -124,13 +124,27 @@ public void removeLibraryGuest(LibraryGuest guest) throws MediaItemCheckedOutExc
124124 this .removeLibraryGuest (guest .getId ());
125125 }
126126
127+ /**
128+ * Returns all librarians registered for this library.
129+ *
130+ * @return A unique set of librarians.
131+ */
127132 public Set <Librarian > getLibrarians () {
128133 return this .guestsById .values ().stream ()
129134 .filter (g -> g instanceof Librarian )
130135 .map (g -> (Librarian ) g )
131136 .collect (Collectors .toSet ());
132137 }
133138
139+ /**
140+ * Returns all registered library patrons.
141+ *
142+ * @return A unique set of all Library patrons.
143+ */
144+ public Set <LibraryGuest > getPatrons () {
145+ return this .guestsById .values ().stream ().collect (Collectors .toSet ());
146+ }
147+
134148 /**
135149 * Check out a item to a guest.
136150 *
Original file line number Diff line number Diff line change 55
66import com .codedifferently .lesson16 .library .exceptions .MediaItemCheckedOutException ;
77import java .util .List ;
8+ import java .util .Set ;
89import java .util .UUID ;
910import org .junit .jupiter .api .BeforeEach ;
1011import org .junit .jupiter .api .Test ;
@@ -334,4 +335,19 @@ void testLibrary_preventsGuestFromCheckingOutNewspaper() {
334335 assertThat (wasCheckedOut ).isFalse ();
335336 assertThat (patron .getCheckedOutMediaItems ().contains (newspaper )).isFalse ();
336337 }
338+
339+ @ Test
340+ void testLibrary_retrievesAllPatrons () {
341+ // Arrange
342+ Patron patron1 = new Patron ("John Doe" , "john@example.com" );
343+ Patron patron2 = new Patron ("Jane Doe" , "jane@example.com" );
344+ classUnderTest .addLibraryGuest (patron1 );
345+ classUnderTest .addLibraryGuest (patron2 );
346+
347+ // Act
348+ Set <LibraryGuest > guests = classUnderTest .getPatrons ();
349+
350+ // Assert
351+ assertThat (classUnderTest .getPatrons ().size ()).isEqualTo (2 );
352+ }
337353}
Original file line number Diff line number Diff line change 1515 </classpathentry >
1616 <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/" />
1717 <classpathentry kind =" con" path =" org.eclipse.buildship.core.gradleclasspathcontainer" />
18- <classpathentry kind =" output" path =" bin/default " />
18+ <classpathentry kind =" output" path =" bin" />
1919</classpath >
You can’t perform that action at this time.
0 commit comments