@Before
public void setUp() {
final Map<Object, Object> attributes = new HashMap<Object, Object>();
final Conversation mockConversation = mock(Conversation.class);
when(mockConversation.getId()).thenReturn(new SimpleConversationId("ABC123"));
when(mockConversation.getAttribute(anyString())).thenAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
return attributes.get(invocation.getArguments()[0]);
}
});
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
final Object[] args = invocation.getArguments();
return attributes.put(args[0], args[1]);
}
}).when(mockConversation).putAttribute(anyObject(), anyObject());
this.mockConversationManager = mock(ConversationManager.class);
when(this.mockConversationManager.beginConversation((ConversationParameters) any())).thenReturn(mockConversation);
when(this.mockConversationManager.getConversation((ConversationId) any())).thenReturn(mockConversation);
when(this.mockConversationManager.parseConversationId(anyString())).thenAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
return new SimpleConversationId((String) invocation.getArguments()[0]);
}
});
}