Skip to content

Commit b3c82b3

Browse files
committed
chore: adding missing method for retrieving patrons
Signed-off-by: Anthony D. Mays <[email protected]>
1 parent 41528e9 commit b3c82b3

File tree

3 files changed

+31
-1
lines changed
  • lesson_16/api/api_app/src
  • lib/java/codedifferently-instructional/instructional-lib

3 files changed

+31
-1
lines changed

lesson_16/api/api_app/src/main/java/com/codedifferently/lesson16/library/Library.java

+14
Original file line numberDiff line numberDiff 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
*

lesson_16/api/api_app/src/test/java/com/codedifferently/lesson16/library/LibraryTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.codedifferently.lesson16.library.exceptions.MediaItemCheckedOutException;
77
import java.util.List;
8+
import java.util.Set;
89
import java.util.UUID;
910
import org.junit.jupiter.api.BeforeEach;
1011
import 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", "[email protected]");
343+
Patron patron2 = new Patron("Jane Doe", "[email protected]");
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
}

lib/java/codedifferently-instructional/instructional-lib/.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
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>

0 commit comments

Comments
 (0)