Created
June 12, 2015 04:03
-
-
Save nwertzberger/f763d2b418f02e0fbdbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ideaheap.decisions.tmt.agents.tmtAgent.behaviours; | |
import com.ideaheap.decisions.tmt.dto.TmtAgentState; | |
import com.ideaheap.decisions.tmt.dto.TmtSuggestion; | |
import com.ideaheap.jade.fluent.df.DfServiceFinder; | |
import com.ideaheap.jade.fluent.df.DfServiceFinderFactory; | |
import com.ideaheap.jade.fluent.messages.BaseMessageReceiver; | |
import com.ideaheap.jade.fluent.messages.MessageReceiver; | |
import com.ideaheap.jade.fluent.messages.MessageReceiverFactory; | |
import com.ideaheap.jade.fluent.messages.MessageSender; | |
import jade.core.AID; | |
import jade.core.behaviours.Behaviour; | |
import jade.lang.acl.ACLMessage; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.*; | |
import org.mockito.runners.MockitoJUnitRunner; | |
import static org.mockito.Matchers.isA; | |
import static org.mockito.Mockito.*; | |
/** | |
* Created by nwertzberger on 6/11/15. | |
*/ | |
@RunWith(MockitoJUnitRunner.class) | |
public class AskForSuggestionsTest { | |
private AskForSuggestions askForSuggestions; | |
@Mock(answer = Answers.RETURNS_DEEP_STUBS) | |
private MessageSender sender; | |
@Mock | |
private MessageReceiverFactory receiverFactory; | |
@Mock(answer = Answers.RETURNS_DEEP_STUBS) | |
private MessageReceiver receiver; | |
@Mock | |
private DfServiceFinderFactory finderFactory; | |
@Mock(answer = Answers.RETURNS_DEEP_STUBS) | |
private DfServiceFinder finder; | |
@Mock | |
private PreferenceUpdater updater; | |
@Captor | |
private ArgumentCaptor<BaseMessageReceiver> captor; | |
private StateMachineFactory stateMachineFactory = new StateMachineFactory(); | |
private TmtAgentState agentState = new TmtAgentState(); | |
private AID aid = new AID(); | |
@Before | |
public void setUp() throws Exception { | |
when(finderFactory.find()).thenReturn(finder); | |
when(receiverFactory.listen(isA(Behaviour.class))).thenReturn(receiver); | |
askForSuggestions = new AskForSuggestions( | |
sender, | |
receiverFactory, | |
finderFactory, | |
stateMachineFactory, | |
updater, | |
agentState | |
); | |
} | |
@Test | |
public void testAskForSuggestion_negotiatesCorrectly() throws Exception { | |
when(finder.findOne()).thenReturn(aid); | |
triggerActionRepeatedly(); | |
verify(finder).forServiceType("suggestion"); | |
verify(sender).send(isA(ACLMessage.class)); | |
verify(receiver, atLeastOnce()).forClass(Matchers.any(), captor.capture()); | |
reset(sender); | |
captor.getValue().onMessage(aid, new TmtSuggestion()); | |
verify(sender).send(isA(ACLMessage.class)); | |
} | |
private void triggerActionRepeatedly() { | |
for (int i = 0; i < 10; i++) { | |
askForSuggestions.action(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment