Package org.mockito.stubbing

Examples of org.mockito.stubbing.Answer


  @Before
  public void setUp() {
    Configuration conf = new Configuration();
    FSNamesystem fsn = mock(FSNamesystem.class);
    doAnswer(new Answer() {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable {
        Object[] args = invocation.getArguments();
        FsPermission perm = (FsPermission) args[0];
        return new PermissionStatus(SUPERUSER, SUPERGROUP, perm);
View Full Code Here


    GrapheneContext context;

    @Before
    public void before() throws Throwable {
        Answer invoke = new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                return ((InvocationContext) invocation.getArguments()[0]).invoke();
            }
        };
View Full Code Here

        file.setName("users.properties");
        byte b = 1;
        file.setFileType(b);
        vector.add(file);

        Mockito.doAnswer(new Answer() {
            public Object answer(InvocationOnMock invocation) {
                return null;
            }}).when(ftpProtocol).setActive();

        Mockito.doReturn(vector).when(ftpProtocol).ftpList("*", null);

        Mockito.doAnswer(new Answer() {
            public Object answer(InvocationOnMock invocation) {
                return null;
            }}).when(ftpProtocol).connect("localhost", auth);

        Mockito.doAnswer(new Answer() {
            public Object answer(InvocationOnMock invocation) {
                return null;
            }}).when(ftpProtocol).cd(new ProtocolFile("testdata", true));


View Full Code Here

  public void testCDandPWDandLS() throws IOException, ProtocolException {
    int port = context.getPort();
    File pubKeyFile = createPubKeyForPort(port);
    JschSftpProtocol sftpProtocol = spy(new JschSftpProtocol(port));
        Mockito.doAnswer(new Answer() {
            public Object answer(InvocationOnMock invocation) {
                return null;
            }}).when(sftpProtocol).connect("localhost", new HostKeyAuthentication("bfoster", "",
                pubKeyFile.getAbsoluteFile().getAbsolutePath()));
View Full Code Here

    int port = context.getPort();
    File pubKeyFile = createPubKeyForPort(port);
    //JschSftpProtocol sftpProtocol = new JschSftpProtocol(port);
        JschSftpProtocol mockc = mock(JschSftpProtocol.class);

        Mockito.doAnswer(new Answer() {
                  public Object answer(InvocationOnMock invocation) {
                          return null;
                      }}).when(mockc).connect("localhost", new HostKeyAuthentication("bfoster", "",
                pubKeyFile.getAbsoluteFile().getAbsolutePath()));
        mockc.connect("localhost", new HostKeyAuthentication("bfoster", "",
        pubKeyFile.getAbsoluteFile().getAbsolutePath()));


    File bogusFile = File.createTempFile("bogus", "bogus");
    final File tmpFile = new File(bogusFile.getParentFile(), "TestJschSftpProtocol");
    bogusFile.delete();
    tmpFile.mkdirs();
        mockc.cd(new ProtocolFile("sshTestDir", true));
    File testDownloadFile = new File(tmpFile, "testDownloadFile");

        Mockito.doAnswer(new Answer(){
            public Object answer(InvocationOnMock invocationOnMock) throws IOException {

                PrintWriter writer = new PrintWriter(tmpFile+"/testDownloadFile", "UTF-8");
                writer.print(readFile("src/testdata/sshTestDir/sshTestFile"));
                writer.close();
View Full Code Here

            attributes.put(Queue.EXCLUSIVE, ExclusivityPolicy.CONTAINER);
        }
            when(queue.getAvailableAttributes()).thenReturn(attributes.keySet());
            final ArgumentCaptor<String> requestedAttribute = ArgumentCaptor.forClass(String.class);
            when(queue.getAttribute(requestedAttribute.capture())).then(
                    new Answer()
                    {

                        @Override
                        public Object answer(final InvocationOnMock invocation) throws Throwable
                        {
View Full Code Here

    private void mockQueueRegistry()
    {
        _queueRegistry = mock(QueueRegistry.class);

        final ArgumentCaptor<AMQQueue> capturedQueue = ArgumentCaptor.forClass(AMQQueue.class);
        doAnswer(new Answer()
        {

            @Override
            public Object answer(final InvocationOnMock invocation) throws Throwable
            {
View Full Code Here

        when(_exchangeRegistry.getExchange(eq(TOPIC_EXCHANGE_ID))).thenReturn(_topicExchange);

        when(_vhost.getQueue(eq(QUEUE_ID))).thenReturn(queue);

        final ArgumentCaptor<ExchangeImpl> registeredExchange = ArgumentCaptor.forClass(ExchangeImpl.class);
        doAnswer(new Answer()
        {

            @Override
            public Object answer(final InvocationOnMock invocation) throws Throwable
            {
                ExchangeImpl exchange = registeredExchange.getValue();
                when(_exchangeRegistry.getExchange(eq(exchange.getId()))).thenReturn(exchange);
                when(_exchangeRegistry.getExchange(eq(exchange.getName()))).thenReturn(exchange);
                return null;
            }
        }).when(_exchangeRegistry).registerExchange(registeredExchange.capture());



        final ArgumentCaptor<Map> attributesArg = ArgumentCaptor.forClass(Map.class);

        _queueFactory = mock(QueueFactory.class);

        when(_queueFactory.restoreQueue(attributesArg.capture())).then(
                new Answer()
                {

                    @Override
                    public Object answer(final InvocationOnMock invocation) throws Throwable
                    {
                        final AMQQueue queue = mock(AMQQueue.class);

                        final Map attributes = attributesArg.getValue();
                        final String queueName = (String) attributes.get(Queue.NAME);
                        final UUID queueId = MapValueConverter.getUUIDAttribute(Queue.ID, attributes);

                        when(queue.getName()).thenReturn(queueName);
                        when(queue.getId()).thenReturn(queueId);
                        when(_vhost.getQueue(eq(queueName))).thenReturn(queue);
                        when(_vhost.getQueue(eq(queueId))).thenReturn(queue);

                        final ArgumentCaptor<ExchangeImpl> altExchangeArg = ArgumentCaptor.forClass(ExchangeImpl.class);
                        doAnswer(
                                new Answer()
                                {
                                    @Override
                                    public Object answer(InvocationOnMock invocation) throws Throwable
                                    {
                                        final ExchangeImpl value = altExchangeArg.getValue();
View Full Code Here

        assertEquals(customExchange, _vhost.getQueue(queueId).getAlternateExchange());
    }

    private void verifyCorrectUpdates(final ConfiguredObjectRecord[] expected) throws StoreException
    {
        doAnswer(new Answer()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                Object[] args = invocation.getArguments();
View Full Code Here

    @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]);
           }
        });
    }
View Full Code Here

TOP

Related Classes of org.mockito.stubbing.Answer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.