### Question:
ConsoleListener { public void discardMessages(int mask) { synchronized (this) { m_lastMessagesReceived &= ~mask; m_messagesReceived &= ~mask; } } ConsoleListener(Condition notifyOnMessage, Logger logger); void shutdown(); void waitForMessage(); boolean checkForMessage(int mask); void discardMessages(int mask); synchronized boolean received(int mask); void registerMessageHandlers(
    MessageDispatchRegistry messageDispatcher); StartGrinderMessage getLastStartGrinderMessage(); static final int START; static final int RESET; static final int STOP; static final int SHUTDOWN; static final int ANY; }### Answer:
@Test public void testDiscardMessages() throws Exception { final Condition myCondition = new Condition(); final ConsoleListener listener = new ConsoleListener(myCondition, m_logger); assertFalse(listener.checkForMessage(ConsoleListener.ANY)); assertFalse(listener.checkForMessage(ConsoleListener.RESET | ConsoleListener.SHUTDOWN)); assertFalse(listener.checkForMessage(ConsoleListener.SHUTDOWN)); final MessageDispatchSender messageDispatcher = new MessageDispatchSender(); listener.registerMessageHandlers(messageDispatcher); listener.discardMessages(ConsoleListener.ANY); messageDispatcher.send( new StartGrinderMessage(new GrinderProperties(), -1)); messageDispatcher.send(new MyMessage()); messageDispatcher.send(new ResetGrinderMessage()); assertTrue(listener.checkForMessage(ConsoleListener.START | ConsoleListener.STOP)); assertTrue(listener.received(ConsoleListener.START)); assertFalse(listener.received(ConsoleListener.RESET)); listener.discardMessages(ConsoleListener.RESET); assertFalse(listener.checkForMessage(ConsoleListener.RESET)); assertFalse(listener.received(ConsoleListener.RESET)); messageDispatcher.send(new ResetGrinderMessage()); assertTrue(listener.checkForMessage(ConsoleListener.RESET)); listener.discardMessages(ConsoleListener.RESET); assertFalse(listener.received(ConsoleListener.RESET)); listener.discardMessages(ConsoleListener.RESET); assertFalse(listener.received(ConsoleListener.RESET)); messageDispatcher.shutdown(); assertTrue(listener.checkForMessage(ConsoleListener.SHUTDOWN)); assertTrue(listener.received(ConsoleListener.SHUTDOWN)); listener.discardMessages(ConsoleListener.SHUTDOWN); assertFalse(listener.received(ConsoleListener.SHUTDOWN)); }