Package org.mockito.stubbing

Examples of org.mockito.stubbing.Answer


   
    when(mockManagedVertex.getTotalTasks()).thenReturn(managedTasks.size());
    when(mockManagedVertex.getTasks()).thenReturn(managedTasks);
   
    final HashSet<TezTaskID> scheduledTasks = new HashSet<TezTaskID>();
    doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) {
          Object[] args = invocation.getArguments();
          scheduledTasks.clear();
          scheduledTasks.addAll((Collection<TezTaskID>)args[0]);
          return null;
      }}).when(mockManagedVertex).scheduleTasks(anyCollection());
   
    final Map<Vertex, EdgeManager> newEdgeManagers = new HashMap<Vertex, EdgeManager>();
   
    doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) {
          managedTasks.remove(mockTaskId3);
          managedTasks.remove(mockTaskId4);
          newEdgeManagers.clear();
          newEdgeManagers.putAll((Map<Vertex, EdgeManager>)invocation.getArguments()[1]);
View Full Code Here


   
    when(mockManagedVertex.getTotalTasks()).thenReturn(3);
    when(mockManagedVertex.getTasks()).thenReturn(managedTasks);
   
    final HashSet<TezTaskID> scheduledTasks = new HashSet<TezTaskID>();
    doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) {
          Object[] args = invocation.getArguments();
          scheduledTasks.clear();
          scheduledTasks.addAll((Collection<TezTaskID>)args[0]);
          return null;
View Full Code Here

          }

        });
   
    final AtomicInteger count = new AtomicInteger(0);
    Mockito.doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) {
        count.incrementAndGet();
        return null;
      }})
    .when(mockApp).taskAllocated(any(), any(), (Container)any());
View Full Code Here

            @Override
            public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
                return maxPoolSize.get();
            }
        });
        doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                Integer nextPoolSize = (Integer) invocationOnMock.getArguments()[0];
                maxPoolSize.set(nextPoolSize);
                return nextPoolSize;
View Full Code Here

    @Test
    public void shouldFailInRuntimeWhenCallingRealMethodOnInterface() throws Exception {
        //given
        List list = mock(List.class);
        when(list.get(0)).thenAnswer(
            new Answer() {
                public Object answer(InvocationOnMock invocation) throws Throwable {
                    return invocation.callRealMethod();
                }
            }
        );
View Full Code Here

        //then
        verify(importLogDao).alter(any(ImportLogBean.class));
    }

    private Answer byCheckingLogEquals(final ImportLogBean status) {
        return new Answer() {
            public Object answer(InvocationOnMock invocation) throws Throwable {
                ImportLogBean bean = (ImportLogBean) invocation.getArguments()[0];
                assertEquals(status, bean);
                return null;
            }
View Full Code Here

    public void waitForServerThread() throws InterruptedException, BrokenBarrierException {
      barrier.await();
    }

    private Answer newAwaitAndBlockAnswer() {
      return new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          newAwaitBarrierAnswer().answer(invocation);
          newBlockAnswer().answer(invocation);
          return null;
View Full Code Here

        }
      };
    }

    private Answer newAwaitBarrierAnswer() {
      return new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          barrier.await();
          return null;
        }
View Full Code Here

        }
      };
    }

    private Answer newBlockAnswer() {
      return new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          Thread.sleep(Long.MAX_VALUE);
          return null;
        }
View Full Code Here

    Message message = mock(Message.class);
    OutputStream out = mock(OutputStream.class);

    when(source.open()).thenReturn(stream);
    when(stream.getOutputStream()).thenReturn(out);
    doAnswer(new Answer() {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable {
        barrier.await(1, TimeUnit.SECONDS);
        return null;
      }
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.