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
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
124
124
this .removeLibraryGuest (guest .getId ());
125
125
}
126
126
127
+ /**
128
+ * Returns all librarians registered for this library.
129
+ *
130
+ * @return A unique set of librarians.
131
+ */
127
132
public Set <Librarian > getLibrarians () {
128
133
return this .guestsById .values ().stream ()
129
134
.filter (g -> g instanceof Librarian )
130
135
.map (g -> (Librarian ) g )
131
136
.collect (Collectors .toSet ());
132
137
}
133
138
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
+
134
148
/**
135
149
* Check out a item to a guest.
136
150
*
Original file line number Diff line number Diff line change 5
5
6
6
import com .codedifferently .lesson16 .library .exceptions .MediaItemCheckedOutException ;
7
7
import java .util .List ;
8
+ import java .util .Set ;
8
9
import java .util .UUID ;
9
10
import org .junit .jupiter .api .BeforeEach ;
10
11
import org .junit .jupiter .api .Test ;
@@ -334,4 +335,19 @@ void testLibrary_preventsGuestFromCheckingOutNewspaper() {
334
335
assertThat (wasCheckedOut ).isFalse ();
335
336
assertThat (patron .getCheckedOutMediaItems ().contains (newspaper )).isFalse ();
336
337
}
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
+ }
337
353
}
Original file line number Diff line number Diff line change 15
15
</classpathentry >
16
16
<classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/" />
17
17
<classpathentry kind =" con" path =" org.eclipse.buildship.core.gradleclasspathcontainer" />
18
- <classpathentry kind =" output" path =" bin/default " />
18
+ <classpathentry kind =" output" path =" bin" />
19
19
</classpath >
You can’t perform that action at this time.
0 commit comments