edu.cmu.hcii.calo.test.MessagePassingTestHarness Class Reference

Inherits edu.cmu.hcii.calo.messagePassing.MessageTarget.

Inherited by edu.cmu.hcii.calo.test.HistoryTest, edu.cmu.hcii.calo.test.NotificationTest, edu.cmu.hcii.calo.test.PackTest, edu.cmu.hcii.calo.test.RelevantInfoTest, edu.cmu.hcii.calo.test.ScheduleTest, and edu.cmu.hcii.calo.test.TaskTest.

Inheritance diagram for edu.cmu.hcii.calo.test.MessagePassingTestHarness:

Inheritance graph
[legend]
Collaboration diagram for edu.cmu.hcii.calo.test.MessagePassingTestHarness:

Collaboration graph
[legend]
List of all members.

Detailed Description

A handy test harness to use when testing message passing.

MessagePassingTestHarness should be subclassed by tests that need to ensure that the right messages are being passed around when changes to a model object are made. It provides methods to quickly check that messages are received when expected and are exactly what they are expected to be.

Author:
Brian Ellis


Public Member Functions

void clearMessages ()
 Clears the list of messages, returning to the state that existed just after the test started.
Message firstMessage ()
 Retrieves the first (least recent) message received during this test.
boolean hasMessages ()
 Returns true if we have received any messages since the test began (or the last call to clearMessages()), false otherwise.
Iterator< Messageiterator ()
 Returns an iterator over the messages, in case direct access is needed.
Message lastMessage ()
 Retrieves the last (most recent) message received during this test.
void onMessageReceived (Observable sender, Message msg)
 We override onMessageReceived so you don't have to™.

Protected Member Functions

void expectMessage (Class<?extends Observable > managerClass, Class<?extends Message > messageClass, MessageType expectedType)
 Performs checks and assertions to ensure the following things are true:.
void expectMessages (Class<?extends Observable > managerClasses[], Class<?extends Message > messageClasses[], MessageType expectedTypes[])
 Performs checks and assertions to ensure the following things are true:.
void expectUserInfoValueForKey (String key, Object value)
 Performs checks and assertions to ensure the following things are true:.
void expectUserInfoValuesForKeys (String keys[], Object values[])
 Performs checks and assertions to ensure the following things are true:.

Private Attributes

List< Messagemessages = new ArrayList<Message>()
 A list of all the messages we have received during this test since clearMessages() was last called.


Member Function Documentation

void edu.cmu.hcii.calo.test.MessagePassingTestHarness.clearMessages (  ) 

Clears the list of messages, returning to the state that existed just after the test started.

Message edu.cmu.hcii.calo.test.MessagePassingTestHarness.firstMessage (  ) 

Retrieves the first (least recent) message received during this test.

Returns:
the least recent message

boolean edu.cmu.hcii.calo.test.MessagePassingTestHarness.hasMessages (  ) 

Returns true if we have received any messages since the test began (or the last call to clearMessages()), false otherwise.

Returns:
true if we have messages, false if we don't

Iterator<Message> edu.cmu.hcii.calo.test.MessagePassingTestHarness.iterator (  ) 

Returns an iterator over the messages, in case direct access is needed.

The iterator will return messages in order from least to most recent (earliest to latest received).

Returns:
an iterator over the messages
See also:
java.util.Collection.iterator()

Message edu.cmu.hcii.calo.test.MessagePassingTestHarness.lastMessage (  ) 

Retrieves the last (most recent) message received during this test.

Returns:
the most recent message

void edu.cmu.hcii.calo.test.MessagePassingTestHarness.onMessageReceived ( Observable  sender,
Message  msg 
) [virtual]

We override onMessageReceived so you don't have to™.

This onMessageReceived method checks to make sure that the message's sender matches the sender argument, but performs no other checks.

Parameters:
sender the sender of this message
msg the message itself

Implements edu.cmu.hcii.calo.messagePassing.MessageTarget.

void edu.cmu.hcii.calo.test.MessagePassingTestHarness.expectMessage ( Class<?extends Observable >  managerClass,
Class<?extends Message messageClass,
MessageType  expectedType 
) [protected]

Performs checks and assertions to ensure the following things are true:.

1. We have received exactly one message since the start of the test.

2. The message we have received was from a manager of class managerClass.

3. The message we have received is of the class messageClass.

4. The message we have received has a MessageType equal to expectedType.

Parameters:
managerClass the manager class to check for
messageClass the message class to check for
expectedType the MessageType value to check for

void edu.cmu.hcii.calo.test.MessagePassingTestHarness.expectMessages ( Class<?extends Observable >  managerClasses[],
Class<?extends Message messageClasses[],
MessageType  expectedTypes[] 
) [protected]

Performs checks and assertions to ensure the following things are true:.

1. The managerClasses, messageClasses, and expectedTypes arrays all contain the same number of elements (if not, this is a runtime assertion, not a test failure).

2. We have received exactly as many messages since the start of the test as there are items in the messageClasses array.

3. For each message i we have received:

a. The message was from a manager of class managerClasses[i].

b. The message we have received is of the class messageClasses[i].

c. The message we have received has a MessageType equal to expectedTypes[i].

Parameters:
managerClasses the manager classes to check for
messageClasses the message classes to check for
expectedTypes the MessageType values to check for

void edu.cmu.hcii.calo.test.MessagePassingTestHarness.expectUserInfoValueForKey ( String  key,
Object  value 
) [protected]

Performs checks and assertions to ensure the following things are true:.

1. We have received exactly one message since the start of the test.

2. The message we have received had a non-null userInfo map.

3. The value for key in the userInfo map exists and is equal to value.

Parameters:
key the key to check for
value the value to check for

void edu.cmu.hcii.calo.test.MessagePassingTestHarness.expectUserInfoValuesForKeys ( String  keys[],
Object  values[] 
) [protected]

Performs checks and assertions to ensure the following things are true:.

1. The keys and values arrays have the same number of elements (if not, this is a runtime assertion, not a test failure).

2. We have received exactly as many messages since the start of the test as there are items in the keys array.

3. For each message i we have received:

2. The message had a non-null userInfo map.

3. The value for key in the userInfo map exists and is equal to value.

Note:
This method does NOT check for multiple key-value pairs in the same message. It checks for a single key-value pair in each message. To get the former behavior, simply call expectUserInfoValueForKey(String, Object) multiple times.
Parameters:
keys the keys to check for
values the values to check for


Member Data Documentation

List<Message> edu.cmu.hcii.calo.test.MessagePassingTestHarness.messages = new ArrayList<Message>() [private]

A list of all the messages we have received during this test since clearMessages() was last called.


The documentation for this class was generated from the following file:
Generated on Mon Aug 13 15:06:18 2007 for CALO by  doxygen 1.5.2