AsyncMessageResponderWrapper implements MessageResponder { void waitForUserToIdentify(final int userCode) { int counter = 0; while (waitingList.isWaitingUser(userCode) && counter < 40) { counter++; sleeper.sleep(50); } } AsyncMessageResponderWrapper(final MessageResponder messageResponder, final Controller controller); @Override void messageArrived(final int userCode, final String msg, final int color); @Override void topicChanged(final int userCode, final String newTopic, final String nick, final long time); @Override void topicRequested(); @Override void awayChanged(final int userCode, final boolean away, final String awayMsg); @Override void nickChanged(final int userCode, final String newNick); @Override void nickCrash(); @Override void meLogOn(final String ipAddress); @Override void userLogOn(final User newUser); @Override void userLogOff(final int userCode); @Override void userExposing(final User user); @Override void exposeRequested(); @Override void writingChanged(final int userCode, final boolean writing); @Override void meIdle(final String ipAddress); @Override void userIdle(final int userCode, final String ipAddress); @Override void fileSend(final int userCode, final long byteSize, final String fileName,
                         final String user, final int fileHash); @Override void fileSendAborted(final int userCode, final String fileName, final int fileHash); @Override void fileSendAccepted(final int userCode, final String fileName, final int fileHash, final int port); @Override void clientInfo(final int userCode, final String client, final long timeSinceLogon,
                           final String operatingSystem, final int privateChatPort, final int tcpChatPort);  }
@Test public void waitForUserToIdentifyShouldAbortAfter40SleepsIfUserNeverIdentifies() { when(waitingList.isWaitingUser(100)).thenReturn(true); wrapper.waitForUserToIdentify(100); verify(sleeper, times(40)).sleep(50); verify(waitingList, times(41)).isWaitingUser(100); }
@Test public void waitForUserToIdentifyShouldAbortWhenUserHasIdentified() { when(waitingList.isWaitingUser(100)).thenReturn(true, true, true, false); wrapper.waitForUserToIdentify(100); verify(sleeper, times(3)).sleep(50); verify(waitingList, times(4)).isWaitingUser(100); }
@Test public void waitForUserToIdentifyShouldNeverSleepIfUserIsIdentified() { when(waitingList.isWaitingUser(100)).thenReturn(false); wrapper.waitForUserToIdentify(100); verifyZeroInteractions(sleeper); verify(waitingList).isWaitingUser(100); }