Messenger facade, a few miscellaneous bits

* more logging
* comments
* more tests



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@33894 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2012-02-14 16:34:42 +00:00
parent e40bd92c21
commit b85e786025
5 changed files with 106 additions and 39 deletions

View File

@@ -31,6 +31,7 @@ public class MessengerTestHelper
{
private String receivedMsg;
private final static int SLEEP_MILLIS = 50;
private static final int MAX_TRIES = 30;
public MessengerTestHelper()
@@ -51,7 +52,7 @@ public class MessengerTestHelper
{
int tries = 0;
while (tries < 30)
while (tries < MAX_TRIES)
{
try
{
@@ -72,6 +73,32 @@ public class MessengerTestHelper
fail("No message received, tried " + tries +
" times, sleeping " + SLEEP_MILLIS + "ms each time.");
}
/**
* Assert that no message was received in the given period.
*/
public void checkNoMessageReceived()
{
int tries = 0;
while (tries < MAX_TRIES)
{
try
{
Thread.sleep(SLEEP_MILLIS);
}
catch (InterruptedException e)
{
// Carry on
e.printStackTrace();
}
if (getReceivedMsg() != null)
{
fail("Message received but should NOT have been. Message was: " + getReceivedMsg());
}
tries++;
}
}
/**
* @return the receivedMsg
@@ -88,4 +115,16 @@ public class MessengerTestHelper
{
this.receivedMsg = receivedMsg;
}
public static class TestMessageReceiver implements MessageReceiver<String>
{
MessengerTestHelper helper = new MessengerTestHelper();
@Override
public void onReceive(String message)
{
helper.setReceivedMsg(message);
}
}
}