77
88import static oop .ObservableChatRoom .ObservingChatUser ;
99import static oop .ObservableChatRoom .CountingUser ;
10- import static org .junit .jupiter .api .Assertions .assertEquals ;
11- import static org .junit .jupiter .api .Assertions .assertNotEquals ;
10+ import static org .junit .jupiter .api .Assertions .*;
1211
1312@ Grade
1413public class ObservableChatRoomTest {
@@ -104,11 +103,14 @@ public void testManySubscribers() {
104103 @ Test
105104 @ Grade (value = 1 , cpuTimeout = 1000 )
106105 public void testNotification () {
107- boolean messageReceive = false ;
108106
109107 // We define here our own user class because
110108 // we want to verify whether the user is correctly notified.
109+ // To do this, we simply extend the CountingUser
110+ // class and override the receiveNotification method.
111111 class BobUser extends CountingUser {
112+ boolean notificationReceived ;
113+
112114 BobUser (String name ) {
113115 super (name );
114116 }
@@ -117,6 +119,7 @@ class BobUser extends CountingUser {
117119 public void receiveNotification (String senderName , String text ) {
118120 assertEquals ("Alice" , senderName );
119121 assertEquals ("Hello" , text );
122+ notificationReceived = true ;
120123 }
121124 }
122125
@@ -126,6 +129,7 @@ public void receiveNotification(String senderName, String text) {
126129
127130 room .subscribe (bob );
128131 room .writeMessage (alice , "Hello" );
132+ assertTrue (bob .notificationReceived );
129133 }
130134
131135 @ Test
0 commit comments