Skip to content

Package: ChangeBroker_Test$3

ChangeBroker_Test$3

nameinstructionbranchcomplexitylinemethod
handleNotification(Notification)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * jfaltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.changebroker.test;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertSame;
19: import static org.junit.Assert.assertTrue;
20: import static org.mockito.Matchers.any;
21: import static org.mockito.Mockito.mock;
22: import static org.mockito.Mockito.times;
23: import static org.mockito.Mockito.verify;
24:
25: import java.math.BigInteger;
26: import java.util.Set;
27: import java.util.concurrent.CountDownLatch;
28: import java.util.concurrent.TimeUnit;
29:
30: import org.eclipse.emf.common.notify.Notification;
31: import org.eclipse.emf.ecp.changebroker.internal.ChangeBrokerImpl;
32: import org.eclipse.emf.ecp.changebroker.spi.ChangeObserver;
33: import org.eclipse.emf.ecp.changebroker.spi.NotificationProvider;
34: import org.eclipse.emf.ecp.changebroker.spi.ReadOnlyChangeObserver;
35: import org.eclipse.emf.emfstore.bowling.BowlingFactory;
36: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
37: import org.eclipse.emf.emfstore.bowling.Matchup;
38: import org.eclipse.emf.emfstore.bowling.Tournament;
39: import org.eclipse.emf.emfstore.bowling.TournamentType;
40: import org.junit.Before;
41: import org.junit.Test;
42:
43: /**
44: * @author jfaltermeier
45: *
46: */
47: public class ChangeBroker_Test {
48:
49:         private ChangeBrokerImpl broker;
50:         private Tournament tournament;
51:         private ContentAdapterNotificationProvider provider;
52:
53:         @Before
54:         public void before() {
55:                 broker = new ChangeBrokerImpl();
56:                 tournament = BowlingFactory.eINSTANCE.createTournament();
57:                 provider = new ContentAdapterNotificationProvider(tournament);
58:                 broker.addNotificationProvider(provider);
59:         }
60:
61:         @Test
62:         public void testMultipleEMFObserver() throws InterruptedException {
63:                 // setup
64:                 final CountDownLatch latch1 = new CountDownLatch(1);
65:                 final CountDownLatch latch2 = new CountDownLatch(1);
66:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
67:                 broker.subscribe(new ChangeObserver() {
68:
69:                         @Override
70:                         public void handleNotification(Notification notification) {
71:                                 latch1.countDown();
72:                         }
73:                 });
74:                 broker.subscribe(new ChangeObserver() {
75:
76:                         @Override
77:                         public void handleNotification(Notification notification) {
78:                                 latch2.countDown();
79:                         }
80:                 });
81:
82:                 // act
83:                 tournament.getMatchups().add(matchup);
84:
85:                 // assert
86:                 assertTrue("Notify was not called", latch1.await(1, TimeUnit.MILLISECONDS));
87:                 assertTrue("Notify was not called", latch2.await(1, TimeUnit.MILLISECONDS));
88:         }
89:
90:         @Test
91:         public void testRemoveObserver() throws InterruptedException {
92:                 // setup
93:                 final CountDownLatch latch = new CountDownLatch(1);
94:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
95:                 broker.subscribe(new ChangeObserver() {
96:
97:                         @Override
98:                         public void handleNotification(Notification notification) {
99:                                 latch.countDown();
100:                         }
101:                 });
102:
103:                 // act
104:                 broker.removeNotificationProvider(provider);
105:                 tournament.getMatchups().add(matchup);
106:
107:                 // assert
108:                 assertFalse("Notify was called although it shouln't be called", latch.await(1, TimeUnit.MILLISECONDS));
109:         }
110:
111:         @Test
112:         public void testAddSameEMFObserverTwiceAndRemove() throws InterruptedException {
113:                 // setup
114:                 final CountDownLatch latch = new CountDownLatch(1);
115:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
116:                 broker.subscribe(new ChangeObserver() {
117:
118:                         @Override
119:                         public void handleNotification(Notification notification) {
120:                                 latch.countDown();
121:                         }
122:                 });
123:                 broker.addNotificationProvider(provider);
124:                 broker.removeNotificationProvider(provider);
125:
126:                 // act
127:                 tournament.getMatchups().add(matchup);
128:
129:                 // assert
130:                 assertFalse("Notify was called although it shouln't be called", latch.await(1, TimeUnit.MILLISECONDS));
131:         }
132:
133:         @Test
134:         public void testRemoveUnregisteredObserver() throws InterruptedException {
135:                 // setup
136:                 final CountDownLatch latch = new CountDownLatch(1);
137:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
138:                 broker.subscribe(new ChangeObserver() {
139:
140:                         @Override
141:                         public void handleNotification(Notification notification) {
142:                                 latch.countDown();
143:                         }
144:                 });
145:
146:                 // act
147:
148:                 broker.removeNotificationProvider(new ContentAdapterNotificationProvider(tournament));
149:                 tournament.getMatchups().add(matchup);
150:
151:                 // assert
152:                 assertTrue("Notify was not called", latch.await(1, TimeUnit.MILLISECONDS));
153:         }
154:
155:         @Test
156:         public void testEMFObserverNoStrategy() throws InterruptedException {
157:                 // setup
158:                 final CountDownLatch latch = new CountDownLatch(1);
159:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
160:                 broker.subscribe(new ChangeObserver() {
161:
162:                         @Override
163:                         public void handleNotification(Notification notification) {
164:                                 assertSame(Notification.ADD, notification.getEventType());
165:                                 assertSame(BowlingPackage.eINSTANCE.getTournament_Matchups(), notification.getFeature());
166:                                 assertSame(matchup, notification.getNewValue());
167:                                 latch.countDown();
168:                         }
169:                 });
170:
171:                 // act
172:                 tournament.getMatchups().add(matchup);
173:
174:                 // assert
175:                 assertTrue("Notify was not called", latch.await(1, TimeUnit.MILLISECONDS));
176:         }
177:
178:         @Test
179:         public void testEMFObserverEClassStrategy() throws InterruptedException {
180:                 // setup
181:                 final CountDownLatch latch1 = new CountDownLatch(1);
182:                 final CountDownLatch latch2 = new CountDownLatch(1);
183:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
184:                 tournament.getMatchups().add(matchup);
185:                 broker.subscribeToEClass(new ChangeObserver() {
186:
187:                         @Override
188:                         public void handleNotification(Notification notification) {
189:                                 if (notification.getNotifier() == tournament) {
190:                                         latch1.countDown();
191:                                 } else if (notification.getNotifier() == matchup) {
192:                                         latch2.countDown();
193:                                 }
194:                         }
195:                 }, BowlingPackage.eINSTANCE.getTournament());
196:
197:                 // act&assert
198:                 tournament.setType(TournamentType.PRO);
199:                 assertTrue(latch1.await(1, TimeUnit.MILLISECONDS));
200:
201:                 // act&assert
202:                 matchup.setNrSpectators(new BigInteger("1"));
203:                 assertFalse("Notify was called although it shouln't be called", latch2.await(1, TimeUnit.MILLISECONDS));
204:         }
205:
206:         @Test
207:         public void testEMFObserverContainingEClassStrategy() throws InterruptedException {
208:                 // setup
209:                 final CountDownLatch latch1 = new CountDownLatch(1);
210:                 final CountDownLatch latch2 = new CountDownLatch(1);
211:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
212:                 tournament.getMatchups().add(matchup);
213:                 broker.subscribeToTree(new ChangeObserver() {
214:
215:                         @Override
216:                         public void handleNotification(Notification notification) {
217:                                 if (notification.getNotifier() == tournament) {
218:                                         latch1.countDown();
219:                                 } else if (notification.getNotifier() == matchup) {
220:                                         latch2.countDown();
221:                                 }
222:                         }
223:                 }, BowlingPackage.eINSTANCE.getTournament());
224:
225:                 // act&assert
226:                 tournament.setType(TournamentType.PRO);
227:                 assertTrue("Notify was not called", latch1.await(1, TimeUnit.MILLISECONDS));
228:
229:                 // act&assert
230:                 matchup.setNrSpectators(new BigInteger("1"));
231:                 assertTrue("Notify was not called", latch2.await(1, TimeUnit.MILLISECONDS));
232:         }
233:
234:         @Test
235:         public void testIgnoreNotifactionsByChangesFromEMFObserver() throws InterruptedException {
236:                 // setup
237:                 final CountDownLatch latch1 = new CountDownLatch(1);
238:                 final CountDownLatch latch2 = new CountDownLatch(1);
239:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
240:                 tournament.getMatchups().add(matchup);
241:                 broker.subscribeToEClass(new ChangeObserver() {
242:
243:                         @Override
244:                         public void handleNotification(Notification notification) {
245:                                 matchup.setNrSpectators(new BigInteger("1"));
246:                                 latch1.countDown();
247:
248:                         }
249:                 }, BowlingPackage.eINSTANCE.getTournament());
250:                 broker.subscribeToEClass(new ChangeObserver() {
251:
252:                         @Override
253:                         public void handleNotification(Notification notification) {
254:                                 latch2.countDown();
255:
256:                         }
257:                 }, BowlingPackage.eINSTANCE.getMatchup());
258:
259:                 // act
260:                 tournament.setType(TournamentType.PRO);
261:
262:                 // assert
263:                 assertTrue("Notify was not called", latch1.await(1, TimeUnit.MILLISECONDS));
264:                 assertFalse("Notify was called although it shouln't be called", latch2.await(1, TimeUnit.MILLISECONDS));
265:         }
266:
267:         @Test
268:         public void testIgnoreNotifactionsByCallingStopNotification() throws InterruptedException {
269:                 // setup
270:                 final CountDownLatch latch1 = new CountDownLatch(1);
271:                 broker.subscribeToEClass(new ChangeObserver() {
272:
273:                         @Override
274:                         public void handleNotification(Notification notification) {
275:                                 latch1.countDown();
276:                         }
277:                 }, BowlingPackage.eINSTANCE.getTournament());
278:                 broker.stopNotification();
279:
280:                 // act
281:                 tournament.setType(TournamentType.PRO);
282:
283:                 // assert
284:                 assertFalse("Notify was called although it shouln't be called", latch1.await(1, TimeUnit.MILLISECONDS));
285:         }
286:
287:         @Test
288:         public void testEMFObserverContinueNotification() throws InterruptedException {
289:                 // setup
290:                 final CountDownLatch latch1 = new CountDownLatch(1);
291:                 broker.subscribeToEClass(new ChangeObserver() {
292:
293:                         @Override
294:                         public void handleNotification(Notification notification) {
295:                                 latch1.countDown();
296:                         }
297:                 }, BowlingPackage.eINSTANCE.getTournament());
298:
299:                 broker.stopNotification();
300:
301:                 tournament.setType(TournamentType.PRO);
302:                 assertFalse("Notify was called although it shouln't be called", latch1.await(1, TimeUnit.MILLISECONDS));
303:
304:                 // act
305:                 broker.continueNotification();
306:                 tournament.setType(TournamentType.AMATEUR);
307:
308:                 // assert
309:                 assertTrue("Notify was not called", latch1.await(1, TimeUnit.MILLISECONDS));
310:         }
311:
312:         @Test
313:         public void testEMFObserverFeatureStrategy() throws InterruptedException {
314:                 // setup
315:                 final CountDownLatch latch1 = new CountDownLatch(1);
316:                 final CountDownLatch latch2 = new CountDownLatch(1);
317:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
318:
319:                 broker.subscribeToFeature(new ChangeObserver() {
320:
321:                         @Override
322:                         public void handleNotification(Notification notification) {
323:                                 if (notification.getFeature() == BowlingPackage.eINSTANCE.getTournament_Type()) {
324:                                         latch1.countDown();
325:                                 } else if (notification.getFeature() == BowlingPackage.eINSTANCE.getTournament_Matchups()) {
326:                                         latch2.countDown();
327:                                 }
328:                         }
329:                 }, BowlingPackage.eINSTANCE.getTournament_Type());
330:
331:                 // act&assert
332:                 tournament.setType(TournamentType.PRO);
333:                 assertTrue(latch1.await(1, TimeUnit.MILLISECONDS));
334:
335:                 // act&assert
336:                 tournament.getMatchups().add(matchup);
337:                 assertFalse("Notify was called although it shouln't be called", latch2.await(1, TimeUnit.MILLISECONDS));
338:         }
339:
340:         @Test
341:         public void testRemoveObserverNoStrategy() throws InterruptedException {
342:                 // setup
343:                 final CountDownLatch latch1 = new CountDownLatch(1);
344:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
345:                 final ChangeObserver receiver = new ChangeObserver() {
346:
347:                         @Override
348:                         public void handleNotification(Notification notification) {
349:                                 latch1.countDown();
350:                         }
351:                 };
352:                 broker.subscribe(receiver);
353:
354:                 // act
355:                 broker.unsubsribe(receiver);
356:                 tournament.getMatchups().add(matchup);
357:
358:                 // assert
359:                 assertFalse("Notify was called although it shouln't be called", latch1.await(1, TimeUnit.MILLISECONDS));
360:         }
361:
362:         @Test
363:         public void testRemoveObserverEClassStrategy() throws InterruptedException {
364:                 // setup
365:                 final CountDownLatch latch1 = new CountDownLatch(1);
366:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
367:                 final ChangeObserver receiver = new ChangeObserver() {
368:
369:                         @Override
370:                         public void handleNotification(Notification notification) {
371:                                 latch1.countDown();
372:                         }
373:                 };
374:                 broker.subscribeToEClass(receiver, BowlingPackage.eINSTANCE.getTournament());
375:
376:                 // act
377:                 broker.unsubsribe(receiver);
378:                 tournament.getMatchups().add(matchup);
379:
380:                 // assert
381:                 assertFalse("Notify was called although it shouln't be called", latch1.await(1, TimeUnit.MILLISECONDS));
382:         }
383:
384:         @Test
385:         public void testRemoveObserverContainingEClassStrategy() throws InterruptedException {
386:                 // setup
387:                 final CountDownLatch latch1 = new CountDownLatch(1);
388:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
389:                 final ChangeObserver receiver = new ChangeObserver() {
390:
391:                         @Override
392:                         public void handleNotification(Notification notification) {
393:                                 latch1.countDown();
394:                         }
395:                 };
396:                 broker.subscribeToTree(receiver, BowlingPackage.eINSTANCE.getTournament());
397:
398:                 // act
399:                 broker.unsubsribe(receiver);
400:                 tournament.getMatchups().add(matchup);
401:
402:                 // assert
403:                 assertFalse("Notify was called although it shouln't be called", latch1.await(1, TimeUnit.MILLISECONDS));
404:         }
405:
406:         @Test
407:         public void testRemoveObserverFeatureStrategy() throws InterruptedException {
408:                 // setup
409:                 final CountDownLatch latch1 = new CountDownLatch(1);
410:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
411:                 final ChangeObserver receiver = new ChangeObserver() {
412:
413:                         @Override
414:                         public void handleNotification(Notification notification) {
415:                                 latch1.countDown();
416:                         }
417:                 };
418:                 broker.subscribeToFeature(receiver, BowlingPackage.eINSTANCE.getTournament_Matchups());
419:
420:                 // act
421:                 broker.unsubsribe(receiver);
422:                 tournament.getMatchups().add(matchup);
423:
424:                 // assert
425:                 assertFalse("Notify was called although it shouln't be called", latch1.await(1, TimeUnit.MILLISECONDS));
426:         }
427:
428:         @Test
429:         public void testReadOnlyEMFObserverNoStrategy() throws InterruptedException {
430:                 // setup
431:                 final CountDownLatch latch = new CountDownLatch(1);
432:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
433:                 broker.subscribe(new ReadOnlyChangeObserver() {
434:
435:                         @Override
436:                         public void handleNotification(Notification notification) {
437:                                 assertSame(Notification.ADD, notification.getEventType());
438:                                 assertSame(BowlingPackage.eINSTANCE.getTournament_Matchups(), notification.getFeature());
439:                                 assertSame(matchup, notification.getNewValue());
440:                                 latch.countDown();
441:                         }
442:                 });
443:
444:                 // act
445:                 tournament.getMatchups().add(matchup);
446:
447:                 // assert
448:                 assertTrue("Notify was not called", latch.await(1, TimeUnit.MILLISECONDS));
449:         }
450:
451:         @Test
452:         public void testReadOnlyEMFObserverEClassStrategy() throws InterruptedException {
453:                 // setup
454:                 final CountDownLatch latch1 = new CountDownLatch(1);
455:                 final CountDownLatch latch2 = new CountDownLatch(1);
456:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
457:                 tournament.getMatchups().add(matchup);
458:                 broker.subscribeToEClass(new ReadOnlyChangeObserver() {
459:
460:                         @Override
461:                         public void handleNotification(Notification notification) {
462:                                 if (notification.getNotifier() == tournament) {
463:                                         latch1.countDown();
464:                                 } else if (notification.getNotifier() == matchup) {
465:                                         latch2.countDown();
466:                                 }
467:                         }
468:                 }, BowlingPackage.eINSTANCE.getTournament());
469:
470:                 // act&assert
471:                 tournament.setType(TournamentType.PRO);
472:                 assertTrue(latch1.await(1, TimeUnit.MILLISECONDS));
473:
474:                 // act&assert
475:                 matchup.setNrSpectators(new BigInteger("1"));
476:                 assertFalse("Notify was called although it shouln't be called", latch2.await(1, TimeUnit.MILLISECONDS));
477:         }
478:
479:         @Test
480:         public void testReadOnlyEMFObserverContainingEClassStrategy() throws InterruptedException {
481:                 // setup
482:                 final CountDownLatch latch1 = new CountDownLatch(1);
483:                 final CountDownLatch latch2 = new CountDownLatch(1);
484:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
485:                 tournament.getMatchups().add(matchup);
486:                 broker.subscribeToTree(new ReadOnlyChangeObserver() {
487:
488:                         @Override
489:                         public void handleNotification(Notification notification) {
490:                                 if (notification.getNotifier() == tournament) {
491:                                         latch1.countDown();
492:                                 } else if (notification.getNotifier() == matchup) {
493:                                         latch2.countDown();
494:                                 }
495:                         }
496:                 }, BowlingPackage.eINSTANCE.getTournament());
497:
498:                 // act&assert
499:                 tournament.setType(TournamentType.PRO);
500:                 assertTrue("Notify was not called", latch1.await(1, TimeUnit.MILLISECONDS));
501:
502:                 // act&assert
503:                 matchup.setNrSpectators(new BigInteger("1"));
504:                 assertTrue("Notify was not called", latch2.await(1, TimeUnit.MILLISECONDS));
505:         }
506:
507:         @Test
508:         public void testReadOnlyEMFObserverFeatureStrategy() throws InterruptedException {
509:                 // setup
510:                 final CountDownLatch latch1 = new CountDownLatch(1);
511:                 final CountDownLatch latch2 = new CountDownLatch(1);
512:                 final Matchup matchup = BowlingFactory.eINSTANCE.createMatchup();
513:
514:                 broker.subscribeToFeature(new ReadOnlyChangeObserver() {
515:
516:                         @Override
517:                         public void handleNotification(Notification notification) {
518:                                 if (notification.getFeature() == BowlingPackage.eINSTANCE.getTournament_Type()) {
519:                                         latch1.countDown();
520:                                 } else if (notification.getFeature() == BowlingPackage.eINSTANCE.getTournament_Matchups()) {
521:                                         latch2.countDown();
522:                                 }
523:                         }
524:                 }, BowlingPackage.eINSTANCE.getTournament_Type());
525:
526:                 // act&assert
527:                 tournament.setType(TournamentType.PRO);
528:                 assertTrue(latch1.await(1, TimeUnit.MILLISECONDS));
529:
530:                 // act&assert
531:                 tournament.getMatchups().add(matchup);
532:                 assertFalse("Notify was called although it shouln't be called", latch2.await(1, TimeUnit.MILLISECONDS));
533:         }
534:
535:         @Test
536:         public void testReadOnlyObserversStillCalledDuringChangesFromEMFObserver() throws InterruptedException {
537:                 final CountDownLatch latch1 = new CountDownLatch(2);
538:                 final CountDownLatch latch2 = new CountDownLatch(2);
539:
540:                 broker.subscribe(new ChangeObserver() {
541:                         @Override
542:                         public void handleNotification(Notification notification) {
543:                                 tournament.getReceivesTrophy().add(Boolean.TRUE);
544:                                 latch1.countDown();
545:                         }
546:                 });
547:                 broker.subscribe(new ReadOnlyChangeObserver() {
548:                         @Override
549:                         public void handleNotification(Notification notification) {
550:                                 latch2.countDown();
551:                         }
552:                 });
553:
554:                 tournament.setType(TournamentType.PRO);
555:                 assertTrue(latch2.await(1, TimeUnit.MICROSECONDS));
556:                 assertEquals(1, latch1.getCount());
557:         }
558:
559:         @Test
560:         public void testReadOnlyObserversStillCalledWhenStopNotificationUsed() throws InterruptedException {
561:                 final CountDownLatch latch = new CountDownLatch(1);
562:
563:                 broker.subscribe(new ReadOnlyChangeObserver() {
564:                         @Override
565:                         public void handleNotification(Notification notification) {
566:                                 latch.countDown();
567:                         }
568:                 });
569:                 broker.stopNotification();
570:                 tournament.setType(TournamentType.PRO);
571:                 assertTrue(latch.await(1, TimeUnit.MICROSECONDS));
572:         }
573:
574:         @Test
575:         public void testReadOnlyObserversStillCalledDuringChangesFromEMFObserverComplex() throws InterruptedException {
576:                 final CountDownLatch latch = new CountDownLatch(5);
577:                 addEMFObserverAddingTrophies();
578:                 addEMFObserverAddingTrophies();
579:                 broker.subscribe(new ReadOnlyChangeObserver() {
580:                         @Override
581:                         public void handleNotification(Notification notification) {
582:                                 latch.countDown();
583:                         }
584:                 });
585:                 addEMFObserverAddingTrophies();
586:                 addEMFObserverAddingTrophies();
587:                 tournament.setType(TournamentType.PRO);
588:                 assertTrue(latch.await(1, TimeUnit.MICROSECONDS));
589:         }
590:
591:         private void addEMFObserverAddingTrophies() {
592:                 broker.subscribe(new ChangeObserver() {
593:                         @Override
594:                         public void handleNotification(Notification notification) {
595:                                 tournament.getReceivesTrophy().add(Boolean.TRUE);
596:                         }
597:                 });
598:         }
599:
600:         @Test
601:         public void testGetNotificationProviders() {
602:                 final Set<NotificationProvider> notificationProviders = broker.getNotificationProviders();
603:                 assertEquals(1, notificationProviders.size());
604:                 assertTrue(notificationProviders.contains(provider));
605:         }
606:
607:         @Test
608:         public void testGetRegisteredObservers() {
609:                 final ReadOnlyChangeObserver obs1 = new ReadOnlyChangeObserver() {
610:                         @Override
611:                         public void handleNotification(Notification notification) {
612:                                 // no op
613:                         }
614:                 };
615:                 final ChangeObserver obs2 = new ChangeObserver() {
616:                         @Override
617:                         public void handleNotification(Notification notification) {
618:                                 // no op
619:                         }
620:                 };
621:                 broker.subscribe(obs1);
622:                 broker.subscribeToEClass(obs2, BowlingPackage.eINSTANCE.getPlayer());
623:                 final Set<ChangeObserver> registeredObservers = broker.getRegisteredObservers();
624:                 assertEquals(2, registeredObservers.size());
625:                 assertTrue(registeredObservers.contains(obs1));
626:                 assertTrue(registeredObservers.contains(obs2));
627:         }
628:
629:         @Test
630:         public void testBlockNotification() {
631:                 final ReadOnlyChangeObserver readOnlyEMFObserver = mock(ReadOnlyChangeObserver.class);
632:                 final ChangeObserver emfObserver = mock(ChangeObserver.class);
633:                 broker.subscribe(readOnlyEMFObserver);
634:                 broker.subscribe(emfObserver);
635:
636:                 broker.stopNotification(this);
637:                 tournament.setType(TournamentType.PRO);
638:
639:                 verify(readOnlyEMFObserver, times(1)).handleNotification(any(Notification.class));
640:                 verify(emfObserver, times(0)).handleNotification(any(Notification.class));
641:         }
642:
643:         @Test
644:         public void testBlockNotificationAndCallContinue() {
645:                 final ReadOnlyChangeObserver readOnlyEMFObserver = mock(ReadOnlyChangeObserver.class);
646:                 final ChangeObserver emfObserver = mock(ChangeObserver.class);
647:                 broker.subscribe(readOnlyEMFObserver);
648:                 broker.subscribe(emfObserver);
649:
650:                 broker.stopNotification(this);
651:                 broker.continueNotification();
652:                 tournament.setType(TournamentType.PRO);
653:
654:                 verify(readOnlyEMFObserver, times(1)).handleNotification(any(Notification.class));
655:                 verify(emfObserver, times(0)).handleNotification(any(Notification.class));
656:         }
657:
658:         @Test
659:         public void testUnBlockNotification() {
660:                 final ReadOnlyChangeObserver readOnlyEMFObserver = mock(ReadOnlyChangeObserver.class);
661:                 final ChangeObserver emfObserver = mock(ChangeObserver.class);
662:                 broker.subscribe(readOnlyEMFObserver);
663:                 broker.subscribe(emfObserver);
664:
665:                 broker.stopNotification(this);
666:                 broker.continueNotification(this);
667:                 tournament.setType(TournamentType.PRO);
668:
669:                 verify(readOnlyEMFObserver, times(1)).handleNotification(any(Notification.class));
670:                 verify(emfObserver, times(1)).handleNotification(any(Notification.class));
671:         }
672:
673:         @Test
674:         public void testMultipleBlockers() {
675:                 final ReadOnlyChangeObserver readOnlyEMFObserver = mock(ReadOnlyChangeObserver.class);
676:                 final ChangeObserver emfObserver = mock(ChangeObserver.class);
677:                 broker.subscribe(readOnlyEMFObserver);
678:                 broker.subscribe(emfObserver);
679:
680:                 broker.stopNotification(this);
681:                 broker.stopNotification(this.getClass());
682:                 broker.continueNotification(this);
683:                 tournament.setType(TournamentType.PRO);
684:
685:                 verify(readOnlyEMFObserver, times(1)).handleNotification(any(Notification.class));
686:                 verify(emfObserver, times(0)).handleNotification(any(Notification.class));
687:         }
688:
689:         @Test
690:         public void testRemoveMultipleBlockers() {
691:                 final ReadOnlyChangeObserver readOnlyEMFObserver = mock(ReadOnlyChangeObserver.class);
692:                 final ChangeObserver emfObserver = mock(ChangeObserver.class);
693:                 broker.subscribe(readOnlyEMFObserver);
694:                 broker.subscribe(emfObserver);
695:
696:                 broker.stopNotification(this);
697:                 broker.stopNotification(this.getClass());
698:                 broker.continueNotification(this);
699:                 broker.continueNotification(this.getClass());
700:                 tournament.setType(TournamentType.PRO);
701:
702:                 verify(readOnlyEMFObserver, times(1)).handleNotification(any(Notification.class));
703:                 verify(emfObserver, times(1)).handleNotification(any(Notification.class));
704:         }
705:
706:         @Test
707:         public void testRemovingBlockerContinuesUpdate() {
708:
709:                 final ReadOnlyChangeObserver readOnlyEMFObserver = mock(ReadOnlyChangeObserver.class);
710:                 final ChangeObserver emfObserver = mock(ChangeObserver.class);
711:                 broker.subscribe(readOnlyEMFObserver);
712:                 broker.subscribe(emfObserver);
713:
714:                 broker.stopNotification(this);
715:                 broker.stopNotification();
716:                 broker.continueNotification(this);
717:                 tournament.setType(TournamentType.PRO);
718:
719:                 verify(readOnlyEMFObserver, times(1)).handleNotification(any(Notification.class));
720:                 verify(emfObserver, times(1)).handleNotification(any(Notification.class));
721:         }
722: }