### Question:
PlainMailbox implements Mailbox, AlarmListener { public void registerNotify( Notify newNotify, Object newState, int maxDelay ) { if (newNotify == null) throw new NullPointerException( "newNotify == null" ); if (maxDelay < 0) throw new IllegalArgumentException( "maxDelay < 0" ); boolean isNotEmptyOrIsClosed; synchronized (queue) { if (notify != null) throw new IllegalStateException( "this.notify != null" ); notify = newNotify; state = newState; if (maxDelay > 0) { alarmSet = true; AlarmManager.staticAdd( this, null, maxDelay ); } isNotEmptyOrIsClosed = !queue.isEmpty() || queue.isClosed(); } if (isNotEmptyOrIsClosed) fireNotify(); } PlainMailbox( MailboxManager mailboxManager, Long messageId ); MailboxManager getMailboxManager(); Long getMessageId(); boolean message( Who sender, Message msg ); Mailbox.Element read(); Mailbox.Element read( int maxDelay ); boolean closeDelivery(); boolean closeRead(); int wakeup( AlarmManager manager, Object xstate, long due ); void registerNotify( Notify newNotify, Object newState, int maxDelay ); void unregisterNotify( Notify oldNotify ); boolean isEmpty(); boolean isClosed(); boolean isFull();  }### Answer:
@Test public void notify1() throws Exception { PlainMailbox mb = new PlainMailbox( mmgr, 1L ); notify.checkMailboxStatus( false, null, null, false ); Object state = new Object(); mb.registerNotify( notify, state, 0 ); notify.checkMailboxStatus( false, null, null, false ); checkCloseDelivery( mb, true ); notify.checkMailboxStatus( true, mb, state, true ); }
@Test public void notify2() throws Exception { PlainMailbox mb = new PlainMailbox( mmgr, 1L ); notify.checkMailboxStatus( false, null, null, false ); Object state = new Object(); mb.registerNotify( notify, state, 1000 ); notify.checkMailboxStatus( false, null, null, false ); Thread.sleep( 2000 ); notify.checkMailboxStatus( true, mb, state, true ); }
@Test public void notify3() throws Exception { PlainMailbox mb = new PlainMailbox( mmgr, 1L ); notify.checkMailboxStatus( false, null, null, false ); Object state = new Object(); mb.registerNotify( notify, state, 0 ); notify.checkMailboxStatus( false, null, null, false ); Thread.sleep( 2000 ); notify.checkMailboxStatus( false, null, null, false ); }
@Test( expected = NullPointerException.class ) public void reg1() throws Exception { PlainMailbox mb = new PlainMailbox( mmgr, 1L ); mb.registerNotify( null, null, 0 ); }
@Test( expected = IllegalArgumentException.class ) public void reg2() throws Exception { PlainMailbox mb = new PlainMailbox( mmgr, 1L ); mb.registerNotify( notify, null, -1 ); }
@Test public void reg3() throws Exception { PlainMailbox mb = new PlainMailbox( mmgr, 1L ); mb.registerNotify( notify, null, 0 ); }
@Test( expected = IllegalStateException.class ) public void reg4() throws Exception { PlainMailbox mb = new PlainMailbox( mmgr, 1L ); mb.registerNotify( notify, null, 0 ); mb.registerNotify( notify, null, 0 ); }
@Test( expected = IllegalStateException.class ) public void reg5() throws Exception { PlainMailbox mb = new PlainMailbox( mmgr, 1L ); mb.registerNotify( notify, null, 0 ); mb.registerNotify( notify1, null, 0 ); }